[ADD] Added new widget, Many2OneButton, to view_form.js and view_list.js.
bzr revid: vta@openerp.com-20121105130232-rpde2k1ihbquznmg
This commit is contained in:
parent
6f57449dcd
commit
3b87df079e
|
@ -3148,6 +3148,54 @@ 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();
|
||||
}
|
||||
this.string = this.get('value') ? _t('Edit') : _t('Create');
|
||||
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;
|
||||
ev.stopPropagation();
|
||||
var popup = new instance.web.form.FormOpenPopup(this);
|
||||
popup.show_element(
|
||||
this.field.relation,
|
||||
this.get('value'),
|
||||
this.build_context(),
|
||||
{title: this.string + ' ' +_t("Voucher: ")}
|
||||
);
|
||||
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();
|
||||
if (this.is_started) {
|
||||
this.render_value();
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
/*
|
||||
# Values: (0, 0, { fields }) create
|
||||
# (1, ID, { fields }) update
|
||||
|
@ -4332,6 +4380,7 @@ instance.web.form.AbstractFormPopup = instance.web.Widget.extend({
|
|||
this.dataset.create_function = function(data, sup) {
|
||||
var fct = self.options.create_function || sup;
|
||||
return fct.call(this, data).then(function(r) {
|
||||
self.trigger('create_completed');
|
||||
self.created_elements.push(r);
|
||||
});
|
||||
};
|
||||
|
@ -5130,6 +5179,7 @@ instance.web.form.widgets = new instance.web.Registry({
|
|||
'datetime' : 'instance.web.form.FieldDatetime',
|
||||
'selection' : 'instance.web.form.FieldSelection',
|
||||
'many2one' : 'instance.web.form.FieldMany2One',
|
||||
'many2onebutton' : 'instance.web.form.Many2OneButton',
|
||||
'many2many' : 'instance.web.form.FieldMany2Many',
|
||||
'many2many_tags' : 'instance.web.form.FieldMany2ManyTags',
|
||||
'many2many_kanban' : 'instance.web.form.FieldMany2ManyKanban',
|
||||
|
|
|
@ -2010,6 +2010,7 @@ instance.web.list.columns = new instance.web.Registry({
|
|||
'field.progressbar': 'instance.web.list.ProgressBar',
|
||||
'field.handle': 'instance.web.list.Handle',
|
||||
'button': 'instance.web.list.Button',
|
||||
'field.many2onebutton': 'instance.web.list.Many2OneButton',
|
||||
});
|
||||
instance.web.list.columns.for_ = function (id, field, node) {
|
||||
var description = _.extend({tag: node.tag}, field, node.attrs);
|
||||
|
@ -2197,5 +2198,15 @@ instance.web.list.Handle = instance.web.list.Column.extend({
|
|||
return '<div class="oe_list_handle">';
|
||||
}
|
||||
});
|
||||
instance.web.list.Many2OneButton = instance.web.list.Column.extend({
|
||||
_format: function (row_data, options) {
|
||||
if (row_data.voucher_id.value) {
|
||||
this.icon = '/web/static/src/img/icons/gtk-yes.png';
|
||||
} else {
|
||||
this.icon = '/web/static/src/img/icons/gtk-no.png';
|
||||
}
|
||||
return QWeb.render('Many2OneButton.cell', {'widget': this});
|
||||
},
|
||||
});
|
||||
};
|
||||
// vim:et fdc=0 fdl=0 foldnestmax=3 fdm=syntax:
|
||||
|
|
|
@ -1029,6 +1029,13 @@
|
|||
</t>
|
||||
</span>
|
||||
</t>
|
||||
<t t-name="Many2OneButton">
|
||||
<span class="oe_form_field">
|
||||
</span>
|
||||
</t>
|
||||
<t t-name="Many2OneButton.cell"
|
||||
><img t-if="widget.icon" t-att-src="_s + widget.icon" width="16" height="16"/>
|
||||
</t>
|
||||
<t t-name="FieldMany2ManyTags">
|
||||
<div class="oe_form_field oe_tags" t-att-style="widget.node.attrs.style">
|
||||
<t t-if="! widget.get('effective_readonly')">
|
||||
|
|
Loading…
Reference in New Issue