diff options
| author | Thibault Delavallée <tde@openerp.com> | 2013-05-17 11:06:26 +0200 |
|---|---|---|
| committer | Thibault Delavallée <tde@openerp.com> | 2013-05-17 11:06:26 +0200 |
| commit | dddabd3e0cefb0f4fbc622d2e5df05f2d4fafef7 (patch) | |
| tree | 81af3e85bdb50ef8a61f4ef6443b54787ac5fccb /addons/web/static/src/js/view_form.js | |
| parent | d24e53c6ed4da8acd516be32d9d8067b43d771bc (diff) | |
| parent | 8adb904c2367de9f7b2c30ea6eb4724e32c90c86 (diff) | |
[MERGE] [IMP] 'Stage Bar Manu' Task. This task improves the statusbar widget. Folded columns are
not hidden anymore, but available in a side menu accessible after other stages. The
purpose is to be able to have access to all stages using this widget. This way we will be
able to remove some action buttons in form views in a future task.
This web branch updates the statusbar widget (JS and CSS).
bzr revid: tde@openerp.com-20130517090626-n1g1k1o4r8wk9l4v
Diffstat (limited to 'addons/web/static/src/js/view_form.js')
| -rw-r--r-- | addons/web/static/src/js/view_form.js | 147 |
1 files changed, 109 insertions, 38 deletions
diff --git a/addons/web/static/src/js/view_form.js b/addons/web/static/src/js/view_form.js index 53a7425c036..454f20ddcd5 100644 --- a/addons/web/static/src/js/view_form.js +++ b/addons/web/static/src/js/view_form.js @@ -765,7 +765,11 @@ instance.web.FormView = instance.web.View.extend(instance.web.form.FieldManagerM this.has_been_loaded.done(function() { if (self.datarecord.id && confirm(_t("Do you really want to delete this record?"))) { self.dataset.unlink([self.datarecord.id]).done(function() { - self.execute_pager_action('next'); + if (self.dataset.size()) { + self.execute_pager_action('next'); + } else { + self.do_action('history_back'); + } def.resolve(); }); } else { @@ -802,6 +806,8 @@ instance.web.FormView = instance.web.View.extend(instance.web.form.FieldManagerM if (save_obj.error) return $.Deferred().reject(); return $.when.apply($, save_obj.ret); + }).done(function() { + self.$el.removeClass('oe_form_dirty'); }); }, _process_save: function(save_obj) { @@ -1021,7 +1027,7 @@ instance.web.FormView = instance.web.View.extend(instance.web.form.FieldManagerM return value; } var fields = _.chain(this.fields) - .map(function (field, name) { + .map(function (field) { var value = field.get_value(); // ignore fields which are empty, invisible, readonly, o2m // or m2m @@ -1036,7 +1042,7 @@ instance.web.FormView = instance.web.View.extend(instance.web.form.FieldManagerM } return { - name: name, + name: field.name, string: field.string, value: value, displayed: display(field, value), @@ -1047,10 +1053,10 @@ instance.web.FormView = instance.web.View.extend(instance.web.form.FieldManagerM .value(); var conditions = _.chain(self.fields) .filter(function (field) { return field.field.change_default; }) - .map(function (field, name) { + .map(function (field) { var value = field.get_value(); return { - name: name, + name: field.name, string: field.string, value: value, displayed: display(field, value), @@ -1444,6 +1450,9 @@ instance.web.form.FormRenderingEngine = instance.web.form.FormRenderingEngineInt $(this).children().each(function() { var $td = $(this), $child = $td.children(':first'); + if ($child.attr('cell-class')) { + $td.addClass($child.attr('cell-class')); + } switch ($child[0].tagName.toLowerCase()) { case 'separator': break; @@ -1520,7 +1529,7 @@ instance.web.form.FormRenderingEngine = instance.web.form.FormRenderingEngineInt if (! page.__ic) return; page.__ic.on("change:effective_invisible", null, function() { - if (!page.__ic.get('effective_invisible')) { + if (!page.__ic.get('effective_invisible') && page.autofocus) { $new_notebook.tabs('select', i); return; } @@ -2126,7 +2135,7 @@ instance.web.form.AbstractField = instance.web.form.FormWidget.extend(instance.w value without triggering a re-rendering. */ internal_set_value: function(value_) { - var tmp = this.no_render; + var tmp = this.no_rerender; this.no_rerender = true; this.set({'value': value_}); this.no_rerender = tmp; @@ -2296,7 +2305,8 @@ instance.web.form.FieldChar = instance.web.form.AbstractField.extend(instance.we return this.get('value') === '' || this._super(); }, focus: function() { - this.$('input:first')[0].focus(); + var input = this.$('input:first')[0]; + return input ? input.focus() : false; }, set_dimensions: function (height, width) { this._super(height, width); @@ -2393,7 +2403,8 @@ instance.web.form.FieldFloat = instance.web.form.FieldChar.extend({ this._super.apply(this, [value_]); }, focus: function () { - this.$('input:first').select(); + var $input = this.$('input:first'); + return $input.length ? $input.select() : false; } }); @@ -2413,6 +2424,42 @@ instance.web.DateTimeWidget = instance.web.Widget.extend({ this.$input = this.$el.find('input.oe_datepicker_master'); this.$input_picker = this.$el.find('input.oe_datepicker_container'); + $.datepicker.setDefaults({ + clearText: _t('Clear'), + clearStatus: _t('Erase the current date'), + closeText: _t('Done'), + closeStatus: _t('Close without change'), + prevText: _t('<Prev'), + prevStatus: _t('Show the previous month'), + nextText: _t('Next>'), + nextStatus: _t('Show the next month'), + currentText: _t('Today'), + currentStatus: _t('Show the current month'), + monthNames: Date.CultureInfo.monthNames, + monthNamesShort: Date.CultureInfo.abbreviatedMonthNames, + monthStatus: _t('Show a different month'), + yearStatus: _t('Show a different year'), + weekHeader: _t('Wk'), + weekStatus: _t('Week of the year'), + dayNames: Date.CultureInfo.dayNames, + dayNamesShort: Date.CultureInfo.abbreviatedDayNames, + dayNamesMin: Date.CultureInfo.shortestDayNames, + dayStatus: _t('Set DD as first week day'), + dateStatus: _t('Select D, M d'), + firstDay: Date.CultureInfo.firstDayOfWeek, + initStatus: _t('Select a date'), + isRTL: false + }); + $.timepicker.setDefaults({ + timeOnlyTitle: _t('Choose Time'), + timeText: _t('Time'), + hourText: _t('Hour'), + minuteText: _t('Minute'), + secondText: _t('Second'), + currentText: _t('Now'), + closeText: _t('Done') + }); + this.picker({ onClose: this.on_picker_select, onSelect: this.on_picker_select, @@ -2539,9 +2586,8 @@ instance.web.form.FieldDatetime = instance.web.form.AbstractField.extend(instanc return this.get('value') === '' || this._super(); }, focus: function() { - if (this.datewidget && this.datewidget.$input) { - this.datewidget.$input[0].focus(); - } + var input = this.datewidget && this.datewidget.$input[0]; + return input ? input.focus() : false; }, set_dimensions: function (height, width) { this._super(height, width); @@ -2622,9 +2668,8 @@ instance.web.form.FieldText = instance.web.form.AbstractField.extend(instance.we return this.get('value') === '' || this._super(); }, focus: function($el) { - if (!this.get("effective_readonly") && this.$textarea) { - this.$textarea[0].focus(); - } + var input = !this.get("effective_readonly") && this.$textarea && this.$textarea[0]; + return input ? input.focus() : false; }, set_dimensions: function (height, width) { this._super(height, width); @@ -2707,7 +2752,8 @@ instance.web.form.FieldBoolean = instance.web.form.AbstractField.extend({ this.$checkbox[0].checked = this.get('value'); }, focus: function() { - this.$checkbox[0].focus(); + var input = this.$checkbox && this.$checkbox[0]; + return input ? input.focus() : false; } }); @@ -2793,7 +2839,8 @@ instance.web.form.FieldSelection = instance.web.form.AbstractField.extend(instan } }, focus: function() { - this.$('select:first')[0].focus(); + var input = this.$('select:first')[0]; + return input ? input.focus() : false; }, set_dimensions: function (height, width) { this._super(height, width); @@ -3336,7 +3383,7 @@ instance.web.form.FieldMany2One = instance.web.form.AbstractField.extend(instanc } if (! no_recurse) { var dataset = new instance.web.DataSetStatic(this, this.field.relation, self.build_context()); - dataset.name_get([self.get("value")]).done(function(data) { + this.alive(dataset.name_get([self.get("value")])).done(function(data) { self.display_value["" + self.get("value")] = data[0][1]; self.render_value(true); }); @@ -3401,9 +3448,8 @@ instance.web.form.FieldMany2One = instance.web.form.AbstractField.extend(instanc return ! this.get("value"); }, focus: function () { - if (!this.get('effective_readonly')) { - this.$input && this.$input[0].focus(); - } + var input = !this.get('effective_readonly') && this.$input && this.$input[0]; + return input ? input.focus() : false; }, _quick_create: function() { this.no_ed = true; @@ -4263,7 +4309,8 @@ instance.web.form.FieldMany2ManyTags = instance.web.form.AbstractField.extend(in this.set({'value': _.uniq(this.get('value').concat([id]))}); }, focus: function () { - this.$text[0].focus(); + var input = this.$text && this.$text[0]; + return input ? input.focus() : false; }, set_dimensions: function (height, width) { this._super(height, width); @@ -5356,14 +5403,14 @@ instance.web.form.FieldStatus = instance.web.form.AbstractField.extend({ this.options.clickable = this.options.clickable || (this.node.attrs || {}).clickable || false; this.options.visible = this.options.visible || (this.node.attrs || {}).statusbar_visible || false; this.set({value: false}); - this.selection = []; - this.set("selection", []); + this.selection = {'unfolded': [], 'folded': []}; + this.set("selection", {'unfolded': [], 'folded': []}); this.selection_dm = new instance.web.DropMisordered(); + this.dataset = new instance.web.DataSetStatic(this, this.field.relation, this.build_context()); }, start: function() { this.field_manager.on("view_content_has_changed", this, this.calc_domain); this.calc_domain(); - this.on("change:value", this, this.get_selection); this.on("change:evaluated_selection_domain", this, this.get_selection); this.on("change:selection", this, function() { this.selection = this.get("selection"); @@ -5371,7 +5418,7 @@ instance.web.form.FieldStatus = instance.web.form.AbstractField.extend({ }); this.get_selection(); if (this.options.clickable) { - this.$el.on('click','li',this.on_click_stage); + this.$el.on('click','li:not(.oe_folded)',this.on_click_stage); } if (this.$el.parent().is('header')) { this.$el.after('<div class="oe_clear"/>'); @@ -5386,17 +5433,20 @@ instance.web.form.FieldStatus = instance.web.form.AbstractField.extend({ }, render_value: function() { var self = this; - var content = QWeb.render("FieldStatus.content", {widget: self}); + var content = QWeb.render("FieldStatus.content", { + 'widget': self, + 'value_folded': _.find(self.selection.folded, function(i){return i[0] === self.get('value')}) + }); self.$el.html(content); }, calc_domain: function() { var d = instance.web.pyeval.eval('domain', this.build_domain()); var domain = []; //if there is no domain defined, fetch all the records - + if (d.length) { domain = ['|',['id', '=', this.get('value')]].concat(d); } - + if (! _.isEqual(domain, this.get("evaluated_selection_domain"))) { this.set("evaluated_selection_domain", domain); } @@ -5408,17 +5458,27 @@ instance.web.form.FieldStatus = instance.web.form.AbstractField.extend({ */ get_selection: function() { var self = this; - var selection = []; + var selection_unfolded = []; + var selection_folded = []; var calculation = _.bind(function() { if (this.field.type == "many2one") { - var domain = []; - var ds = new instance.web.DataSetSearch(this, this.field.relation, - self.build_context(), this.get("evaluated_selection_domain")); - return ds.read_slice(['name'], {}).then(function (records) { - for(var i = 0; i < records.length; i++) { - selection.push([records[i].id, records[i].name]); - } + return self.get_distant_fields().then(function(fields) { + return new instance.web.DataSetSearch(self, self.field.relation, self.build_context(), self.get("evaluated_selection_domain")) + .read_slice(fields.fold ? ['fold'] : ['id'], {}).then(function (records) { + + var ids = _.map(records, function (val) {return val.id}); + return self.dataset.name_get(ids).then(function (records_name) { + _.each(records, function (record) { + var name = _.find(records_name, function (val) {return val[0] == record.id;})[1]; + if (record.fold && record.id != self.get('value')) { + selection_folded.push([record.id, name]); + } else { + selection_unfolded.push([record.id, name]); + } + }); + }) + }); }); } else { // For field type selection filter values according to @@ -5428,18 +5488,29 @@ instance.web.form.FieldStatus = instance.web.form.AbstractField.extend({ for(var i=0; i < select.length; i++) { var key = select[i][0]; if(key == this.get('value') || !this.options.visible || this.options.visible.indexOf(key) != -1) { - selection.push(select[i]); + selection_unfolded.push(select[i]); } } return $.when(); } }, this); this.selection_dm.add(calculation()).then(function () { + var selection = {'unfolded': selection_unfolded, 'folded': selection_folded}; if (! _.isEqual(selection, self.get("selection"))) { self.set("selection", selection); } }); }, + get_distant_fields: function() { + var self = this; + if (this.distant_fields) { + return $.when(this.distant_fields); + } + return new instance.web.Model(self.field.relation).call("fields_get", [["fold"]]).then(function(fields) { + self.distant_fields = fields; + return fields; + }) + }, on_click_stage: function (ev) { var self = this; var $li = $(ev.currentTarget); |
