[imp] switched m2o page to m2o readonly

bzr revid: nicolas.vanhoren@openerp.com-20120313143805-s42lc32kh12tkh4h
This commit is contained in:
niv-openerp
2012-03-13 15:38:05 +01:00
parent ec8c17161c
commit d4ecfc4c4f
2 changed files with 10 additions and 49 deletions
+8 -5
View File
@@ -1919,6 +1919,9 @@ openerp.web.form.FieldMany2One = openerp.web.form.Field.extend({
this.last_search = [];
this.tmp_value = undefined;
},
is_readonly: function() {
return this.readonly || this.force_readonly;
},
start: function() {
this._super();
var self = this;
@@ -1938,12 +1941,12 @@ openerp.web.form.FieldMany2One = openerp.web.form.Field.extend({
$cmenu.append(QWeb.render("FieldMany2One.context_menu", {widget: self}));
var bindings = {};
bindings[self.cm_id + "_search"] = function() {
if (self.readonly)
if (self.is_readonly())
return;
self._search_create_popup("search");
};
bindings[self.cm_id + "_create"] = function() {
if (self.readonly)
if (self.is_readonly())
return;
self._search_create_popup("form");
};
@@ -1977,7 +1980,7 @@ openerp.web.form.FieldMany2One = openerp.web.form.Field.extend({
} else {
$("#" + self.cm_id + " .oe_m2o_menu_item_mandatory").addClass("oe-m2o-disabled-cm");
}
if (!self.readonly) {
if (!self.is_readonly()) {
$("#" + self.cm_id + " .oe_m2o_menu_item_noreadonly").removeClass("oe-m2o-disabled-cm");
} else {
$("#" + self.cm_id + " .oe_m2o_menu_item_noreadonly").addClass("oe-m2o-disabled-cm");
@@ -2000,7 +2003,7 @@ openerp.web.form.FieldMany2One = openerp.web.form.Field.extend({
}
});
this.$drop_down.click(function() {
if (self.readonly)
if (self.is_readonly())
return;
if (self.$input.autocomplete("widget").is(":visible")) {
self.$input.autocomplete("close");
@@ -2234,7 +2237,7 @@ openerp.web.form.FieldMany2One = openerp.web.form.Field.extend({
},
update_dom: function() {
this._super.apply(this, arguments);
this.$input.prop('readonly', this.readonly);
this.$input.prop('readonly', this.is_readonly());
}
});
+2 -44
View File
@@ -142,50 +142,8 @@ openerp.web.page = function (openerp) {
this.$element.find('div').text(option ? option[1] : this.values[0][1]);
}
});
openerp.web.page.FieldMany2OneReadonly = openerp.web.page.FieldURIReadonly.extend({
set_value: function (value) {
value = value || null;
this.invalid = false;
var self = this;
this.value = value;
self.update_dom();
self.on_value_changed();
var real_set_value = function(rval) {
self.value = rval;
self.$element.find('a')
.unbind('click')
.text(rval ? rval[1] : '')
.click(function () {
self.do_action({
type: 'ir.actions.act_window',
res_model: self.field.relation,
res_id: self.value[0],
context: self.build_context(),
views: [[false, 'page'], [false, 'form']],
target: 'current'
});
return false;
});
};
if (value && !(value instanceof Array)) {
new openerp.web.DataSetStatic(
this, this.field.relation, self.build_context())
.name_get([value], function(data) {
real_set_value(data[0]);
});
} else {
$.async_when().then(function() {real_set_value(value);});
}
},
get_value: function() {
if (!this.value) {
return false;
} else if (this.value instanceof Array) {
return this.value[0];
} else {
return this.value;
}
}
openerp.web.page.FieldMany2OneReadonly = openerp.web.form.FieldMany2One.extend({
force_readonly: true,
});
openerp.web.page.FieldReferenceReadonly = openerp.web.page.FieldMany2OneReadonly.extend({
set_value: function (value) {