2011-09-05 11:03:09 +00:00
|
|
|
openerp.web.search = function(openerp) {
|
2011-11-14 10:12:21 +00:00
|
|
|
var QWeb = openerp.web.qweb,
|
2011-12-20 17:51:37 +00:00
|
|
|
_t = openerp.web._t,
|
|
|
|
_lt = openerp.web._lt;
|
2011-03-29 13:18:54 +00:00
|
|
|
|
2012-03-19 16:43:04 +00:00
|
|
|
// Have SearchBox optionally use callback function to produce inputs and facets
|
|
|
|
// (views) set on callbacks.make_facet and callbacks.make_input keys when
|
|
|
|
// initializing VisualSearch
|
|
|
|
var SearchBox_renderFacet = function (facet, position) {
|
|
|
|
var view = new (this.app.options.callbacks['make_facet'] || VS.ui.SearchFacet)({
|
|
|
|
app : this.app,
|
|
|
|
model : facet,
|
|
|
|
order : position
|
|
|
|
});
|
|
|
|
|
|
|
|
// Input first, facet second.
|
|
|
|
this.renderSearchInput();
|
|
|
|
this.facetViews.push(view);
|
|
|
|
this.$('.VS-search-inner').children().eq(position*2).after(view.render().el);
|
|
|
|
|
|
|
|
view.calculateSize();
|
|
|
|
_.defer(_.bind(view.calculateSize, view));
|
|
|
|
|
|
|
|
return view;
|
|
|
|
}; // warning: will not match
|
|
|
|
// Ensure we're replacing the function we think
|
|
|
|
if (SearchBox_renderFacet.toString() !== VS.ui.SearchBox.prototype.renderFacet.toString().replace(/(VS\.ui\.SearchFacet)/, "(this.app.options.callbacks['make_facet'] || $1)")) {
|
|
|
|
throw new Error(
|
|
|
|
"Trying to replace wrong version of VS.ui.SearchBox#renderFacet. "
|
|
|
|
+ "Please fix replacement.");
|
|
|
|
}
|
|
|
|
var SearchBox_renderSearchInput = function () {
|
|
|
|
var input = new (this.app.options.callbacks['make_input'] || VS.ui.SearchInput)({position: this.inputViews.length, app: this.app});
|
|
|
|
this.$('.VS-search-inner').append(input.render().el);
|
|
|
|
this.inputViews.push(input);
|
|
|
|
};
|
|
|
|
// Ensure we're replacing the function we think
|
|
|
|
if (SearchBox_renderSearchInput.toString() !== VS.ui.SearchBox.prototype.renderSearchInput.toString().replace(/(VS\.ui\.SearchInput)/, "(this.app.options.callbacks['make_input'] || $1)")) {
|
|
|
|
throw new Error(
|
|
|
|
"Trying to replace wrong version of VS.ui.SearchBox#renderSearchInput. "
|
|
|
|
+ "Please fix replacement.");
|
|
|
|
}
|
|
|
|
_.extend(VS.ui.SearchBox.prototype, {
|
|
|
|
renderFacet: SearchBox_renderFacet,
|
|
|
|
renderSearchInput: SearchBox_renderSearchInput
|
|
|
|
});
|
2012-03-16 11:16:08 +00:00
|
|
|
|
2012-03-09 13:51:22 +00:00
|
|
|
openerp.web.SearchView = openerp.web.Widget.extend(/** @lends openerp.web.SearchView# */{
|
2012-03-19 16:43:04 +00:00
|
|
|
template: "SearchView",
|
2011-09-12 12:06:04 +00:00
|
|
|
/**
|
|
|
|
* @constructs openerp.web.SearchView
|
2012-01-24 14:58:10 +00:00
|
|
|
* @extends openerp.web.OldWidget
|
2011-12-09 12:35:14 +00:00
|
|
|
*
|
2011-09-12 12:06:04 +00:00
|
|
|
* @param parent
|
|
|
|
* @param element_id
|
|
|
|
* @param dataset
|
|
|
|
* @param view_id
|
|
|
|
* @param defaults
|
|
|
|
*/
|
2011-09-28 15:13:06 +00:00
|
|
|
init: function(parent, dataset, view_id, defaults, hidden) {
|
2011-09-15 09:52:14 +00:00
|
|
|
this._super(parent);
|
2011-03-17 13:41:55 +00:00
|
|
|
this.dataset = dataset;
|
|
|
|
this.model = dataset.model;
|
|
|
|
this.view_id = view_id;
|
2011-03-24 16:18:42 +00:00
|
|
|
|
2011-03-25 10:34:25 +00:00
|
|
|
this.defaults = defaults || {};
|
2011-09-28 15:13:06 +00:00
|
|
|
this.has_defaults = !_.isEmpty(this.defaults);
|
2011-03-25 10:34:25 +00:00
|
|
|
|
2011-03-24 16:18:42 +00:00
|
|
|
this.inputs = [];
|
2011-03-25 15:59:17 +00:00
|
|
|
this.enabled_filters = [];
|
2011-04-06 13:58:37 +00:00
|
|
|
|
|
|
|
this.has_focus = false;
|
2011-07-15 11:58:00 +00:00
|
|
|
|
2011-09-28 15:13:06 +00:00
|
|
|
this.hidden = !!hidden;
|
|
|
|
this.headless = this.hidden && !this.has_defaults;
|
|
|
|
|
2011-07-15 11:58:00 +00:00
|
|
|
this.ready = $.Deferred();
|
2011-03-17 13:41:55 +00:00
|
|
|
},
|
|
|
|
start: function() {
|
2012-03-09 13:51:22 +00:00
|
|
|
var p = this._super();
|
|
|
|
|
2012-03-19 16:43:04 +00:00
|
|
|
this.setup_global_completion();
|
|
|
|
this.vs = VS.init({
|
2012-03-09 13:51:22 +00:00
|
|
|
container: this.$element,
|
|
|
|
query: '',
|
|
|
|
callbacks: {
|
2012-03-19 16:43:04 +00:00
|
|
|
make_facet: this.proxy('make_visualsearch_facet'),
|
|
|
|
make_input: this.proxy('make_visualsearch_input'),
|
2012-03-09 13:51:22 +00:00
|
|
|
search: function (query, searchCollection) {
|
|
|
|
console.log(query, searchCollection);
|
|
|
|
},
|
|
|
|
facetMatches: function (callback) {
|
|
|
|
},
|
|
|
|
valueMatches : function(facet, searchTerm, callback) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2011-09-28 15:13:06 +00:00
|
|
|
if (this.hidden) {
|
|
|
|
this.$element.hide();
|
|
|
|
}
|
|
|
|
if (this.headless) {
|
|
|
|
this.ready.resolve();
|
|
|
|
} else {
|
2011-11-16 13:38:03 +00:00
|
|
|
this.rpc("/web/searchview/load", {
|
|
|
|
model: this.model,
|
|
|
|
view_id: this.view_id,
|
|
|
|
context: this.dataset.get_context()
|
|
|
|
}, this.on_loaded);
|
2011-09-28 15:13:06 +00:00
|
|
|
}
|
2012-03-19 16:43:04 +00:00
|
|
|
return $.when(p, this.ready);
|
2011-03-17 13:41:55 +00:00
|
|
|
},
|
2011-04-01 10:45:00 +00:00
|
|
|
show: function () {
|
|
|
|
this.$element.show();
|
|
|
|
},
|
|
|
|
hide: function () {
|
|
|
|
this.$element.hide();
|
2011-03-17 13:41:55 +00:00
|
|
|
},
|
2012-03-19 16:43:04 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets up search view's view-wide auto-completion widget
|
|
|
|
*/
|
|
|
|
setup_global_completion: function () {
|
|
|
|
var self = this;
|
|
|
|
this.$element.autocomplete({
|
|
|
|
source: this.proxy('complete_global_search'),
|
|
|
|
select: this.proxy('select_completion'),
|
|
|
|
focus: function (e) { e.preventDefault(); },
|
|
|
|
html: true,
|
|
|
|
minLength: 0,
|
|
|
|
delay: 0
|
|
|
|
}).data('autocomplete')._renderItem = function (ul, item) {
|
|
|
|
// item of completion list
|
|
|
|
var $item = $( "<li></li>" )
|
|
|
|
.data( "item.autocomplete", item )
|
|
|
|
.appendTo( ul );
|
|
|
|
if (item.type === 'section') {
|
|
|
|
$item.text(item.label)
|
|
|
|
.css({
|
|
|
|
borderTop: '1px solid #cccccc',
|
|
|
|
margin: 0,
|
|
|
|
padding: 0,
|
|
|
|
zoom: 1,
|
|
|
|
'float': 'left',
|
|
|
|
clear: 'left',
|
|
|
|
width: '100%'
|
|
|
|
});
|
|
|
|
} else if (item.type === 'base') {
|
|
|
|
// FIXME: translation
|
|
|
|
$item.append("<a>Search for: \"<strong>" + item.value + "</strong>\"</a>");
|
|
|
|
} else {
|
|
|
|
$item.append($("<a>").text(item.label));
|
|
|
|
}
|
|
|
|
return $item;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
* Provide auto-completion result for req.term (an array to `resp`)
|
|
|
|
*
|
|
|
|
* @param {Object} req request to complete
|
|
|
|
* @param {String} req.term searched term to complete
|
|
|
|
* @param {Function} resp response callback
|
|
|
|
*/
|
|
|
|
complete_global_search: function (req, resp) {
|
|
|
|
var completion = [{value: req.term, type: 'base'}];
|
|
|
|
$.when.apply(null, _(this.inputs).chain()
|
|
|
|
.invoke('complete', req.term)
|
|
|
|
.value()).then(function () {
|
|
|
|
var results = completion.concat.apply(
|
|
|
|
completion, _(arguments).compact());
|
|
|
|
resp(results);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Action to perform in case of selection: create a facet (model)
|
|
|
|
* and add it to the search collection
|
|
|
|
*
|
|
|
|
* @param {Object} e selection event, preventDefault to avoid setting value on object
|
|
|
|
* @param {Object} ui selection information
|
|
|
|
* @param {Object} ui.item selected completion item
|
|
|
|
*/
|
|
|
|
select_completion: function (e, ui) {
|
|
|
|
e.preventDefault();
|
|
|
|
if (ui.item.type === 'base') {
|
|
|
|
this.vs.searchQuery.add(new VS.model.SearchFacet({
|
|
|
|
category: null,
|
|
|
|
value: ui.item.value,
|
|
|
|
app: this.vs
|
|
|
|
}));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.vs.searchQuery.add(new VS.model.SearchFacet({
|
|
|
|
category: ui.item.category,
|
|
|
|
value: ui.item.label,
|
|
|
|
real_value: ui.item.value,
|
|
|
|
app: this.vs
|
|
|
|
}));
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Builds the right SearchFacet view based on the facet object to render
|
|
|
|
* (e.g. readonly facets for filters)
|
|
|
|
*
|
|
|
|
* @param {Object} options
|
|
|
|
* @param {VS.model.SearchFacet} options.model facet object to render
|
|
|
|
*/
|
|
|
|
make_visualsearch_facet: function (options) {
|
|
|
|
return new VS.ui.SearchFacet(options);
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
* Proxies searches on a SearchInput to the search view's global completion
|
|
|
|
*
|
|
|
|
* Also disables SearchInput.autocomplete#_move so search view's
|
|
|
|
* autocomplete can get the corresponding events, or something.
|
|
|
|
*
|
|
|
|
* @param options
|
|
|
|
*/
|
|
|
|
make_visualsearch_input: function (options) {
|
|
|
|
var self = this, input = new VS.ui.SearchInput(options);
|
|
|
|
input.setupAutocomplete = function () {
|
|
|
|
this.box.autocomplete({
|
|
|
|
minLength: 1,
|
|
|
|
delay: 0,
|
|
|
|
search: function () {
|
|
|
|
self.$element.autocomplete('search', input.box.val());
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}).data('autocomplete')._move = function () {};
|
|
|
|
};
|
|
|
|
return input;
|
|
|
|
},
|
|
|
|
|
2011-03-24 12:46:53 +00:00
|
|
|
/**
|
|
|
|
* Builds a list of widget rows (each row is an array of widgets)
|
|
|
|
*
|
|
|
|
* @param {Array} items a list of nodes to convert to widgets
|
|
|
|
* @param {Object} fields a mapping of field names to (ORM) field attributes
|
2011-03-24 16:18:42 +00:00
|
|
|
* @returns Array
|
2011-03-24 12:46:53 +00:00
|
|
|
*/
|
|
|
|
make_widgets: function (items, fields) {
|
|
|
|
var rows = [],
|
|
|
|
row = [];
|
|
|
|
rows.push(row);
|
|
|
|
var filters = [];
|
|
|
|
_.each(items, function (item) {
|
|
|
|
if (filters.length && item.tag !== 'filter') {
|
|
|
|
row.push(
|
2011-09-05 11:03:09 +00:00
|
|
|
new openerp.web.search.FilterGroup(
|
2011-03-24 12:46:53 +00:00
|
|
|
filters, this));
|
|
|
|
filters = [];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (item.tag === 'newline') {
|
|
|
|
row = [];
|
|
|
|
rows.push(row);
|
|
|
|
} else if (item.tag === 'filter') {
|
2011-04-06 13:58:37 +00:00
|
|
|
if (!this.has_focus) {
|
|
|
|
item.attrs.default_focus = '1';
|
|
|
|
this.has_focus = true;
|
|
|
|
}
|
2011-03-24 12:46:53 +00:00
|
|
|
filters.push(
|
2011-09-05 11:03:09 +00:00
|
|
|
new openerp.web.search.Filter(
|
2011-03-24 12:46:53 +00:00
|
|
|
item, this));
|
|
|
|
} else if (item.tag === 'separator') {
|
|
|
|
// a separator is a no-op
|
|
|
|
} else {
|
|
|
|
if (item.tag === 'group') {
|
|
|
|
// TODO: group and field should be fetched from registries, maybe even filters
|
|
|
|
row.push(
|
2011-09-05 11:03:09 +00:00
|
|
|
new openerp.web.search.Group(
|
2011-03-24 12:46:53 +00:00
|
|
|
item, this, fields));
|
|
|
|
} else if (item.tag === 'field') {
|
2011-04-06 13:58:37 +00:00
|
|
|
if (!this.has_focus) {
|
|
|
|
item.attrs.default_focus = '1';
|
|
|
|
this.has_focus = true;
|
|
|
|
}
|
2011-03-24 12:46:53 +00:00
|
|
|
row.push(
|
|
|
|
this.make_field(
|
|
|
|
item, fields[item['attrs'].name]));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}, this);
|
2011-03-24 17:39:26 +00:00
|
|
|
if (filters.length) {
|
2011-09-05 11:03:09 +00:00
|
|
|
row.push(new openerp.web.search.FilterGroup(filters, this));
|
2011-03-24 17:39:26 +00:00
|
|
|
}
|
|
|
|
|
2011-03-24 12:46:53 +00:00
|
|
|
return rows;
|
2011-03-17 13:41:55 +00:00
|
|
|
},
|
2011-03-24 12:46:53 +00:00
|
|
|
/**
|
2011-03-24 16:18:42 +00:00
|
|
|
* Creates a field for the provided field descriptor item (which comes
|
|
|
|
* from fields_view_get)
|
2011-03-24 12:46:53 +00:00
|
|
|
*
|
2011-03-24 16:18:42 +00:00
|
|
|
* @param {Object} item fields_view_get node for the field
|
|
|
|
* @param {Object} field fields_get result for the field
|
2011-09-05 11:03:09 +00:00
|
|
|
* @returns openerp.web.search.Field
|
2011-03-24 12:46:53 +00:00
|
|
|
*/
|
|
|
|
make_field: function (item, field) {
|
2011-03-31 10:40:12 +00:00
|
|
|
try {
|
[FIX] m2o fields with selection widget in search view
Plan was originally to just ignore this because "it should just work"
but turns out m2o and m2o[@widget=selection] fields have very
different behaviors when it comes to default values, especially
custom domains and contexts:
* An m2o field uses its string value always (behaves like a char
field), for UI and clarity purposes we added an [[name, '=', id]]
case when the user specifically selects an autocompletion value,
but that's not "cannon", when it comes to dealing with custom
domains (filter_domain) and contexts the field always uses its
string value.
* An m2o[@widget=selection] field on the other hand uses its ids
always (behaves like a selection field).
That's not entirely true, really, because it has the converse to
what we implemented on the m2o field in the web client (in the GTK
client): if there is no @filter_domain *and* the user has entered a
value which is not in the dropdown (it's a combobox in the GTK
client), then it falls back on using 'ilike'. This string value is
*not* used in custom domains and custom filters, which simply are
not submitted.
This second section has *not* been implemented so far in the web
client, we'll come round to it if people actually need it.
bzr revid: xmo@openerp.com-20111006063949-fl5rbg3wwubcaay8
2011-10-06 06:39:49 +00:00
|
|
|
return new (openerp.web.search.fields.get_any(
|
|
|
|
[item.attrs.widget, field.type]))
|
|
|
|
(item, field, this);
|
2011-03-31 10:40:12 +00:00
|
|
|
} catch (e) {
|
2011-09-05 11:03:09 +00:00
|
|
|
if (! e instanceof openerp.web.KeyNotFound) {
|
2011-03-31 10:40:12 +00:00
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
// KeyNotFound means unknown field type
|
|
|
|
console.group('Unknown field type ' + field.type);
|
|
|
|
console.error('View node', item);
|
|
|
|
console.info('View field', field);
|
|
|
|
console.info('In view', this);
|
|
|
|
console.groupEnd();
|
|
|
|
return null;
|
2011-03-24 12:46:53 +00:00
|
|
|
}
|
|
|
|
},
|
2011-03-17 13:41:55 +00:00
|
|
|
on_loaded: function(data) {
|
2012-03-20 10:28:46 +00:00
|
|
|
var self = this;
|
2011-11-23 21:53:56 +00:00
|
|
|
this.fields_view = data.fields_view;
|
2011-11-14 12:39:48 +00:00
|
|
|
if (data.fields_view.type !== 'search' ||
|
|
|
|
data.fields_view.arch.tag !== 'search') {
|
2011-11-15 12:30:59 +00:00
|
|
|
throw new Error(_.str.sprintf(
|
2011-11-14 12:39:48 +00:00
|
|
|
"Got non-search view after asking for a search view: type %s, arch root %s",
|
|
|
|
data.fields_view.type, data.fields_view.arch.tag));
|
|
|
|
}
|
2012-03-19 16:43:04 +00:00
|
|
|
|
2012-03-20 10:28:46 +00:00
|
|
|
this.make_widgets(
|
2011-07-25 09:10:49 +00:00
|
|
|
data.fields_view['arch'].children,
|
|
|
|
data.fields_view.fields);
|
2011-03-17 13:41:55 +00:00
|
|
|
|
2012-03-20 10:28:46 +00:00
|
|
|
// load defaults
|
|
|
|
return $.when.apply(null, _(this.inputs).invoke('facet_for_defaults', this.defaults))
|
|
|
|
.then(function () {
|
|
|
|
self.vs.searchQuery.reset(_(arguments).compact());
|
|
|
|
self.ready.resolve();
|
|
|
|
});
|
2012-03-19 16:43:04 +00:00
|
|
|
|
2011-03-25 15:11:20 +00:00
|
|
|
// for extended search view
|
2011-09-05 11:03:09 +00:00
|
|
|
var ext = new openerp.web.search.ExtendedSearch(this, this.model);
|
2011-03-29 14:35:25 +00:00
|
|
|
lines.push([ext]);
|
2011-12-14 10:13:44 +00:00
|
|
|
this.extended_search = ext;
|
2011-12-09 12:35:14 +00:00
|
|
|
|
2011-03-25 10:51:51 +00:00
|
|
|
// start() all the widgets
|
2011-07-15 11:58:00 +00:00
|
|
|
var widget_starts = _(lines).chain().flatten().map(function (widget) {
|
|
|
|
return widget.start();
|
|
|
|
}).value();
|
2011-08-03 11:06:15 +00:00
|
|
|
|
2011-07-22 15:44:19 +00:00
|
|
|
$.when.apply(null, widget_starts).then(function () {
|
|
|
|
self.ready.resolve();
|
|
|
|
});
|
2011-12-09 12:35:14 +00:00
|
|
|
|
2011-07-25 11:37:40 +00:00
|
|
|
this.reload_managed_filters();
|
|
|
|
},
|
|
|
|
reload_managed_filters: function() {
|
|
|
|
var self = this;
|
2011-09-05 11:03:09 +00:00
|
|
|
return this.rpc('/web/searchview/get_filters', {
|
2011-07-22 15:35:05 +00:00
|
|
|
model: this.dataset.model
|
|
|
|
}).then(function(result) {
|
|
|
|
self.managed_filters = result;
|
2011-07-22 15:05:37 +00:00
|
|
|
var filters = self.$element.find(".oe_search-view-filters-management");
|
2012-02-14 14:29:54 +00:00
|
|
|
filters.html(QWeb.render("SearchView.managed-filters", {
|
|
|
|
filters: result,
|
|
|
|
disabled_filter_message: _t('Filter disabled due to invalid syntax')
|
|
|
|
}));
|
2011-07-22 15:05:37 +00:00
|
|
|
filters.change(self.on_filters_management);
|
|
|
|
});
|
2011-05-27 10:25:27 +00:00
|
|
|
},
|
|
|
|
/**
|
|
|
|
* Handle event when the user make a selection in the filters management select box.
|
|
|
|
*/
|
|
|
|
on_filters_management: function(e) {
|
2011-07-25 11:37:40 +00:00
|
|
|
var self = this;
|
2011-07-22 15:44:19 +00:00
|
|
|
var select = this.$element.find(".oe_search-view-filters-management");
|
|
|
|
var val = select.val();
|
2011-11-24 10:13:52 +00:00
|
|
|
switch(val) {
|
2011-12-14 10:13:44 +00:00
|
|
|
case 'advanced_filter':
|
|
|
|
this.extended_search.on_activate();
|
|
|
|
break;
|
2011-11-24 10:13:52 +00:00
|
|
|
case 'add_to_dashboard':
|
|
|
|
this.on_add_to_dashboard();
|
|
|
|
break;
|
|
|
|
case 'manage_filters':
|
|
|
|
this.do_action({
|
|
|
|
res_model: 'ir.filters',
|
|
|
|
views: [[false, 'list'], [false, 'form']],
|
|
|
|
type: 'ir.actions.act_window',
|
|
|
|
context: {"search_default_user_id": this.session.uid,
|
|
|
|
"search_default_model_id": this.dataset.model},
|
|
|
|
target: "current",
|
2011-12-06 11:36:58 +00:00
|
|
|
limit : 80
|
2011-11-24 10:13:52 +00:00
|
|
|
});
|
|
|
|
break;
|
|
|
|
case 'save_filter':
|
2011-07-25 11:37:40 +00:00
|
|
|
var data = this.build_search_data();
|
2011-09-05 11:03:09 +00:00
|
|
|
var context = new openerp.web.CompoundContext();
|
2011-07-25 11:37:40 +00:00
|
|
|
_.each(data.contexts, function(x) {
|
|
|
|
context.add(x);
|
|
|
|
});
|
2011-09-05 11:03:09 +00:00
|
|
|
var domain = new openerp.web.CompoundDomain();
|
2011-07-25 11:37:40 +00:00
|
|
|
_.each(data.domains, function(x) {
|
|
|
|
domain.add(x);
|
|
|
|
});
|
2012-01-06 16:25:33 +00:00
|
|
|
var groupbys = _.pluck(data.groupbys, "group_by").join();
|
|
|
|
context.add({"group_by": groupbys});
|
2011-07-25 11:37:40 +00:00
|
|
|
var dial_html = QWeb.render("SearchView.managed-filters.add");
|
|
|
|
var $dial = $(dial_html);
|
2012-02-17 11:43:57 +00:00
|
|
|
openerp.web.dialog($dial, {
|
2011-07-25 11:37:40 +00:00
|
|
|
modal: true,
|
2011-11-14 10:12:21 +00:00
|
|
|
title: _t("Filter Entry"),
|
|
|
|
buttons: [
|
|
|
|
{text: _t("Cancel"), click: function() {
|
2011-07-25 11:37:40 +00:00
|
|
|
$(this).dialog("close");
|
2011-11-14 10:12:21 +00:00
|
|
|
}},
|
|
|
|
{text: _t("OK"), click: function() {
|
2011-07-25 11:37:40 +00:00
|
|
|
$(this).dialog("close");
|
|
|
|
var name = $(this).find("input").val();
|
2011-09-05 11:03:09 +00:00
|
|
|
self.rpc('/web/searchview/save_filter', {
|
2011-07-25 11:37:40 +00:00
|
|
|
model: self.dataset.model,
|
|
|
|
context_to_save: context,
|
|
|
|
domain: domain,
|
|
|
|
name: name
|
2011-08-03 10:49:28 +00:00
|
|
|
}).then(function() {
|
2011-07-25 11:37:40 +00:00
|
|
|
self.reload_managed_filters();
|
|
|
|
});
|
2011-11-14 10:12:21 +00:00
|
|
|
}}
|
|
|
|
]
|
2011-07-25 11:37:40 +00:00
|
|
|
});
|
2011-11-24 10:13:52 +00:00
|
|
|
break;
|
2012-01-26 08:56:36 +00:00
|
|
|
case '':
|
|
|
|
this.do_clear();
|
2011-11-24 10:13:52 +00:00
|
|
|
}
|
|
|
|
if (val.slice(0, 4) == "get:") {
|
|
|
|
val = val.slice(4);
|
|
|
|
val = parseInt(val, 10);
|
|
|
|
var filter = this.managed_filters[val];
|
2012-01-26 09:23:04 +00:00
|
|
|
this.do_clear(false).then(_.bind(function() {
|
2012-01-26 08:55:26 +00:00
|
|
|
select.val('get:' + val);
|
2012-02-21 14:05:17 +00:00
|
|
|
|
|
|
|
var groupbys = [];
|
|
|
|
var group_by = filter.context.group_by;
|
|
|
|
if (group_by) {
|
|
|
|
groupbys = _.map(
|
|
|
|
group_by instanceof Array ? group_by : group_by.split(','),
|
|
|
|
function (el) { return { group_by: el }; });
|
|
|
|
}
|
2012-01-06 16:25:33 +00:00
|
|
|
this.on_search([filter.domain], [filter.context], groupbys);
|
2012-01-06 15:08:26 +00:00
|
|
|
}, this));
|
2011-11-24 10:21:30 +00:00
|
|
|
} else {
|
|
|
|
select.val('');
|
2011-05-27 10:25:27 +00:00
|
|
|
}
|
2011-03-17 13:41:55 +00:00
|
|
|
},
|
2011-11-23 21:53:56 +00:00
|
|
|
on_add_to_dashboard: function() {
|
|
|
|
this.$element.find(".oe_search-view-filters-management")[0].selectedIndex = 0;
|
|
|
|
var self = this,
|
|
|
|
menu = openerp.webclient.menu,
|
|
|
|
$dialog = $(QWeb.render("SearchView.add_to_dashboard", {
|
|
|
|
dashboards : menu.data.data.children,
|
|
|
|
selected_menu_id : menu.$element.find('a.active').data('menu')
|
|
|
|
}));
|
|
|
|
$dialog.find('input').val(this.fields_view.name);
|
2012-02-17 11:43:57 +00:00
|
|
|
openerp.web.dialog($dialog, {
|
2011-11-23 21:53:56 +00:00
|
|
|
modal: true,
|
|
|
|
title: _t("Add to Dashboard"),
|
|
|
|
buttons: [
|
|
|
|
{text: _t("Cancel"), click: function() {
|
|
|
|
$(this).dialog("close");
|
|
|
|
}},
|
|
|
|
{text: _t("OK"), click: function() {
|
|
|
|
$(this).dialog("close");
|
|
|
|
var menu_id = $(this).find("select").val(),
|
|
|
|
title = $(this).find("input").val(),
|
|
|
|
data = self.build_search_data(),
|
|
|
|
context = new openerp.web.CompoundContext(),
|
|
|
|
domain = new openerp.web.CompoundDomain();
|
|
|
|
_.each(data.contexts, function(x) {
|
|
|
|
context.add(x);
|
|
|
|
});
|
|
|
|
_.each(data.domains, function(x) {
|
|
|
|
domain.add(x);
|
|
|
|
});
|
|
|
|
self.rpc('/web/searchview/add_to_dashboard', {
|
|
|
|
menu_id: menu_id,
|
2012-02-21 15:30:23 +00:00
|
|
|
action_id: self.getParent().action.id,
|
2011-11-23 21:53:56 +00:00
|
|
|
context_to_save: context,
|
|
|
|
domain: domain,
|
2012-02-21 15:30:23 +00:00
|
|
|
view_mode: self.getParent().active_view,
|
2011-11-23 21:53:56 +00:00
|
|
|
name: title
|
|
|
|
}, function(r) {
|
|
|
|
if (r === false) {
|
|
|
|
self.do_warn("Could not add filter to dashboard");
|
|
|
|
} else {
|
|
|
|
self.do_notify("Filter added to dashboard", '');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}}
|
|
|
|
]
|
|
|
|
});
|
|
|
|
},
|
2011-03-29 10:47:44 +00:00
|
|
|
/**
|
|
|
|
* Performs the search view collection of widget data.
|
|
|
|
*
|
|
|
|
* If the collection went well (all fields are valid), then triggers
|
2011-09-05 11:03:09 +00:00
|
|
|
* :js:func:`openerp.web.SearchView.on_search`.
|
2011-03-29 10:47:44 +00:00
|
|
|
*
|
|
|
|
* If at least one field failed its validation, triggers
|
2011-09-05 11:03:09 +00:00
|
|
|
* :js:func:`openerp.web.SearchView.on_invalid` instead.
|
2011-03-29 10:47:44 +00:00
|
|
|
*
|
|
|
|
* @param e jQuery event object coming from the "Search" button
|
|
|
|
*/
|
2011-03-25 08:12:27 +00:00
|
|
|
do_search: function (e) {
|
2012-03-19 16:43:04 +00:00
|
|
|
console.log(this.vs.searchBox.value());
|
|
|
|
console.log(this.vs.searchQuery.facets());
|
2012-03-09 13:51:22 +00:00
|
|
|
return this.on_search([], [], []);
|
2012-03-19 16:43:04 +00:00
|
|
|
|
2011-09-28 15:13:06 +00:00
|
|
|
if (this.headless && !this.has_defaults) {
|
|
|
|
return this.on_search([], [], []);
|
|
|
|
}
|
2011-07-22 15:44:19 +00:00
|
|
|
// reset filters management
|
|
|
|
var select = this.$element.find(".oe_search-view-filters-management");
|
|
|
|
select.val("_filters");
|
2011-09-28 15:13:06 +00:00
|
|
|
|
2011-03-25 10:51:51 +00:00
|
|
|
if (e && e.preventDefault) { e.preventDefault(); }
|
2011-04-07 23:41:30 +00:00
|
|
|
|
2011-07-25 11:37:40 +00:00
|
|
|
var data = this.build_search_data();
|
|
|
|
|
|
|
|
if (data.errors.length) {
|
|
|
|
this.on_invalid(data.errors);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.on_search(data.domains, data.contexts, data.groupbys);
|
|
|
|
},
|
|
|
|
build_search_data: function() {
|
2011-07-15 08:01:45 +00:00
|
|
|
var domains = [],
|
|
|
|
contexts = [],
|
|
|
|
errors = [];
|
2011-04-07 23:41:30 +00:00
|
|
|
|
2011-03-29 10:47:44 +00:00
|
|
|
_.each(this.inputs, function (input) {
|
|
|
|
try {
|
|
|
|
var domain = input.get_domain();
|
|
|
|
if (domain) {
|
|
|
|
domains.push(domain);
|
|
|
|
}
|
|
|
|
|
|
|
|
var context = input.get_context();
|
|
|
|
if (context) {
|
|
|
|
contexts.push(context);
|
|
|
|
}
|
|
|
|
} catch (e) {
|
2011-09-05 11:03:09 +00:00
|
|
|
if (e instanceof openerp.web.search.Invalid) {
|
2011-03-29 10:47:44 +00:00
|
|
|
errors.push(e);
|
|
|
|
} else {
|
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2011-03-24 16:18:42 +00:00
|
|
|
|
2011-03-28 16:39:17 +00:00
|
|
|
// TODO: do we need to handle *fields* with group_by in their context?
|
|
|
|
var groupbys = _(this.enabled_filters)
|
|
|
|
.chain()
|
|
|
|
.map(function (filter) { return filter.get_context();})
|
|
|
|
.compact()
|
|
|
|
.value();
|
2011-07-25 11:37:40 +00:00
|
|
|
return {domains: domains, contexts: contexts, errors: errors, groupbys: groupbys};
|
2011-03-24 16:18:42 +00:00
|
|
|
},
|
2011-03-25 08:12:27 +00:00
|
|
|
/**
|
2011-03-29 10:47:44 +00:00
|
|
|
* Triggered after the SearchView has collected all relevant domains and
|
|
|
|
* contexts.
|
2011-03-25 08:12:27 +00:00
|
|
|
*
|
|
|
|
* It is provided with an Array of domains and an Array of contexts, which
|
|
|
|
* may or may not be evaluated (each item can be either a valid domain or
|
|
|
|
* context, or a string to evaluate in order in the sequence)
|
|
|
|
*
|
2011-03-29 10:47:44 +00:00
|
|
|
* It is also passed an array of contexts used for group_by (they are in
|
|
|
|
* the correct order for group_by evaluation, which contexts may not be)
|
|
|
|
*
|
|
|
|
* @event
|
2011-03-28 16:39:17 +00:00
|
|
|
* @param {Array} domains an array of literal domains or domain references
|
|
|
|
* @param {Array} contexts an array of literal contexts or context refs
|
|
|
|
* @param {Array} groupbys ordered contexts which may or may not have group_by keys
|
2011-03-25 08:12:27 +00:00
|
|
|
*/
|
2011-04-07 23:41:30 +00:00
|
|
|
on_search: function (domains, contexts, groupbys) {
|
|
|
|
},
|
2011-03-29 10:47:44 +00:00
|
|
|
/**
|
|
|
|
* Triggered after a validation error in the SearchView fields.
|
|
|
|
*
|
|
|
|
* Error objects have three keys:
|
|
|
|
* * ``field`` is the name of the invalid field
|
|
|
|
* * ``value`` is the invalid value
|
|
|
|
* * ``message`` is the (in)validation message provided by the field
|
|
|
|
*
|
|
|
|
* @event
|
|
|
|
* @param {Array} errors a never-empty array of error objects
|
|
|
|
*/
|
2011-04-07 23:41:30 +00:00
|
|
|
on_invalid: function (errors) {
|
2011-11-14 10:12:21 +00:00
|
|
|
this.do_notify(_t("Invalid Search"), _t("triggered from search view"));
|
2011-04-07 23:41:30 +00:00
|
|
|
},
|
2012-01-26 09:23:04 +00:00
|
|
|
/**
|
|
|
|
* @param {Boolean} [reload_view=true]
|
|
|
|
*/
|
|
|
|
do_clear: function (reload_view) {
|
2011-10-06 15:23:32 +00:00
|
|
|
this.$element.find('.filter_label, .filter_icon').removeClass('enabled');
|
2011-09-20 13:19:45 +00:00
|
|
|
this.enabled_filters.splice(0);
|
2011-09-01 14:52:24 +00:00
|
|
|
var string = $('a.searchview_group_string');
|
2011-08-12 06:03:06 +00:00
|
|
|
_.each(string, function(str){
|
|
|
|
$(str).closest('div.searchview_group').removeClass("expanded").addClass('folded');
|
|
|
|
});
|
|
|
|
this.$element.find('table:last').hide();
|
2011-08-29 12:19:43 +00:00
|
|
|
|
2011-08-04 11:09:22 +00:00
|
|
|
$('.searchview_extended_groups_list').empty();
|
2012-02-10 15:52:35 +00:00
|
|
|
return $.async_when.apply(
|
|
|
|
null, _(this.inputs).invoke('clear')).pipe(
|
|
|
|
reload_view !== false ? this.on_clear : null);
|
2011-03-25 08:12:27 +00:00
|
|
|
},
|
|
|
|
/**
|
2011-03-29 10:47:44 +00:00
|
|
|
* Triggered when the search view gets cleared
|
|
|
|
*
|
|
|
|
* @event
|
2011-03-25 08:12:27 +00:00
|
|
|
*/
|
2011-09-01 14:52:24 +00:00
|
|
|
on_clear: function () {
|
|
|
|
this.do_search();
|
|
|
|
},
|
2011-03-25 15:59:17 +00:00
|
|
|
/**
|
|
|
|
* Called by a filter propagating its state changes
|
|
|
|
*
|
2011-09-05 11:03:09 +00:00
|
|
|
* @param {openerp.web.search.Filter} filter a filter which got toggled
|
2011-03-25 15:59:17 +00:00
|
|
|
* @param {Boolean} default_enabled filter got enabled through the default values, at render time.
|
|
|
|
*/
|
|
|
|
do_toggle_filter: function (filter, default_enabled) {
|
|
|
|
if (default_enabled || filter.is_enabled()) {
|
|
|
|
this.enabled_filters.push(filter);
|
|
|
|
} else {
|
|
|
|
this.enabled_filters = _.without(
|
|
|
|
this.enabled_filters, filter);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!default_enabled) {
|
|
|
|
// selecting a filter after initial loading automatically
|
|
|
|
// triggers refresh
|
|
|
|
this.$element.find('form').submit();
|
|
|
|
}
|
2011-03-17 13:41:55 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2011-03-31 10:40:12 +00:00
|
|
|
/** @namespace */
|
2011-09-05 11:03:09 +00:00
|
|
|
openerp.web.search = {};
|
2011-03-31 10:40:12 +00:00
|
|
|
/**
|
2011-09-05 11:03:09 +00:00
|
|
|
* Registry of search fields, called by :js:class:`openerp.web.SearchView` to
|
2011-03-31 10:40:12 +00:00
|
|
|
* find and instantiate its field widgets.
|
|
|
|
*/
|
2011-09-05 11:03:09 +00:00
|
|
|
openerp.web.search.fields = new openerp.web.Registry({
|
|
|
|
'char': 'openerp.web.search.CharField',
|
|
|
|
'text': 'openerp.web.search.CharField',
|
|
|
|
'boolean': 'openerp.web.search.BooleanField',
|
|
|
|
'integer': 'openerp.web.search.IntegerField',
|
2012-01-31 14:02:10 +00:00
|
|
|
'id': 'openerp.web.search.IntegerField',
|
2011-09-05 11:03:09 +00:00
|
|
|
'float': 'openerp.web.search.FloatField',
|
|
|
|
'selection': 'openerp.web.search.SelectionField',
|
|
|
|
'datetime': 'openerp.web.search.DateTimeField',
|
|
|
|
'date': 'openerp.web.search.DateField',
|
|
|
|
'many2one': 'openerp.web.search.ManyToOneField',
|
|
|
|
'many2many': 'openerp.web.search.CharField',
|
|
|
|
'one2many': 'openerp.web.search.CharField'
|
2011-03-31 10:40:12 +00:00
|
|
|
});
|
2011-09-05 11:03:09 +00:00
|
|
|
openerp.web.search.Invalid = openerp.web.Class.extend( /** @lends openerp.web.search.Invalid# */{
|
2011-03-30 15:27:36 +00:00
|
|
|
/**
|
|
|
|
* Exception thrown by search widgets when they hold invalid values,
|
|
|
|
* which they can not return when asked.
|
|
|
|
*
|
2011-09-12 11:34:37 +00:00
|
|
|
* @constructs openerp.web.search.Invalid
|
|
|
|
* @extends openerp.web.Class
|
|
|
|
*
|
2011-03-30 15:27:36 +00:00
|
|
|
* @param field the name of the field holding an invalid value
|
|
|
|
* @param value the invalid value
|
|
|
|
* @param message validation failure message
|
|
|
|
*/
|
2011-03-24 17:37:21 +00:00
|
|
|
init: function (field, value, message) {
|
|
|
|
this.field = field;
|
|
|
|
this.value = value;
|
|
|
|
this.message = message;
|
|
|
|
},
|
|
|
|
toString: function () {
|
2011-11-15 12:30:59 +00:00
|
|
|
return _.str.sprintf(
|
2011-11-14 10:12:21 +00:00
|
|
|
_t("Incorrect value for field %(fieldname)s: [%(value)s] is %(message)s"),
|
|
|
|
{fieldname: this.field, value: this.value, message: this.message}
|
|
|
|
);
|
2011-03-24 17:37:21 +00:00
|
|
|
}
|
|
|
|
});
|
2012-01-24 14:58:10 +00:00
|
|
|
openerp.web.search.Widget = openerp.web.OldWidget.extend( /** @lends openerp.web.search.Widget# */{
|
2011-03-30 15:27:36 +00:00
|
|
|
template: null,
|
|
|
|
/**
|
|
|
|
* Root class of all search widgets
|
|
|
|
*
|
2011-09-12 11:34:37 +00:00
|
|
|
* @constructs openerp.web.search.Widget
|
2012-01-24 14:58:10 +00:00
|
|
|
* @extends openerp.web.OldWidget
|
2011-03-30 15:27:36 +00:00
|
|
|
*
|
|
|
|
* @param view the ancestor view of this widget
|
|
|
|
*/
|
2011-03-24 12:46:53 +00:00
|
|
|
init: function (view) {
|
2011-11-02 11:11:05 +00:00
|
|
|
this._super(view);
|
2011-03-24 12:46:53 +00:00
|
|
|
this.view = view;
|
2011-03-17 13:41:55 +00:00
|
|
|
},
|
2011-03-24 16:18:42 +00:00
|
|
|
/**
|
|
|
|
* Sets and returns a globally unique identifier for the widget.
|
|
|
|
*
|
2011-03-28 19:48:09 +00:00
|
|
|
* If a prefix is specified, the identifier will be appended to it.
|
2011-03-24 16:18:42 +00:00
|
|
|
*
|
2011-03-28 19:48:09 +00:00
|
|
|
* @params prefix prefix sections, empty/falsy sections will be removed
|
2011-03-24 16:18:42 +00:00
|
|
|
*/
|
|
|
|
make_id: function () {
|
|
|
|
this.element_id = _.uniqueId(
|
|
|
|
['search'].concat(
|
|
|
|
_.compact(_.toArray(arguments)),
|
|
|
|
['']).join('_'));
|
|
|
|
return this.element_id;
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
* "Starts" the widgets. Called at the end of the rendering, this allows
|
|
|
|
* widgets to hook themselves to their view sections.
|
|
|
|
*
|
|
|
|
* On widgets, if they kept a reference to a view and have an element_id,
|
|
|
|
* will fetch and set their root element on $element.
|
|
|
|
*/
|
|
|
|
start: function () {
|
|
|
|
this._super();
|
|
|
|
if (this.view && this.element_id) {
|
|
|
|
// id is unique, and no getElementById on elements
|
|
|
|
this.$element = $(document.getElementById(
|
|
|
|
this.element_id));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
* "Stops" the widgets. Called when the view destroys itself, this
|
|
|
|
* lets the widgets clean up after themselves.
|
|
|
|
*/
|
2012-02-21 16:29:12 +00:00
|
|
|
destroy: function () {
|
2011-03-24 16:18:42 +00:00
|
|
|
delete this.view;
|
|
|
|
this._super();
|
2011-03-17 13:41:55 +00:00
|
|
|
}
|
2011-03-24 12:46:53 +00:00
|
|
|
});
|
2011-09-05 11:03:09 +00:00
|
|
|
openerp.web.search.add_expand_listener = function($root) {
|
2011-03-30 15:04:21 +00:00
|
|
|
$root.find('a.searchview_group_string').click(function (e) {
|
2011-03-28 07:37:22 +00:00
|
|
|
$root.toggleClass('folded expanded');
|
|
|
|
e.stopPropagation();
|
|
|
|
e.preventDefault();
|
|
|
|
});
|
|
|
|
};
|
2011-09-05 11:03:09 +00:00
|
|
|
openerp.web.search.Group = openerp.web.search.Widget.extend({
|
2011-03-24 12:46:53 +00:00
|
|
|
template: 'SearchView.group',
|
|
|
|
init: function (view_section, view, fields) {
|
|
|
|
this._super(view);
|
|
|
|
this.attrs = view_section.attrs;
|
|
|
|
this.lines = view.make_widgets(
|
|
|
|
view_section.children, fields);
|
2011-03-24 16:18:42 +00:00
|
|
|
this.make_id('group');
|
|
|
|
},
|
|
|
|
start: function () {
|
|
|
|
this._super();
|
2011-09-05 11:03:09 +00:00
|
|
|
openerp.web.search.add_expand_listener(this.$element);
|
2011-08-03 11:06:15 +00:00
|
|
|
var widget_starts = _(this.lines).chain().flatten()
|
|
|
|
.map(function (widget) { return widget.start(); })
|
|
|
|
.value();
|
|
|
|
return $.when.apply(null, widget_starts);
|
2011-03-24 16:18:42 +00:00
|
|
|
}
|
|
|
|
});
|
2011-03-29 13:18:54 +00:00
|
|
|
|
2011-09-05 11:03:09 +00:00
|
|
|
openerp.web.search.Input = openerp.web.search.Widget.extend( /** @lends openerp.web.search.Input# */{
|
2011-03-30 15:27:36 +00:00
|
|
|
/**
|
2011-09-12 11:34:37 +00:00
|
|
|
* @constructs openerp.web.search.Input
|
2011-09-05 11:03:09 +00:00
|
|
|
* @extends openerp.web.search.Widget
|
2011-03-30 15:27:36 +00:00
|
|
|
*
|
|
|
|
* @param view
|
|
|
|
*/
|
2011-03-24 16:18:42 +00:00
|
|
|
init: function (view) {
|
|
|
|
this._super(view);
|
|
|
|
this.view.inputs.push(this);
|
2011-12-16 15:11:08 +00:00
|
|
|
this.style = undefined;
|
2011-03-24 16:18:42 +00:00
|
|
|
},
|
2012-03-19 16:43:04 +00:00
|
|
|
/**
|
|
|
|
* Fetch auto-completion values for the widget.
|
|
|
|
*
|
|
|
|
* The completion values should be an array of objects with keys category,
|
|
|
|
* label, value prefixed with an object with keys type=section and label
|
|
|
|
*
|
|
|
|
* @param {String} value value to complete
|
2012-03-20 10:28:46 +00:00
|
|
|
* @returns {jQuery.Deferred<null|Array>}
|
2012-03-19 16:43:04 +00:00
|
|
|
*/
|
|
|
|
complete: function (value) {
|
|
|
|
return $.when(null)
|
|
|
|
},
|
2012-03-20 10:28:46 +00:00
|
|
|
/**
|
|
|
|
* Returns a VS.model.SearchFacet instance for the provided defaults if
|
|
|
|
* they apply to this widget, or null if they don't.
|
|
|
|
*
|
|
|
|
* This default implementation will try calling
|
|
|
|
* :js:func:`openerp.web.search.Input#facet_for` if the widget's name
|
|
|
|
* matches the input key
|
|
|
|
*
|
|
|
|
* @param {Object} defaults
|
|
|
|
* @returns {jQuery.Deferred<null|Object>}
|
|
|
|
*/
|
|
|
|
facet_for_defaults: function (defaults) {
|
|
|
|
if (!this.attrs ||
|
|
|
|
!(this.attrs.name in defaults && defaults[this.attrs.name])) {
|
|
|
|
return $.when(null);
|
|
|
|
}
|
|
|
|
return this.facet_for(defaults[this.attrs.name]);
|
|
|
|
},
|
2011-03-24 16:18:42 +00:00
|
|
|
get_context: function () {
|
|
|
|
throw new Error(
|
|
|
|
"get_context not implemented for widget " + this.attrs.type);
|
|
|
|
},
|
|
|
|
get_domain: function () {
|
|
|
|
throw new Error(
|
|
|
|
"get_domain not implemented for widget " + this.attrs.type);
|
2011-12-16 15:11:08 +00:00
|
|
|
},
|
|
|
|
load_attrs: function (attrs) {
|
|
|
|
if (attrs.modifiers) {
|
|
|
|
attrs.modifiers = JSON.parse(attrs.modifiers);
|
|
|
|
attrs.invisible = attrs.modifiers.invisible || false;
|
|
|
|
if (attrs.invisible) {
|
|
|
|
this.style = 'display: none;'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.attrs = attrs;
|
2012-02-10 15:52:35 +00:00
|
|
|
},
|
|
|
|
/**
|
|
|
|
* Specific clearing operations, if any
|
|
|
|
*/
|
|
|
|
clear: function () {}
|
2011-03-24 12:46:53 +00:00
|
|
|
});
|
2011-09-15 08:46:26 +00:00
|
|
|
openerp.web.search.FilterGroup = openerp.web.search.Input.extend(/** @lends openerp.web.search.FilterGroup# */{
|
|
|
|
template: 'SearchView.filters',
|
|
|
|
/**
|
|
|
|
* Inclusive group of filters, creates a continuous "button" with clickable
|
|
|
|
* sections (the normal display for filters is to be a self-contained button)
|
|
|
|
*
|
|
|
|
* @constructs openerp.web.search.FilterGroup
|
|
|
|
* @extends openerp.web.search.Input
|
|
|
|
*
|
|
|
|
* @param {Array<openerp.web.search.Filter>} filters elements of the group
|
|
|
|
* @param {openerp.web.SearchView} view view in which the filters are contained
|
|
|
|
*/
|
|
|
|
init: function (filters, view) {
|
|
|
|
this._super(view);
|
|
|
|
this.filters = filters;
|
|
|
|
this.length = filters.length;
|
|
|
|
},
|
|
|
|
start: function () {
|
|
|
|
this._super();
|
|
|
|
_.each(this.filters, function (filter) {
|
|
|
|
filter.start();
|
|
|
|
});
|
|
|
|
},
|
|
|
|
get_context: function () { },
|
|
|
|
/**
|
|
|
|
* Handles domains-fetching for all the filters within it: groups them.
|
|
|
|
*/
|
|
|
|
get_domain: function () {
|
|
|
|
var domains = _(this.filters).chain()
|
|
|
|
.filter(function (filter) { return filter.is_enabled(); })
|
|
|
|
.map(function (filter) { return filter.attrs.domain; })
|
2011-09-20 13:46:07 +00:00
|
|
|
.reject(_.isEmpty)
|
2011-09-15 08:46:26 +00:00
|
|
|
.value();
|
|
|
|
|
|
|
|
if (!domains.length) { return; }
|
|
|
|
if (domains.length === 1) { return domains[0]; }
|
|
|
|
for (var i=domains.length; --i;) {
|
|
|
|
domains.unshift(['|']);
|
|
|
|
}
|
|
|
|
return _.extend(new openerp.web.CompoundDomain(), {
|
|
|
|
__domains: domains
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
2011-09-12 12:06:04 +00:00
|
|
|
openerp.web.search.Filter = openerp.web.search.Input.extend(/** @lends openerp.web.search.Filter# */{
|
2011-03-24 16:18:42 +00:00
|
|
|
template: 'SearchView.filter',
|
2011-09-12 12:06:04 +00:00
|
|
|
/**
|
|
|
|
* Implementation of the OpenERP filters (button with a context and/or
|
|
|
|
* a domain sent as-is to the search view)
|
|
|
|
*
|
|
|
|
* @constructs openerp.web.search.Filter
|
|
|
|
* @extends openerp.web.search.Input
|
|
|
|
*
|
|
|
|
* @param node
|
|
|
|
* @param view
|
|
|
|
*/
|
2011-03-24 16:18:42 +00:00
|
|
|
init: function (node, view) {
|
|
|
|
this._super(view);
|
2011-12-16 15:11:08 +00:00
|
|
|
this.load_attrs(node.attrs);
|
2011-03-25 10:34:25 +00:00
|
|
|
this.classes = [this.attrs.string ? 'filter_label' : 'filter_icon'];
|
2011-03-24 16:18:42 +00:00
|
|
|
this.make_id('filter', this.attrs.name);
|
|
|
|
},
|
|
|
|
start: function () {
|
|
|
|
this._super();
|
2011-03-25 15:59:17 +00:00
|
|
|
var self = this;
|
2011-04-04 13:47:05 +00:00
|
|
|
this.$element.click(function (e) {
|
2011-03-24 16:18:42 +00:00
|
|
|
$(this).toggleClass('enabled');
|
2011-03-25 15:59:17 +00:00
|
|
|
self.view.do_toggle_filter(self);
|
2011-03-24 16:18:42 +00:00
|
|
|
});
|
2011-03-24 16:23:35 +00:00
|
|
|
},
|
2011-03-25 10:34:25 +00:00
|
|
|
/**
|
|
|
|
* If the filter is present in the defaults (and has a truthy value),
|
|
|
|
* enable the filter.
|
|
|
|
*
|
|
|
|
* @param {Object} defaults the search view's default values
|
|
|
|
*/
|
2012-03-20 10:28:46 +00:00
|
|
|
facet_for: function (value) {
|
|
|
|
return $.when(new VS.model.SearchFacet({
|
|
|
|
category: this.attrs.string || this.attrs.name,
|
|
|
|
value: 'true',
|
|
|
|
app: this.view.vs
|
|
|
|
}));
|
2011-03-25 10:34:25 +00:00
|
|
|
},
|
2011-03-24 16:23:35 +00:00
|
|
|
get_context: function () {
|
2011-03-25 15:59:17 +00:00
|
|
|
if (!this.is_enabled()) {
|
2011-03-24 16:23:35 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
return this.attrs.context;
|
|
|
|
},
|
2011-09-15 08:46:26 +00:00
|
|
|
/**
|
|
|
|
* Does not return anything: filter domain is handled at the FilterGroup
|
|
|
|
* level
|
|
|
|
*/
|
|
|
|
get_domain: function () { }
|
2011-03-24 16:18:42 +00:00
|
|
|
});
|
2011-09-05 11:03:09 +00:00
|
|
|
openerp.web.search.Field = openerp.web.search.Input.extend( /** @lends openerp.web.search.Field# */ {
|
2011-03-24 12:46:53 +00:00
|
|
|
template: 'SearchView.field',
|
2011-03-24 17:37:21 +00:00
|
|
|
default_operator: '=',
|
2011-03-30 15:27:36 +00:00
|
|
|
/**
|
2011-09-12 11:34:37 +00:00
|
|
|
* @constructs openerp.web.search.Field
|
2011-09-05 11:03:09 +00:00
|
|
|
* @extends openerp.web.search.Input
|
2011-03-30 15:27:36 +00:00
|
|
|
*
|
|
|
|
* @param view_section
|
|
|
|
* @param field
|
|
|
|
* @param view
|
|
|
|
*/
|
2011-03-24 12:46:53 +00:00
|
|
|
init: function (view_section, field, view) {
|
|
|
|
this._super(view);
|
2011-12-16 15:11:08 +00:00
|
|
|
this.load_attrs(_.extend({}, field, view_section.attrs));
|
2011-12-16 14:36:07 +00:00
|
|
|
this.filters = new openerp.web.search.FilterGroup(_.compact(_.map(
|
2011-03-24 14:23:30 +00:00
|
|
|
view_section.children, function (filter_node) {
|
2011-10-17 13:41:03 +00:00
|
|
|
if (filter_node.attrs.string &&
|
|
|
|
typeof console !== 'undefined' && console.debug) {
|
|
|
|
console.debug("Filter-in-field with a 'string' attribute "
|
|
|
|
+ "in view", view);
|
|
|
|
}
|
|
|
|
delete filter_node.attrs.string;
|
2011-09-05 11:03:09 +00:00
|
|
|
return new openerp.web.search.Filter(
|
2011-03-24 14:23:30 +00:00
|
|
|
filter_node, view);
|
2011-12-16 14:36:07 +00:00
|
|
|
})), view);
|
2011-03-24 16:18:42 +00:00
|
|
|
this.make_id('input', field.type, this.attrs.name);
|
|
|
|
},
|
2012-03-20 10:28:46 +00:00
|
|
|
facet_for: function (value) {
|
|
|
|
return $.when(new VS.model.SearchFacet({
|
|
|
|
category: this.attrs.name,
|
|
|
|
value: String(value),
|
|
|
|
app: this.view.vs
|
|
|
|
}));
|
|
|
|
},
|
2011-03-24 16:18:42 +00:00
|
|
|
start: function () {
|
|
|
|
this._super();
|
|
|
|
this.filters.start();
|
2011-03-24 17:37:21 +00:00
|
|
|
},
|
|
|
|
get_context: function () {
|
2011-03-24 18:00:28 +00:00
|
|
|
var val = this.get_value();
|
|
|
|
// A field needs a value to be "active", and a context to send when
|
|
|
|
// active
|
2011-03-24 18:47:13 +00:00
|
|
|
var has_value = (val !== null && val !== '');
|
2011-03-29 09:09:41 +00:00
|
|
|
var context = this.attrs.context;
|
|
|
|
if (!(has_value && context)) {
|
2011-03-24 17:37:21 +00:00
|
|
|
return;
|
|
|
|
}
|
2011-03-29 09:09:41 +00:00
|
|
|
return _.extend(
|
|
|
|
{}, context,
|
|
|
|
{own_values: {self: val}});
|
2011-03-24 17:37:21 +00:00
|
|
|
},
|
2011-08-24 14:52:05 +00:00
|
|
|
/**
|
|
|
|
* Function creating the returned domain for the field, override this
|
|
|
|
* methods in children if you only need to customize the field's domain
|
|
|
|
* without more complex alterations or tests (and without the need to
|
|
|
|
* change override the handling of filter_domain)
|
|
|
|
*
|
|
|
|
* @param {String} name the field's name
|
|
|
|
* @param {String} operator the field's operator (either attribute-specified or default operator for the field
|
|
|
|
* @param {Number|String} value parsed value for the field
|
|
|
|
* @returns {Array<Array>} domain to include in the resulting search
|
|
|
|
*/
|
|
|
|
make_domain: function (name, operator, value) {
|
|
|
|
return [[name, operator, value]];
|
|
|
|
},
|
2011-03-24 17:37:21 +00:00
|
|
|
get_domain: function () {
|
2011-03-24 18:00:28 +00:00
|
|
|
var val = this.get_value();
|
2011-07-15 08:01:45 +00:00
|
|
|
if (val === null || val === '') {
|
2011-03-24 18:00:28 +00:00
|
|
|
return;
|
|
|
|
}
|
2011-03-17 13:41:55 +00:00
|
|
|
|
2011-03-29 09:09:41 +00:00
|
|
|
var domain = this.attrs['filter_domain'];
|
|
|
|
if (!domain) {
|
2011-08-24 14:52:05 +00:00
|
|
|
return this.make_domain(
|
2011-03-24 17:37:21 +00:00
|
|
|
this.attrs.name,
|
2011-03-24 17:42:30 +00:00
|
|
|
this.attrs.operator || this.default_operator,
|
2011-08-24 14:52:05 +00:00
|
|
|
val);
|
2011-03-24 17:37:21 +00:00
|
|
|
}
|
2011-07-15 08:01:45 +00:00
|
|
|
return _.extend({}, domain, {own_values: {self: val}});
|
2011-03-24 12:46:53 +00:00
|
|
|
}
|
|
|
|
});
|
2011-03-30 15:27:36 +00:00
|
|
|
/**
|
|
|
|
* Implementation of the ``char`` OpenERP field type:
|
|
|
|
*
|
|
|
|
* * Default operator is ``ilike`` rather than ``=``
|
|
|
|
*
|
|
|
|
* * The Javascript and the HTML values are identical (strings)
|
|
|
|
*
|
|
|
|
* @class
|
2011-09-05 11:03:09 +00:00
|
|
|
* @extends openerp.web.search.Field
|
2011-03-30 15:27:36 +00:00
|
|
|
*/
|
2011-09-05 11:03:09 +00:00
|
|
|
openerp.web.search.CharField = openerp.web.search.Field.extend( /** @lends openerp.web.search.CharField# */ {
|
2011-03-24 18:01:29 +00:00
|
|
|
default_operator: 'ilike',
|
2012-03-19 16:43:04 +00:00
|
|
|
complete: function (value) {
|
|
|
|
// FIXME: formatting
|
|
|
|
var label = _.str.sprintf(_t('Search "%s" for "%s"'),
|
|
|
|
this.attrs.string, value);
|
|
|
|
return $.when([
|
|
|
|
{category: this.attrs.name, label: label, value:value}
|
|
|
|
]);
|
|
|
|
},
|
2011-03-24 17:37:21 +00:00
|
|
|
get_value: function () {
|
|
|
|
return this.$element.val();
|
|
|
|
}
|
2011-03-24 12:46:53 +00:00
|
|
|
});
|
2011-09-05 11:03:09 +00:00
|
|
|
openerp.web.search.NumberField = openerp.web.search.Field.extend(/** @lends openerp.web.search.NumberField# */{
|
2011-03-24 19:24:59 +00:00
|
|
|
get_value: function () {
|
2011-03-25 12:43:15 +00:00
|
|
|
if (!this.$element.val()) {
|
|
|
|
return null;
|
|
|
|
}
|
2011-07-20 11:01:34 +00:00
|
|
|
var val = this.parse(this.$element.val()),
|
|
|
|
check = Number(this.$element.val());
|
|
|
|
if (isNaN(val) || val !== check) {
|
2011-03-29 10:47:44 +00:00
|
|
|
this.$element.addClass('error');
|
2011-09-05 11:03:09 +00:00
|
|
|
throw new openerp.web.search.Invalid(
|
2011-07-20 11:01:34 +00:00
|
|
|
this.attrs.name, this.$element.val(), this.error_message);
|
2011-03-24 19:24:59 +00:00
|
|
|
}
|
2011-03-29 10:47:44 +00:00
|
|
|
this.$element.removeClass('error');
|
2011-03-24 19:24:59 +00:00
|
|
|
return val;
|
|
|
|
}
|
|
|
|
});
|
2011-07-20 11:01:34 +00:00
|
|
|
/**
|
|
|
|
* @class
|
2011-09-05 11:03:09 +00:00
|
|
|
* @extends openerp.web.search.NumberField
|
2011-07-20 11:01:34 +00:00
|
|
|
*/
|
2011-09-05 11:03:09 +00:00
|
|
|
openerp.web.search.IntegerField = openerp.web.search.NumberField.extend(/** @lends openerp.web.search.IntegerField# */{
|
2011-11-14 10:12:21 +00:00
|
|
|
error_message: _t("not a valid integer"),
|
2011-07-20 11:01:34 +00:00
|
|
|
parse: function (value) {
|
2011-09-19 13:46:15 +00:00
|
|
|
try {
|
|
|
|
return openerp.web.parse_value(value, {'widget': 'integer'});
|
|
|
|
} catch (e) {
|
|
|
|
return NaN;
|
|
|
|
}
|
2011-07-20 11:01:34 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
/**
|
|
|
|
* @class
|
2011-09-05 11:03:09 +00:00
|
|
|
* @extends openerp.web.search.NumberField
|
2011-07-20 11:01:34 +00:00
|
|
|
*/
|
2011-09-05 11:03:09 +00:00
|
|
|
openerp.web.search.FloatField = openerp.web.search.NumberField.extend(/** @lends openerp.web.search.FloatField# */{
|
2011-11-14 10:12:21 +00:00
|
|
|
error_message: _t("not a valid number"),
|
2011-07-20 11:01:34 +00:00
|
|
|
parse: function (value) {
|
2011-09-19 13:20:26 +00:00
|
|
|
try {
|
|
|
|
return openerp.web.parse_value(value, {'widget': 'float'});
|
|
|
|
} catch (e) {
|
|
|
|
return NaN;
|
|
|
|
}
|
2011-03-24 17:37:21 +00:00
|
|
|
}
|
2011-03-24 12:46:53 +00:00
|
|
|
});
|
2011-08-10 10:49:10 +00:00
|
|
|
/**
|
|
|
|
* @class
|
2011-09-05 11:03:09 +00:00
|
|
|
* @extends openerp.web.search.Field
|
2011-08-10 10:49:10 +00:00
|
|
|
*/
|
2011-09-05 11:03:09 +00:00
|
|
|
openerp.web.search.SelectionField = openerp.web.search.Field.extend(/** @lends openerp.web.search.SelectionField# */{
|
[FIX] m2o fields with selection widget in search view
Plan was originally to just ignore this because "it should just work"
but turns out m2o and m2o[@widget=selection] fields have very
different behaviors when it comes to default values, especially
custom domains and contexts:
* An m2o field uses its string value always (behaves like a char
field), for UI and clarity purposes we added an [[name, '=', id]]
case when the user specifically selects an autocompletion value,
but that's not "cannon", when it comes to dealing with custom
domains (filter_domain) and contexts the field always uses its
string value.
* An m2o[@widget=selection] field on the other hand uses its ids
always (behaves like a selection field).
That's not entirely true, really, because it has the converse to
what we implemented on the m2o field in the web client (in the GTK
client): if there is no @filter_domain *and* the user has entered a
value which is not in the dropdown (it's a combobox in the GTK
client), then it falls back on using 'ilike'. This string value is
*not* used in custom domains and custom filters, which simply are
not submitted.
This second section has *not* been implemented so far in the web
client, we'll come round to it if people actually need it.
bzr revid: xmo@openerp.com-20111006063949-fl5rbg3wwubcaay8
2011-10-06 06:39:49 +00:00
|
|
|
// This implementation is a basic <select> field, but it may have to be
|
|
|
|
// altered to be more in line with the GTK client, which uses a combo box
|
|
|
|
// (~ jquery.autocomplete):
|
|
|
|
// * If an option was selected in the list, behave as currently
|
|
|
|
// * If something which is not in the list was entered (via the text input),
|
|
|
|
// the default domain should become (`ilike` string_value) but **any
|
|
|
|
// ``context`` or ``filter_domain`` becomes falsy, idem if ``@operator``
|
|
|
|
// is specified. So at least get_domain needs to be quite a bit
|
|
|
|
// overridden (if there's no @value and there is no filter_domain and
|
|
|
|
// there is no @operator, return [[name, 'ilike', str_val]]
|
2011-03-24 18:47:13 +00:00
|
|
|
template: 'SearchView.field.selection',
|
[FIX] m2o fields with selection widget in search view
Plan was originally to just ignore this because "it should just work"
but turns out m2o and m2o[@widget=selection] fields have very
different behaviors when it comes to default values, especially
custom domains and contexts:
* An m2o field uses its string value always (behaves like a char
field), for UI and clarity purposes we added an [[name, '=', id]]
case when the user specifically selects an autocompletion value,
but that's not "cannon", when it comes to dealing with custom
domains (filter_domain) and contexts the field always uses its
string value.
* An m2o[@widget=selection] field on the other hand uses its ids
always (behaves like a selection field).
That's not entirely true, really, because it has the converse to
what we implemented on the m2o field in the web client (in the GTK
client): if there is no @filter_domain *and* the user has entered a
value which is not in the dropdown (it's a combobox in the GTK
client), then it falls back on using 'ilike'. This string value is
*not* used in custom domains and custom filters, which simply are
not submitted.
This second section has *not* been implemented so far in the web
client, we'll come round to it if people actually need it.
bzr revid: xmo@openerp.com-20111006063949-fl5rbg3wwubcaay8
2011-10-06 06:39:49 +00:00
|
|
|
init: function () {
|
|
|
|
this._super.apply(this, arguments);
|
|
|
|
// prepend empty option if there is no empty option in the selection list
|
|
|
|
this.prepend_empty = !_(this.attrs.selection).detect(function (item) {
|
|
|
|
return !item[1];
|
|
|
|
});
|
|
|
|
},
|
2012-03-19 16:43:04 +00:00
|
|
|
complete: function (needle) {
|
|
|
|
var self = this;
|
|
|
|
var results = _(this.attrs.selection).chain()
|
|
|
|
.filter(function (sel) {
|
|
|
|
var value = sel[0], label = sel[1];
|
|
|
|
if (!value) { return false; }
|
|
|
|
return label.toLowerCase().indexOf(needle.toLowerCase()) !== -1;
|
|
|
|
})
|
|
|
|
.map(function (sel) {
|
|
|
|
return {
|
|
|
|
category: self.attrs.name,
|
|
|
|
label: sel[1],
|
|
|
|
value: sel[0]
|
|
|
|
};
|
|
|
|
}).value();
|
|
|
|
if (_.isEmpty(results)) { return $.when(null); }
|
|
|
|
return $.when.apply(null,
|
|
|
|
[{type: 'section', label: this.attrs.string}].concat(results));
|
|
|
|
},
|
2012-03-20 10:28:46 +00:00
|
|
|
facet_for: function (value) {
|
|
|
|
var match = _(this.attrs.selection).detect(function (sel) {
|
|
|
|
return sel[0] === value;
|
|
|
|
});
|
|
|
|
if (!match) { return $.when(null); }
|
|
|
|
return $.when(new VS.model.SearchFacet({
|
|
|
|
category: this.attrs.name,
|
|
|
|
value: match[1],
|
|
|
|
app: this.view.vs
|
|
|
|
}));
|
|
|
|
},
|
2011-03-24 18:47:13 +00:00
|
|
|
get_value: function () {
|
2011-10-06 10:02:35 +00:00
|
|
|
var index = parseInt(this.$element.val(), 10);
|
|
|
|
if (isNaN(index)) { return null; }
|
2011-10-06 14:54:39 +00:00
|
|
|
var value = this.attrs.selection[index][0];
|
|
|
|
if (value === false) { return null; }
|
|
|
|
return value;
|
2011-10-07 08:29:05 +00:00
|
|
|
},
|
2012-02-10 15:52:35 +00:00
|
|
|
clear: function () {
|
|
|
|
var self = this, d = $.Deferred(), selection = this.attrs.selection;
|
|
|
|
for(var index=0; index<selection.length; ++index) {
|
|
|
|
var item = selection[index];
|
|
|
|
if (!item[1]) {
|
|
|
|
setTimeout(function () {
|
|
|
|
// won't override mutable, because we immediately bail out
|
|
|
|
//noinspection JSReferencingMutableVariableFromClosure
|
|
|
|
self.$element.val(index);
|
|
|
|
d.resolve();
|
|
|
|
}, 0);
|
|
|
|
return d.promise();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return d.resolve().promise();
|
2011-03-24 18:47:13 +00:00
|
|
|
}
|
|
|
|
});
|
2011-09-05 11:03:09 +00:00
|
|
|
openerp.web.search.BooleanField = openerp.web.search.SelectionField.extend(/** @lends openerp.web.search.BooleanField# */{
|
2011-08-10 10:49:10 +00:00
|
|
|
/**
|
2011-09-12 11:34:37 +00:00
|
|
|
* @constructs openerp.web.search.BooleanField
|
2011-09-05 11:03:09 +00:00
|
|
|
* @extends openerp.web.search.BooleanField
|
2011-08-10 10:49:10 +00:00
|
|
|
*/
|
|
|
|
init: function () {
|
|
|
|
this._super.apply(this, arguments);
|
|
|
|
this.attrs.selection = [
|
2011-12-20 17:51:37 +00:00
|
|
|
['true', _t("Yes")],
|
|
|
|
['false', _t("No")]
|
2011-08-10 10:49:10 +00:00
|
|
|
];
|
|
|
|
},
|
|
|
|
get_value: function () {
|
|
|
|
switch (this.$element.val()) {
|
|
|
|
case 'false': return false;
|
|
|
|
case 'true': return true;
|
|
|
|
default: return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2011-09-12 12:06:04 +00:00
|
|
|
/**
|
|
|
|
* @class
|
|
|
|
* @extends openerp.web.search.DateField
|
|
|
|
*/
|
|
|
|
openerp.web.search.DateField = openerp.web.search.Field.extend(/** @lends openerp.web.search.DateField# */{
|
2011-09-21 11:50:54 +00:00
|
|
|
template: "SearchView.date",
|
2011-04-01 15:17:35 +00:00
|
|
|
start: function () {
|
|
|
|
this._super();
|
2012-02-13 09:40:15 +00:00
|
|
|
// FIXME: this insanity puts a div inside a span
|
2011-09-21 11:50:54 +00:00
|
|
|
this.datewidget = new openerp.web.DateWidget(this);
|
|
|
|
this.datewidget.prependTo(this.$element);
|
2012-02-13 09:40:15 +00:00
|
|
|
this.datewidget.$element.find("input")
|
|
|
|
.attr("size", 15)
|
2012-02-13 10:05:43 +00:00
|
|
|
.attr("autofocus", this.attrs.default_focus === '1' ? 'autofocus' : null)
|
2012-02-13 09:40:15 +00:00
|
|
|
.removeAttr('style');
|
2011-09-21 11:50:54 +00:00
|
|
|
this.datewidget.set_value(this.defaults[this.attrs.name] || false);
|
2011-04-01 15:17:35 +00:00
|
|
|
},
|
2011-08-10 11:00:55 +00:00
|
|
|
get_value: function () {
|
2011-09-21 11:50:54 +00:00
|
|
|
return this.datewidget.get_value() || null;
|
2012-02-10 15:52:35 +00:00
|
|
|
},
|
|
|
|
clear: function () {
|
|
|
|
this.datewidget.set_value(false);
|
2011-03-24 17:37:21 +00:00
|
|
|
}
|
2011-03-24 12:46:53 +00:00
|
|
|
});
|
2011-08-24 14:56:47 +00:00
|
|
|
/**
|
|
|
|
* Implementation of the ``datetime`` openerp field type:
|
|
|
|
*
|
|
|
|
* * Uses the same widget as the ``date`` field type (a simple date)
|
|
|
|
*
|
|
|
|
* * Builds a slighly more complex, it's a datetime range (includes time)
|
|
|
|
* spanning the whole day selected by the date widget
|
|
|
|
*
|
|
|
|
* @class
|
2011-09-05 11:03:09 +00:00
|
|
|
* @extends openerp.web.DateField
|
2011-08-24 14:56:47 +00:00
|
|
|
*/
|
2011-09-05 11:03:09 +00:00
|
|
|
openerp.web.search.DateTimeField = openerp.web.search.DateField.extend(/** @lends openerp.web.search.DateTimeField# */{
|
2011-08-24 14:52:05 +00:00
|
|
|
make_domain: function (name, operator, value) {
|
|
|
|
return ['&', [name, '>=', value + ' 00:00:00'],
|
|
|
|
[name, '<=', value + ' 23:59:59']];
|
|
|
|
}
|
2011-03-24 18:16:55 +00:00
|
|
|
});
|
2011-09-05 11:03:09 +00:00
|
|
|
openerp.web.search.ManyToOneField = openerp.web.search.CharField.extend({
|
2011-07-15 11:58:00 +00:00
|
|
|
init: function (view_section, field, view) {
|
|
|
|
this._super(view_section, field, view);
|
|
|
|
var self = this;
|
|
|
|
this.got_name = $.Deferred().then(function () {
|
|
|
|
self.$element.val(self.name);
|
|
|
|
});
|
2011-09-05 11:03:09 +00:00
|
|
|
this.dataset = new openerp.web.DataSet(
|
2011-07-18 12:54:22 +00:00
|
|
|
this.view, this.attrs['relation']);
|
2011-07-15 11:58:00 +00:00
|
|
|
},
|
2012-03-19 16:43:04 +00:00
|
|
|
complete: function (needle) {
|
|
|
|
var self = this;
|
|
|
|
// TODO: context
|
|
|
|
// FIXME: "concurrent" searches (multiple requests, mis-ordered responses)
|
|
|
|
return new openerp.web.Model(this.attrs.relation).call('name_search', [], {
|
|
|
|
name: needle,
|
|
|
|
limit: 8,
|
|
|
|
context: {}
|
|
|
|
}).pipe(function (results) {
|
|
|
|
if (_.isEmpty(results)) { return null; }
|
|
|
|
return [{type: 'section', label: self.attrs.string}].concat(
|
|
|
|
_(results).map(function (result) {
|
|
|
|
return {
|
|
|
|
category: self.attrs.name,
|
|
|
|
label: result[1],
|
|
|
|
value: result[0]
|
|
|
|
};
|
|
|
|
}));
|
|
|
|
});
|
|
|
|
},
|
2012-03-20 10:28:46 +00:00
|
|
|
facet_for: function (value) {
|
|
|
|
var self = this;
|
|
|
|
if (value instanceof Array) {
|
|
|
|
return $.when(new VS.model.SearchFacet({
|
|
|
|
category: this.attrs.string,
|
|
|
|
value: value[1],
|
|
|
|
app: this.view.vs
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
return new openerp.web.Model(this.attrs.relation)
|
|
|
|
.call('name_get', [value], {}).pipe(function (names) {
|
|
|
|
return new VS.model.SearchFacet({
|
|
|
|
category: self.attrs.string,
|
|
|
|
value: names[0][1],
|
|
|
|
app: self.view.vs
|
|
|
|
});
|
|
|
|
})
|
|
|
|
},
|
2011-07-15 11:58:00 +00:00
|
|
|
start: function () {
|
|
|
|
this._super();
|
2011-07-15 12:23:05 +00:00
|
|
|
this.setup_autocomplete();
|
2011-07-15 11:58:00 +00:00
|
|
|
var started = $.Deferred();
|
|
|
|
this.got_name.then(function () { started.resolve();},
|
|
|
|
function () { started.resolve(); });
|
|
|
|
return started.promise();
|
|
|
|
},
|
2011-10-05 13:02:52 +00:00
|
|
|
make_domain: function (name, operator, value) {
|
2011-07-15 11:58:00 +00:00
|
|
|
if (this.id && this.name) {
|
2011-08-24 14:52:05 +00:00
|
|
|
if (value === this.name) {
|
2011-10-05 13:02:52 +00:00
|
|
|
return [[name, '=', this.id]];
|
2011-07-15 11:58:00 +00:00
|
|
|
} else {
|
|
|
|
delete this.id;
|
|
|
|
delete this.name;
|
|
|
|
}
|
|
|
|
}
|
2011-10-05 13:02:52 +00:00
|
|
|
return this._super(name, operator, value);
|
2011-07-15 11:58:00 +00:00
|
|
|
}
|
2011-03-17 13:41:55 +00:00
|
|
|
});
|
|
|
|
|
2012-02-10 15:52:35 +00:00
|
|
|
openerp.web.search.ExtendedSearch = openerp.web.search.Input.extend({
|
2011-05-19 15:12:49 +00:00
|
|
|
template: 'SearchView.extended_search',
|
2011-07-18 12:54:22 +00:00
|
|
|
init: function (parent, model) {
|
|
|
|
this._super(parent);
|
2011-05-19 15:12:49 +00:00
|
|
|
this.model = model;
|
|
|
|
},
|
|
|
|
add_group: function() {
|
2011-09-05 11:03:09 +00:00
|
|
|
var group = new openerp.web.search.ExtendedSearchGroup(this, this.fields);
|
2011-07-28 16:59:14 +00:00
|
|
|
group.appendTo(this.$element.find('.searchview_extended_groups_list'));
|
2011-06-21 13:05:01 +00:00
|
|
|
this.check_last_element();
|
2011-05-19 15:12:49 +00:00
|
|
|
},
|
|
|
|
start: function () {
|
2012-01-24 14:33:18 +00:00
|
|
|
this._super();
|
2011-05-20 10:01:09 +00:00
|
|
|
this.$element.closest("table.oe-searchview-render-line").css("display", "none");
|
2011-05-19 15:12:49 +00:00
|
|
|
var self = this;
|
2011-09-05 11:03:09 +00:00
|
|
|
this.rpc("/web/searchview/fields_get",
|
2011-05-19 15:12:49 +00:00
|
|
|
{"model": this.model}, function(data) {
|
|
|
|
self.fields = data.fields;
|
2011-11-14 09:57:38 +00:00
|
|
|
if (!('id' in self.fields)) {
|
|
|
|
self.fields.id = {
|
|
|
|
string: 'ID',
|
|
|
|
type: 'id'
|
|
|
|
}
|
|
|
|
}
|
2011-09-05 11:03:09 +00:00
|
|
|
openerp.web.search.add_expand_listener(self.$element);
|
2011-05-19 15:12:49 +00:00
|
|
|
self.$element.find('.searchview_extended_add_group').click(function (e) {
|
|
|
|
self.add_group();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
get_context: function() {
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
get_domain: function() {
|
2011-07-05 09:37:11 +00:00
|
|
|
if (!this.$element) {
|
|
|
|
return null; // not a logical state but sometimes it happens
|
|
|
|
}
|
2011-05-20 10:01:09 +00:00
|
|
|
if(this.$element.closest("table.oe-searchview-render-line").css("display") == "none") {
|
2011-05-19 15:12:49 +00:00
|
|
|
return null;
|
|
|
|
}
|
2012-02-21 15:51:34 +00:00
|
|
|
return _.reduce(this.getChildren(),
|
2011-05-19 15:12:49 +00:00
|
|
|
function(mem, x) { return mem.concat(x.get_domain());}, []);
|
2011-05-20 10:01:09 +00:00
|
|
|
},
|
|
|
|
on_activate: function() {
|
2011-05-26 14:54:45 +00:00
|
|
|
this.add_group();
|
2011-05-20 10:01:09 +00:00
|
|
|
var table = this.$element.closest("table.oe-searchview-render-line");
|
2011-06-21 14:11:07 +00:00
|
|
|
table.css("display", "");
|
|
|
|
if(this.$element.hasClass("folded")) {
|
|
|
|
this.$element.toggleClass("folded expanded");
|
2011-05-26 14:54:45 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
hide: function() {
|
|
|
|
var table = this.$element.closest("table.oe-searchview-render-line");
|
|
|
|
table.css("display", "none");
|
|
|
|
if(this.$element.hasClass("expanded")) {
|
|
|
|
this.$element.toggleClass("folded expanded");
|
2011-05-20 10:01:09 +00:00
|
|
|
}
|
2011-06-21 13:05:01 +00:00
|
|
|
},
|
|
|
|
check_last_element: function() {
|
2012-02-21 15:51:34 +00:00
|
|
|
_.each(this.getChildren(), function(x) {x.set_last_group(false);});
|
|
|
|
if (this.getChildren().length >= 1) {
|
|
|
|
this.getChildren()[this.getChildren().length - 1].set_last_group(true);
|
2011-07-22 16:27:01 +00:00
|
|
|
}
|
2011-05-19 15:12:49 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2012-01-24 14:58:10 +00:00
|
|
|
openerp.web.search.ExtendedSearchGroup = openerp.web.OldWidget.extend({
|
2011-05-19 15:12:49 +00:00
|
|
|
template: 'SearchView.extended_search.group',
|
|
|
|
init: function (parent, fields) {
|
|
|
|
this._super(parent);
|
|
|
|
this.fields = fields;
|
|
|
|
},
|
|
|
|
add_prop: function() {
|
2011-09-05 11:03:09 +00:00
|
|
|
var prop = new openerp.web.search.ExtendedSearchProposition(this, this.fields);
|
2012-02-21 15:51:34 +00:00
|
|
|
var render = prop.render({'index': this.getChildren().length - 1});
|
2011-05-19 15:12:49 +00:00
|
|
|
this.$element.find('.searchview_extended_propositions_list').append(render);
|
|
|
|
prop.start();
|
|
|
|
},
|
|
|
|
start: function () {
|
|
|
|
var _this = this;
|
|
|
|
this.add_prop();
|
2011-08-12 09:45:41 +00:00
|
|
|
this.$element.find('.searchview_extended_add_proposition').click(function () {
|
2011-05-19 15:12:49 +00:00
|
|
|
_this.add_prop();
|
|
|
|
});
|
2011-08-12 09:45:41 +00:00
|
|
|
this.$element.find('.searchview_extended_delete_group').click(function () {
|
2012-02-21 16:29:12 +00:00
|
|
|
_this.destroy();
|
2011-05-19 15:12:49 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
get_domain: function() {
|
2012-02-21 15:51:34 +00:00
|
|
|
var props = _(this.getChildren()).chain().map(function(x) {
|
2011-05-19 15:12:49 +00:00
|
|
|
return x.get_proposition();
|
|
|
|
}).compact().value();
|
|
|
|
var choice = this.$element.find(".searchview_extended_group_choice").val();
|
|
|
|
var op = choice == "all" ? "&" : "|";
|
2011-08-12 09:45:41 +00:00
|
|
|
return choice == "none" ? ['!'] : [].concat(
|
2011-05-19 15:12:49 +00:00
|
|
|
_.map(_.range(_.max([0,props.length - 1])), function() { return op; }),
|
|
|
|
props);
|
2011-06-21 12:53:17 +00:00
|
|
|
},
|
2012-02-21 16:29:12 +00:00
|
|
|
destroy: function() {
|
2012-02-21 15:30:23 +00:00
|
|
|
var parent = this.getParent();
|
2012-02-21 15:51:34 +00:00
|
|
|
if (this.getParent().getChildren().length == 1)
|
2012-02-21 15:30:23 +00:00
|
|
|
this.getParent().hide();
|
2011-06-21 12:53:17 +00:00
|
|
|
this._super();
|
2011-06-21 13:05:01 +00:00
|
|
|
parent.check_last_element();
|
|
|
|
},
|
|
|
|
set_last_group: function(is_last) {
|
2011-08-12 09:45:41 +00:00
|
|
|
this.$element.toggleClass('last_group', is_last);
|
2011-05-19 15:12:49 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2012-01-24 14:58:10 +00:00
|
|
|
openerp.web.search.ExtendedSearchProposition = openerp.web.OldWidget.extend(/** @lends openerp.web.search.ExtendedSearchProposition# */{
|
2011-04-01 12:53:13 +00:00
|
|
|
template: 'SearchView.extended_search.proposition',
|
2011-09-12 12:06:04 +00:00
|
|
|
/**
|
|
|
|
* @constructs openerp.web.search.ExtendedSearchProposition
|
2012-01-24 14:58:10 +00:00
|
|
|
* @extends openerp.web.OldWidget
|
2011-09-12 12:06:04 +00:00
|
|
|
*
|
|
|
|
* @param parent
|
|
|
|
* @param fields
|
|
|
|
*/
|
2011-04-01 12:53:13 +00:00
|
|
|
init: function (parent, fields) {
|
|
|
|
this._super(parent);
|
|
|
|
this.fields = _(fields).chain()
|
|
|
|
.map(function(val, key) { return _.extend({}, val, {'name': key}); })
|
|
|
|
.sortBy(function(field) {return field.string;})
|
|
|
|
.value();
|
|
|
|
this.attrs = {_: _, fields: this.fields, selected: null};
|
|
|
|
this.value = null;
|
|
|
|
},
|
|
|
|
start: function () {
|
2011-11-10 14:13:43 +00:00
|
|
|
this.$element = $("#" + this.element_id);
|
2011-04-01 12:53:13 +00:00
|
|
|
this.select_field(this.fields.length > 0 ? this.fields[0] : null);
|
|
|
|
var _this = this;
|
|
|
|
this.$element.find(".searchview_extended_prop_field").change(function() {
|
|
|
|
_this.changed();
|
|
|
|
});
|
2011-08-12 09:45:41 +00:00
|
|
|
this.$element.find('.searchview_extended_delete_prop').click(function () {
|
2012-02-21 16:29:12 +00:00
|
|
|
_this.destroy();
|
2011-04-01 12:53:13 +00:00
|
|
|
});
|
|
|
|
},
|
2012-02-21 16:29:12 +00:00
|
|
|
destroy: function() {
|
2011-07-28 14:34:13 +00:00
|
|
|
var parent;
|
2012-02-21 15:51:34 +00:00
|
|
|
if (this.getParent().getChildren().length == 1)
|
2012-02-21 15:30:23 +00:00
|
|
|
parent = this.getParent();
|
2011-06-21 12:53:17 +00:00
|
|
|
this._super();
|
2011-07-28 14:34:13 +00:00
|
|
|
if (parent)
|
2012-02-21 16:29:12 +00:00
|
|
|
parent.destroy();
|
2011-06-21 12:53:17 +00:00
|
|
|
},
|
2011-04-01 12:53:13 +00:00
|
|
|
changed: function() {
|
|
|
|
var nval = this.$element.find(".searchview_extended_prop_field").val();
|
|
|
|
if(this.attrs.selected == null || nval != this.attrs.selected.name) {
|
|
|
|
this.select_field(_.detect(this.fields, function(x) {return x.name == nval;}));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
* Selects the provided field object
|
|
|
|
*
|
|
|
|
* @param field a field descriptor object (as returned by fields_get, augmented by the field name)
|
|
|
|
*/
|
|
|
|
select_field: function(field) {
|
2011-12-20 17:51:37 +00:00
|
|
|
var self = this;
|
2011-04-01 12:53:13 +00:00
|
|
|
if(this.attrs.selected != null) {
|
2012-02-21 16:29:12 +00:00
|
|
|
this.value.destroy();
|
2011-04-01 12:53:13 +00:00
|
|
|
this.value = null;
|
|
|
|
this.$element.find('.searchview_extended_prop_op').html('');
|
|
|
|
}
|
|
|
|
this.attrs.selected = field;
|
|
|
|
if(field == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-04-12 16:27:03 +00:00
|
|
|
var type = field.type;
|
2011-04-01 12:53:13 +00:00
|
|
|
try {
|
2011-09-05 11:03:09 +00:00
|
|
|
openerp.web.search.custom_filters.get_object(type);
|
2011-04-01 12:53:13 +00:00
|
|
|
} catch (e) {
|
2011-09-05 11:03:09 +00:00
|
|
|
if (! e instanceof openerp.web.KeyNotFound) {
|
2011-04-01 12:53:13 +00:00
|
|
|
throw e;
|
|
|
|
}
|
2011-07-15 08:01:45 +00:00
|
|
|
type = "char";
|
2011-09-13 12:17:28 +00:00
|
|
|
console.log('Unknow field type ' + e.key);
|
2011-04-01 12:53:13 +00:00
|
|
|
}
|
2011-09-05 11:03:09 +00:00
|
|
|
this.value = new (openerp.web.search.custom_filters.get_object(type))
|
2011-04-12 16:27:03 +00:00
|
|
|
(this);
|
2011-05-19 17:00:41 +00:00
|
|
|
if(this.value.set_field) {
|
|
|
|
this.value.set_field(field);
|
|
|
|
}
|
2011-04-12 16:27:03 +00:00
|
|
|
_.each(this.value.operators, function(operator) {
|
2011-12-20 17:51:37 +00:00
|
|
|
$('<option>', {value: operator.value})
|
|
|
|
.text(String(operator.text))
|
|
|
|
.appendTo(self.$element.find('.searchview_extended_prop_op'));
|
2011-04-12 16:27:03 +00:00
|
|
|
});
|
|
|
|
this.$element.find('.searchview_extended_prop_value').html(
|
|
|
|
this.value.render({}));
|
|
|
|
this.value.start();
|
2011-12-09 12:35:14 +00:00
|
|
|
|
2011-04-01 12:53:13 +00:00
|
|
|
},
|
|
|
|
get_proposition: function() {
|
|
|
|
if ( this.attrs.selected == null)
|
|
|
|
return null;
|
|
|
|
var field = this.attrs.selected.name;
|
|
|
|
var op = this.$element.find('.searchview_extended_prop_op').val();
|
|
|
|
var value = this.value.get_value();
|
|
|
|
return [field, op, value];
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2012-01-24 14:58:10 +00:00
|
|
|
openerp.web.search.ExtendedSearchProposition.Field = openerp.web.OldWidget.extend({
|
2011-11-14 09:57:38 +00:00
|
|
|
start: function () {
|
|
|
|
this.$element = $("#" + this.element_id);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
openerp.web.search.ExtendedSearchProposition.Char = openerp.web.search.ExtendedSearchProposition.Field.extend({
|
2011-04-01 12:53:13 +00:00
|
|
|
template: 'SearchView.extended_search.proposition.char',
|
|
|
|
operators: [
|
2011-12-20 17:51:37 +00:00
|
|
|
{value: "ilike", text: _lt("contains")},
|
|
|
|
{value: "not ilike", text: _lt("doesn't contain")},
|
|
|
|
{value: "=", text: _lt("is equal to")},
|
|
|
|
{value: "!=", text: _lt("is not equal to")},
|
|
|
|
{value: ">", text: _lt("greater than")},
|
|
|
|
{value: "<", text: _lt("less than")},
|
|
|
|
{value: ">=", text: _lt("greater or equal than")},
|
|
|
|
{value: "<=", text: _lt("less or equal than")}
|
2011-04-01 12:53:13 +00:00
|
|
|
],
|
|
|
|
get_value: function() {
|
|
|
|
return this.$element.val();
|
|
|
|
}
|
|
|
|
});
|
2011-11-14 09:57:38 +00:00
|
|
|
openerp.web.search.ExtendedSearchProposition.DateTime = openerp.web.search.ExtendedSearchProposition.Field.extend({
|
2011-09-21 12:03:47 +00:00
|
|
|
template: 'SearchView.extended_search.proposition.empty',
|
2011-04-01 12:53:13 +00:00
|
|
|
operators: [
|
2011-12-20 17:51:37 +00:00
|
|
|
{value: "=", text: _lt("is equal to")},
|
|
|
|
{value: "!=", text: _lt("is not equal to")},
|
|
|
|
{value: ">", text: _lt("greater than")},
|
|
|
|
{value: "<", text: _lt("less than")},
|
|
|
|
{value: ">=", text: _lt("greater or equal than")},
|
|
|
|
{value: "<=", text: _lt("less or equal than")}
|
2011-04-01 12:53:13 +00:00
|
|
|
],
|
|
|
|
get_value: function() {
|
2011-09-21 12:03:47 +00:00
|
|
|
return this.datewidget.get_value();
|
2011-05-19 15:12:49 +00:00
|
|
|
},
|
2011-05-19 15:53:02 +00:00
|
|
|
start: function() {
|
2011-11-14 09:57:38 +00:00
|
|
|
this._super();
|
2011-09-21 12:03:47 +00:00
|
|
|
this.datewidget = new openerp.web.DateTimeWidget(this);
|
|
|
|
this.datewidget.prependTo(this.$element);
|
2011-04-01 12:53:13 +00:00
|
|
|
}
|
|
|
|
});
|
2011-11-14 09:57:38 +00:00
|
|
|
openerp.web.search.ExtendedSearchProposition.Date = openerp.web.search.ExtendedSearchProposition.Field.extend({
|
2011-09-21 12:03:47 +00:00
|
|
|
template: 'SearchView.extended_search.proposition.empty',
|
2011-05-19 15:53:02 +00:00
|
|
|
operators: [
|
2011-12-20 17:51:37 +00:00
|
|
|
{value: "=", text: _lt("is equal to")},
|
|
|
|
{value: "!=", text: _lt("is not equal to")},
|
|
|
|
{value: ">", text: _lt("greater than")},
|
|
|
|
{value: "<", text: _lt("less than")},
|
|
|
|
{value: ">=", text: _lt("greater or equal than")},
|
|
|
|
{value: "<=", text: _lt("less or equal than")}
|
2011-05-19 15:53:02 +00:00
|
|
|
],
|
|
|
|
get_value: function() {
|
2011-09-21 12:03:47 +00:00
|
|
|
return this.datewidget.get_value();
|
2011-05-19 15:53:02 +00:00
|
|
|
},
|
|
|
|
start: function() {
|
2011-11-14 09:57:38 +00:00
|
|
|
this._super();
|
2011-09-21 12:03:47 +00:00
|
|
|
this.datewidget = new openerp.web.DateWidget(this);
|
|
|
|
this.datewidget.prependTo(this.$element);
|
2011-05-19 15:53:02 +00:00
|
|
|
}
|
|
|
|
});
|
2011-11-14 09:57:38 +00:00
|
|
|
openerp.web.search.ExtendedSearchProposition.Integer = openerp.web.search.ExtendedSearchProposition.Field.extend({
|
2011-05-19 16:18:35 +00:00
|
|
|
template: 'SearchView.extended_search.proposition.integer',
|
|
|
|
operators: [
|
2011-12-20 17:51:37 +00:00
|
|
|
{value: "=", text: _lt("is equal to")},
|
|
|
|
{value: "!=", text: _lt("is not equal to")},
|
|
|
|
{value: ">", text: _lt("greater than")},
|
|
|
|
{value: "<", text: _lt("less than")},
|
|
|
|
{value: ">=", text: _lt("greater or equal than")},
|
|
|
|
{value: "<=", text: _lt("less or equal than")}
|
2011-05-19 16:18:35 +00:00
|
|
|
],
|
|
|
|
get_value: function() {
|
2011-09-19 13:20:26 +00:00
|
|
|
try {
|
2011-09-19 13:46:15 +00:00
|
|
|
return openerp.web.parse_value(this.$element.val(), {'widget': 'integer'});
|
2011-09-19 13:20:26 +00:00
|
|
|
} catch (e) {
|
2011-05-19 16:18:35 +00:00
|
|
|
return "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2011-11-14 09:57:38 +00:00
|
|
|
openerp.web.search.ExtendedSearchProposition.Id = openerp.web.search.ExtendedSearchProposition.Integer.extend({
|
2011-12-20 17:51:37 +00:00
|
|
|
operators: [{value: "=", text: _lt("is")}]
|
2011-11-14 09:57:38 +00:00
|
|
|
});
|
|
|
|
openerp.web.search.ExtendedSearchProposition.Float = openerp.web.search.ExtendedSearchProposition.Field.extend({
|
2011-05-19 16:18:35 +00:00
|
|
|
template: 'SearchView.extended_search.proposition.float',
|
|
|
|
operators: [
|
2011-12-20 17:51:37 +00:00
|
|
|
{value: "=", text: _lt("is equal to")},
|
|
|
|
{value: "!=", text: _lt("is not equal to")},
|
|
|
|
{value: ">", text: _lt("greater than")},
|
|
|
|
{value: "<", text: _lt("less than")},
|
|
|
|
{value: ">=", text: _lt("greater or equal than")},
|
|
|
|
{value: "<=", text: _lt("less or equal than")}
|
2011-05-19 16:18:35 +00:00
|
|
|
],
|
|
|
|
get_value: function() {
|
2011-09-19 13:20:26 +00:00
|
|
|
try {
|
|
|
|
return openerp.web.parse_value(this.$element.val(), {'widget': 'float'});
|
|
|
|
} catch (e) {
|
2011-05-19 16:18:35 +00:00
|
|
|
return "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2011-11-14 09:57:38 +00:00
|
|
|
openerp.web.search.ExtendedSearchProposition.Selection = openerp.web.search.ExtendedSearchProposition.Field.extend({
|
2011-05-19 17:00:41 +00:00
|
|
|
template: 'SearchView.extended_search.proposition.selection',
|
|
|
|
operators: [
|
2011-12-20 17:51:37 +00:00
|
|
|
{value: "=", text: _lt("is")},
|
|
|
|
{value: "!=", text: _lt("is not")}
|
2011-05-19 17:00:41 +00:00
|
|
|
],
|
|
|
|
set_field: function(field) {
|
|
|
|
this.field = field;
|
|
|
|
},
|
|
|
|
get_value: function() {
|
|
|
|
return this.$element.val();
|
|
|
|
}
|
|
|
|
});
|
2011-11-14 09:57:38 +00:00
|
|
|
openerp.web.search.ExtendedSearchProposition.Boolean = openerp.web.search.ExtendedSearchProposition.Field.extend({
|
2011-05-19 17:00:41 +00:00
|
|
|
template: 'SearchView.extended_search.proposition.boolean',
|
|
|
|
operators: [
|
2011-12-20 17:51:37 +00:00
|
|
|
{value: "=", text: _lt("is true")},
|
|
|
|
{value: "!=", text: _lt("is false")}
|
2011-05-19 17:00:41 +00:00
|
|
|
],
|
|
|
|
get_value: function() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
2011-05-19 15:53:02 +00:00
|
|
|
|
2011-09-05 11:03:09 +00:00
|
|
|
openerp.web.search.custom_filters = new openerp.web.Registry({
|
|
|
|
'char': 'openerp.web.search.ExtendedSearchProposition.Char',
|
|
|
|
'text': 'openerp.web.search.ExtendedSearchProposition.Char',
|
|
|
|
'one2many': 'openerp.web.search.ExtendedSearchProposition.Char',
|
|
|
|
'many2one': 'openerp.web.search.ExtendedSearchProposition.Char',
|
|
|
|
'many2many': 'openerp.web.search.ExtendedSearchProposition.Char',
|
2011-12-09 12:35:14 +00:00
|
|
|
|
2011-09-05 11:03:09 +00:00
|
|
|
'datetime': 'openerp.web.search.ExtendedSearchProposition.DateTime',
|
|
|
|
'date': 'openerp.web.search.ExtendedSearchProposition.Date',
|
|
|
|
'integer': 'openerp.web.search.ExtendedSearchProposition.Integer',
|
|
|
|
'float': 'openerp.web.search.ExtendedSearchProposition.Float',
|
|
|
|
'boolean': 'openerp.web.search.ExtendedSearchProposition.Boolean',
|
2011-11-14 09:57:38 +00:00
|
|
|
'selection': 'openerp.web.search.ExtendedSearchProposition.Selection',
|
|
|
|
|
|
|
|
'id': 'openerp.web.search.ExtendedSearchProposition.Id'
|
2011-05-19 15:53:02 +00:00
|
|
|
});
|
2011-04-01 12:53:13 +00:00
|
|
|
|
2011-03-02 23:34:42 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// vim:et fdc=0 fdl=0 foldnestmax=3 fdm=syntax:
|