[MERGE] m2o button
bzr revid: al@openerp.com-20121107151954-aqqtn4w6hpd39kmi
This commit is contained in:
commit
a963bd019a
|
@ -3166,6 +3166,58 @@ instance.web.form.FieldMany2One = instance.web.form.AbstractField.extend(instanc
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
instance.web.form.Many2OneButton = instance.web.form.AbstractField.extend({
|
||||||
|
template: 'Many2OneButton',
|
||||||
|
init: function(field_manager, node) {
|
||||||
|
this._super.apply(this, arguments);
|
||||||
|
},
|
||||||
|
start: function() {
|
||||||
|
this._super.apply(this, arguments);
|
||||||
|
this.set_button();
|
||||||
|
},
|
||||||
|
set_button: function() {
|
||||||
|
var self = this;
|
||||||
|
if (this.$button) {
|
||||||
|
this.$button.remove();
|
||||||
|
}
|
||||||
|
var options = {};
|
||||||
|
try {
|
||||||
|
options = py.eval(this.node.attrs.options);
|
||||||
|
} catch (e) {}
|
||||||
|
if (options.label) {
|
||||||
|
this.string = this.get('value') ? _t(options.label.edit) : _t(options.label.create);
|
||||||
|
} else {
|
||||||
|
this.string = '';
|
||||||
|
}
|
||||||
|
this.node.attrs.icon = this.get('value') ? '/web/static/src/img/icons/gtk-yes.png' : '/web/static/src/img/icons/gtk-no.png';
|
||||||
|
this.$button = $(QWeb.render('WidgetButton', {'widget': this}));
|
||||||
|
this.$el.append(this.$button);
|
||||||
|
this.$button.on('click', self.on_click);
|
||||||
|
},
|
||||||
|
on_click: function(ev) {
|
||||||
|
var self = this;
|
||||||
|
this.popup = new instance.web.form.FormOpenPopup(this);
|
||||||
|
this.popup.show_element(
|
||||||
|
this.field.relation,
|
||||||
|
this.get('value'),
|
||||||
|
this.build_context(),
|
||||||
|
{title: this.string}
|
||||||
|
);
|
||||||
|
this.popup.on('create_completed write_completed', self, function(r) {
|
||||||
|
self.set_value(r);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
set_value: function(value_) {
|
||||||
|
var self = this;
|
||||||
|
if (value_ instanceof Array) {
|
||||||
|
value_ = value_[0];
|
||||||
|
}
|
||||||
|
value_ = value_ || false;
|
||||||
|
this.set('value', value_);
|
||||||
|
this.set_button();
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
/*
|
/*
|
||||||
# Values: (0, 0, { fields }) create
|
# Values: (0, 0, { fields }) create
|
||||||
# (1, ID, { fields }) update
|
# (1, ID, { fields }) update
|
||||||
|
@ -5154,6 +5206,7 @@ instance.web.form.widgets = new instance.web.Registry({
|
||||||
'datetime' : 'instance.web.form.FieldDatetime',
|
'datetime' : 'instance.web.form.FieldDatetime',
|
||||||
'selection' : 'instance.web.form.FieldSelection',
|
'selection' : 'instance.web.form.FieldSelection',
|
||||||
'many2one' : 'instance.web.form.FieldMany2One',
|
'many2one' : 'instance.web.form.FieldMany2One',
|
||||||
|
'many2onebutton' : 'instance.web.form.Many2OneButton',
|
||||||
'many2many' : 'instance.web.form.FieldMany2Many',
|
'many2many' : 'instance.web.form.FieldMany2Many',
|
||||||
'many2many_tags' : 'instance.web.form.FieldMany2ManyTags',
|
'many2many_tags' : 'instance.web.form.FieldMany2ManyTags',
|
||||||
'many2many_kanban' : 'instance.web.form.FieldMany2ManyKanban',
|
'many2many_kanban' : 'instance.web.form.FieldMany2ManyKanban',
|
||||||
|
|
|
@ -2012,6 +2012,7 @@ instance.web.list.columns = new instance.web.Registry({
|
||||||
'field.progressbar': 'instance.web.list.ProgressBar',
|
'field.progressbar': 'instance.web.list.ProgressBar',
|
||||||
'field.handle': 'instance.web.list.Handle',
|
'field.handle': 'instance.web.list.Handle',
|
||||||
'button': 'instance.web.list.Button',
|
'button': 'instance.web.list.Button',
|
||||||
|
'field.many2onebutton': 'instance.web.list.Many2OneButton',
|
||||||
});
|
});
|
||||||
instance.web.list.columns.for_ = function (id, field, node) {
|
instance.web.list.columns.for_ = function (id, field, node) {
|
||||||
var description = _.extend({tag: node.tag}, field, node.attrs);
|
var description = _.extend({tag: node.tag}, field, node.attrs);
|
||||||
|
@ -2199,5 +2200,11 @@ instance.web.list.Handle = instance.web.list.Column.extend({
|
||||||
return '<div class="oe_list_handle">';
|
return '<div class="oe_list_handle">';
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
instance.web.list.Many2OneButton = instance.web.list.Column.extend({
|
||||||
|
_format: function (row_data, options) {
|
||||||
|
this.has_value = !!row_data[this.id].value;
|
||||||
|
return QWeb.render('Many2OneButton.cell', {'widget': this});
|
||||||
|
},
|
||||||
|
});
|
||||||
};
|
};
|
||||||
// vim:et fdc=0 fdl=0 foldnestmax=3 fdm=syntax:
|
// vim:et fdc=0 fdl=0 foldnestmax=3 fdm=syntax:
|
||||||
|
|
|
@ -1027,6 +1027,13 @@
|
||||||
</t>
|
</t>
|
||||||
</span>
|
</span>
|
||||||
</t>
|
</t>
|
||||||
|
<t t-name="Many2OneButton">
|
||||||
|
<span class="oe_form_field">
|
||||||
|
</span>
|
||||||
|
</t>
|
||||||
|
<t t-name="Many2OneButton.cell"
|
||||||
|
><img t-attf-src="#{_s}/web/static/src/img/icons/gtk-#{widget.has_value ? 'yes' : 'no'}.png" width="16" height="16"/>
|
||||||
|
</t>
|
||||||
<t t-name="FieldMany2ManyTags">
|
<t t-name="FieldMany2ManyTags">
|
||||||
<div class="oe_form_field oe_tags" t-att-style="widget.node.attrs.style">
|
<div class="oe_form_field oe_tags" t-att-style="widget.node.attrs.style">
|
||||||
<t t-if="! widget.get('effective_readonly')">
|
<t t-if="! widget.get('effective_readonly')">
|
||||||
|
|
Loading…
Reference in New Issue