From 73d87f1ad21c7312517f04038b54a0ec084a5d64 Mon Sep 17 00:00:00 2001 From: Brian Federle Date: Thu, 18 Apr 2013 13:49:43 -0700 Subject: [PATCH] UI Plugin/module API: Fix load order, refactor -Fixes issue with load order, where plugin's initialization function were not called in order of the list -Refactor so that modules and plugins are loaded via the same block, to avoid redundant code -Load modules before plugins --- ui/scripts/plugins.js | 77 ++++++++++++++++++++----------------------- 1 file changed, 35 insertions(+), 42 deletions(-) diff --git a/ui/scripts/plugins.js b/ui/scripts/plugins.js index 9d1991cc759..122f4a03491 100644 --- a/ui/scripts/plugins.js +++ b/ui/scripts/plugins.js @@ -15,7 +15,9 @@ // specific language governing permissions and limitations // under the License. (function($, cloudStack, require) { - if (!cloudStack.pluginAPI) cloudStack.pluginAPI = {}; + if (!cloudStack.pluginAPI) { + cloudStack.pluginAPI = {}; + } var loadCSS = function(path) { var $link = $(''); @@ -40,7 +42,7 @@ error: function(json) { args.error(parseXMLHttpResponse(json)); } - }) + }); }, addSection: function(section) { cloudStack.sections[section.id] = $.extend(section, { @@ -58,49 +60,40 @@ show: cloudStack.uiCustom.pluginListing }; - // Load plugins - $(cloudStack.plugins).map(function(index, pluginID) { - var basePath = 'plugins/' + pluginID + '/'; - var pluginJS = basePath + pluginID + '.js'; - var configJS = basePath + 'config.js'; - var pluginCSS = basePath + pluginID + '.css'; + // Load + $(['modules', 'plugins']).each(function() { + var type = this; + var paths = $(cloudStack[type]).map(function(index, id) { + return type + '/' + id + '/' + id; + }).toArray(); - require([pluginJS], function() { - require([configJS]); - loadCSS(pluginCSS); + // Load modules + require( + paths, + function() { + $(cloudStack[type]).map(function(index, id) { + var basePath = type + '/' + id + '/'; + var css = basePath + id + '.css'; + var configJS = type == 'plugins' ? basePath + 'config' : null; - // Execute plugin - cloudStack.plugins[pluginID]( - $.extend(true, {}, cloudStack.pluginAPI, { - pluginAPI: { - extend: function(api) { - cloudStack.pluginAPI[pluginID] = api; - } + if (configJS) { + // Load config metadata + require([configJS]); } - }) - ); - }); - }); - // Load modules - $(cloudStack.modules).map(function(index, moduleID) { - var basePath = 'modules/' + moduleID + '/'; - var moduleJS = basePath + moduleID + '.js'; - var moduleCSS = basePath + moduleID + '.css'; - - require([moduleJS], function() { - loadCSS(moduleCSS); - - // Execute module - cloudStack.modules[moduleID]( - $.extend(true, {}, cloudStack.pluginAPI, { - pluginAPI: { - extend: function(api) { - cloudStack.pluginAPI[moduleID] = api; - } - } - }) - ); - }); + // Execute module + cloudStack[type][id]( + $.extend(true, {}, cloudStack.pluginAPI, { + pluginAPI: { + extend: function(api) { + cloudStack.pluginAPI[id] = api; + } + } + }) + ); + loadCSS(css); + }); + } + ); }); }(jQuery, cloudStack, require));