summaryrefslogtreecommitdiff
path: root/addons/website/static/src/js/editor
diff options
context:
space:
mode:
authorVincent Schippefilt <vsc@odoo.com>2019-03-06 14:02:33 +0100
committerAaron Bohy <aab@odoo.com>2019-03-06 20:07:17 +0100
commit226a6a9e677b1ebded9240e181cc2ea83fa49d72 (patch)
treedb1caaa11b9905589031b10580db28a5486b2b20 /addons/website/static/src/js/editor
parentc39033bc1cff578626b6925ed542cfc8f709e15c (diff)
[REF] website: adapt code after jQuery update
Part of task 1896658 Co-authored-by: Aaron Bohy <aab@odoo.com> Co-authored-by: Christophe Matthieu <chm@odoo.com> Co-authored-by: Mathieu Duckerts-Antoine <dam@odoo.com> Co-authored-by: David Monjoie <dmo@odoo.com> Co-authored-by: Martin Geubelle <mge@odoo.com> Co-authored-by: svs-odoo <svs@odoo.com> Co-authored-by: Vincent Schippefilt <vsc@odoo.com>
Diffstat (limited to 'addons/website/static/src/js/editor')
-rw-r--r--addons/website/static/src/js/editor/editor_menu.js26
-rw-r--r--addons/website/static/src/js/editor/snippets.options.js19
-rw-r--r--addons/website/static/src/js/editor/wysiwyg_multizone.js14
-rw-r--r--addons/website/static/src/js/editor/wysiwyg_multizone_translate.js2
4 files changed, 32 insertions, 29 deletions
diff --git a/addons/website/static/src/js/editor/editor_menu.js b/addons/website/static/src/js/editor/editor_menu.js
index ee504413e2f..46c3fc0b6b1 100644
--- a/addons/website/static/src/js/editor/editor_menu.js
+++ b/addons/website/static/src/js/editor/editor_menu.js
@@ -75,15 +75,17 @@ var EditorMenu = Widget.extend({
*/
cancel: function (reload) {
var self = this;
- var def = $.Deferred();
- if (!this.wysiwyg.isDirty()) {
- def.resolve();
- } else {
- var confirm = Dialog.confirm(this, _t("If you discard the current edition, all unsaved changes will be lost. You can cancel to return to the edition mode."), {
- confirm_callback: def.resolve.bind(def),
- });
- confirm.on('closed', def, def.reject);
- }
+ var def = new Promise(function (resolve, reject) {
+ if (!self.wysiwyg.isDirty()) {
+ resolve();
+ } else {
+ var confirm = Dialog.confirm(self, _t("If you discard the current edition, all unsaved changes will be lost. You can cancel to return to the edition mode."), {
+ confirm_callback: resolve,
+ });
+ confirm.on('closed', self, reject);
+ }
+ });
+
return def.then(function () {
self.trigger_up('edition_will_stopped');
var $wrapwrap = $('#wrapwrap');
@@ -110,10 +112,10 @@ var EditorMenu = Widget.extend({
save: function (reload) {
var self = this;
this.trigger_up('edition_will_stopped');
- return this.wysiwyg.save().then(function (dirty) {
+ return this.wysiwyg.save().then(function (result) {
var $wrapwrap = $('#wrapwrap');
self.editable($wrapwrap).removeClass('o_editable');
- if (dirty && reload !== false) {
+ if (result.isDirty && reload !== false) {
// remove top padding because the connected bar is not visible
$('body').removeClass('o_connected_user');
return self._reload();
@@ -180,7 +182,7 @@ var EditorMenu = Widget.extend({
this.$el.hide();
window.location.hash = 'scrollTop=' + window.document.body.scrollTop;
window.location.reload(true);
- return $.Deferred();
+ return new Promise(function () {});
},
//--------------------------------------------------------------------------
diff --git a/addons/website/static/src/js/editor/snippets.options.js b/addons/website/static/src/js/editor/snippets.options.js
index b90f1f91075..be97a42f96c 100644
--- a/addons/website/static/src/js/editor/snippets.options.js
+++ b/addons/website/static/src/js/editor/snippets.options.js
@@ -57,12 +57,13 @@ options.registry.menu_data = options.Class.extend({
actionName: 'edit_menu',
params: [
function () {
- var def = $.Deferred();
- self.trigger_up('request_save', {
- onSuccess: def.resolve.bind(def),
- onFailure: def.reject.bind(def),
+ var prom = new Promise(function (resolve, reject) {
+ self.trigger_up('request_save', {
+ onSuccess: resolve,
+ onFailure: reject,
+ });
});
- return def;
+ return prom;
},
],
});
@@ -82,10 +83,10 @@ options.registry.company_data = options.Class.extend({
*/
start: function () {
var proto = options.registry.company_data.prototype;
- var def;
+ var prom;
var self = this;
if (proto.__link === undefined) {
- def = this._rpc({route: '/web/session/get_session_info'}).then(function (session) {
+ prom = this._rpc({route: '/web/session/get_session_info'}).then(function (session) {
return self._rpc({
model: 'res.users',
method: 'read',
@@ -95,7 +96,7 @@ options.registry.company_data = options.Class.extend({
proto.__link = '/web#action=base.action_res_company_form&view_type=form&id=' + (res && res[0] && res[0].company_id[0] || 1);
});
}
- return $.when(this._super.apply(this, arguments), def);
+ return Promise.all([this._super.apply(this, arguments), prom]);
},
/**
* When the users selects company data, opens a dialog to ask him if he
@@ -737,7 +738,7 @@ options.registry.facebookPage = options.Class.extend({
}));
}
- return $.when.apply($, defs);
+ return Promise.all(defs);
},
/**
* @override
diff --git a/addons/website/static/src/js/editor/wysiwyg_multizone.js b/addons/website/static/src/js/editor/wysiwyg_multizone.js
index 660afe80bdf..4d29e1f3567 100644
--- a/addons/website/static/src/js/editor/wysiwyg_multizone.js
+++ b/addons/website/static/src/js/editor/wysiwyg_multizone.js
@@ -238,20 +238,20 @@ var WysiwygMultizone = Wysiwyg.extend({
this.savingMutex.exec(this._saveCroppedImages.bind(this));
}
var _super = this._super.bind(this);
- return this.savingMutex.def.then(function () {
+ return this.savingMutex.lock.then(function () {
return _super().then(function (_isDirty, html) {
this._summernote.layoutInfo.editable.html(html);
var $editable = this._getEditableArea();
var $areaDirty = $editable.filter('.o_dirty');
if (!$areaDirty.length) {
- return false;
+ return { isDirty: false };
}
$areaDirty.each(function (index, editable) {
this.savingMutex.exec(this._saveEditable.bind(this, editable));
}.bind(this));
- return this.savingMutex.def.then(function () {
- return true;
+ return this.savingMutex.lock.then(function () {
+ return { isDirty: true };
});
}.bind(this));
}.bind(this));
@@ -402,9 +402,9 @@ var WysiwygMultizone = Wysiwyg.extend({
var recordInfo = this._getRecordInfo({target: editable});
var outerHTML = this._getCleanedHtml(editable).prop('outerHTML');
var def = this._saveElement(outerHTML, recordInfo, editable);
- def.done(function () {
+ def.then(function () {
self.trigger_up('saved', recordInfo);
- }).fail(function () {
+ }).guardedCatch(function () {
self.trigger_up('canceled', recordInfo);
});
return def;
@@ -456,7 +456,7 @@ var WysiwygMultizone = Wysiwyg.extend({
});
}
}).get();
- return $.when.apply($, defs);
+ return Promise.all(defs);
},
/**
* Saves one (dirty) element of the page.
diff --git a/addons/website/static/src/js/editor/wysiwyg_multizone_translate.js b/addons/website/static/src/js/editor/wysiwyg_multizone_translate.js
index 5f68ff09e0f..85eecb1a85a 100644
--- a/addons/website/static/src/js/editor/wysiwyg_multizone_translate.js
+++ b/addons/website/static/src/js/editor/wysiwyg_multizone_translate.js
@@ -171,7 +171,7 @@ var WysiwygTranslate = WysiwygMultizone.extend({
kwargs: {
context: recordInfo.context,
},
- }).fail(function (error) {
+ }).guardedCatch(function (error) {
console.error(error.data.message);
webDialog.alert(null, error.data.message);
});