[CHG] split custom filters handling out of regular filters
bzr revid: xmo@openerp.com-20120510185214-qyh7wybl0un036dt
This commit is contained in:
parent
06aa99eb19
commit
978eae621d
|
@ -1175,6 +1175,14 @@
|
||||||
border: 1px solid #cccccc;
|
border: 1px solid #cccccc;
|
||||||
text-align: left;
|
text-align: left;
|
||||||
}
|
}
|
||||||
|
.openerp .oe_searchview .oe_searchview_drawer > div {
|
||||||
|
border-top: 1px solid #cccccc;
|
||||||
|
margin: 3px 0;
|
||||||
|
}
|
||||||
|
.openerp .oe_searchview .oe_searchview_drawer > div:first-child {
|
||||||
|
border-top: none;
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
.openerp .oe_searchview .oe_searchview_drawer button, .openerp .oe_searchview .oe_searchview_drawer .button {
|
.openerp .oe_searchview .oe_searchview_drawer button, .openerp .oe_searchview .oe_searchview_drawer .button {
|
||||||
border: none;
|
border: none;
|
||||||
background: white;
|
background: white;
|
||||||
|
@ -1228,8 +1236,7 @@
|
||||||
color: #404040;
|
color: #404040;
|
||||||
}
|
}
|
||||||
.openerp .oe_searchview .oe_searchview_drawer .oe_searchview_advanced h4 {
|
.openerp .oe_searchview .oe_searchview_drawer .oe_searchview_advanced h4 {
|
||||||
border-top: 1px solid #cccccc;
|
margin: 0;
|
||||||
margin: 5px 0 3px;
|
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
.openerp .oe_searchview .oe_searchview_drawer .oe_searchview_advanced h4:before {
|
.openerp .oe_searchview .oe_searchview_drawer .oe_searchview_advanced h4:before {
|
||||||
|
|
|
@ -932,6 +932,13 @@ $colour4: #8a89ba
|
||||||
border: 1px solid #ccc
|
border: 1px solid #ccc
|
||||||
text-align: left
|
text-align: left
|
||||||
|
|
||||||
|
> div
|
||||||
|
border-top: 1px solid #ccc
|
||||||
|
margin: 3px 0
|
||||||
|
> div:first-child
|
||||||
|
border-top: none
|
||||||
|
margin: 0
|
||||||
|
|
||||||
button, .button
|
button, .button
|
||||||
border: none
|
border: none
|
||||||
background: white
|
background: white
|
||||||
|
@ -980,8 +987,7 @@ $colour4: #8a89ba
|
||||||
|
|
||||||
.oe_searchview_advanced
|
.oe_searchview_advanced
|
||||||
h4
|
h4
|
||||||
border-top: 1px solid #ccc
|
margin: 0
|
||||||
margin: 5px 0 3px
|
|
||||||
cursor: pointer
|
cursor: pointer
|
||||||
|
|
||||||
h4:before
|
h4:before
|
||||||
|
|
|
@ -624,9 +624,11 @@ instance.web.SearchView = instance.web.Widget.extend(/** @lends instance.web.Sea
|
||||||
data.fields_view.fields);
|
data.fields_view.fields);
|
||||||
|
|
||||||
// add Filters to this.inputs, need view.controls filled
|
// add Filters to this.inputs, need view.controls filled
|
||||||
var filters = new instance.web.search.Filters(this);
|
(new instance.web.search.Filters(this));
|
||||||
|
// add custom filters to this.inputs
|
||||||
|
(new instance.web.search.CustomFilters(this));
|
||||||
// add Advanced to this.inputs
|
// add Advanced to this.inputs
|
||||||
var advanced = new instance.web.search.Advanced(this);
|
(new instance.web.search.Advanced(this));
|
||||||
|
|
||||||
// build drawer
|
// build drawer
|
||||||
var drawer_started = $.when.apply(
|
var drawer_started = $.when.apply(
|
||||||
|
@ -1479,28 +1481,52 @@ instance.web.search.ManyToOneField = instance.web.search.CharField.extend({
|
||||||
|
|
||||||
instance.web.search.CustomFilters = instance.web.search.Input.extend({
|
instance.web.search.CustomFilters = instance.web.search.Input.extend({
|
||||||
template: 'SearchView.CustomFilters',
|
template: 'SearchView.CustomFilters',
|
||||||
|
_in_drawer: true,
|
||||||
start: function () {
|
start: function () {
|
||||||
|
this.model = new instance.web.Model('ir.filters');
|
||||||
|
this.filters = {};
|
||||||
this.$element.on('submit', 'form', this.proxy('save_current'));
|
this.$element.on('submit', 'form', this.proxy('save_current'));
|
||||||
// FIXME: local eval of domain and context to get rid of special endpoint
|
// FIXME: local eval of domain and context to get rid of special endpoint
|
||||||
return this.rpc('/web/searchview/get_filters', {
|
return this.rpc('/web/searchview/get_filters', {
|
||||||
model: this.view.model
|
model: this.view.model
|
||||||
}).pipe(this.proxy('set_filters'));
|
}).pipe(this.proxy('set_filters'));
|
||||||
},
|
},
|
||||||
set_filters: function (filters) {
|
append_filter: function (filter) {
|
||||||
var self = this;
|
var self = this;
|
||||||
var content = this.$element.find('.oe_searchview_custom_list');
|
var key = _.str.sprintf('(%s)%s', filter.user_id, filter.name);
|
||||||
return $.when.apply(null, _(filters).chain()
|
|
||||||
.map(function (filter) {
|
var $filter;
|
||||||
// FIXME: handling of ``disabled`` being set
|
if (key in this.filters) {
|
||||||
var f = new instance.web.search.Filter({attrs: {
|
$filter = this.filters[key];
|
||||||
string: filter.name,
|
} else {
|
||||||
context: filter.context,
|
var id = filter.id;
|
||||||
domain: filter.domain
|
$filter = this.filters[key] = $('<li></li>')
|
||||||
}}, self.view);
|
.appendTo(this.$element.find('.oe_searchview_custom_list'))
|
||||||
return new instance.web.search.FilterGroup([f], self.view);
|
.text(filter.name);
|
||||||
})
|
$('<button type="button">').appendTo($filter)
|
||||||
.invoke('appendTo', content)
|
.text(_t("Delete"))
|
||||||
.value());
|
.click(function () {
|
||||||
|
self.model.call('unlink', [id]).then(function () {
|
||||||
|
$filter.remove();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
$filter.unbind('click').click(function () {
|
||||||
|
self.view.query.reset([{
|
||||||
|
category: _("Custom Filter"),
|
||||||
|
icon: 'M',
|
||||||
|
field: {
|
||||||
|
get_context: function () { return filter.context; },
|
||||||
|
get_groupby: function () { return [filter.context]; },
|
||||||
|
get_domain: function () { return filter.domain; }
|
||||||
|
},
|
||||||
|
values: [{label: filter.name, value: null}]
|
||||||
|
}]);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
set_filters: function (filters) {
|
||||||
|
_(filters).map(_.bind(this.append_filter, this));
|
||||||
},
|
},
|
||||||
save_current: function () {
|
save_current: function () {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
@ -1511,29 +1537,26 @@ instance.web.search.CustomFilters = instance.web.search.Input.extend({
|
||||||
domains: search.domains,
|
domains: search.domains,
|
||||||
contexts: search.contexts,
|
contexts: search.contexts,
|
||||||
group_by_seq: search.groupbys || []
|
group_by_seq: search.groupbys || []
|
||||||
}).pipe(function (results) {
|
}).then(function (results) {
|
||||||
if (!_.isEmpty(results.group_by)) {
|
if (!_.isEmpty(results.group_by)) {
|
||||||
results.context.group_by = results.group_by;
|
results.context.group_by = results.group_by;
|
||||||
}
|
}
|
||||||
var name = $name.val();
|
var filter = {
|
||||||
// FIXME: creates filter and group even if the call fails :/
|
name: $name.val(),
|
||||||
var f = new instance.web.search.Filter({attrs: {
|
// FIXME: optional on public/private checkbox
|
||||||
string: name,
|
|
||||||
context: results.context,
|
|
||||||
domain: results.domain
|
|
||||||
}}, self.view);
|
|
||||||
(new instance.web.search.FilterGroup([f], self.view))
|
|
||||||
.appendTo(self.$element.find('.oe_searchview_custom_list'));
|
|
||||||
// FIXME: current context?
|
|
||||||
return new instance.web.Model('ir.filters').call('create_or_replace', [{
|
|
||||||
name: name,
|
|
||||||
user_id: instance.connection.uid,
|
user_id: instance.connection.uid,
|
||||||
model_id: self.view.model,
|
model_id: self.view.model,
|
||||||
context: results.context,
|
context: results.context,
|
||||||
domain: results.domain
|
domain: results.domain
|
||||||
}]);
|
};
|
||||||
}).then(function () {
|
// FIXME: current context?
|
||||||
$name.val('');
|
return self.model.call('create_or_replace', [filter]).then(function (id) {
|
||||||
|
if (id) {
|
||||||
|
filter.id = id;
|
||||||
|
}
|
||||||
|
self.append_filter(filter);
|
||||||
|
$name.val('');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -1574,13 +1597,6 @@ instance.web.search.Filters = instance.web.search.Input.extend({
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a Custom Filter FilterGroup for each custom filter read from
|
|
||||||
// the db, add all of this as a group in the smallest column
|
|
||||||
(col1.length <= col2.length ? col1 : col2).push({
|
|
||||||
name: _t("Custom Filters"),
|
|
||||||
filters: [new instance.web.search.CustomFilters(self.view)],
|
|
||||||
length: 1
|
|
||||||
});
|
|
||||||
return $.when(
|
return $.when(
|
||||||
this.render_column(col1, $('<div>').appendTo(this.$element)),
|
this.render_column(col1, $('<div>').appendTo(this.$element)),
|
||||||
this.render_column(col2, $('<div>').appendTo(this.$element)));
|
this.render_column(col2, $('<div>').appendTo(this.$element)));
|
||||||
|
|
|
@ -1471,7 +1471,7 @@
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
<div t-name="SearchView.CustomFilters" class="oe_searchview_custom">
|
<div t-name="SearchView.CustomFilters" class="oe_searchview_custom">
|
||||||
<div class="oe_searchview_custom_list"/>
|
<ul class="oe_searchview_custom_list"/>
|
||||||
<form>
|
<form>
|
||||||
<label for="oe_searchview_custom_input">Save current search:</label>
|
<label for="oe_searchview_custom_input">Save current search:</label>
|
||||||
<input id="oe_searchview_custom_input"/>
|
<input id="oe_searchview_custom_input"/>
|
||||||
|
|
Loading…
Reference in New Issue