summaryrefslogtreecommitdiff
path: root/addons/web_editor/static/src/js/common/ace.js
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
commit2e8222dee737215cbad0dd3556d6ec0ffe60bf00 (patch)
tree83cf89fa39aa53a86ef044c661b5ed5c52231446 /addons/web_editor/static/src/js/common/ace.js
parenta3dfd04ad670b425df4d36ff714a4d4e260ff5a9 (diff)
[REF] web_editor: 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/web_editor/static/src/js/common/ace.js')
-rw-r--r--addons/web_editor/static/src/js/common/ace.js65
1 files changed, 29 insertions, 36 deletions
diff --git a/addons/web_editor/static/src/js/common/ace.js b/addons/web_editor/static/src/js/common/ace.js
index 2f9108b4d0d..8fc1d0ac1f9 100644
--- a/addons/web_editor/static/src/js/common/ace.js
+++ b/addons/web_editor/static/src/js/common/ace.js
@@ -189,10 +189,10 @@ var ViewEditor = Widget.extend({
* @override
*/
willStart: function () {
- return $.when(
+ return Promise.all([
this._super.apply(this, arguments),
this._loadResources()
- );
+ ]);
},
/**
* Initializes the library and initial view once the DOM is ready. It also
@@ -432,7 +432,7 @@ var ViewEditor = Widget.extend({
* is loading the activate views, index them and build their hierarchy.
*
* @private
- * @returns {Deferred}
+ * @returns {Promise}
*/
_loadResources: function () {
// Reset resources
@@ -523,14 +523,14 @@ var ViewEditor = Widget.extend({
* @private
* @param {integer|string} [resID] (default to the currently selected one)
* @param {string} [type] (default to the currently selected one)
- * @returns {Deferred}
+ * @returns {Promise}
*/
_resetResource: function (resID, type) {
resID = resID || this._getSelectedResource();
type = type || this.currentType;
if (this.currentType === 'xml') {
- return $.Defered().reject(_t("Reseting views is not supported yet"));
+ return Promise.reject(_t("Reseting views is not supported yet"));
} else {
var resource = type === 'scss' ? this.scss[resID] : this.js[resID];
return this._rpc({
@@ -543,22 +543,20 @@ var ViewEditor = Widget.extend({
}
},
/**
- * Saves an unique SCSS or JS file.
+ * Saves a unique SCSS or JS file.
*
* @private
* @param {Object} session - contains the 'id' (url) and the 'text' of the
* SCSS or JS file to save.
- * @return {Deferred} status indicates if the save is finished or if an
+ * @return {Promise} status indicates if the save is finished or if an
* error occured.
*/
_saveSCSSorJS: function (session) {
- var def = $.Deferred();
-
var self = this;
var sessionIdEndsWithJS = _.string.endsWith(session.id, '.js');
var bundleXmlID = sessionIdEndsWithJS ? this.js[session.id].bundle_xmlid : this.scss[session.id].bundle_xmlid;
var fileType = sessionIdEndsWithJS ? 'js' : 'scss';
- self._rpc({
+ return self._rpc({
route: '/web_editor/save_asset',
params: {
url: session.id,
@@ -568,19 +566,14 @@ var ViewEditor = Widget.extend({
},
}).then(function () {
self._toggleDirtyInfo(session.id, fileType, false);
- def.resolve();
- }, function (source, error) {
- def.reject(session, error);
});
-
- return def;
},
/**
* Saves every resource that has been modified. If one cannot be saved, none
* is saved and an error message is displayed.
*
* @private
- * @return {Deferred} status indicates if the save is finished or if an
+ * @return {Promise} status indicates if the save is finished or if an
* error occured.
*/
_saveResources: function () {
@@ -609,7 +602,7 @@ var ViewEditor = Widget.extend({
}
}
}).bind(this));
- if (errorFound) return $.Deferred().reject(errorFound);
+ if (errorFound) return Promise.reject(errorFound);
var defs = [];
var mutex = new concurrency.Mutex();
@@ -623,8 +616,10 @@ var ViewEditor = Widget.extend({
});
}).bind(this));
- return $.when.apply($, defs).fail((function (session, error) {
- Dialog.alert(this, '', {
+ var self = this;
+ return Promise.all(defs).guardedCatch(function (results) {
+ var error = results[1];
+ Dialog.alert(self, '', {
title: _t("Server error"),
$content: $('<div/>').html(
_t("A server error occured. Please check you correctly signed in and that the file you are saving is correctly formatted.")
@@ -632,34 +627,32 @@ var ViewEditor = Widget.extend({
+ error
)
});
- }).bind(this));
+ });
},
/**
* Saves an unique XML view.
*
* @private
* @param {Object} session - the 'id' and the 'text' of the view to save.
- * @returns {Deferred} status indicates if the save is finished or if an
+ * @returns {Promise} status indicates if the save is finished or if an
* error occured.
*/
_saveView: function (session) {
- var def = $.Deferred();
-
var self = this;
- this._rpc({
- model: 'ir.ui.view',
- method: 'write',
- args: [[session.id], {arch: session.text}],
- }, {
- noContextKeys: 'lang',
- }).then(function () {
- self._toggleDirtyInfo(session.id, 'xml', false);
- def.resolve();
- }, function (source, error) {
- def.reject(session, error);
+ return new Promise(function (resolve, reject) {
+ self._rpc({
+ model: 'ir.ui.view',
+ method: 'write',
+ args: [[session.id], {arch: session.text}],
+ }, {
+ noContextKeys: 'lang',
+ }).then(function () {
+ self._toggleDirtyInfo(session.id, 'xml', false);
+ resolve();
+ }, function (source, error) {
+ reject(session, error);
+ });
});
-
- return def;
},
/**
* Shows a line which produced an error. Red color is added to the editor,