diff options
| author | Olivier Dony <odo@openerp.com> | 2017-06-01 01:46:13 +0200 |
|---|---|---|
| committer | Olivier Dony <odo@openerp.com> | 2017-06-01 01:46:13 +0200 |
| commit | 5d2869cbc812f716e3115b5efb9bd1c3082f47b7 (patch) | |
| tree | 364844fc326f0d095997120d10d83e67fdf341e9 /addons/web/static/src/js/views/basic/basic_controller.js | |
| parent | 04111cae39e36015d3c8494f52b110ab5ab6ad80 (diff) | |
| parent | ba15df47cb25625cb0921cba554aa0879048c90a (diff) | |
[MERGE] Forward-port saas-16 up to ba15df47cb25625cb0921cba554aa0879048c90a
Diffstat (limited to 'addons/web/static/src/js/views/basic/basic_controller.js')
| -rw-r--r-- | addons/web/static/src/js/views/basic/basic_controller.js | 78 |
1 files changed, 68 insertions, 10 deletions
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 1e0187b348e..53e5be8ff6e 100644 --- a/addons/web/static/src/js/views/basic/basic_controller.js +++ b/addons/web/static/src/js/views/basic/basic_controller.js @@ -18,6 +18,8 @@ var _t = core._t; var BasicController = AbstractController.extend(FieldManagerMixin, { custom_events: _.extend({}, AbstractController.prototype.custom_events, FieldManagerMixin.custom_events, { + discard_changes: '_onDiscardChanges', + mutexify: '_onMutexify', reload: '_onReload', sidebar_data_asked: '_onSidebarDataAsked', translate: '_onTranslate', @@ -247,9 +249,7 @@ var BasicController = AbstractController.extend(FieldManagerMixin, { var self = this; var def = $.Deferred(); var reload = function () { - if (!self.isDestroyed()) { - self.reload(); - } + return self.isDestroyed() ? $.when() : self.reload(); }; record = record || this.model.get(this.handle); var recordID = record.data.id; @@ -258,13 +258,17 @@ var BasicController = AbstractController.extend(FieldManagerMixin, { context: record.getContext({additionalContext: attrs.context}), }), model: record.model, - record_id: recordID, + res_ids: [recordID], on_closed: function (reason) { if (!_.isObject(reason)) { - reload(); + reload(reason); } }, - on_fail: reload, + on_fail: function (reason) { + reload().always(function() { + def.reject(reason); + }) + }, on_success: def.resolve.bind(def), }); return this.alive(def); @@ -306,6 +310,26 @@ var BasicController = AbstractController.extend(FieldManagerMixin, { } }, /** + * Disables buttons so that they can't be clicked anymore. + * + * @private + */ + _disableButtons: function () { + if (this.$buttons) { + this.$buttons.find('button').attr('disabled', true); + } + }, + /** + * Enables buttons so they can be clicked again. + * + * @private + */ + _enableButtons: function () { + if (this.$buttons) { + this.$buttons.find('button').removeAttr('disabled'); + } + }, + /** * Returns the new sidebar env * * @private @@ -385,18 +409,19 @@ var BasicController = AbstractController.extend(FieldManagerMixin, { // Note: it is the model's job to do nothing if there is nothing to save if (this.canBeSaved(recordID)) { var self = this; - var def = this.model.save(recordID, { // Save then leave edit mode + var saveDef = this.model.save(recordID, { // Save then leave edit mode reload: options.reload, savePoint: options.savePoint, }); if (!options.stayInEdit) { - def = def.then(function (fieldNames) { - return self._confirmSave(recordID).then(function () { + saveDef = saveDef.then(function (fieldNames) { + var def = fieldNames.length ? self._confirmSave(recordID) : self._setMode('readonly'); + return def.then(function () { return fieldNames; }); }); } - return def; + return saveDef; } else { return $.Deferred().reject(); // Cannot be saved } @@ -457,6 +482,31 @@ var BasicController = AbstractController.extend(FieldManagerMixin, { //-------------------------------------------------------------------------- /** + * Called when a list element asks to discard the changes made to one of + * its rows. It can happen with a x2many (if we are in a form view) or with + * a list view. + * + * @private + * @param {OdooEvent} ev + */ + _onDiscardChanges: function (ev) { + var self = this; + ev.stopPropagation(); + var recordID = ev.data.recordID; + this.discardChanges(recordID) + .done(function () { + if (self.model.isNew(recordID)) { + self._abandonRecord(recordID); + } + // TODO this will tell the renderer to rerender the widget that + // asked for the discard but will unfortunately lose the click + // made on another row if any + self._confirmChange(self.handle, [ev.data.fieldName], ev) + .always(ev.data.onSuccess); + }) + .fail(ev.data.onFailure); + }, + /** * Forces to save directly the changes if the controller is in readonly, * because in that case the changes come from widgets that are editable even * in readonly (e.g. Priority). @@ -471,6 +521,14 @@ var BasicController = AbstractController.extend(FieldManagerMixin, { FieldManagerMixin._onFieldChanged.apply(this, arguments); }, /** + * @private + * @param {OdooEvent} ev + * @param {function} ev.data.action the function to execute in the mutex + */ + _onMutexify: function (ev) { + this.mutex.exec(ev.data.action); + }, + /** * When a reload event triggers up, we need to reload the full view. * For example, after a form view dialog saved some data. * |
