blob: 0e25f2566de3af160bc0581670dff7375e85fe34 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
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;
});
|