Source : Agile Business Group Planet Following my recent article on “How to export current ‘tree’ view to XLS: use web_export_view” I’d like to show how you can add more functionalities to your sidebar on OpenERP web 6.1. The interesting code from web_export_view module looks like this:
// @@@ web_export_view custom JS @@@
openerp.web_export_view = function(openerp) {
_t = openerp.web._t;
openerp.web.Sidebar = openerp.web.Sidebar.extend({
add_default_sections: function() {
// IMHO sections should be registered objects
// as views and retrieved using a specific registry
// so that we don't have to override this
var self = this,
view = this.widget_parent,
view_manager = view.widget_parent,
action = view_manager.action;
if (this.session.uid === 1) {
this.add_section(_t('Customize'), 'customize');
this.add_items('customize', [{
label: _t("Translate"),
callback: view.on_sidebar_translate,
title: _t("Technical translation")
}]);
}
this.add_section(_t('Other Options'), 'other');
this.add_items('other', [
{
label: _t("Import"),
callback: view.on_sidebar_import
}, {
label: _t("Export"),
callback: view.on_sidebar_export
},
{
label: _t("Export current view"),
callback: this.on_sidebar_export_view
}
]);
},
});
}
- First (line 3) define your module’s namespace.
- then extend (line 7) the sidebar object
- and override ‘add_default_sections’ method (line 9)
- then we add our new action with its callback to the ‘other’ section using ‘add_items’ function (line 37)
Unfortunately the sidebar is not so modular at this point. As I commented into the code, if we had a registry for sidebar sections/actions we could just define ours and register it. But, for the time being you’ll need to override the original method and maintain by copy&paste the “real default” sections/actions (for the original one, have a look at the core web module). If you need help on how to create your web module, check openerp_bootstrap. A ‘must-say recommendation’: use Firebug to debug your javascript experiments, it will save you a lot of time