<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;">&nbsp; 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;">&nbsp;&nbsp;&nbsp; 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;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <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);">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // 'arguments' contain host entities currently selected</span><br style="color: rgb(0, 102, 0);">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; window.alert(arguments.length + ' host(s) selected');<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; window.alert('first selected host ID = ' + arguments[0].entityId);<br><br><span style="color: rgb(0, 102, 0);">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Open new popup window</span><br style="color: rgb(0, 102, 0);"><span style="color: rgb(0, 102, 0);">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // In future, we might use "dialog UI" plugin API here</span><br style="color: rgb(0, 102, 0);">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 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;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; },</span><br><br style="font-family: courier new,courier,monaco,monospace,sans-serif;"><span style="font-family: courier new,courier,monaco,monospace,sans-serif;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <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);">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // 'true' means the button is enabled and clickable (default)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // 'false' means the button is disabled and non-clickable<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Enable button only when the number of selected items &gt; 0<br></span><span style="font-family: courier new,courier,monaco,monospace,sans-serif;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return arguments.length &gt; 0;</span><br style="font-family: courier new,courier,monaco,monospace,sans-serif;"><span style="font-family: courier new,courier,monaco,monospace,sans-serif;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; },</span><br><br style="font-family: courier new,courier,monaco,monospace,sans-serif;"><span style="font-family: courier new,courier,monaco,monospace,sans-serif;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <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);">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // 'true' means the button is visible (default)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // '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;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 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;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</span><br><br style="font-family: courier new,courier,monaco,monospace,sans-serif;"><span style="font-family: courier new,courier,monaco,monospace,sans-serif;">&nbsp;&nbsp;&nbsp; });</span><br><br style="font-family: courier new,courier,monaco,monospace,sans-serif;"><span style="font-family: courier new,courier,monaco,monospace,sans-serif;">&nbsp; }</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: "&lt;whatever&gt;" }</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>