[imp] added display of relateds

bzr revid: nicolas.vanhoren@openerp.com-20110825151701-frwri4f5ge6rnsvf
This commit is contained in:
niv-openerp 2011-08-25 17:17:01 +02:00
parent 2ca0749fd5
commit 9225fe4074
3 changed files with 49 additions and 35 deletions

View File

@ -396,18 +396,18 @@ openerp.base.DataSet = openerp.base.Widget.extend( /** @lends openerp.base.Data
*
* @param {String} method
* @param {Array} [args]
* @param {Number} [domain_id] index of a domain to evaluate in the args array
* @param {Number} [context_id] index of a context to evaluate in the args array
* @param {Number} [domain_index] index of a domain to evaluate in the args array
* @param {Number} [context_index] index of a context to evaluate in the args array
* @param {Function} callback
* @param {Function }error_callback
* @returns {$.Deferred}
*/
call_and_eval: function (method, args, domain_id, context_id, callback, error_callback) {
call_and_eval: function (method, args, domain_index, context_index, callback, error_callback) {
return this.rpc('/base/dataset/call', {
model: this.model,
method: method,
domain_id: domain_id || null,
context_id: context_id || null,
domain_id: domain_index || null,
context_id: context_index || null,
args: args || []
}, callback, error_callback);
},

View File

@ -1309,37 +1309,44 @@ openerp.base.form.FieldMany2One = openerp.base.form.Field.extend({
// context menu
var init_context_menu_def = $.Deferred().then(function(e) {
var $cmenu = $("#" + self.cm_id);
$cmenu.append(QWeb.render("FieldMany2One.context_menu", {widget: self}));
var bindings = {};
bindings[self.cm_id + "_search"] = function() {
self._search_create_popup("search");
};
bindings[self.cm_id + "_create"] = function() {
self._search_create_popup("form");
};
bindings[self.cm_id + "_open"] = function() {
if (!self.value) {
return;
}
var pop = new openerp.base.form.FormOpenPopup(self.view);
pop.show_element(self.field.relation, self.value[0],self.build_context(), {});
pop.on_write_completed.add_last(function() {
self.set_value(self.value[0]);
});
};
var cmenu = self.$menu_btn.contextMenu(self.cm_id, {'leftClickToo': true,
bindings: bindings, itemStyle: {"color": ""},
onContextMenu: function() {
if(self.value) {
$("#" + self.cm_id + "_open").removeClass("oe-m2o-disabled-cm");
} else {
$("#" + self.cm_id + "_open").addClass("oe-m2o-disabled-cm");
var rdataset = new openerp.base.DataSetStatic(self, "ir.values", self.build_context());
rdataset.call("get", ['action', 'client_action_relate',
[[self.field.relation, false]], false, rdataset.get_context()], false, 0)
.then(function(result) {
self.related_entries = result;
var $cmenu = $("#" + self.cm_id);
$cmenu.append(QWeb.render("FieldMany2One.context_menu", {widget: self}));
var bindings = {};
bindings[self.cm_id + "_search"] = function() {
self._search_create_popup("search");
};
bindings[self.cm_id + "_create"] = function() {
self._search_create_popup("form");
};
bindings[self.cm_id + "_open"] = function() {
if (!self.value) {
return;
}
return true;
}
var pop = new openerp.base.form.FormOpenPopup(self.view);
pop.show_element(self.field.relation, self.value[0],self.build_context(), {});
pop.on_write_completed.add_last(function() {
self.set_value(self.value[0]);
});
};
var cmenu = self.$menu_btn.contextMenu(self.cm_id, {'leftClickToo': true,
bindings: bindings, itemStyle: {"color": ""},
onContextMenu: function() {
if(self.value) {
$("#" + self.cm_id + " .oe_m2o_menu_item_mandatory").removeClass("oe-m2o-disabled-cm");
} else {
$("#" + self.cm_id + " .oe_m2o_menu_item_mandatory").addClass("oe-m2o-disabled-cm");
}
return true;
}, menuStyle: {width: "200px"}
});
setTimeout(function() {self.$menu_btn.trigger(e);}, 0);
});
setTimeout(function() {self.$menu_btn.trigger(e);}, 0);
});
var ctx_callback = function(e) {init_context_menu_def.resolve(e); e.preventDefault()};
this.$menu_btn.bind('contextmenu', ctx_callback);

View File

@ -813,7 +813,14 @@
<ul>
<li t-att-id="widget.cm_id + '_open'" style="color:grey">Open...</li>
<li t-att-id="widget.cm_id + '_create'">Create...</li>
<li t-att-id="widget.cm_id + '_search'">Search...</li>
<li t-att-id="widget.cm_id + '_search'" class="oe_m2o_menu_item_mandatory">Search...</li>
<t t-set="i" t-value="0"/>
<t t-foreach="widget.related_entries" t-as="entry">
<li t-att-id="widget.cm_id + '_related_' + i" style="color:grey" class="oe_m2o_menu_item_mandatory">
... <t t-esc="(entry[2] || {})['name'] || ''"/>
</li>
<t t-set="i" t-value="i+1"/>
</t>
</ul>
</t>
<t t-name="FieldOne2Many">