[deep-cleaning] first step of rewriting m2o
bzr revid: nicolas.vanhoren@openerp.com-20110606165043-dae2xm6d48vq4z7m
This commit is contained in:
parent
1ab89fb420
commit
a4e8b8e017
|
@ -447,9 +447,9 @@ class DataSet(openerpweb.Controller):
|
||||||
return {'result': r}
|
return {'result': r}
|
||||||
|
|
||||||
@openerpweb.jsonrequest
|
@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)
|
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}
|
return {'result': r}
|
||||||
|
|
||||||
class DataGroup(openerpweb.Controller):
|
class DataGroup(openerpweb.Controller):
|
||||||
|
|
|
@ -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/list.js"></script>
|
||||||
<script type="text/javascript" src="/base/static/src/js/tree.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/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/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" />
|
<link rel="stylesheet" type="text/css" media="screen" href="/base/static/lib/jquery.ui.notify/css/ui.notify.css" />
|
||||||
|
|
|
@ -130,7 +130,6 @@ openerp.base = function(instance) {
|
||||||
openerp.base.search(instance);
|
openerp.base.search(instance);
|
||||||
openerp.base.list(instance);
|
openerp.base.list(instance);
|
||||||
openerp.base.tree(instance);
|
openerp.base.tree(instance);
|
||||||
openerp.base.m2o(instance);
|
|
||||||
openerp.base.form(instance);
|
openerp.base.form(instance);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -325,13 +325,14 @@ openerp.base.DataSet = openerp.base.Controller.extend( /** @lends openerp.base.
|
||||||
args: args
|
args: args
|
||||||
}, callback);
|
}, callback);
|
||||||
},
|
},
|
||||||
name_search: function (search_str, callback) {
|
name_search: function (search_str, limit, callback) {
|
||||||
search_str = search_str || '';
|
search_str = search_str || '';
|
||||||
return this.rpc('/base/dataset/name_search', {
|
return this.rpc('/base/dataset/name_search', {
|
||||||
model: this.model,
|
model: this.model,
|
||||||
search_str: search_str,
|
search_str: search_str,
|
||||||
domain: this.domain || [],
|
domain: this.domain || [],
|
||||||
context: this.context
|
context: this.context,
|
||||||
|
limit: limit || null
|
||||||
}, callback);
|
}, callback);
|
||||||
},
|
},
|
||||||
exec_workflow: function (id, signal, callback) {
|
exec_workflow: function (id, signal, callback) {
|
||||||
|
|
|
@ -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({
|
openerp.base.form.FieldMany2One = openerp.base.form.Field.extend({
|
||||||
init: function(view, node) {
|
init: function(view, node) {
|
||||||
this._super(view, node);
|
this._super(view, node);
|
||||||
this.template = "FieldMany2One";
|
this.template = "FieldMany2One";
|
||||||
this.is_field_m2o = true;
|
this.is_field_m2o = true;
|
||||||
|
this.limit = 7;
|
||||||
},
|
},
|
||||||
start: function() {
|
start: function() {
|
||||||
this.$element = $('#' + this.element_id);
|
this._super();
|
||||||
this.dataset = new openerp.base.form.FieldMany2OneDatasSet(this.session, this.field.relation);
|
var self = this;
|
||||||
var views = [ [false,"list"], [false,"form"] ];
|
this.$input = this.$element.find("input");
|
||||||
new openerp.base.m2o(this.$element, this.field.relation, this.dataset, this.session)
|
this.$drop_down = this.$element.find("span");
|
||||||
this.$element.find('input').change(this.on_ui_change);
|
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) {
|
set_value: function(value) {
|
||||||
this._super.apply(this, arguments);
|
if (value != false) {
|
||||||
var show_value = '';
|
this.data_id = value;
|
||||||
if (value != null && value !== false) {
|
|
||||||
show_value = value[1];
|
|
||||||
this.value = value[0];
|
|
||||||
}
|
}
|
||||||
this.$element.find('input').val(show_value);
|
|
||||||
this.$element.find('input').attr('m2o_id', this.value);
|
|
||||||
},
|
},
|
||||||
|
|
||||||
get_value: function() {
|
get_value: function() {
|
||||||
var val = this.$element.find('input').attr('m2o_id') || this.value
|
return "";
|
||||||
return val;
|
|
||||||
},
|
},
|
||||||
|
|
||||||
on_ui_change: function() {
|
|
||||||
this.touched = this.view.touched = true;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
openerp.base.form.FieldOne2Many = openerp.base.form.Field.extend({
|
openerp.base.form.FieldOne2Many = openerp.base.form.Field.extend({
|
||||||
|
|
|
@ -1,4 +1,16 @@
|
||||||
openerp.base.m2o = function(openerp){
|
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({
|
openerp.base.m2o = openerp.base.Controller.extend({
|
||||||
init: function(element_id, model, dataset, session){
|
init: function(element_id, model, dataset, session){
|
||||||
|
|
|
@ -498,15 +498,12 @@
|
||||||
</select>
|
</select>
|
||||||
</t>
|
</t>
|
||||||
<t t-name="FieldMany2One">
|
<t t-name="FieldMany2One">
|
||||||
<div style="padding-right: 16px;white-space: nowrap;">
|
<div t-att-id="widget.element_id" style="padding-right: 16px;white-space: nowrap;">
|
||||||
<input type="text"
|
<input t-att-id="widget.element_id + '_input'" type="text" style="width: 100%;"/>
|
||||||
t-att-name="widget.name"
|
<span t-att-id="widget.element_id + '_drop_down'" type="button" class="ui_combo"
|
||||||
t-att-id="widget.element_id + '_field'"
|
tabindex="-1" title="Show All Items"></span>
|
||||||
t-att-class="'field_' + widget.type"
|
<img t-att-id="widget.name + '_open'" alt="Open" title="Create"
|
||||||
t-att-type="widget.type"
|
src="/base/static/src/img/iconset-d-drop.gif" class="m2o_open"/>
|
||||||
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>
|
</div>
|
||||||
</t>
|
</t>
|
||||||
<t t-name="FieldOne2Many">
|
<t t-name="FieldOne2Many">
|
||||||
|
|
Loading…
Reference in New Issue