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
7 initialize: function (attributes
) {
9 var name
= "applet_"+(new Date().getTime().toString()) + Math
.ceil(Math
.random()*100).toString();
10 this.view
= new kiwi
.view
.Applet({model
: this, name
: name
});
16 // Holds the loaded applet
17 this.loaded_applet
= null;
20 // Load an applet within this panel
21 load: function (applet_object
, applet_name
) {
22 if (typeof applet_object
=== 'object') {
23 // Make sure this is a valid Applet
24 if (applet_object
.get || applet_object
.extend
) {
26 // Try find a title for the applet
27 this.set('title', applet_object
.get('title') || 'Unknown Applet');
29 // Update the tabs title if the applet changes it
30 applet_object
.bind('change:title', function (obj
, new_value
) {
31 this.set('title', new_value
);
34 // If this applet has a UI, add it now
35 this.view
.$el
.html('');
36 if (applet_object
.view
) {
37 this.view
.$el
.append(applet_object
.view
.$el
);
40 // Keep a reference to this applet
41 this.loaded_applet
= applet_object
;
44 } else if (typeof applet_object
=== 'string') {
45 // Treat this as a URL to an applet script and load it
46 this.loadFromUrl(applet_object
, applet_name
);
52 loadFromUrl: function(applet_url
, applet_name
) {
55 this.view
.$el
.html('Loading..');
56 $script(applet_url
, function () {
57 // Check if the applet loaded OK
58 if (!kiwi
.applets
[applet_name
]) {
59 that
.view
.$el
.html('Not found');
63 // Load a new instance of this applet
64 that
.load(new kiwi
.applets
[applet_name
]());
69 this.view
.$el
.remove();
72 this.view
= undefined;
74 // Call the applets dispose method if it has one
75 if (this.loaded_applet
&& this.loaded_applet
.dispose
) {
76 this.loaded_applet
.dispose();