From 4baeda09fd9aa94914d44b937d57cb0d45d53718 Mon Sep 17 00:00:00 2001 From: Darren Date: Sat, 15 Sep 2012 20:51:28 +0100 Subject: [PATCH] Applet title updating tab; Revised applet code structure --- client_backbone/dev/applet_settings.js | 50 +++++++++++++++----------- client_backbone/dev/model_applet.js | 27 ++++++++++++-- client_backbone/dev/view.js | 7 +++- 3 files changed, 60 insertions(+), 24 deletions(-) diff --git a/client_backbone/dev/applet_settings.js b/client_backbone/dev/applet_settings.js index 4dc4e0c..1edad21 100644 --- a/client_backbone/dev/applet_settings.js +++ b/client_backbone/dev/applet_settings.js @@ -1,23 +1,33 @@ -kiwi.applets.Settings = Backbone.View.extend({ - events: { - 'click .save': 'saveSettings' - }, +(function () { + var View = Backbone.View.extend({ + events: { + 'click .save': 'saveSettings' + }, - initialize: function (options) { - this.$el = $($('#tmpl_applet_settings').html()); - this.title = 'Settings'; - window.s = this; - }, - - saveSettings: function () { - var theme = $('.theme', this.$el).val(), - containers = $('#panels > .panel_container'); + initialize: function (options) { + this.$el = $($('#tmpl_applet_settings').html()); + }, + + saveSettings: function () { + var theme = $('.theme', this.$el).val(), + containers = $('#panels > .panel_container'); - // Clear any current theme - containers.removeClass(function (i, css) { - return (css.match (/\btheme_\S+/g) || []).join(' '); - }); + // Clear any current theme + containers.removeClass(function (i, css) { + return (css.match (/\btheme_\S+/g) || []).join(' '); + }); - if (theme) containers.addClass('theme_' + theme); - } -}); \ No newline at end of file + if (theme) containers.addClass('theme_' + theme); + } + }); + + + + kiwi.applets.Settings = Backbone.Model.extend({ + initialize: function () { + this.set('title', 'Settings'); + this.view = new View(); + window.s = this; + } + }); +})(); \ No newline at end of file diff --git a/client_backbone/dev/model_applet.js b/client_backbone/dev/model_applet.js index b9610d5..36f548a 100644 --- a/client_backbone/dev/model_applet.js +++ b/client_backbone/dev/model_applet.js @@ -3,6 +3,8 @@ kiwi.model.Applet = kiwi.model.Panel.extend({ // differently than others applet: true, + loaded_applet: null, + initialize: function (attributes) { // Temporary name var name = "applet_"+(new Date().getTime().toString()) + Math.ceil(Math.random()*100).toString(); @@ -16,14 +18,33 @@ kiwi.model.Applet = kiwi.model.Panel.extend({ // Load an applet within this panel load: function (applet_object, applet_name) { if (typeof applet_object === 'object') { - this.set('title', applet_object.title || 'Something..'); - this.view.$el.html(''); - this.view.$el.append(applet_object.$el); + // Make sure this is a valid Applet + if (applet_object.get || applet_object.extend) { + + // Try find a title for the applet + this.set('title', applet_object.get('title') || 'Unknown Applet'); + + // Update the tabs title if the applet changes it + applet_object.bind('change:title', function (obj, new_value) { + this.set('title', new_value); + }, this); + + // If this applet has a UI, add it now + this.view.$el.html(''); + if (applet_object.view) { + this.view.$el.append(applet_object.view.$el); + } + + // Keep a reference to this applet + this.loaded_applet = applet_object; + } } else if (typeof applet_object === 'string') { // Treat this as a URL to an applet script and load it this.loadFromUrl(applet_object, applet_name); } + + return this; }, loadFromUrl: function(applet_url, applet_name) { diff --git a/client_backbone/dev/view.js b/client_backbone/dev/view.js index e8e0eb0..19238a4 100644 --- a/client_backbone/dev/view.js +++ b/client_backbone/dev/view.js @@ -357,12 +357,17 @@ kiwi.view.Tabs = Backbone.View.extend({ kiwi.app.view.doLayout(); }, + updateTabTitle: function (panel, new_title) { + $('span', panel.tab).text(new_title); + }, + panelAdded: function (panel) { // Add a tab to the panel - panel.tab = $('
  • ' + (panel.get("title") || panel.get("name")) + '
  • '); + panel.tab = $('
  • ' + (panel.get('title') || panel.get('name')) + '
  • '); panel.tab.data('panel_id', panel.cid) .appendTo(panel.isApplet() ? this.tabs_applets : this.tabs_msg); + panel.bind('change:title', this.updateTabTitle); kiwi.app.view.doLayout(); }, panelRemoved: function (panel) { -- 2.25.1