Enable Dark Mode!
how-to-open-a-drop-down-from-systray-in-odoo-16.jpg
By: Cybrosys Technologies

How to Open a Drop Down From Systray in Odoo 16

Technical Odoo 16 Odoo Enterprises Odoo Community

Odoo's Systray represents the top navbar in the Odoo interface. Systray icons are used to give users easy access to certain functionality or to show them notifications, and it is found in the interface's upper right corner. In Odoo, the default icons include a drop-down list linked to the installed username and the app launcher icon. However, the systray can be customized.

The below-marked section in the image shows the systray icons in Odoo.

How to Open a Drop Down From Systray in Odoo 16-cybrosys

To set up a systray in the menu bar and define an action for it, begin by creating a directory. Within this directory, establish a "static" folder and include "JS" and "XML" directories inside it.

How to Open a Drop Down From Systray in Odoo 16-cybrosys

Next, develop a view for the systray icon to be displayed in the notification bar. In the XML file, create a template for the systray, and inside the <i> tag, provide the icon for the systray and define styles for the icon. As a result, the icon for the systray will be displayed in the notification bar.

<templates>
   <t t-name="IconSystrayDropdown">
       <div class="SystrayMenuContainer">
           <div class="o_MessagingMenu dropdown ">
               <div class="o-dropdown dropdown o_debug_manager o-dropdown--no-caret">
                   <a class="o_MessagingMenu_toggler dropdown-toggle o-no-caret o-dropdown--narrow" href="#"
                      title="Systray Dropdown" role="button" aria-haspopup="true" aria-expanded="">
                       <i id='create_so' class="fa fa-cloud"/>
                   </a>
               </div>
               <div id="systray_notif" class="o_MessagingMenu_dropdownMenu  o-dropdown-menu ">
                   <div class="container" style="padding-top: 4%;">
                       <div class="systray_notification"/>
                   </div>
               </div>
           </div>
       </div>
   </t>
   <t t-name="SystrayDetails">
       <div class="container">
           HI
           This Is a dropdown Systray.
       </div>
   </t>
</templates>

From this above template, “IconSystrayDropdown ” will help to add the icon for systray. Here this template adds a weather icon for the systray and also adds some classes to make it open a dropdown. And there another one more template “SystrayDetails” is used to add the contents that need to be shown in the dropdown.

After adding the template, we need to add some JS code to display the icon in the systray and to provide the click functions for the systray.

/** @odoo-module **/
import core from 'web.core';
import SystrayMenu from 'web.SystrayMenu';
import Widget from 'web.Widget';
var qweb = core.qweb
const SystrayWidget = Widget.extend({
  template: 'IconSystrayDropdown',
  events: {
      'click .o-dropdown': '_onClick',
  },
  _onClick: function(ev){
       var self = this
       let dropBox = $(ev.currentTarget.parentElement).find('#systray_notif')
       if (dropBox[0].style.display == 'block'){
           dropBox[0].style.display = 'none'
       }
       else{
           dropBox[0].style.display = 'block'
       }
       $('.systray_notification').html((qweb.render("SystrayDetails")))
  },
});
SystrayMenu.Items.push(SystrayWidget);
export default SystrayWidget;

In order to provide action for this icon, we must first import the Widget and SystrayMenu classes. Existing classes can be extended in Odoo JavaScript by utilizing the extend function. By using this method, you can create a new class called SystrayWidget, which inherits all the properties and methods of the original class (widget class) while also allowing you to override or add new properties and methods. It will help to add a new widget to the systray icon. After that, we can mention the template name of the systray icon, and inside the events, mention a _onClick function to open the drop-down. In this click, the function lets make the properties to show and hide the drop-down box. After that, we can render the “SystrayDetails” template to show the contents.

After creating the JS file and the XML template file, the next step is to add both of these files to the manifest file of the module.

'assets': {
    'web.assets_backend': [
        'systray_icon_dropdown/static/src/js/systray_icon_dropdown.js',
        'systray_icon_dropdown/static/src/xml/systray_icon_dropdown.xml',
    ]
 }

 After completing all the steps, let's install the module and check the results.

How to Open a Drop Down From Systray in Odoo 16-cybrosys

After the installation, the weather icon will be visible on the notification bar.

How to Open a Drop Down From Systray in Odoo 16-cybrosys

On clicking the icon, a drop-down is opened, and you can see the content that we provided on the template “SystrayDetails” in drop-down.


If you need any assistance in odoo, we are online, please chat with us.



0
Comments



Leave a comment



whatsapp_icon
location

Calicut

Cybrosys Technologies Pvt. Ltd.
Neospace, Kinfra Techno Park
Kakkancherry, Calicut
Kerala, India - 673635

location

Kochi

Cybrosys Technologies Pvt. Ltd.
1st Floor, Thapasya Building,
Infopark, Kakkanad,
Kochi, India - 682030.

location

Bangalore

Cybrosys Techno Solutions
The Estate, 8th Floor,
Dickenson Road,
Bangalore, India - 560042

Send Us A Message