summaryrefslogtreecommitdiff
path: root/addons/web/static/src/js/view_form.js
diff options
context:
space:
mode:
authorniv-openerp <nicolas.vanhoren@openerp.com>2012-11-08 11:01:45 +0100
committerniv-openerp <nicolas.vanhoren@openerp.com>2012-11-08 11:01:45 +0100
commit86f9f5db35d4b438e42e99f8abd985e80932b1c0 (patch)
treebc2418ba4feba17e15769e45196b9250b0e9c91a /addons/web/static/src/js/view_form.js
parentfd2bb078fb297c59b0359816e5cff5a33dbfc1a7 (diff)
parenta963bd019a70c58adf6e5a190bcb3294493bdcb5 (diff)
merge trunk
bzr revid: nicolas.vanhoren@openerp.com-20121108100145-i1ey2f6g07nri18a
Diffstat (limited to 'addons/web/static/src/js/view_form.js')
-rw-r--r--addons/web/static/src/js/view_form.js91
1 files changed, 84 insertions, 7 deletions
diff --git a/addons/web/static/src/js/view_form.js b/addons/web/static/src/js/view_form.js
index dd9d8fe7c09..1b4ecfcbaf7 100644
--- a/addons/web/static/src/js/view_form.js
+++ b/addons/web/static/src/js/view_form.js
@@ -2270,6 +2270,13 @@ instance.web.form.FieldChar = instance.web.form.AbstractField.extend(instance.we
focus: function() {
this.$('input:first').focus();
},
+ set_dimensions: function (height, width) {
+ this._super(height, width);
+ this.$('input').css({
+ height: height,
+ width: width
+ });
+ }
});
instance.web.form.FieldID = instance.web.form.FieldChar.extend({
@@ -2555,7 +2562,7 @@ instance.web.form.FieldText = instance.web.form.AbstractField.extend(instance.we
this.$textarea.focus();
},
set_dimensions: function (height, width) {
- this._super();
+ this._super(height, width);
this.$textarea.css({
width: width,
minHeight: height
@@ -2717,6 +2724,13 @@ instance.web.form.FieldSelection = instance.web.form.AbstractField.extend(instan
},
focus: function() {
this.$el.find('select:first').focus();
+ },
+ set_dimensions: function (height, width) {
+ this._super(height, width);
+ this.$('select').css({
+ height: height,
+ width: width
+ });
}
});
@@ -3199,6 +3213,62 @@ instance.web.form.FieldMany2One = instance.web.form.AbstractField.extend(instanc
this.ed_def.reject();
return instance.web.form.CompletionFieldMixin._search_create_popup.apply(this, arguments);
},
+ set_dimensions: function (height, width) {
+ this._super(height, width);
+ this.$input.css('height', height);
+ }
+});
+
+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();
+ },
});
/*
@@ -3962,6 +4032,8 @@ instance.web.form.FieldMany2ManyTags = instance.web.form.AbstractField.extend(in
var dataset = new instance.web.DataSetStatic(this, this.field.relation, self.build_context());
var values = self.get("value")
var handle_names = function(data) {
+ if (self.isDestroyed())
+ return;
var indexed = {};
_.each(data, function(el) {
indexed[el[0]] = el;
@@ -4372,13 +4444,14 @@ 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 saved', r);
self.created_elements.push(r);
});
};
this.dataset.write_function = function(id, data, options, sup) {
var fct = self.options.write_function || sup;
return fct.call(this, id, data, options).then(function() {
- self.trigger('write_completed');
+ self.trigger('write_completed saved');
});
};
this.dataset.parent_view = this.options.parent_view;
@@ -4455,9 +4528,11 @@ instance.web.form.AbstractFormPopup = instance.web.Widget.extend({
this.select_elements(this.created_elements);
this.created_elements = [];
}
+ this.trigger('closed');
this.destroy();
},
destroy: function () {
+ this.trigger('closed');
this.$el.dialog('close');
this._super();
},
@@ -4861,6 +4936,7 @@ instance.web.form.FieldBinaryFile = instance.web.form.FieldBinary.extend({
instance.web.form.FieldBinaryImage = instance.web.form.FieldBinary.extend({
template: 'FieldBinaryImage',
+ placeholder: "/web/static/src/img/placeholder.png",
render_value: function() {
var self = this;
var url;
@@ -4874,7 +4950,7 @@ instance.web.form.FieldBinaryImage = instance.web.form.FieldBinary.extend({
url = '/web/binary/image?session_id=' + this.session.session_id + '&model=' +
this.view.dataset.model +'&id=' + id + '&field=' + field + '&t=' + (new Date().getTime());
} else {
- url = "/web/static/src/img/placeholder.png";
+ url = this.placeholder;
}
var $img = $(QWeb.render("FieldBinaryImage-img", { widget: this, url: url }));
this.$el.find('> img').remove();
@@ -4887,10 +4963,10 @@ instance.web.form.FieldBinaryImage = instance.web.form.FieldBinary.extend({
$img.css("margin-left", "" + (self.options.size[0] - $img.width()) / 2 + "px");
$img.css("margin-top", "" + (self.options.size[1] - $img.height()) / 2 + "px");
});
- },
- on_file_change: function() {
- this.render_value();
- this._super.apply(this, arguments);
+ $img.on('error', function() {
+ $img.attr('src', self.placeholder);
+ instance.webclient.notification.warn(_t("Image"), _t("Could not display the selected image."));
+ });
},
on_file_uploaded_and_valid: function(size, name, content_type, file_base64) {
this.internal_set_value(file_base64);
@@ -5170,6 +5246,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',