[deep-cleaning] first step of rewriting m2o

bzr revid: nicolas.vanhoren@openerp.com-20110606165043-dae2xm6d48vq4z7m
This commit is contained in:
niv-openerp 2011-06-06 18:50:43 +02:00
parent 1ab89fb420
commit a4e8b8e017
7 changed files with 63 additions and 42 deletions

View File

@ -447,9 +447,9 @@ class DataSet(openerpweb.Controller):
return {'result': r}
@openerpweb.jsonrequest
def name_search(self, req, model, search_str, domain=[], context={}):
def name_search(self, req, model, search_str, domain=[], context={}, limit=None):
m = req.session.model(model)
r = m.name_search(search_str+'%', domain, '=ilike', context)
r = m.name_search(search_str+'%', domain, '=ilike', context, limit)
return {'result': r}
class DataGroup(openerpweb.Controller):

View File

@ -30,7 +30,6 @@
<script type="text/javascript" src="/base/static/src/js/list.js"></script>
<script type="text/javascript" src="/base/static/src/js/tree.js"></script>
<script type="text/javascript" src="/base/static/src/js/search.js"></script>
<script type="text/javascript" src="/base/static/src/js/m2o.js"></script>
<link rel="stylesheet" type="text/css" media="screen" href="/base/static/lib/jquery.ui/css/smoothness/jquery-ui-1.8.9.custom.css" />
<link rel="stylesheet" type="text/css" media="screen" href="/base/static/lib/jquery.ui.notify/css/ui.notify.css" />

View File

@ -130,7 +130,6 @@ openerp.base = function(instance) {
openerp.base.search(instance);
openerp.base.list(instance);
openerp.base.tree(instance);
openerp.base.m2o(instance);
openerp.base.form(instance);
};

View File

@ -325,13 +325,14 @@ openerp.base.DataSet = openerp.base.Controller.extend( /** @lends openerp.base.
args: args
}, callback);
},
name_search: function (search_str, callback) {
name_search: function (search_str, limit, callback) {
search_str = search_str || '';
return this.rpc('/base/dataset/name_search', {
model: this.model,
search_str: search_str,
domain: this.domain || [],
context: this.context
context: this.context,
limit: limit || null
}, callback);
},
exec_workflow: function (id, signal, callback) {

View File

@ -951,46 +951,59 @@ openerp.base.form.FieldSelection = openerp.base.form.Field.extend({
}
});
openerp.base.form.FieldMany2OneDatasSet = openerp.base.DataSetStatic.extend({
start: function() {
},
write: function (id, data, callback) {
this._super(id, data, callback);
}
});
openerp.base.form.FieldMany2One = openerp.base.form.Field.extend({
init: function(view, node) {
this._super(view, node);
this.template = "FieldMany2One";
this.is_field_m2o = true;
this.limit = 7;
},
start: function() {
this.$element = $('#' + this.element_id);
this.dataset = new openerp.base.form.FieldMany2OneDatasSet(this.session, this.field.relation);
var views = [ [false,"list"], [false,"form"] ];
new openerp.base.m2o(this.$element, this.field.relation, this.dataset, this.session)
this.$element.find('input').change(this.on_ui_change);
this._super();
var self = this;
this.$input = this.$element.find("input");
this.$drop_down = this.$element.find("span");
this.$menu_btn = this.$element.find("button");
this.$drop_down.button({
icons: {primary: "ui-icon-triangle-1-s"}, text: false
});
this.$input.autocomplete({
source: function(req, resp) { self.get_search_result(req, resp); }
});
},
get_search_result: function(request, response) {
var search_val = request.term;
var self = this;
var dataset = new openerp.base.DataSetStatic(this.session, this.field.relation, []);
dataset.name_search(search_val, this.limit + 1, function(data){
var result = data.result;
var values = [];
$.each(result, function(i, val){
values.push({
value: val[1],
id: val[0]
});
});
var overflow = false;
if (values.length > this.limit) {
values = values.slice(0, this.limit);
overflow = true;
}
response(values);
});
},
set_value: function(value) {
this._super.apply(this, arguments);
var show_value = '';
if (value != null && value !== false) {
show_value = value[1];
this.value = value[0];
if (value != false) {
this.data_id = value;
}
this.$element.find('input').val(show_value);
this.$element.find('input').attr('m2o_id', this.value);
},
get_value: function() {
var val = this.$element.find('input').attr('m2o_id') || this.value
return val;
return "";
},
on_ui_change: function() {
this.touched = this.view.touched = true;
}
});
openerp.base.form.FieldOne2Many = openerp.base.form.Field.extend({

View File

@ -1,4 +1,16 @@
openerp.base.m2o = function(openerp){
/*
<input type="text"
t-att-name="widget.name"
t-att-id="widget.element_id + '_field'"
t-att-class="'field_' + widget.type"
t-att-type="widget.type"
style="width: 100%;"/>
<span type='button' t-att-class="'ui_combo'" tabindex="'-1'" title="'Show All Items'"></span>
<img t-att-id="widget.name + '_open'" t-att-alt="'Open'" t-att-title="'Create'"
t-att-src="'/base/static/src/img/iconset-d-drop.gif'" t-att-class="'m2o_open'"/>
*/
openerp.base.m2o = openerp.base.Controller.extend({
init: function(element_id, model, dataset, session){

View File

@ -498,15 +498,12 @@
</select>
</t>
<t t-name="FieldMany2One">
<div style="padding-right: 16px;white-space: nowrap;">
<input type="text"
t-att-name="widget.name"
t-att-id="widget.element_id + '_field'"
t-att-class="'field_' + widget.type"
t-att-type="widget.type"
style="width: 100%;"/>
<span type='button' t-att-class="'ui_combo'" tabindex="'-1'" title="'Show All Items'"></span>
<img t-att-id="widget.name + '_open'" t-att-alt="'Open'" t-att-title="'Create'" t-att-src="'/base/static/src/img/iconset-d-drop.gif'" t-att-class="'m2o_open'"/>
<div t-att-id="widget.element_id" style="padding-right: 16px;white-space: nowrap;">
<input t-att-id="widget.element_id + '_input'" type="text" style="width: 100%;"/>
<span t-att-id="widget.element_id + '_drop_down'" type="button" class="ui_combo"
tabindex="-1" title="Show All Items"></span>
<img t-att-id="widget.name + '_open'" alt="Open" title="Create"
src="/base/static/src/img/iconset-d-drop.gif" class="m2o_open"/>
</div>
</t>
<t t-name="FieldOne2Many">