Ported field status
bzr revid: nicolas.vanhoren@openerp.com-20121011161816-lnz7prb3ag6nrbi3
This commit is contained in:
parent
f5b1729758
commit
fb944a77fa
|
@ -4848,15 +4848,12 @@ instance.web.form.FieldStatus = instance.web.form.AbstractField.extend({
|
||||||
this._super(field_manager, node);
|
this._super(field_manager, node);
|
||||||
this.options.clickable = this.options.clickable || (this.node.attrs || {}).clickable || false;
|
this.options.clickable = this.options.clickable || (this.node.attrs || {}).clickable || false;
|
||||||
this.options.visible = this.options.visible || (this.node.attrs || {}).statusbar_visible || false;
|
this.options.visible = this.options.visible || (this.node.attrs || {}).statusbar_visible || false;
|
||||||
this.selected_value = null;
|
this.set({value: false});
|
||||||
},
|
},
|
||||||
start: function() {
|
start: function() {
|
||||||
// backward compatibility
|
|
||||||
this.loaded = new $.Deferred();
|
|
||||||
if (this.options.clickable) {
|
if (this.options.clickable) {
|
||||||
this.$el.on('click','li',this.on_click_stage);
|
this.$el.on('click','li',this.on_click_stage);
|
||||||
}
|
}
|
||||||
// TODO move the following into css :after
|
|
||||||
if (this.$el.parent().is('header')) {
|
if (this.$el.parent().is('header')) {
|
||||||
this.$el.after('<div class="oe_clear"/>');
|
this.$el.after('<div class="oe_clear"/>');
|
||||||
}
|
}
|
||||||
|
@ -4867,16 +4864,18 @@ instance.web.form.FieldStatus = instance.web.form.AbstractField.extend({
|
||||||
value_ = value_[0];
|
value_ = value_[0];
|
||||||
}
|
}
|
||||||
this._super(value_);
|
this._super(value_);
|
||||||
// trick to be sure all values are loaded in the form, therefore
|
|
||||||
// enabling the evaluation of dynamic domains
|
|
||||||
self.selection = [];
|
|
||||||
$.async_when().then(function() {
|
|
||||||
self.get_selection();
|
|
||||||
});
|
|
||||||
return this.loaded;
|
|
||||||
},
|
},
|
||||||
render_value: function() {
|
render_value: function() {
|
||||||
this.get_selection();
|
var self = this;
|
||||||
|
self.get_selection().then(function() {
|
||||||
|
var content = QWeb.render("FieldStatus.content", {widget: self});
|
||||||
|
self.$el.html(content);
|
||||||
|
var colors = JSON.parse((self.node.attrs || {}).statusbar_colors || "{}");
|
||||||
|
var color = colors[self.get('value')];
|
||||||
|
if (color) {
|
||||||
|
self.$("oe_active").css("color", color);
|
||||||
|
}
|
||||||
|
});
|
||||||
},
|
},
|
||||||
/** Get the selection and render it
|
/** Get the selection and render it
|
||||||
* selection: [[identifier, value_to_display], ...]
|
* selection: [[identifier, value_to_display], ...]
|
||||||
|
@ -4885,53 +4884,37 @@ instance.web.form.FieldStatus = instance.web.form.AbstractField.extend({
|
||||||
*/
|
*/
|
||||||
get_selection: function() {
|
get_selection: function() {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
self.selection = [];
|
||||||
if (this.field.type == "many2one") {
|
if (this.field.type == "many2one") {
|
||||||
var domain = [];
|
var domain = [];
|
||||||
if(!_.isEmpty(this.field.domain) || !_.isEmpty(this.node.attrs.domain)) {
|
if(!_.isEmpty(this.field.domain) || !_.isEmpty(this.node.attrs.domain)) {
|
||||||
domain = new instance.web.CompoundDomain(['|'], self.build_domain(), [['id', '=', self.selected_value]]);
|
domain = new instance.web.CompoundDomain(['|'], self.build_domain(), [['id', '=', self.get('value')]]);
|
||||||
}
|
}
|
||||||
var ds = new instance.web.DataSetSearch(this, this.field.relation, self.build_context(), domain);
|
var ds = new instance.web.DataSetSearch(this, this.field.relation, self.build_context(), domain);
|
||||||
ds.read_slice(['name'], {}).done( function (records) {
|
return ds.read_slice(['name'], {}).pipe(function (records) {
|
||||||
for(var i = 0; i < records.length; i++) {
|
for(var i = 0; i < records.length; i++) {
|
||||||
self.selection.push([records[i].id, records[i].name]);
|
self.selection.push([records[i].id, records[i].name]);
|
||||||
}
|
}
|
||||||
self.render_elements();
|
|
||||||
self.loaded.resolve();
|
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
this.loaded.resolve();
|
|
||||||
// For field type selection filter values according to
|
// For field type selection filter values according to
|
||||||
// statusbar_visible attribute of the field. For example:
|
// statusbar_visible attribute of the field. For example:
|
||||||
// statusbar_visible="draft,open".
|
// statusbar_visible="draft,open".
|
||||||
var selection = this.field.selection;
|
var selection = this.field.selection;
|
||||||
for(var i=0; i< selection.length; i++) {
|
for(var i=0; i < selection.length; i++) {
|
||||||
var key = selection[i][0];
|
var key = selection[i][0];
|
||||||
if(key == this.selected_value || !this.options.visible || this.options.visible.indexOf(key) != -1) {
|
if(key == this.get('value') || !this.options.visible || this.options.visible.indexOf(key) != -1) {
|
||||||
this.selection.push(selection[i]);
|
this.selection.push(selection[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.render_elements();
|
return $.when();
|
||||||
}
|
|
||||||
},
|
|
||||||
/** Renders the widget. This function also checks for statusbar_colors='{"pending": "blue"}'
|
|
||||||
* attribute in the widget. This allows to set a given color to a given
|
|
||||||
* state (given by the key of (key, label)).
|
|
||||||
*/
|
|
||||||
render_elements: function () {
|
|
||||||
var self = this;
|
|
||||||
var content = QWeb.render("FieldStatus.content", {widget: this});
|
|
||||||
this.$el.html(content);
|
|
||||||
var colors = JSON.parse((this.node.attrs || {}).statusbar_colors || "{}");
|
|
||||||
var color = colors[this.selected_value];
|
|
||||||
if (color) {
|
|
||||||
this.$("oe_active").css("color", color);
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
on_click_stage: function (ev) {
|
on_click_stage: function (ev) {
|
||||||
var self = this;
|
var self = this;
|
||||||
var $li = $(ev.currentTarget);
|
var $li = $(ev.currentTarget);
|
||||||
var val = parseInt($li.data("id"));
|
var val = parseInt($li.data("id"));
|
||||||
if (val != self.selected_value) {
|
if (val != self.get('value')) {
|
||||||
this.view.recursive_save().then(function() {
|
this.view.recursive_save().then(function() {
|
||||||
var change = {};
|
var change = {};
|
||||||
change[self.name] = val;
|
change[self.name] = val;
|
||||||
|
|
Loading…
Reference in New Issue