-kiwi.applets.Settings = Backbone.View.extend({\r
- events: {\r
- 'click .save': 'saveSettings'\r
- },\r
+(function () {\r
+ var View = Backbone.View.extend({\r
+ events: {\r
+ 'click .save': 'saveSettings'\r
+ },\r
\r
- initialize: function (options) {\r
- this.$el = $($('#tmpl_applet_settings').html());\r
- this.title = 'Settings';\r
- window.s = this;\r
- },\r
- \r
- saveSettings: function () {\r
- var theme = $('.theme', this.$el).val(),\r
- containers = $('#panels > .panel_container');\r
+ initialize: function (options) {\r
+ this.$el = $($('#tmpl_applet_settings').html());\r
+ },\r
+ \r
+ saveSettings: function () {\r
+ var theme = $('.theme', this.$el).val(),\r
+ containers = $('#panels > .panel_container');\r
\r
- // Clear any current theme\r
- containers.removeClass(function (i, css) {\r
- return (css.match (/\btheme_\S+/g) || []).join(' ');\r
- });\r
+ // Clear any current theme\r
+ containers.removeClass(function (i, css) {\r
+ return (css.match (/\btheme_\S+/g) || []).join(' ');\r
+ });\r
\r
- if (theme) containers.addClass('theme_' + theme);\r
- }\r
-});
\ No newline at end of file
+ if (theme) containers.addClass('theme_' + theme);\r
+ }\r
+ });\r
+\r
+\r
+\r
+ kiwi.applets.Settings = Backbone.Model.extend({\r
+ initialize: function () {\r
+ this.set('title', 'Settings');\r
+ this.view = new View();\r
+ window.s = this;\r
+ }\r
+ });\r
+})();
\ No newline at end of file
// differently than others\r
applet: true,\r
\r
+ loaded_applet: null,\r
+\r
initialize: function (attributes) {\r
// Temporary name\r
var name = "applet_"+(new Date().getTime().toString()) + Math.ceil(Math.random()*100).toString();\r
// Load an applet within this panel\r
load: function (applet_object, applet_name) {\r
if (typeof applet_object === 'object') {\r
- this.set('title', applet_object.title || 'Something..');\r
- this.view.$el.html('');\r
- this.view.$el.append(applet_object.$el);\r
+ // Make sure this is a valid Applet\r
+ if (applet_object.get || applet_object.extend) {\r
+\r
+ // Try find a title for the applet\r
+ this.set('title', applet_object.get('title') || 'Unknown Applet');\r
+\r
+ // Update the tabs title if the applet changes it\r
+ applet_object.bind('change:title', function (obj, new_value) {\r
+ this.set('title', new_value);\r
+ }, this);\r
+\r
+ // If this applet has a UI, add it now\r
+ this.view.$el.html('');\r
+ if (applet_object.view) {\r
+ this.view.$el.append(applet_object.view.$el);\r
+ }\r
+\r
+ // Keep a reference to this applet\r
+ this.loaded_applet = applet_object;\r
+ }\r
\r
} else if (typeof applet_object === 'string') {\r
// Treat this as a URL to an applet script and load it\r
this.loadFromUrl(applet_object, applet_name);\r
}\r
+\r
+ return this;\r
},\r
\r
loadFromUrl: function(applet_url, applet_name) {\r
kiwi.app.view.doLayout();\r
},\r
\r
+ updateTabTitle: function (panel, new_title) {\r
+ $('span', panel.tab).text(new_title);\r
+ },\r
+\r
panelAdded: function (panel) {\r
// Add a tab to the panel\r
- panel.tab = $('<li><span>' + (panel.get("title") || panel.get("name")) + '</span></li>');\r
+ panel.tab = $('<li><span>' + (panel.get('title') || panel.get('name')) + '</span></li>');\r
panel.tab.data('panel_id', panel.cid)\r
.appendTo(panel.isApplet() ? this.tabs_applets : this.tabs_msg);\r
\r
+ panel.bind('change:title', this.updateTabTitle);\r
kiwi.app.view.doLayout();\r
},\r
panelRemoved: function (panel) {\r