Client: Simplar applet interface with .loadOnce() #139
authorDarren <darren@darrenwhitlen.com>
Thu, 22 Nov 2012 12:25:35 +0000 (12:25 +0000)
committerDarren <darren@darrenwhitlen.com>
Thu, 22 Nov 2012 12:25:35 +0000 (12:25 +0000)
client/assets/dev/applet_settings.js
client/assets/dev/model_applet.js
client/assets/dev/model_application.js

index 2072fe183f66844fd56532fc00ac6c4f92c0ae34..8b9a06166f257eec5ec7222d48b860ddbcec012b 100644 (file)
@@ -12,6 +12,8 @@
 \r
             // Now actually show the current settings\r
             this.loadSettings();\r
+\r
+\r
         },\r
         \r
 \r
 \r
 \r
 \r
-    _kiwi.applets.Settings = Backbone.Model.extend({\r
+    var Applet = Backbone.Model.extend({\r
         initialize: function () {\r
             this.set('title', 'Settings');\r
             this.view = new View();\r
         }\r
     });\r
+\r
+\r
+    _kiwi.model.Applet.register('kiwi_settings', Applet);\r
 })();
\ No newline at end of file
index e4477499498b770eef30d645275c0826147f9c54..07cc5f90ea7985de22b84d8d0141db2471067560 100644 (file)
@@ -17,6 +17,7 @@ _kiwi.model.Applet = _kiwi.model.Panel.extend({
         this.loaded_applet = null;\r
     },\r
 \r
+\r
     // Load an applet within this panel\r
     load: function (applet_object, applet_name) {\r
         if (typeof applet_object === 'object') {\r
@@ -49,6 +50,7 @@ _kiwi.model.Applet = _kiwi.model.Panel.extend({
         return this;\r
     },\r
 \r
+\r
     loadFromUrl: function(applet_url, applet_name) {\r
         var that = this;\r
 \r
@@ -65,6 +67,7 @@ _kiwi.model.Applet = _kiwi.model.Panel.extend({
         });\r
     },\r
 \r
+\r
     close: function () {\r
         this.view.$el.remove();\r
         this.destroy();\r
@@ -78,4 +81,53 @@ _kiwi.model.Applet = _kiwi.model.Panel.extend({
 \r
         this.closePanel();\r
     }\r
+},\r
+\r
+\r
+{\r
+    // Load an applet type once only. If it already exists, return that\r
+    loadOnce: function (applet_name) {\r
+\r
+        // See if we have an instance loaded already\r
+        var applet = _.find(_kiwi.app.panels.models, function(panel) {\r
+            // Ignore if it's not an applet\r
+            if (!panel.isApplet()) return;\r
+\r
+            // Ignore if it doesn't have an applet loaded\r
+            if (!panel.loaded_applet) return;\r
+\r
+            if (panel.loaded_applet.get('_applet_name') === applet_name) {\r
+                return true;\r
+            }\r
+        });\r
+\r
+        if (applet) return applet;\r
+\r
+\r
+        // If we didn't find an instance, load a new one up\r
+        return this.load(applet_name);\r
+    },\r
+\r
+\r
+    load: function (applet_name) {\r
+        var applet;\r
+\r
+        // Find the applet within the registered applets\r
+        if (!_kiwi.applets[applet_name]) return;\r
+\r
+        // Create the applet and load the content\r
+        applet = new _kiwi.model.Applet();\r
+        applet.load(new _kiwi.applets[applet_name]({_applet_name: applet_name}));\r
+\r
+        // Add it into the tab list\r
+        _kiwi.app.panels.add(applet);\r
+\r
+\r
+        return applet;\r
+    },\r
+\r
+\r
+    register: function (applet_name, applet) {\r
+        _kiwi.applets[applet_name] = applet;\r
+    }\r
 });
\ No newline at end of file
index 262383b4567929d8959b194ee9ce6b4a526d2def..156b0f8db50d37dc853c9314e1ac817acf782772 100644 (file)
@@ -648,7 +648,7 @@ _kiwi.model.Application = function () {
                         member.set('away', !(!event.trailing));\r
                     }\r
                 });\r
-            });
+            });\r
 \r
 \r
             gw.on('onlist_start', function (data) {\r
@@ -989,11 +989,8 @@ _kiwi.model.Application = function () {
         }\r
 \r
         function settingsCommand (ev) {\r
-            var panel = new _kiwi.model.Applet();\r
-            panel.load(new _kiwi.applets.Settings());\r
-            \r
-            _kiwi.app.panels.add(panel);\r
-            panel.view.show();\r
+            var settings = _kiwi.model.Applet.loadOnce('kiwi_settings');\r
+            settings.view.show();\r
         }\r
 \r
         function appletCommand (ev) {\r