[Engine-devel] Update on UI Plugins: Improved plugin API

Vojtech Szocs vszocs at redhat.com
Tue Aug 28 10:17:29 UTC 2012


Hi guys, 

I was thinking about improving JavaScript plugin API so that each time a plugin calls WebAdmin, the plugin name will be part of the call. This way, PluginManager (WebAdmin) can validate the call before doing any further actions, e.g. "plugin invocation must be allowed && plugin must be initialized". In other words, this is just to ensure consistent behavior for "plugin -> WebAdmin" calls. 

Here's a draft of new JavaScript API in action: http://jsfiddle.net/tHk5n/ (see the code below the comment saying "ACTUAL TEST CODE") 
(I took my inspiration from jQuery source code, even though I don't fully understand JavaScript prototype OOP concept, seems a bit weird to me.) 



For comparison, here's some plugin code that uses current plugin API: 

// Register our plugin object (containing event handler functions) into pluginApi.plugins 
pluginApi.plugins['myPlugin'] = { 
UiInit: function() { 
pluginApi.ui.addMainTab('Custom Tab', 'custom-tab', 'http://www.example.com/'); 
} 
}; 

// Tell WebAdmin that we are ready, we need the plugin name to identify this plugin 
pluginApi.ready('myPlugin'); 



And here's an equivalent plugin code that uses new plugin API: 

// Plugin API instance for our plugin 
var myPlugin = pluginApi('myPlugin'); 

// Register our plugin object (containing event handler functions) into myPlugin 
myPlugin.register({ 
UiInit: function() { 
myPlugin.ui.addMainTab('Custom Tab', 'custom-tab', 'http://www.example.com/'); 
} 
}); 

// Tell WebAdmin that we are ready , plugin name is already part of myPlugin 
myPlugin.ready(); 
// Note: the above line is equivalent to: pluginApi('myPlugin').ready() ; 



Let me know what you think. 

Cheers, 
Vojtech 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ovirt.org/pipermail/devel/attachments/20120828/fc87b670/attachment-0002.html>


More information about the Devel mailing list