[IMP] cleanup advanced search fields

bzr revid: xmo@openerp.com-20120516122551-c670k5lrqxnyx5ej
This commit is contained in:
Xavier Morel 2012-05-16 14:25:51 +02:00
parent 5bd32b9373
commit 378100e3ac
3 changed files with 43 additions and 46 deletions

View File

@ -1772,22 +1772,18 @@ instance.web.search.ExtendedSearchProposition = instance.web.OldWidget.extend(/*
} }
var type = field.type; var type = field.type;
var obj = instance.web.search.custom_filters.get_object(type); var Field = instance.web.search.custom_filters.get_object(type);
if(obj === null) { if(!Field) {
obj = instance.web.search.custom_filters.get_object("char"); Field = instance.web.search.custom_filters.get_object("char");
}
this.value = new (obj) (this);
if(this.value.set_field) {
this.value.set_field(field);
} }
this.value = new Field(this, field);
_.each(this.value.operators, function(operator) { _.each(this.value.operators, function(operator) {
$('<option>', {value: operator.value}) $('<option>', {value: operator.value})
.text(String(operator.text)) .text(String(operator.text))
.appendTo(self.$element.find('.searchview_extended_prop_op')); .appendTo(self.$element.find('.searchview_extended_prop_op'));
}); });
this.$element.find('.searchview_extended_prop_value').html( var $value_loc = this.$element.find('.searchview_extended_prop_value').empty();
this.value.render({})); this.value.appendTo($value_loc);
this.value.start();
}, },
get_proposition: function() { get_proposition: function() {
@ -1800,9 +1796,10 @@ instance.web.search.ExtendedSearchProposition = instance.web.OldWidget.extend(/*
} }
}); });
instance.web.search.ExtendedSearchProposition.Field = instance.web.OldWidget.extend({ instance.web.search.ExtendedSearchProposition.Field = instance.web.Widget.extend({
start: function () { init: function (parent, field) {
this.$element = $("#" + this.element_id); this._super(parent);
this.field = field;
} }
}); });
instance.web.search.ExtendedSearchProposition.Char = instance.web.search.ExtendedSearchProposition.Field.extend({ instance.web.search.ExtendedSearchProposition.Char = instance.web.search.ExtendedSearchProposition.Field.extend({
@ -1827,33 +1824,23 @@ instance.web.search.ExtendedSearchProposition.DateTime = instance.web.search.Ext
{value: ">=", text: _lt("greater or equal than")}, {value: ">=", text: _lt("greater or equal than")},
{value: "<=", text: _lt("less or equal than")} {value: "<=", text: _lt("less or equal than")}
], ],
/**
* Date widgets live in view_form which is not yet loaded when this is
* initialized -_-
*/
widget: function () { return instance.web.DateTimeWidget; },
get_value: function() { get_value: function() {
return this.datewidget.get_value(); return this.datewidget.get_value();
}, },
start: function() { start: function() {
this._super(); var ready = this._super();
this.datewidget = new instance.web.DateTimeWidget(this); this.datewidget = new (this.widget())(this);
this.datewidget.prependTo(this.$element); this.datewidget.appendTo(this.$element);
return ready;
} }
}); });
instance.web.search.ExtendedSearchProposition.Date = instance.web.search.ExtendedSearchProposition.Field.extend({ instance.web.search.ExtendedSearchProposition.Date = instance.web.search.ExtendedSearchProposition.DateTime.extend({
template: 'SearchView.extended_search.proposition.empty', widget: function () { return instance.web.DateWidget; }
operators: [
{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")}
],
get_value: function() {
return this.datewidget.get_value();
},
start: function() {
this._super();
this.datewidget = new instance.web.DateWidget(this);
this.datewidget.prependTo(this.$element);
}
}); });
instance.web.search.ExtendedSearchProposition.Integer = instance.web.search.ExtendedSearchProposition.Field.extend({ instance.web.search.ExtendedSearchProposition.Integer = instance.web.search.ExtendedSearchProposition.Field.extend({
template: 'SearchView.extended_search.proposition.integer', template: 'SearchView.extended_search.proposition.integer',
@ -1900,9 +1887,6 @@ instance.web.search.ExtendedSearchProposition.Selection = instance.web.search.Ex
{value: "=", text: _lt("is")}, {value: "=", text: _lt("is")},
{value: "!=", text: _lt("is not")} {value: "!=", text: _lt("is not")}
], ],
set_field: function(field) {
this.field = field;
},
get_value: function() { get_value: function() {
return this.$element.val(); return this.$element.val();
} }

View File

@ -975,11 +975,12 @@
</div> </div>
</t> </t>
<t t-name="web.datetimepicker"> <t t-name="web.datetimepicker">
<t t-set="placeholder" t-value="widget.getParent().node and widget.getParent().node.attrs.placeholder"/>
<div class="oe_datepicker_root oe_form_field_datetime"> <div class="oe_datepicker_root oe_form_field_datetime">
<input type="text" class="oe_datepicker_container" disabled="disabled" style="display: none;"/> <input type="text" class="oe_datepicker_container" disabled="disabled" style="display: none;"/>
<input type="text" <input type="text"
t-att-name="widget.name" t-att-name="widget.name"
t-att-placeholder="widget.getParent().node.attrs.placeholder" t-att-placeholder="placeholder"
t-attf-class="oe_datepicker_master field_#{widget.type_of_date} oe_form_field_#{widget.type_of_date}" t-attf-class="oe_datepicker_master field_#{widget.type_of_date} oe_form_field_#{widget.type_of_date}"
/><img class="oe_input_icon oe_datepicker_trigger" t-att-src='_s + "/web/static/src/img/ui/field_calendar.png"' /><img class="oe_input_icon oe_datepicker_trigger" t-att-src='_s + "/web/static/src/img/ui/field_calendar.png"'
title="Select date" width="16" height="16" border="0"/> title="Select date" width="16" height="16" border="0"/>
@ -1513,21 +1514,21 @@
</li> </li>
</t> </t>
<t t-name="SearchView.extended_search.proposition.char"> <t t-name="SearchView.extended_search.proposition.char">
<input t-att-id="widget.element_id" class="field_char"/> <input class="field_char"/>
</t> </t>
<t t-name="SearchView.extended_search.proposition.empty"> <t t-name="SearchView.extended_search.proposition.empty">
<span t-att-id="widget.element_id"></span> <span/>
</t> </t>
<t t-name="SearchView.extended_search.proposition.integer"> <t t-name="SearchView.extended_search.proposition.integer">
<input type="number" t-att-id="widget.element_id" class="field_integer" step="1"/> <input type="number" class="field_integer" step="1"/>
</t> </t>
<t t-name="SearchView.extended_search.proposition.float"> <t t-name="SearchView.extended_search.proposition.float">
<input type="number" t-att-id="widget.element_id" class="field_float" step="0.01"/> <input type="number" class="field_float" step="0.01"/>
</t> </t>
<t t-name="SearchView.extended_search.proposition.boolean"> <t t-name="SearchView.extended_search.proposition.boolean">
</t> </t>
<t t-name="SearchView.extended_search.proposition.selection"> <t t-name="SearchView.extended_search.proposition.selection">
<select t-att-id="widget.element_id"> <select>
<t t-foreach="widget.field.selection" t-as="element"> <t t-foreach="widget.field.selection" t-as="element">
<option t-att-value="element[0]"><t t-esc="element[1]"/></option> <option t-att-value="element[0]"><t t-esc="element[1]"/></option>
</t> </t>

View File

@ -462,9 +462,21 @@ Many To One
Advanced Search Advanced Search
+++++++++++++++ +++++++++++++++
The advanced search is now a more standard * The advanced search is now a more standard
:js:class:`~openerp.web.search.Input` configured to be rendered in the :js:class:`~openerp.web.search.Input` configured to be rendered in
drawer. the drawer.
* :js:class:`~openerp.web.search.ExtendedSearchProposition.Field` are
now standard widgets, with the "right" behaviors (they don't rebind
their ``$element`` in ``start()``)
* The ad-hoc optional setting of the openerp field descriptor on a
:js:class:`~openerp.web.search.ExtendedSearchProposition.Field` has
been removed, the field descriptor is now passed as second argument
to the
:js:class:`~openerp.web.search.ExtendedSearchProposition.Field`'s
constructor, and bound to its
:js:attr:`~openerp.web.search.ExtendedSearchProposition.Field.field`.
.. [#previous] .. [#previous]