cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bfede...@apache.org
Subject [7/35] git commit: refs/heads/master - UI Plugin: Use new format
Date Wed, 13 Feb 2013 22:59:38 GMT
UI Plugin: Use new format

Define plugins as namespaced objects instead of as function calls. This
is easier to implement and manage by the framework.

New format changes for defining plugins:

Now create 2 JS files in plugin folder:
  -config.js
  -[pluginName].js

plugins.js (listing) format:

  cloudStack.plugins = [
    'testPlugin'
  ];

config.js format:

  cloudStack.plugins.testPlugin.config = {
    title: 'Test Plugin',
    desc: 'Sample plugin'
  };

[pluginName].js format:

  cloudStack.plugins.testPlugin = function(plugin) {
    //
    // Plugin code goes here
    //
  };


Project: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/commit/347ac311
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/tree/347ac311
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/diff/347ac311

Branch: refs/heads/master
Commit: 347ac311a072b89e99b890fe535d4ba2fdaab3a8
Parents: 59c77b4
Author: Brian Federle <brian.federle@citrix.com>
Authored: Thu Dec 20 11:55:44 2012 -0800
Committer: Brian Federle <brian.federle@citrix.com>
Committed: Thu Dec 20 11:55:44 2012 -0800

----------------------------------------------------------------------
 ui/index.jsp                          |    7 ++--
 ui/plugins/plugins.js                 |    7 ++--
 ui/plugins/testPlugin/config.js       |    6 +++
 ui/plugins/testPlugin/testPlugin.js   |    7 ++++
 ui/plugins/testPlugin1/testPlugin1.js |   12 ------
 ui/plugins/testPlugin2/testPlugin2.js |   12 ------
 ui/scripts/plugins.js                 |   51 +++++++++++----------------
 ui/scripts/ui-custom/plugins.js       |    6 ++--
 8 files changed, 44 insertions(+), 64 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/347ac311/ui/index.jsp
----------------------------------------------------------------------
diff --git a/ui/index.jsp b/ui/index.jsp
index 7f78da6..98c6161 100644
--- a/ui/index.jsp
+++ b/ui/index.jsp
@@ -1674,11 +1674,12 @@ under the License.
     <script type="text/javascript" src="scripts/system.js?t=<%=now%>"></script>
     <script type="text/javascript" src="scripts/domains.js?t=<%=now%>"></script>
     <script type="text/javascript" src="scripts/docs.js?t=<%=now%>"></script>
-    <script type="text/javascript" src="scripts/ui-custom/plugins.js?t=<%=now%>"></script>
-    <script type="text/javascript" src="scripts/plugins.js?t=<%=now%>"></script>
 
-    <!-- Plugin listing -->
+    <script type="text/javascript" src="scripts/ui-custom/plugins.js?t=<%=now%>"></script>
+    
+    <!-- Plugins -->
     <script type="text/javascript" src="plugins/plugins.js?t=<%=now%>"></script>
+    <script type="text/javascript" src="scripts/plugins.js?t=<%=now%>"></script>
   </body>
 </html>
 <jsp:include page="dictionary.jsp" />

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/347ac311/ui/plugins/plugins.js
----------------------------------------------------------------------
diff --git a/ui/plugins/plugins.js b/ui/plugins/plugins.js
index e86af59..50b5e14 100644
--- a/ui/plugins/plugins.js
+++ b/ui/plugins/plugins.js
@@ -1,6 +1,5 @@
 (function($, cloudStack) {
-  cloudStack.plugins.load([
-    'testPlugin1',
-    'testPlugin2'
-  ]);
+  cloudStack.plugins = [
+    'testPlugin'
+  ];
 }(jQuery, cloudStack));

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/347ac311/ui/plugins/testPlugin/config.js
----------------------------------------------------------------------
diff --git a/ui/plugins/testPlugin/config.js b/ui/plugins/testPlugin/config.js
new file mode 100644
index 0000000..7b653db
--- /dev/null
+++ b/ui/plugins/testPlugin/config.js
@@ -0,0 +1,6 @@
+(function (cloudStack) {
+  cloudStack.plugins.testPlugin.config = {
+    title: 'Test Plugin',
+    desc: 'Sample plugin'
+  };
+}(cloudStack));
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/347ac311/ui/plugins/testPlugin/testPlugin.js
----------------------------------------------------------------------
diff --git a/ui/plugins/testPlugin/testPlugin.js b/ui/plugins/testPlugin/testPlugin.js
new file mode 100644
index 0000000..4539924
--- /dev/null
+++ b/ui/plugins/testPlugin/testPlugin.js
@@ -0,0 +1,7 @@
+(function (cloudStack) {
+  cloudStack.plugins.testPlugin = function(plugin) {
+    //
+    // Plugin code goes here
+    //
+  };
+}(cloudStack));
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/347ac311/ui/plugins/testPlugin1/testPlugin1.js
----------------------------------------------------------------------
diff --git a/ui/plugins/testPlugin1/testPlugin1.js b/ui/plugins/testPlugin1/testPlugin1.js
deleted file mode 100644
index 3c31223..0000000
--- a/ui/plugins/testPlugin1/testPlugin1.js
+++ /dev/null
@@ -1,12 +0,0 @@
-(function (cloudStack) {
-  var testPlugin1 = function(plugin) {
-    // Plugin code goes here
-  };
-
-  cloudStack.plugin({
-    id: 'testPlugin1',
-    title: 'Test Plugin 1',
-    desc: 'Sample plugin 1',
-    load: testPlugin1
-  });
-}(cloudStack));
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/347ac311/ui/plugins/testPlugin2/testPlugin2.js
----------------------------------------------------------------------
diff --git a/ui/plugins/testPlugin2/testPlugin2.js b/ui/plugins/testPlugin2/testPlugin2.js
deleted file mode 100644
index 18f5a47..0000000
--- a/ui/plugins/testPlugin2/testPlugin2.js
+++ /dev/null
@@ -1,12 +0,0 @@
-(function (cloudStack) {
-  var testPlugin2 = function(plugin) {
-    // Plugin code goes here
-  };
-
-  cloudStack.plugin({
-    id: 'testPlugin2',
-    title: 'Test Plugin 2',
-    desc: 'Sample plugin 2',
-    load: testPlugin2
-  });
-}(cloudStack));
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/347ac311/ui/scripts/plugins.js
----------------------------------------------------------------------
diff --git a/ui/scripts/plugins.js b/ui/scripts/plugins.js
index 201a97d..250d507 100644
--- a/ui/scripts/plugins.js
+++ b/ui/scripts/plugins.js
@@ -1,35 +1,26 @@
-(function($, cloudStack) {
-  cloudStack.plugin = function(args) {
-    var id = args.id;
-    var title = args.title;
-    var desc = args.desc;
-
-    cloudStack.plugins.registry[id] = {
-      title: title,
-      desc: desc
-    };
+(function($, cloudStack, require) {
+  cloudStack.sections.plugins = {
+    title: 'Plugins',
+    show: cloudStack.uiCustom.plugins
   };
 
-  cloudStack.plugins = {
-    loaded: [], // Lists loaded plugins by ID
-    registry: {}, // Stores metadata for plugins
-
-    // Loads/executes script
-    load: function(plugins) {
-      $(plugins).map(function(index, pluginID) {
-        var path = '/client/plugins/' + pluginID + '/' + pluginID + '.js';
+  // Load plugins
+  $(cloudStack.plugins).map(function(index, pluginID) {
+    var basePath = 'plugins/' + pluginID + '/';
+    var pluginJS = basePath + pluginID + '.js';
+    var configJS = basePath + 'config.js';
 
-        require([path], function() {
-          cloudStack.plugins.loaded.push(pluginID);
-        });
+    require([pluginJS], function() {
+      require([configJS]);
 
-        return path;
+      // Execute plugin
+      cloudStack.plugins[pluginID]({
+        ui: {
+          extend: function(obj) {
+            $.extend(true, cloudStack, obj);
+          }
+        }
       });
-    }
-  };
-
-  cloudStack.sections.plugins = {
-    title: 'Plugins',
-    show: cloudStack.uiCustom.plugins
-  }
-}(jQuery, cloudStack));
+    });
+  });
+}(jQuery, cloudStack, require));

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/347ac311/ui/scripts/ui-custom/plugins.js
----------------------------------------------------------------------
diff --git a/ui/scripts/ui-custom/plugins.js b/ui/scripts/ui-custom/plugins.js
index e81202d..03bf55c 100644
--- a/ui/scripts/ui-custom/plugins.js
+++ b/ui/scripts/ui-custom/plugins.js
@@ -37,14 +37,14 @@
   };
 
   cloudStack.uiCustom.plugins = function() {
-    var plugins = cloudStack.plugins.loaded;
+    var plugins = cloudStack.plugins;
 
     return elems.pluginListing({
       plugins: $(plugins).map(function(index, pluginID) {
-        var plugin = cloudStack.plugins.registry[pluginID];
+        var plugin = cloudStack.plugins[pluginID].config;
 
         return {
-          id: plugin.id,
+          id: pluginID,
           title: plugin.title,
           desc: plugin.desc
         };


Mime
View raw message