User Tools

Site Tools


scratchpad:staff_client_menus

how to add top-level menu items to the staff client

One day this may be scripted, or the framework might be able to handle this dynamically, but for now…

constants.js

Edit ILS/Open-ILS/xul/staff_client/chrome/content/main/constants.js and add the path for your interface to the urls object.

If this is a remote interface, don't include the domain if you can help it. Use something like '/xul/server/admin/backdoor.xul' or '/opac/en-US/skin/default/xml/index.xml'. I plan to do text mangling with sed on release builds and change 'xul/server' to some variation of 'xul/BUILD_STAMP/server' outside of CVS to support versioning, so be aware of that.

For this example, let's say you add 'XUL_LOCATION_EDITOR' : '/xul/server/admin/location.xul' to urls.

var urls = {
        'opac' : '/opac/en-US/skin/default/xml/advanced.xml',
        'XUL_DEBUG_CONSOLE' : 'chrome://global/content/console.xul',
        'XUL_LOCATION_EDITOR' : '/xul/server/admin/location.xul',
}

Now edit ILS/Open-ILS/xul/staff_client/chrome/content/main/menu_frame_menus.xul (note: this may move back to ILS/Open-ILS/xul/staff_client/server/main/menu_frame_menus.xul once I migrate from XUL interfaces that require chrome, such as wizards).

Within the <commandset> element, let's add something like <command id="cmd_edit_location" />. If you'd like to create a shortcut key, add an attribute like key="location_editor_key", and then in the <keyset> element, add something like <key id="location_editor_key" modifiers="accel" key="E" command="cmd_edit_location" />.

<commandset id="universal_cmds">
        <command id="cmd_close_window" key="close-window-key" />
        <command id="cmd_search_opac" key="search-opac-key" />
        <command id="cmd_edit_location" key="location_editor_key" />
</commandset>
 
<keyset id="menu_frame_keys">
        <key id="close-window-key" modifiers="accel" key="Q" command="cmd_close_window"/>
        <key id="search-opac-key" keycode="VK_F3" command="cmd_search_opac"/>
        <key id="location_editor_key" modifiers="accel" key="E" command="cmd_edit_location" />
</keyset>

Now, find the <menu> element you're interested in. It should have a <menupopup> element as it's child. Within the <menupopup>, add something like <menuitem label="Location Editor" accesskey="E" key="location_editor_key" command="cmd_edit_location"/> We'll let Adam, our intern, handle localization. :D

<menu id="main.menu.admin" label="&staff.main.menu.admin.label;" accesskey="&staff.main.menu.admin.key;">
        <menupopup id="main.menu.admin.popup">
                <menuitem label="Receipt Template Editor" accesskey="R" command="cmd_receipt_template_editor"/>
                <menuitem label="Survey Wizard" accesskey="S" command="cmd_survey_wizard"/>
                <menuitem label="Location Editor" accesskey="E" key="location_editor_key" command="cmd_edit_location"/>
        </menupopup>
</menu>

Lastly, edit ILS/Open-ILS/xul/staff_client/chrome/content/main/menu.js. This is the controller for our menus.

In main.menu.prototype, in 'init', in cmd_map add something like this:

'cmd_edit_location' : [
    ['oncommand'],
    function() {
        obj.set_tab(
            obj.url_prefix(urls.XUL_LOCATION_EDITOR) + '?ses='+escape(session),
            { 'tab_name' : 'Location Editor' },
            { 'extra' : too_big_for_url_param, 'on_edit' : function(loc){ alert('Location is now ' + loc); } }
        );
    }
],

This applies a command event listener to the corresponding <command> element. Both <key> and <menu> are observing and broadcasting to that <command>. If you were to disable that element (say with obj.controller.view.cmd_edit_location.disabled = true), all the observers would disable as well–the shortcut key would cease to work and the menu option would be greyed out.

"obj" refers to that instance of the 'main.menu' object. set_tab loads the specified interface in the current tab. You could use new_tab, or even something like window.open. The 3rd parameter for new_tab/set_tab is an alternate way to pass data. It will push the parameter into the loaded interface's window scope as xulG. Generally, it's better to use URL query params as that makes your interface more portable outside the staff client environment, but you'll need to use xulG if you want to push in functions for use as callbacks.

That's it. :)

scratchpad/staff_client_menus.txt · Last modified: 2006/01/29 07:21 (external edit)

© 2008-2017 GPLS and others. Evergreen is open source software, freely licensed under GNU GPLv2 or later.
The Evergreen Project is a member of Software Freedom Conservancy.