Skip to Content
Menu
This question has been flagged

How can I create a custom javascript file that adds a new property and function to an inherited object, so that my custom menu item will open a new website?

So far, I created a custom web module that inherits from the original web module in Openerp 7.  

I added a new menu item in the User Menu by extending from the UserMenu template in the base.xml file.

Here is my custom xml code that adds a new menu item to the User Menu template.

(custom xml file.  This new menu item does appear in the User Menu )

<templates>

    <t t-extend="UserMenu">

        <t t-jquery="ul" t-operation="append">

           <li><a href="#" data-menu="website">Website Menu Item</a></li>

        </t>

    </t>

</templates>


base.xml (original)

<t t-name="UserMenu">

    <span class="oe_user_menu oe_topbar_item oe_dropdown_toggle oe_dropdown_arrow">

        <img class="oe_topbar_avatar" t-att-data-default-src="_s + '/web/static/src/img/user_menu_avatar.png'"/>

        <span class="oe_topbar_name"/>

        <ul class="oe_dropdown_menu">

            <li><a href="#" data-menu="settings">Preferences</a></li>

            <li><a href="#" data-menu="account">My OpenERP.com account</a></li>

            <li><a href="#" data-menu="about">About OpenERP</a></li>

            <li><a href="#" data-menu="help">Help</a></li>

            <li><a href="#" data-menu="logout">Log out</a></li>

        </ul>

    </span>

</t>


What I want to do now is inherit the UserMenu object that is defined in the web module's chrome.js file, into my custom javascript file.   Then I want to add a property to the UserMenu object so that a new website is opened when the menu item is clicked

Here is what I have so far:

 

openerp.web_custom = function(instance){

     // Add the on_menu_website property to the UserMenu object

     instance.web.UserMenu.on_menu_website = function() {

         //open the website  ...  its not working though

         window.open('http://www.website.com', '_blank');

     }

}


Here is the original js file code:

instance.web.UserMenu = instance.web.Widget.extend({

    template: "UserMenu",

    init: function(parent) {

       ... some code here ...

    },

    start: function() {

        ... some code here ...

    },

    do_update: function () {

        ... some code here ...

    },

    on_menu_help: function() {

        ... some code here ...

    },

    on_menu_logout: function() {

        ... some code here ...

    },

    on_menu_settings: function() {

        ... some code here ...

    },

    on_menu_account: function() {

        ... some code here ...

    },

    on_menu_about: function() {

        ... some code here ...

    },

});


One thing to note, if I add my new code the the original web module files (base.xml, chrome.js) then it works fine.  But I want to be able to create a custom web module so that I can add new functionality without modifying the original web module.  So my question is, how can I create a custom javascript file that adds a new property and function so that my menu item will open the new website?  Thank you for your help

Avatar
Discard
Author Best Answer

I changed my custom javascript file to this. Then it worked


openerp.web_custom = function(instance){

     instance.web.UserMenu.include({

          on_menu_website: function () {

               window.open('http://www.website.com', '_blank');

          },

     });

}

Avatar
Discard

Saved my day!! Thanks :)

Related Posts Replies Views Activity
1
Mar 22
5469
2
Dec 21
8095
2
Jul 24
1335
3
May 24
1243
0
May 24
510