<html><head><style type='text/css'>p { margin: 0; }</style></head><body><div style='font-family: times new roman,new york,times,serif; font-size: 12pt; color: #000000'>Hi guys,<br><br>I've been working on implementing "custom context-sensitive button / menu item" plugin API feature recently, and wanted to share some code with you.<br><br>Here's a sample code that adds "Do something with selected host(s)" button to Hosts main tab data grid:<br><br><span style="font-family: courier new,courier,monaco,monospace,sans-serif;"></span><span style="font-family: courier new,courier,monaco,monospace,sans-serif;">api.register({</span><br style="font-family: courier new,courier,monaco,monospace,sans-serif;"><span style="font-family: courier new,courier,monaco,monospace,sans-serif;"> UiInit: function() {</span><br><br style="font-family: courier new,courier,monaco,monospace,sans-serif;"><span style="font-family: courier new,courier,monaco,monospace,sans-serif;"> api.<span style="font-weight: bold; color: rgb(51, 51, 255);">addMainTabActionButton</span>('Host', 'Do something with selected host(s)', {</span><br><br style="font-family: courier new,courier,monaco,monospace,sans-serif;"><span style="font-family: courier new,courier,monaco,monospace,sans-serif;"> <span style="color: rgb(204, 51, 204); font-weight: bold;">onClick</span>: function() {</span><span style="white-space:pre"><br style="font-family: courier new,courier,monaco,monospace,sans-serif;"></span><span style="font-family: courier new,courier,monaco,monospace,sans-serif;"><span style="color: rgb(0, 102, 0);"> // 'arguments' contain host entities currently selected</span><br style="color: rgb(0, 102, 0);"> window.alert(arguments.length + ' host(s) selected');<br> window.alert('first selected host ID = ' + arguments[0].entityId);<br><br><span style="color: rgb(0, 102, 0);"> // Open new popup window</span><br style="color: rgb(0, 102, 0);"><span style="color: rgb(0, 102, 0);"> // In future, we might use "dialog UI" plugin API here</span><br style="color: rgb(0, 102, 0);"> window.open('http://example.com', '_blank');<br></span><span style="font-family: courier new,courier,monaco,monospace,sans-serif;"></span><span style="font-family: courier new,courier,monaco,monospace,sans-serif;"> },</span><br><br style="font-family: courier new,courier,monaco,monospace,sans-serif;"><span style="font-family: courier new,courier,monaco,monospace,sans-serif;"> <span style="font-weight: bold; color: rgb(204, 51, 204);">isEnabled</span>: function() {</span><br style="font-family: courier new,courier,monaco,monospace,sans-serif;"><span style="font-family: courier new,courier,monaco,monospace,sans-serif; color: rgb(0, 102, 0);"> // 'true' means the button is enabled and clickable (default)<br> // 'false' means the button is disabled and non-clickable<br><br> // Enable button only when the number of selected items > 0<br></span><span style="font-family: courier new,courier,monaco,monospace,sans-serif;"> return arguments.length > 0;</span><br style="font-family: courier new,courier,monaco,monospace,sans-serif;"><span style="font-family: courier new,courier,monaco,monospace,sans-serif;"> },</span><br><br style="font-family: courier new,courier,monaco,monospace,sans-serif;"><span style="font-family: courier new,courier,monaco,monospace,sans-serif;"> <span style="font-weight: bold; color: rgb(204, 51, 204);">isAccessible</span>: function() {</span><br style="font-family: courier new,courier,monaco,monospace,sans-serif;"><span style="font-family: courier new,courier,monaco,monospace,sans-serif; color: rgb(0, 102, 0);"> // 'true' means the button is visible (default)<br> // 'false' means the button is hidden<br style="font-family: courier new,courier,monaco,monospace,sans-serif;"></span><span style="font-family: courier new,courier,monaco,monospace,sans-serif;"> return true;</span><br style="font-family: courier new,courier,monaco,monospace,sans-serif;"><span style="font-family: courier new,courier,monaco,monospace,sans-serif;"> }</span><br><br style="font-family: courier new,courier,monaco,monospace,sans-serif;"><span style="font-family: courier new,courier,monaco,monospace,sans-serif;"> });</span><br><br style="font-family: courier new,courier,monaco,monospace,sans-serif;"><span style="font-family: courier new,courier,monaco,monospace,sans-serif;"> }</span><br style="font-family: courier new,courier,monaco,monospace,sans-serif;"><span style="font-family: courier new,courier,monaco,monospace,sans-serif;">});</span><br style="font-family: courier new,courier,monaco,monospace,sans-serif;"><br>The signature of <strong>addMainTabActionButton</strong> plugin API function is following:<br><br><span style="font-family: courier new,courier,monaco,monospace,sans-serif;">addMainTabActionButton(entityTypeName, label, actionButtonInterface)</span><br><br><em>entityTypeName</em> 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?]<br><br><span style="font-style: italic;">label</span> is the title displayed on the button.<br><br><span style="font-style: italic;">actionButtonInterface</span> represents an object that "implements the button interface" by declaring its functions: <span style="font-style: italic;">onClick</span>, <span style="font-style: italic;">isEnabled</span>, <span style="font-style: italic;">isAccessible</span>. 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.<br><br>All functions of <span style="font-style: italic;">actionButtonInterface</span> receive currently selected item(s) as function arguments. Within a JavaScript function, "arguments" represents an implicit array of its arguments.<br><br>For now, WebAdmin will pass simple JSON-like objects to these functions, for example:<br><br><span style="font-family: courier new,courier,monaco,monospace,sans-serif;">{ entityId: "<whatever>" }</span><br><br>In future, we can extend or modify this concept to match the contract of various oVirt REST API entities.<br><br>This feature will be part of UI Plugins PoC rev.6, which should come out next week.<br><br>Regards,<br>Vojtech<br><br></div></body></html>