mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
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
This commit is contained in:
parent
a51b566fb6
commit
73d87f1ad2
@ -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 = $('<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));
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user