summaryrefslogtreecommitdiff
path: root/addons/web/static/src/js
diff options
context:
space:
mode:
authorThibault Delavallée <tde@openerp.com>2014-10-31 11:48:03 +0100
committerThibault Delavallée <tde@openerp.com>2014-11-07 11:57:52 +0100
commitfe41553623ecc994c34fc29b1690d8375d18dd4b (patch)
tree6730375fcbfb84861cbe6bac2d1f16b21417c4bb /addons/web/static/src/js
parent90af54ca4decc92ea6ad41fce781f4619eaea5c2 (diff)
[IMP] kanban, web: kanban tooltips and kanban states tooltips improvements.
Kanban and form view kanban selection widgets can now be dependent of the current stage of the record. The displayed legend can be taken directly from the stage instead of the field selection values. - added states_legend option on kanban selection widget for kanban and form view: used to change the selection displayed value by a value coming from the record given by group_by (kanban) / states_legend_field (form view). This allows customizing the kanban selection widget depending on stages. Improved the tooltip of kanban groups customization by improving the first implementation of group_by_tooltip parameter in kanban view declaration. This is done by adding some options and improving the first (still not used) implementation: - added group_by_tooltip option on field used to group on kanban view. Its values is a collection of fields on the record used to group. The tooltip of the group header will be the text formed from those fields values, allowing custom tooltips for different kanban columns. - now all data of the kanban columns are fetched in one call instead of doing one call for each column. The various fields to read are collected by introspecting the view definition. Future commits will aim at using those features various addons, notably in recruitment, project and crm.
Diffstat (limited to 'addons/web/static/src/js')
-rw-r--r--addons/web/static/src/js/view_form.js59
1 files changed, 44 insertions, 15 deletions
diff --git a/addons/web/static/src/js/view_form.js b/addons/web/static/src/js/view_form.js
index 57569be8b1c..e364e38e461 100644
--- a/addons/web/static/src/js/view_form.js
+++ b/addons/web/static/src/js/view_form.js
@@ -2337,29 +2337,58 @@ instance.web.form.KanbanSelection = instance.web.form.FieldChar.extend({
init: function (field_manager, node) {
this._super(field_manager, node);
},
+ start: function () {
+ var self = this;
+ this.states = [];
+ this._super.apply(this, arguments);
+ // hook on form view content changed: recompute the states, because it may be related to the current stage
+ this.getParent().on('view_content_has_changed', self, function () {
+ self.render_value();
+ });
+ },
prepare_dropdown_selection: function() {
var self = this;
var data = [];
- var selection = self.field.selection || [];
- _.map(selection, function(res) {
- var value = {
- 'name': res[0],
- 'tooltip': res[1],
- 'state_name': res[1],
- }
- if (res[0] == 'normal') { value['state_class'] = 'oe_kanban_status'; }
- else if (res[0] == 'done') { value['state_class'] = 'oe_kanban_status oe_kanban_status_green'; }
- else { value['state_class'] = 'oe_kanban_status oe_kanban_status_red'; }
- data.push(value);
+ var selection = this.field.selection || [];
+ var stage_id = _.isArray(this.view.datarecord.stage_id) ? this.view.datarecord.stage_id[0] : this.view.datarecord.stage_id;
+ var legend_field = this.options && this.options.states_legend_field || false;
+ var fields_to_read = _.map(
+ this.options && this.options.states_legend || {},
+ function (value, key, list) { return value; });
+ if (legend_field && fields_to_read && stage_id) {
+ var fetch_stage = new openerp.web.DataSet(
+ this,
+ self.view.fields[legend_field].field.relation).read_ids([stage_id],
+ fields_to_read);
+ }
+ else { var fetch_stage = $.Deferred().resolve(false); }
+ return $.when(fetch_stage).then(function (stage_data) {
+ _.map(selection, function(res) {
+ var value = {
+ 'name': res[0],
+ 'tooltip': res[1],
+ 'state_name': res[1],
+ }
+ if (stage_data && stage_data[0][self.options.states_legend[res[0]]]) {
+ value['state_name'] = stage_data[0][self.options.states_legend[res[0]]];
+ }
+ if (res[0] == 'normal') { value['state_class'] = 'oe_kanban_status'; }
+ else if (res[0] == 'done') { value['state_class'] = 'oe_kanban_status oe_kanban_status_green'; }
+ else { value['state_class'] = 'oe_kanban_status oe_kanban_status_red'; }
+ data.push(value);
+ });
+ return data;
});
- return data;
},
render_value: function() {
var self = this;
this.record_id = this.view.datarecord.id;
- this.states = this.prepare_dropdown_selection();;
- this.$el.html(QWeb.render("KanbanSelection", {'widget': self}));
- this.$el.find('li').on('click', this.set_kanban_selection.bind(this));
+ var dd_fetched = this.prepare_dropdown_selection();;
+ return $.when(dd_fetched).then(function (states) {
+ self.states = states;
+ self.$el.html(QWeb.render("KanbanSelection", {'widget': self}));
+ self.$el.find('li').on('click', this.set_kanban_selection.bind(this));
+ })
},
/* setting the value: in view mode, perform an asynchronous call and reload
the form view; in edit mode, use set_value to save the new value that will