836c1d1ea70b8a8c103e8e1df96bb48935d6ce2d
1 kiwi
.model
.Applet
= kiwi
.model
.Panel
.extend({
2 // Used to determine if this is an applet panel. Applet panel tabs are treated
3 // differently than others
8 initialize: function (attributes
) {
10 var name
= "applet_"+(new Date().getTime().toString()) + Math
.ceil(Math
.random()*100).toString();
11 this.view
= new kiwi
.view
.Applet({model
: this, name
: name
});
18 // Load an applet within this panel
19 load: function (applet_object
, applet_name
) {
20 if (typeof applet_object
=== 'object') {
21 // Make sure this is a valid Applet
22 if (applet_object
.get || applet_object
.extend
) {
24 // Try find a title for the applet
25 this.set('title', applet_object
.get('title') || 'Unknown Applet');
27 // Update the tabs title if the applet changes it
28 applet_object
.bind('change:title', function (obj
, new_value
) {
29 this.set('title', new_value
);
32 // If this applet has a UI, add it now
33 this.view
.$el
.html('');
34 if (applet_object
.view
) {
35 this.view
.$el
.append(applet_object
.view
.$el
);
38 // Keep a reference to this applet
39 this.loaded_applet
= applet_object
;
42 } else if (typeof applet_object
=== 'string') {
43 // Treat this as a URL to an applet script and load it
44 this.loadFromUrl(applet_object
, applet_name
);
50 loadFromUrl: function(applet_url
, applet_name
) {
53 this.view
.$el
.html('Loading..');
54 $script(applet_url
, function () {
55 // Check if the applet loaded OK
56 if (!kiwi
.applets
[applet_name
]) {
57 that
.view
.$el
.html('Not found');
61 // Load a new instance of this applet
62 that
.load(new kiwi
.applets
[applet_name
]());
67 this.view
.$el
.remove();
70 this.view
= undefined;