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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
odoo.define('web.FavoriteMenu', function (require) {
"use strict";
const Dialog = require('web.OwlDialog');
const DropdownMenu = require('web.DropdownMenu');
const { FACET_ICONS } = require("web.searchUtils");
const Registry = require('web.Registry');
const { useModel } = require('web/static/src/js/model.js');
/**
* 'Favorites' menu
*
* Simple rendering of the filters of type `favorites` given by the control panel
* model. It uses most of the behaviours implemented by the dropdown menu Component,
* with the addition of a submenu registry used to display additional components.
* Only the favorite generator (@see CustomFavoriteItem) is registered in
* the `web` module.
* @see DropdownMenu for additional details.
* @extends DropdownMenu
*/
class FavoriteMenu extends DropdownMenu {
constructor() {
super(...arguments);
this.model = useModel('searchModel');
this.state.deletedFavorite = false;
}
//---------------------------------------------------------------------
// Getters
//---------------------------------------------------------------------
/**
* @override
*/
get icon() {
return FACET_ICONS.favorite;
}
/**
* @override
*/
get items() {
const favorites = this.model.get('filters', f => f.type === 'favorite');
const registryMenus = this.constructor.registry.values().reduce(
(menus, Component) => {
if (Component.shouldBeDisplayed(this.env)) {
menus.push({
key: Component.name,
groupNumber: Component.groupNumber,
Component,
});
}
return menus;
},
[]
);
return [...favorites, ...registryMenus];
}
/**
* @override
*/
get title() {
return this.env._t("Favorites");
}
//---------------------------------------------------------------------
// Handlers
//---------------------------------------------------------------------
/**
* @private
* @param {OwlEvent} ev
*/
_onItemRemoved(ev) {
const favorite = this.items.find(fav => fav.id === ev.detail.item.id);
this.state.deletedFavorite = favorite;
}
/**
* @private
* @param {OwlEvent} ev
*/
_onItemSelected(ev) {
ev.stopPropagation();
this.model.dispatch('toggleFilter', ev.detail.item.id);
}
/**
* @private
*/
async _onRemoveFavorite() {
this.model.dispatch('deleteFavorite', this.state.deletedFavorite.id);
this.state.deletedFavorite = false;
}
}
FavoriteMenu.registry = new Registry();
FavoriteMenu.components = Object.assign({}, DropdownMenu.components, {
Dialog,
});
FavoriteMenu.template = 'web.FavoriteMenu';
return FavoriteMenu;
});
|