summaryrefslogtreecommitdiff
path: root/addons/web/static/src/js/chrome/systray_menu.js
diff options
context:
space:
mode:
authorstephanchrst <stephanchrst@gmail.com>2022-05-10 21:51:50 +0700
committerstephanchrst <stephanchrst@gmail.com>2022-05-10 21:51:50 +0700
commit3751379f1e9a4c215fb6eb898b4ccc67659b9ace (patch)
treea44932296ef4a9b71d5f010906253d8c53727726 /addons/web/static/src/js/chrome/systray_menu.js
parent0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff)
initial commit 2
Diffstat (limited to 'addons/web/static/src/js/chrome/systray_menu.js')
-rw-r--r--addons/web/static/src/js/chrome/systray_menu.js65
1 files changed, 65 insertions, 0 deletions
diff --git a/addons/web/static/src/js/chrome/systray_menu.js b/addons/web/static/src/js/chrome/systray_menu.js
new file mode 100644
index 00000000..0e25f256
--- /dev/null
+++ b/addons/web/static/src/js/chrome/systray_menu.js
@@ -0,0 +1,65 @@
+odoo.define('web.SystrayMenu', function (require) {
+"use strict";
+
+var dom = require('web.dom');
+var Widget = require('web.Widget');
+
+/**
+ * The SystrayMenu is the class that manage the list of icons in the top right
+ * of the menu bar.
+ */
+var SystrayMenu = Widget.extend({
+ /**
+ * This widget renders the systray menu. It creates and renders widgets
+ * pushed in instance.web.SystrayItems.
+ */
+ init: function (parent) {
+ this._super(parent);
+ this.items = [];
+ this.widgets = [];
+ },
+ /**
+ * Instanciate the items and add them into a temporary fragmenet
+ * @override
+ */
+ willStart: function () {
+ var self = this;
+ var proms = [];
+ SystrayMenu.Items = _.sortBy(SystrayMenu.Items, function (item) {
+ return !_.isUndefined(item.prototype.sequence) ? item.prototype.sequence : 50;
+ });
+
+ SystrayMenu.Items.forEach(function (WidgetClass) {
+ var cur_systray_item = new WidgetClass(self);
+ self.widgets.push(cur_systray_item);
+ proms.push(cur_systray_item.appendTo($('<div>')));
+ });
+
+ return this._super.apply(this, arguments).then(function () {
+ return Promise.all(proms);
+ });
+ },
+ on_attach_callback() {
+ this.widgets
+ .filter(widget => widget.on_attach_callback)
+ .forEach(widget => widget.on_attach_callback());
+ },
+ /**
+ * Add the instanciated items, using the object located in this.wisgets
+ */
+ start: function () {
+ var self = this;
+ return this._super.apply(this, arguments).then(function () {
+ self.widgets.forEach(function (widget) {
+ dom.prepend(self.$el, widget.$el);
+ });
+ });
+ },
+});
+
+SystrayMenu.Items = [];
+
+return SystrayMenu;
+
+});
+