diff options
| author | Christophe Simonis <chs@odoo.com> | 2017-10-10 19:14:30 +0200 |
|---|---|---|
| committer | Christophe Simonis <chs@odoo.com> | 2017-10-10 19:14:30 +0200 |
| commit | 0be264b29eac11a5dec5e6565d23d4ea86bd905a (patch) | |
| tree | 79362f2340c89cb3cf2e8d8a467f357b7c7a8326 /addons/web/static/src/js/views | |
| parent | cf753a7fdf1739dcf37d2ad74f4c8efb3d4ff3b3 (diff) | |
| parent | e1104ac344cbc349a46b22339b13dfe9cbab8bcb (diff) | |
[MERGE] forward port branch 11.0 up to e1104ac344c
Diffstat (limited to 'addons/web/static/src/js/views')
3 files changed, 41 insertions, 41 deletions
diff --git a/addons/web/static/src/js/views/basic/basic_model.js b/addons/web/static/src/js/views/basic/basic_model.js index 57c4a1f3743..5c6f5d2d851 100644 --- a/addons/web/static/src/js/views/basic/basic_model.js +++ b/addons/web/static/src/js/views/basic/basic_model.js @@ -198,7 +198,7 @@ var BasicModel = AbstractModel.extend({ * behind must be applied. This function applies changes stored in * '_rawChanges' for a given viewType. * - * @param {string} id local resource id of a record + * @param {string} recordID local resource id of a record * @param {string} viewType the current viewType * @returns {Deferred<string>} resolves to the id of the record */ @@ -3666,10 +3666,16 @@ var BasicModel = AbstractModel.extend({ var self = this; // sort records according to ordered_by[0] - var order = list.orderedBy[0]; var data = list.data; var res_ids = list.res_ids; - data.sort(function (record1ID, record2ID) { + var compareRecords = function (record1ID, record2ID, level) { + if(!level) { + level = 0; + } + if(list.orderedBy.length < level + 1) { + return 0; + } + var order = list.orderedBy[level]; var r1 = self.localData[record1ID]; var r2 = self.localData[record2ID]; var data1 = _.extend({}, r1.data, r1._changes); @@ -3680,8 +3686,9 @@ var BasicModel = AbstractModel.extend({ if (data1[order.name] > data2[order.name]) { return order.asc ? 1 : -1; } - return 0; - }); + return compareRecords(record1ID, record2ID, level + 1); + }; + data.sort(compareRecords); // sort res_ids accordingly (only the current range of ids, the one // mapping the data, needs to be sorted) diff --git a/addons/web/static/src/js/views/list/list_editable_renderer.js b/addons/web/static/src/js/views/list/list_editable_renderer.js index 8f0e73cb466..9027fc3c984 100644 --- a/addons/web/static/src/js/views/list/list_editable_renderer.js +++ b/addons/web/static/src/js/views/list/list_editable_renderer.js @@ -47,7 +47,6 @@ ListRenderer.include({ this.addTrashIcon = params.addTrashIcon; this.currentRow = null; - this.currentCol = null; this.currentFieldIndex = null; }, /** @@ -175,7 +174,7 @@ ListRenderer.include({ }); if (self.currentRow !== null) { self.currentRow = newRowIndex; - return self._selectCell(newRowIndex, self.currentCol, {force: true}).then(function () { + return self._selectCell(newRowIndex, self.currentFieldIndex, {force: true}).then(function () { // restore the cursor position currentRowID = self.state.data[newRowIndex].id; currentWidget = self.allFieldWidgets[currentRowID][self.currentFieldIndex]; @@ -458,7 +457,6 @@ ListRenderer.include({ */ _render: function () { this.currentRow = null; - this.currentCol = null; this.currentFieldIndex = null; return this._super.apply(this, arguments); }, @@ -560,22 +558,22 @@ ListRenderer.include({ * is, if necessary. * * @param {integer} rowIndex - * @param {integer} colIndex + * @param {integer} fieldIndex * @param {Object} [options] * @param {Event} [options.event] original target of the event which * @param {boolean} [options.wrap=true] if true and no widget could be * triggered the cell selection - * selected from the colIndex to the last column, then we wrap around and + * selected from the fieldIndex to the last column, then we wrap around and * try to select a widget starting from the beginning * @param {boolean} [options.force=false] if true, force selecting the cell * even if seems to be already the selected one (useful after a re- * rendering, to reset the focus on the correct field) * @return {Deferred} fails if no cell could be selected */ - _selectCell: function (rowIndex, colIndex, options) { + _selectCell: function (rowIndex, fieldIndex, options) { options = options || {}; // Do nothing if the user tries to select current cell - if (!options.force && rowIndex === this.currentRow && colIndex === this.currentCol) { + if (!options.force && rowIndex === this.currentRow && fieldIndex === this.currentFieldIndex) { return $.when(); } var wrap = options.wrap === undefined ? true : options.wrap; @@ -584,32 +582,18 @@ ListRenderer.include({ var self = this; return this._selectRow(rowIndex).then(function () { var record = self.state.data[rowIndex]; - var correctedIndex = colIndex - getNbButtonBefore(colIndex); - if (correctedIndex >= (self.allFieldWidgets[record.id] || []).length) { + if (fieldIndex >= (self.allFieldWidgets[record.id] || []).length) { return $.Deferred().reject(); } - var fieldIndex = self._activateFieldWidget(record, correctedIndex, { + fieldIndex = self._activateFieldWidget(record, fieldIndex, { inc: 1, wrap: wrap, event: options && options.event, }); - if (fieldIndex < 0) { return $.Deferred().reject(); } - - self.currentCol = fieldIndex + getNbButtonBefore(fieldIndex); self.currentFieldIndex = fieldIndex; - - function getNbButtonBefore(index) { - var nbButtons = 0; - for (var i = 0 ; i < index ; i++) { - if (self.columns[i].tag === 'button') { - nbButtons++; - } - } - return nbButtons; - } }); }, /** @@ -682,8 +666,8 @@ ListRenderer.include({ var $td = $(event.currentTarget); var $tr = $td.parent(); var rowIndex = this.$('.o_data_row').index($tr); - var colIndex = $tr.find('.o_data_cell').index($td); - this._selectCell(rowIndex, colIndex, {event: event}); + var fieldIndex = Math.max($tr.find('.o_data_cell').not('.o_list_button').index($td), 0); + this._selectCell(rowIndex, fieldIndex, {event: event}); }, /** * We need to manually unselect row, because noone else would do it @@ -725,35 +709,35 @@ ListRenderer.include({ switch (ev.data.direction) { case 'up': if (this.currentRow > 0) { - this._selectCell(this.currentRow - 1, this.currentCol); + this._selectCell(this.currentRow - 1, this.currentFieldIndex); } break; case 'right': - if (this.currentCol + 1 < this.columns.length) { - this._selectCell(this.currentRow, this.currentCol + 1); + if (this.currentFieldIndex + 1 < this.columns.length) { + this._selectCell(this.currentRow, this.currentFieldIndex + 1); } break; case 'down': if (this.currentRow < this.state.data.length - 1) { - this._selectCell(this.currentRow + 1, this.currentCol); + this._selectCell(this.currentRow + 1, this.currentFieldIndex); } break; case 'left': - if (this.currentCol > 0) { - this._selectCell(this.currentRow, this.currentCol - 1); + if (this.currentFieldIndex > 0) { + this._selectCell(this.currentRow, this.currentFieldIndex - 1); } break; case 'previous': - if (this.currentCol > 0) { - this._selectCell(this.currentRow, this.currentCol - 1, {wrap: false}) + if (this.currentFieldIndex > 0) { + this._selectCell(this.currentRow, this.currentFieldIndex - 1, {wrap: false}) .fail(this._moveToPreviousLine.bind(this)); } else { this._moveToPreviousLine(); } break; case 'next': - if (this.currentCol + 1 < this.columns.length) { - this._selectCell(this.currentRow, this.currentCol + 1, {wrap: false}) + if (this.currentFieldIndex + 1 < this.columns.length) { + this._selectCell(this.currentRow, this.currentFieldIndex + 1, {wrap: false}) .fail(this._moveToNextLine.bind(this)); } else { this._moveToNextLine(); diff --git a/addons/web/static/src/js/views/list/list_renderer.js b/addons/web/static/src/js/views/list/list_renderer.js index 3ba80210714..d37120339d6 100644 --- a/addons/web/static/src/js/views/list/list_renderer.js +++ b/addons/web/static/src/js/views/list/list_renderer.js @@ -4,6 +4,7 @@ odoo.define('web.ListRenderer', function (require) { var BasicRenderer = require('web.BasicRenderer'); var config = require('web.config'); var core = require('web.core'); +var Dialog = require('web.Dialog'); var dom = require('web.dom'); var field_utils = require('web.field_utils'); var Pager = require('web.Pager'); @@ -323,7 +324,15 @@ var ListRenderer = BasicRenderer.extend({ }); }); } else { - $button.prop('disabled', true); + if (node.attrs.options.warn) { + var self = this; + $button.on("click", function (e) { + e.stopPropagation(); + self.do_warn(_t("Warning"), _t('Please click on the "save" button first')); + }); + } else { + $button.prop('disabled', true); + } } return $button; |
