Skip to content
Extraits de code Groupes Projets
Valider 7963abed rédigé par Benjamin - Le Filament's avatar Benjamin - Le Filament
Parcourir les fichiers

[add] select all / unselect all

parent 3988e9df
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -14,6 +14,7 @@ This module adds the following functionalities : ...@@ -14,6 +14,7 @@ This module adds the following functionalities :
* adds hide/show on search panel * adds hide/show on search panel
* add collapse function on section headers * add collapse function on section headers
* option filters on field to select/unselect all on multi select
Credits Credits
......
odoo.define("web_search_panel_options.SearchPanelModelExtension", function (require) {
"use strict";
var core = require("web.core");
var QWeb = core.qweb;
const utils = require("web.utils");
const pyUtils = require("web.py_utils");
const SearchPanelModelExtension = require("web/static/src/js/views/search_panel_model_extension.js");
let nextSectionId = 1;
utils.patch(SearchPanelModelExtension, "search.panel.extension.options", {
/**
* Override parent to add filters value
* @private
*/
_createSectionsFromArch() {
this._super();
this.config.archNodes.forEach(({ attrs, tag }, index) => {
const section = this.state.sections.get(nextSectionId)
section.filters = section.type === "filter" ? !!pyUtils.py_eval(attrs.filters || "0") : false;
this.state.sections.set(section.id, section);
nextSectionId++;
})
}
});
});
...@@ -48,5 +48,37 @@ odoo.define("web_search_panel_options.SPanel", function (require) { ...@@ -48,5 +48,37 @@ odoo.define("web_search_panel_options.SPanel", function (require) {
$(this.el).removeClass("o_hidden"); $(this.el).removeClass("o_hidden");
} }
}, },
/**
* @private
* @param {number} filterId
* @param {Object} child values
* @param {MouseEvent} ev
*/
_selectAll(filterId, values, ev) {
ev.stopPropagation();
ev.preventDefault();
const valueIds = [];
values.forEach(({ id }) => {
valueIds.push(id);
this.state.active[filterId][id] = true;
});
this.model.dispatch("toggleFilterValues", filterId, valueIds, true);
},
/**
* @private
* @param {number} filterId
* @param {Object} child values
* @param {MouseEvent} ev
*/
_unSelectAll(filterId, values, ev) {
ev.stopPropagation();
ev.preventDefault();
const valueIds = [];
values.forEach(({ id }) => {
valueIds.push(id);
this.state.active[filterId][id] = true;
});
this.model.dispatch("toggleFilterValues", filterId, valueIds, false);
},
}); });
}); });
...@@ -17,6 +17,14 @@ ...@@ -17,6 +17,14 @@
>o_search_panel_section_header text-uppercase</attribute> >o_search_panel_section_header text-uppercase</attribute>
<attribute name="t-att-aria-controls">section.fieldName</attribute> <attribute name="t-att-aria-controls">section.fieldName</attribute>
</xpath> </xpath>
<xpath expr="//section/header" position="after">
<div t-if="section.filters" class="text-center">
<a t-attf-href="#select-{{section.id}}" t-on-click="_selectAll(section.id, section.values)">Tous</a>
<span style="padding-left: 8px; padding-right: 8px;"> | </span>
<a t-attf-href="#unselect-{{section.id}}" t-on-click="_unSelectAll(section.id, section.values)">Aucun</a>
<hr/>
</div>
</xpath>
<xpath expr="//section/ul" position="replace"> <xpath expr="//section/ul" position="replace">
<div t-else="" class="collapse show" t-att-id="section.fieldName"> <div t-else="" class="collapse show" t-att-id="section.fieldName">
<ul class="list-group d-block o_search_panel_field"> <ul class="list-group d-block o_search_panel_field">
......
...@@ -13,6 +13,9 @@ ...@@ -13,6 +13,9 @@
<script <script
src="/web_search_panel_options/static/src/js/search_panel_options.js" src="/web_search_panel_options/static/src/js/search_panel_options.js"
/> />
<script
src="/web_search_panel_options/static/src/js/search_panel_model_extension.js"
/>
</xpath> </xpath>
</template> </template>
</odoo> </odoo>
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter