summaryrefslogtreecommitdiff
path: root/addons/web/static/src/js
diff options
context:
space:
mode:
authorniv-openerp <nicolas.vanhoren@openerp.com>2011-09-08 16:58:45 +0200
committerniv-openerp <nicolas.vanhoren@openerp.com>2011-09-08 16:58:45 +0200
commit6f178015e187c852cefef4149b58fb6b0a394cc5 (patch)
treea57d5323c1a163d9b71cc0350b2f9965674c8626 /addons/web/static/src/js
parente60032e11c335472d384921d62c288a84b1ca08a (diff)
[imp] setup of status widget
bzr revid: nicolas.vanhoren@openerp.com-20110908145845-85ao2yvkpvsnc6kg
Diffstat (limited to 'addons/web/static/src/js')
-rw-r--r--addons/web/static/src/js/form.js56
1 files changed, 55 insertions, 1 deletions
diff --git a/addons/web/static/src/js/form.js b/addons/web/static/src/js/form.js
index d4bf9d76573..232cc7fbb30 100644
--- a/addons/web/static/src/js/form.js
+++ b/addons/web/static/src/js/form.js
@@ -2478,6 +2478,59 @@ openerp.web.form.FieldBinaryImage = openerp.web.form.FieldBinary.extend({
}
});
+openerp.web.form.FieldStatus = openerp.web.form.Field.extend({
+ init: function(view, node) {
+ var self = this;
+ this._super(view, node);
+ this.template = "FieldSelection";
+ this.values = this.field.selection;
+ _.each(this.values, function(v, i) {
+ if (v[0] === false && v[1] === '') {
+ self.values.splice(i, 1);
+ }
+ });
+ this.values.unshift([false, '']);
+ },
+ start: function() {
+ var ischanging = false;
+ this._super.apply(this, arguments);
+ this.$element.find('select')
+ .change(this.on_ui_change)
+ .change(function () { ischanging = true; })
+ .click(function () { ischanging = false; })
+ .keyup(function (e) {
+ if (e.which !== 13 || !ischanging) { return; }
+ e.stopPropagation();
+ ischanging = false;
+ });
+ },
+ set_value: function(value) {
+ value = value === null ? false : value;
+ value = value instanceof Array ? value[0] : value;
+ this._super(value);
+ var index = 0;
+ for (var i = 0, ii = this.values.length; i < ii; i++) {
+ if (this.values[i][0] === value) index = i;
+ }
+ this.$element.find('select')[0].selectedIndex = index;
+ },
+ set_value_from_ui: function() {
+ this.value = this.values[this.$element.find('select')[0].selectedIndex][0];
+ this._super();
+ },
+ update_dom: function() {
+ this._super.apply(this, arguments);
+ this.$element.find('select').attr('disabled', this.readonly);
+ },
+ validate: function() {
+ var value = this.values[this.$element.find('select')[0].selectedIndex];
+ this.invalid = !(value && !(this.required && value[0] === false));
+ },
+ focus: function() {
+ this.$element.find('select').focus();
+ }
+});
+
/**
* Registry of form widgets, called by :js:`openerp.web.FormView`
*/
@@ -2507,7 +2560,8 @@ openerp.web.form.widgets = new openerp.web.Registry({
'float_time': 'openerp.web.form.FieldFloat',
'progressbar': 'openerp.web.form.FieldProgressBar',
'image': 'openerp.web.form.FieldBinaryImage',
- 'binary': 'openerp.web.form.FieldBinaryFile'
+ 'binary': 'openerp.web.form.FieldBinaryFile',
+ 'status': 'openerp.web.form.FieldStatus'
});
};