diff options
| author | Christophe Simonis <chs@odoo.com> | 2018-02-22 10:39:15 +0100 |
|---|---|---|
| committer | Christophe Simonis <chs@odoo.com> | 2018-02-22 10:39:15 +0100 |
| commit | 9a84ba55330204c49e9c72d9e53660dfd11556ae (patch) | |
| tree | 10c207733941a30d5ab86285ecb1c8b130c14200 /addons/web/static/src/js | |
| parent | 898cd0a5c1a9696f051477c1318a76c31eb40a16 (diff) | |
| parent | e750bb6e1149cb05e13424d66d4ff12198b4cffe (diff) | |
[MERGE] forward port branch saas-11.1 up to e750bb6e114
Diffstat (limited to 'addons/web/static/src/js')
6 files changed, 86 insertions, 20 deletions
diff --git a/addons/web/static/src/js/core/domain.js b/addons/web/static/src/js/core/domain.js index 75aaf0105ed..8ce570b8605 100644 --- a/addons/web/static/src/js/core/domain.js +++ b/addons/web/static/src/js/core/domain.js @@ -240,7 +240,7 @@ var Domain = collections.Tree.extend({ */ stringToArray: function (domain, evalContext) { if (!_.isString(domain)) return _.clone(domain); - return pyeval.eval("domain", domain || "[]", evalContext); + return pyeval.eval("domain", domain ? domain.replace(/%%/g, '%') : "[]", evalContext); }, /** * Makes implicit "&" operators explicit in the given JS prefix-array diff --git a/addons/web/static/src/js/core/utils.js b/addons/web/static/src/js/core/utils.js index 1bdd9e70a69..251cd2b508c 100644 --- a/addons/web/static/src/js/core/utils.js +++ b/addons/web/static/src/js/core/utils.js @@ -392,6 +392,23 @@ var utils = { array[i2] = elem1; array[i1] = elem2; }, + + /** + * @param {string} value + * @param {boolean} allow_mailto + * @returns boolean + */ + is_email: function (value, allow_mailto) { + // http://stackoverflow.com/questions/46155/validate-email-address-in-javascript + var re; + if (allow_mailto) { + re = /^(mailto:)?(([^<>()\[\]\.,;:\s@\"]+(\.[^<>()\[\]\.,;:\s@\"]+)*)|(\".+\"))@(([^<>()[\]\.,;:\s@\"]+\.)+[^<>()[\]\.,;:\s@\"]{2,})$/i; + } else { + re = /^(([^<>()\[\]\.,;:\s@\"]+(\.[^<>()\[\]\.,;:\s@\"]+)*)|(\".+\"))@(([^<>()[\]\.,;:\s@\"]+\.)+[^<>()[\]\.,;:\s@\"]{2,})$/i; + } + return re.test(value); + }, + /** * @param {any} str * @param {any} elseValues diff --git a/addons/web/static/src/js/views/basic/basic_controller.js b/addons/web/static/src/js/views/basic/basic_controller.js index 2ddadfb0027..bc82710905b 100644 --- a/addons/web/static/src/js/views/basic/basic_controller.js +++ b/addons/web/static/src/js/views/basic/basic_controller.js @@ -335,7 +335,9 @@ var BasicController = AbstractController.extend(FieldManagerMixin, { } self.model.discardChanges(recordID); if (self.model.isNew(recordID)) { - self._abandonRecord(recordID); + if (self.model.canBeAbandoned(recordID)) { + self._abandonRecord(recordID); + } return; } return self._confirmSave(recordID); 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 119adaacec4..2042c2d1ce5 100644 --- a/addons/web/static/src/js/views/basic/basic_model.js +++ b/addons/web/static/src/js/views/basic/basic_model.js @@ -478,6 +478,30 @@ var BasicModel = AbstractModel.extend({ return _t("New"); }, /** + * Returns true if a record can be abandoned from a list datapoint. + * + * A record cannot be abandonned if it has been registered as "added" + * in the parent's savepoint, otherwise it can be abandonned. + * + * This is useful when discarding changes on this record, as it means that + * we must keep the record even if some fields are invalids (e.g. required + * field is empty). + * + * @param {string} id id for a local resource + * @returns {boolean} + */ + canBeAbandoned: function (id) { + var data = this.localData[id]; + var parent = this.localData[data.parentID]; + var abandonable = true; + if (parent) { + abandonable = !_.some(parent._savePoint, function (entry) { + return entry.operation === 'ADD' && entry.id === id; + }); + } + return abandonable; + }, + /** * Returns true if a record is dirty. A record is considered dirty if it has * some unsaved changes, marked by the _isDirty property on the record or * one of its subrecords. @@ -1428,25 +1452,23 @@ var BasicModel = AbstractModel.extend({ defs.push(self._applyOnChange(command[2], rec)); } else if (command[0] === 4) { // LINK TO - rec = self.localData[list._cache[command[1]]]; - if (rec) { - // modifications done on a record are discarded if - // the onchange uses a LINK TO - self.discardChanges(rec.id); - } - // the dataPoint id will be set when the record will be - // fetched (for now, this dataPoint may not exist yet) - list._changes.push({ - operation: 'ADD', - id: rec ? rec.id : null, - resID: command[1], - }); + linkRecord(list, command[1]); } else if (command[0] === 5) { // DELETE ALL list._changes = [{operation: 'REMOVE_ALL'}]; + } else if (command[0] === 6) { + list._changes = [{operation: 'REMOVE_ALL'}]; + _.each(command[2], function (resID) { + linkRecord(list, resID); + }); } }); - defs.push(self._readUngroupedList(list)); + var def = self._readUngroupedList(list).then(function () { + var x2ManysDef = self._fetchX2ManysBatched(list); + var referencesDef = self._fetchReferencesBatched(list); + return $.when(x2ManysDef, referencesDef); + }); + defs.push(def); } else { var newValue = self._parseServerValue(field, val); if (newValue !== oldValue) { @@ -1455,6 +1477,25 @@ var BasicModel = AbstractModel.extend({ } }); return $.when.apply($, defs); + + // inner function that adds a record (based on its res_id) to a list + // dataPoint (used for onchanges that return commands 4 (LINK TO) or + // commands 6 (REPLACE WITH)) + function linkRecord (list, resID) { + rec = self.localData[list._cache[resID]]; + if (rec) { + // modifications done on a record are discarded if the onchange + // uses a LINK TO or a REPLACE WITH + self.discardChanges(rec.id); + } + // the dataPoint id will be set when the record will be fetched (for + // now, this dataPoint may not exist yet) + list._changes.push({ + operation: 'ADD', + id: rec ? rec.id : null, + resID: resID, + }); + } }, /** * When an operation is applied to a x2many field, the field widgets @@ -1952,7 +1993,9 @@ var BasicModel = AbstractModel.extend({ _.each(list.data, function (dataPoint) { var record = self.localData[dataPoint]; var value = record.data[fieldName]; - if (value) { + // if the reference field has already been fetched, the value is a + // datapoint ID, and in this case there's nothing to do + if (value && !self.localData[value]) { var model = value.split(',')[0]; var resID = value.split(',')[1]; if (!(model in toFetch)) { diff --git a/addons/web/static/src/js/views/kanban/kanban_model.js b/addons/web/static/src/js/views/kanban/kanban_model.js index ba6b2ce3dbd..676dfdfac86 100644 --- a/addons/web/static/src/js/views/kanban/kanban_model.js +++ b/addons/web/static/src/js/views/kanban/kanban_model.js @@ -74,7 +74,6 @@ var KanbanModel = BasicModel.extend({ domain: parent.domain.concat([[groupBy,"=",result[0]]]), fields: parent.fields, fieldsInfo: parent.fieldsInfo, - groupedBy: parent.groupedBy, isOpen: true, limit: parent.limit, parentID: parent.id, 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 91a914be8df..8155862dbb4 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 @@ -58,8 +58,13 @@ ListRenderer.include({ * @returns {Deferred} */ start: function () { - if (this._isEditable()) { - this.$el.css({height: '100%'}); + // deliberately use the 'editable' attribute instead of '_isEditable' + // function, because the groupBy must not be taken into account to + // enable the '_onWindowClicked' handler (otherwise, an editable grouped + // list which is reloaded without groupBy wouldn't have this handler + // bound, and edited rows couldn't be left by clicking outside the list) + if (this.editable) { + this.$el.css({height: '100%'}); // seems useless: to remove in master core.bus.on('click', this, this._onWindowClicked.bind(this)); } return this._super(); |
