[Engine-devel] Update on UI Plugins: context-sensitive button API preview

Vojtech Szocs vszocs at redhat.com
Fri Oct 12 13:03:31 UTC 2012


Hi guys, 

I've been working on implementing "custom context-sensitive button / menu item" plugin API feature recently, and wanted to share some code with you. 

Here's a sample code that adds "Do something with selected host(s)" button to Hosts main tab data grid: 

api.register({ 
UiInit: function() { 

api. addMainTabActionButton ('Host', 'Do something with selected host(s)', { 

onClick : function() { 
// 'arguments' contain host entities currently selected 
window.alert(arguments.length + ' host(s) selected'); 
window.alert('first selected host ID = ' + arguments[0].entityId); 

// Open new popup window 
// In future, we might use "dialog UI" plugin API here 
window.open('http://example.com', '_blank'); 
}, 

isEnabled : function() { 
// 'true' means the button is enabled and clickable (default) 
// 'false' means the button is disabled and non-clickable 

// Enable button only when the number of selected items > 0 
return arguments.length > 0; 
}, 

isAccessible : function() { 
// 'true' means the button is visible (default) 
// 'false' means the button is hidden 
return true; 
} 

}); 

} 
}); 

The signature of addMainTabActionButton plugin API function is following: 

addMainTabActionButton(entityTypeName, label, actionButtonInterface) 

entityTypeName indicates which main tab the button should be added to, e.g. "Host" for Host main tab. [Quick question for NetApp guys: do we want to support all main tab entity types?] 

label is the title displayed on the button. 

actionButtonInterface represents an object that "implements the button interface" by declaring its functions: onClick , isEnabled , isAccessible . Since JavaScript language uses different techniques and syntax to achieve OOP programming model, I've decided to keep things simple and stay with plain objects containing functions. While some JavaScript guru could advocate different approach, from WebAdmin vs. plugin integration perspective, the above mentioned approach is the easiest way. I'm also interested to hear your opinion on this. 

All functions of actionButtonInterface receive currently selected item(s) as function arguments. Within a JavaScript function, "arguments" represents an implicit array of its arguments. 

For now, WebAdmin will pass simple JSON-like objects to these functions, for example: 

{ entityId: "<whatever>" } 

In future, we can extend or modify this concept to match the contract of various oVirt REST API entities. 

This feature will be part of UI Plugins PoC rev.6, which should come out next week. 

Regards, 
Vojtech 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ovirt.org/pipermail/engine-devel/attachments/20121012/933a084d/attachment.html>


More information about the Engine-devel mailing list