[REF] web: split search_menus in separate files

This commit is contained in:
Mathieu Duckerts-Antoine
2018-06-12 09:22:04 +02:00
committed by Géry Debongnie
parent e476c0f15f
commit 7bf5dd687b
9 changed files with 293 additions and 190 deletions
@@ -303,189 +303,3 @@ return Widget.extend({
});
});
odoo.define('web.FilterMenu', function (require) {
"use strict";
var config = require('web.config');
var search_filters = require('web.search_filters');
var search_inputs = require('web.search_inputs');
var Widget = require('web.Widget');
return Widget.extend({
template: 'SearchView.FilterMenu',
events: {
'click .o_add_filter': function (event) {
event.preventDefault();
this.toggle_custom_filter_menu();
},
'click li': function (event) {
event.preventDefault();
event.stopImmediatePropagation();
},
'hidden.bs.dropdown': function () {
this.toggle_custom_filter_menu(false);
},
'click .o_add_condition': 'append_proposition',
'click .o_apply_filter': 'commit_search',
'keyup .o_searchview_extended_prop_value': function (ev) {
if (ev.which === $.ui.keyCode.ENTER) {
this.commit_search();
}
},
},
init: function (parent, filters, fields) {
this._super(parent);
this.isMobile = config.device.isMobile;
this.filters = filters || [];
this.searchview = parent;
this.propositions = [];
this.custom_filters_open = false;
this.fields = _.pick(fields, function (field, name) {
return field.selectable !== false && name !== 'id';
});
this.fields.id = { string: 'ID', type: 'id', searchable: true };
},
start: function () {
var self = this;
this.$menu = this.$('.o_filters_menu');
this.$add_filter = this.$('.o_add_filter');
this.$apply_filter = this.$('.o_apply_filter');
this.$add_filter_menu = this.$('.o_add_filter_menu');
_.each(this.filters, function (group) {
if (group.is_visible()) {
group.insertBefore(self.$add_filter);
$('<li class="divider">').insertBefore(self.$add_filter);
}
});
},
toggle_custom_filter_menu: function (is_open) {
var self = this;
this.custom_filters_open = !_.isUndefined(is_open) ? is_open : !this.custom_filters_open;
var def;
if (this.custom_filters_open && !this.propositions.length) {
def = this.append_proposition();
}
$.when(def).then(function () {
self.$add_filter
.toggleClass('o_closed_menu', !self.custom_filters_open)
.toggleClass('o_open_menu', self.custom_filters_open);
self.$add_filter_menu.toggle(self.custom_filters_open);
self.$('.o_filter_condition').toggle(self.custom_filters_open);
});
},
append_proposition: function () {
var prop = new search_filters.ExtendedSearchProposition(this, this.fields);
this.propositions.push(prop);
this.$apply_filter.prop('disabled', false);
return prop.insertBefore(this.$add_filter_menu);
},
remove_proposition: function (prop) {
this.propositions = _.without(this.propositions, prop);
if (!this.propositions.length) {
this.$apply_filter.prop('disabled', true);
}
prop.destroy();
},
commit_search: function () {
var filters = _.invoke(this.propositions, 'get_filter'),
filters_widgets = _.map(filters, function (filter) {
return new search_inputs.Filter(filter, this);
}),
filter_group = new search_inputs.FilterGroup(filters_widgets, this.searchview),
facets = filters_widgets.map(function (filter) {
return filter_group.make_facet([filter_group.make_value(filter)]);
});
filter_group.insertBefore(this.$add_filter);
$('<li class="divider">').insertBefore(this.$add_filter);
this.searchview.query.add(facets, {silent: true});
this.searchview.query.trigger('reset');
_.invoke(this.propositions, 'destroy');
this.propositions = [];
this.append_proposition();
this.toggle_custom_filter_menu(false);
},
});
});
odoo.define('web.GroupByMenu', function (require) {
"use strict";
var config = require('web.config');
var core = require('web.core');
var search_inputs = require('web.search_inputs');
var Widget = require('web.Widget');
var QWeb = core.qweb;
return Widget.extend({
template: 'SearchView.GroupByMenu',
events: {
'click li': function (event) {
event.stopImmediatePropagation();
},
'hidden.bs.dropdown': function () {
this.toggle_add_menu(false);
},
'click .o_add_custom_group a': function (event) {
event.preventDefault();
this.toggle_add_menu();
},
},
init: function (parent, groups, fields) {
var self = this;
this._super(parent);
this.searchview = parent;
this.isMobile = config.device.isMobile;
this.groups = groups || [];
this.groupableFields = [];
var groupable_types = ['many2one', 'char', 'boolean', 'selection', 'date', 'datetime'];
_.each(fields, function (field, name) {
if (field.sortable && _.contains(groupable_types, field.type)) {
self.groupableFields.push(_.extend({}, field, {name: name}));
}
});
self.groupableFields = _.sortBy(this.groupableFields, 'string');
},
start: function () {
var self = this;
this.$menu = this.$('.o_group_by_menu');
var divider = this.$menu.find('.divider');
_.invoke(this.groups, 'insertBefore', divider);
if (this.groups.length) {
divider.show();
}
this.$add_group = this.$menu.find('.o_add_custom_group');
this.$menu.append(QWeb.render('GroupByMenuSelector', this));
this.$add_group_menu = this.$('.o_add_group');
this.$group_selector = this.$('.o_group_selector');
this.$('.o_select_group').click(function () {
self.toggle_add_menu(false);
var field = self.$group_selector.find(':selected').data('name');
self.add_groupby_to_menu(field);
});
},
toggle_add_menu: function (is_open) {
this.$add_group
.toggleClass('o_closed_menu', !(_.isUndefined(is_open)) ? !is_open : undefined)
.toggleClass('o_open_menu', is_open);
this.$add_group_menu.toggle(is_open);
if (this.$add_group.hasClass('o_open_menu')) {
this.$group_selector.focus();
}
},
add_groupby_to_menu: function (field_name) {
var filter = new search_inputs.Filter({attrs:{
context:"{'group_by':'" + field_name + "''}",
name: _.find(this.groupableFields, {name: field_name}).string,
}}, this.searchview);
var group = new search_inputs.FilterGroup([filter], this.searchview),
divider = this.$('.divider').show();
group.insertBefore(divider);
group.toggle(filter);
},
});
});
@@ -0,0 +1,103 @@
odoo.define('web.FilterMenu', function (require) {
"use strict";
var search_filters = require('web.search_filters');
var search_inputs = require('web.search_inputs');
var Widget = require('web.Widget');
return Widget.extend({
template: 'SearchView.FilterMenu',
events: {
'click .o_add_filter': function (event) {
event.preventDefault();
this.toggle_custom_filter_menu();
},
'click li': function (event) {
event.preventDefault();
event.stopImmediatePropagation();
},
'hidden.bs.dropdown': function () {
this.toggle_custom_filter_menu(false);
},
'click .o_add_condition': 'append_proposition',
'click .o_apply_filter': 'commit_search',
'keyup .o_searchview_extended_prop_value': function (ev) {
if (ev.which === $.ui.keyCode.ENTER) {
this.commit_search();
}
},
},
init: function (parent, filters, fields) {
this._super(parent);
this.filters = filters || [];
this.searchview = parent;
this.propositions = [];
this.custom_filters_open = false;
this.fields = _.pick(fields, function (field, name) {
return field.selectable !== false && name !== 'id';
});
this.fields.id = { string: 'ID', type: 'id', searchable: true };
},
start: function () {
var self = this;
this.$menu = this.$('.o_filters_menu');
this.$add_filter = this.$('.o_add_filter');
this.$apply_filter = this.$('.o_apply_filter');
this.$add_filter_menu = this.$('.o_add_filter_menu');
_.each(this.filters, function (group) {
if (group.is_visible()) {
group.insertBefore(self.$add_filter);
$('<li class="divider">').insertBefore(self.$add_filter);
}
});
},
toggle_custom_filter_menu: function (is_open) {
var self = this;
this.custom_filters_open = !_.isUndefined(is_open) ? is_open : !this.custom_filters_open;
var def;
if (this.custom_filters_open && !this.propositions.length) {
def = this.append_proposition();
}
$.when(def).then(function () {
self.$add_filter
.toggleClass('o_closed_menu', !self.custom_filters_open)
.toggleClass('o_open_menu', self.custom_filters_open);
self.$add_filter_menu.toggle(self.custom_filters_open);
self.$('.o_filter_condition').toggle(self.custom_filters_open);
});
},
append_proposition: function () {
var prop = new search_filters.ExtendedSearchProposition(this, this.fields);
this.propositions.push(prop);
this.$apply_filter.prop('disabled', false);
return prop.insertBefore(this.$add_filter_menu);
},
remove_proposition: function (prop) {
this.propositions = _.without(this.propositions, prop);
if (!this.propositions.length) {
this.$apply_filter.prop('disabled', true);
}
prop.destroy();
},
commit_search: function () {
var filters = _.invoke(this.propositions, 'get_filter'),
filters_widgets = _.map(filters, function (filter) {
return new search_inputs.Filter(filter, this);
}),
filter_group = new search_inputs.FilterGroup(filters_widgets, this.searchview),
facets = filters_widgets.map(function (filter) {
return filter_group.make_facet([filter_group.make_value(filter)]);
});
filter_group.insertBefore(this.$add_filter);
$('<li class="divider">').insertBefore(this.$add_filter);
this.searchview.query.add(facets, {silent: true});
this.searchview.query.trigger('reset');
_.invoke(this.propositions, 'destroy');
this.propositions = [];
this.append_proposition();
this.toggle_custom_filter_menu(false);
},
});
});
@@ -0,0 +1,105 @@
odoo.define('web.FilterMenu', function (require) {
"use strict";
var config = require('web.config');
var search_filters = require('web.search_filters');
var search_inputs = require('web.search_inputs');
var Widget = require('web.Widget');
return Widget.extend({
template: 'SearchView.FilterMenu',
events: {
'click .o_add_filter': function (event) {
event.preventDefault();
this.toggle_custom_filter_menu();
},
'click li': function (event) {
event.preventDefault();
event.stopImmediatePropagation();
},
'hidden.bs.dropdown': function () {
this.toggle_custom_filter_menu(false);
},
'click .o_add_condition': 'append_proposition',
'click .o_apply_filter': 'commit_search',
'keyup .o_searchview_extended_prop_value': function (ev) {
if (ev.which === $.ui.keyCode.ENTER) {
this.commit_search();
}
},
},
init: function (parent, filters, fields) {
this._super(parent);
this.isMobile = config.device.isMobile;
this.filters = filters || [];
this.searchview = parent;
this.propositions = [];
this.custom_filters_open = false;
this.fields = _.pick(fields, function (field, name) {
return field.selectable !== false && name !== 'id';
});
this.fields.id = { string: 'ID', type: 'id', searchable: true };
},
start: function () {
var self = this;
this.$menu = this.$('.o_filters_menu');
this.$add_filter = this.$('.o_add_filter');
this.$apply_filter = this.$('.o_apply_filter');
this.$add_filter_menu = this.$('.o_add_filter_menu');
_.each(this.filters, function (group) {
if (group.is_visible()) {
group.insertBefore(self.$add_filter);
$('<li class="divider">').insertBefore(self.$add_filter);
}
});
},
toggle_custom_filter_menu: function (is_open) {
var self = this;
this.custom_filters_open = !_.isUndefined(is_open) ? is_open : !this.custom_filters_open;
var def;
if (this.custom_filters_open && !this.propositions.length) {
def = this.append_proposition();
}
$.when(def).then(function () {
self.$add_filter
.toggleClass('o_closed_menu', !self.custom_filters_open)
.toggleClass('o_open_menu', self.custom_filters_open);
self.$add_filter_menu.toggle(self.custom_filters_open);
self.$('.o_filter_condition').toggle(self.custom_filters_open);
});
},
append_proposition: function () {
var prop = new search_filters.ExtendedSearchProposition(this, this.fields);
this.propositions.push(prop);
this.$apply_filter.prop('disabled', false);
return prop.insertBefore(this.$add_filter_menu);
},
remove_proposition: function (prop) {
this.propositions = _.without(this.propositions, prop);
if (!this.propositions.length) {
this.$apply_filter.prop('disabled', true);
}
prop.destroy();
},
commit_search: function () {
var filters = _.invoke(this.propositions, 'get_filter'),
filters_widgets = _.map(filters, function (filter) {
return new search_inputs.Filter(filter, this);
}),
filter_group = new search_inputs.FilterGroup(filters_widgets, this.searchview),
facets = filters_widgets.map(function (filter) {
return filter_group.make_facet([filter_group.make_value(filter)]);
});
filter_group.insertBefore(this.$add_filter);
$('<li class="divider">').insertBefore(this.$add_filter);
this.searchview.query.add(facets, {silent: true});
this.searchview.query.trigger('reset');
_.invoke(this.propositions, 'destroy');
this.propositions = [];
this.append_proposition();
this.toggle_custom_filter_menu(false);
},
});
});
@@ -0,0 +1,79 @@
odoo.define('web.GroupByMenu', function (require) {
"use strict";
var config = require('web.config');
var core = require('web.core');
var search_inputs = require('web.search_inputs');
var Widget = require('web.Widget');
var QWeb = core.qweb;
return Widget.extend({
template: 'SearchView.GroupByMenu',
events: {
'click li': function (event) {
event.stopImmediatePropagation();
},
'hidden.bs.dropdown': function () {
this.toggle_add_menu(false);
},
'click .o_add_custom_group a': function (event) {
event.preventDefault();
this.toggle_add_menu();
},
},
init: function (parent, groups, fields) {
var self = this;
this._super(parent);
this.searchview = parent;
this.isMobile = config.device.isMobile;
this.groups = groups || [];
this.groupableFields = [];
var groupable_types = ['many2one', 'char', 'boolean', 'selection', 'date', 'datetime'];
_.each(fields, function (field, name) {
if (field.sortable && _.contains(groupable_types, field.type)) {
self.groupableFields.push(_.extend({}, field, {name: name}));
}
});
self.groupableFields = _.sortBy(this.groupableFields, 'string');
},
start: function () {
var self = this;
this.$menu = this.$('.o_group_by_menu');
var divider = this.$menu.find('.divider');
_.invoke(this.groups, 'insertBefore', divider);
if (this.groups.length) {
divider.show();
}
this.$add_group = this.$menu.find('.o_add_custom_group');
this.$menu.append(QWeb.render('GroupByMenuSelector', this));
this.$add_group_menu = this.$('.o_add_group');
this.$group_selector = this.$('.o_group_selector');
this.$('.o_select_group').click(function () {
self.toggle_add_menu(false);
var field = self.$group_selector.find(':selected').data('name');
self.add_groupby_to_menu(field);
});
},
toggle_add_menu: function (is_open) {
this.$add_group
.toggleClass('o_closed_menu', !(_.isUndefined(is_open)) ? !is_open : undefined)
.toggleClass('o_open_menu', is_open);
this.$add_group_menu.toggle(is_open);
if (this.$add_group.hasClass('o_open_menu')) {
this.$group_selector.focus();
}
},
add_groupby_to_menu: function (field_name) {
var filter = new search_inputs.Filter({attrs:{
context:"{'group_by':'" + field_name + "''}",
name: _.find(this.groupableFields, {name: field_name}).string,
}}, this.searchview);
var group = new search_inputs.FilterGroup([filter], this.searchview),
divider = this.$('.divider').show();
group.insertBefore(divider);
group.toggle(filter);
},
});
});
+6 -4
View File
@@ -211,11 +211,13 @@
<script type="text/javascript" src="/web/static/src/js/widgets/switch_company_menu.js"></script>
<script type="text/javascript" src="/web/static/src/js/chrome/user_menu.js"></script>
<script type="text/javascript" src="/web/static/src/js/chrome/menu.js"></script>
<script type="text/javascript" src="/web/static/src/js/chrome/search_view.js"></script>
<script type="text/javascript" src="/web/static/src/js/views/search/search_view.js"></script>
<script type="text/javascript" src="/web/static/src/js/chrome/search_view_mobile.js"></script>
<script type="text/javascript" src="/web/static/src/js/chrome/search_filters.js"></script>
<script type="text/javascript" src="/web/static/src/js/chrome/search_inputs.js"></script>
<script type="text/javascript" src="/web/static/src/js/chrome/search_menus.js"></script>
<script type="text/javascript" src="/web/static/src/js/views/search/search_filters.js"></script>
<script type="text/javascript" src="/web/static/src/js/views/search/search_inputs.js"></script>
<script type="text/javascript" src="/web/static/src/js/views/search/favorites_menu.js"></script>
<script type="text/javascript" src="/web/static/src/js/views/search/groupby_menu.js"></script>
<script type="text/javascript" src="/web/static/src/js/views/search/filters_menu.js"></script>
<script type="text/javascript" src="/web/static/src/js/apps.js"></script>
<script type="text/javascript" src="/web/static/src/js/fields/abstract_field.js"></script>