From f98810d87fbe673ed779ebed5cda1fe696ae89c6 Mon Sep 17 00:00:00 2001 From: Yuri Kuznetsov Date: Wed, 1 Apr 2020 16:23:02 +0300 Subject: [PATCH] code formatting and cleanup --- client/src/ajax.js | 13 +------ client/src/views/notification/badge.js | 48 ++++++++++++++++---------- 2 files changed, 30 insertions(+), 31 deletions(-) diff --git a/client/src/ajax.js b/client/src/ajax.js index 19a3b4d999..8f96630da6 100644 --- a/client/src/ajax.js +++ b/client/src/ajax.js @@ -39,20 +39,9 @@ define('ajax', [], function () { options.data = data; } - var xhr = $.ajax(options); - - return xhr; - - var obj = { - then: xhr.then, - fail: xhr.fail, - catch: xhr.fail - }; - - return obj; + return $.ajax(options); }, - postRequest: function (url, data, options) { if (data) { data = JSON.stringify(data); diff --git a/client/src/views/notification/badge.js b/client/src/views/notification/badge.js index 4e4bc3f43d..83ce341263 100644 --- a/client/src/views/notification/badge.js +++ b/client/src/views/notification/badge.js @@ -206,27 +206,37 @@ define('views/notification/badge', 'view', function (Dep) { if (!url || !interval) return; - (new Promise(function (resolve) { - if (this.checkBypass()) { - resolve(); - return; - } - var jqxhr = Espo.Ajax.getRequest(url).done(function (list) { - list.forEach(function (item) { - this.showPopupNotification(name, item, isNotFirstCheck); - }, this); - }.bind(this)); + (new Promise( + function (resolve) { + if (this.checkBypass()) { + resolve(); + return; + } - jqxhr.always(function() { - resolve(); - }); - }.bind(this))).then(function () { - if (useWebSocket) return; + Espo.Ajax.getRequest(url) + .then( + function (list) { + list.forEach(function (item) { + this.showPopupNotification(name, item, isNotFirstCheck); + }, this); + }.bind(this) + ) + .always( + function() { + resolve(); + } + ); - this.popoupTimeouts[name] = setTimeout(function () { - this.checkPopupNotifications(name, isNotFirstCheck); - }.bind(this), interval * 1000); - }.bind(this)); + }.bind(this) + )).then( + function () { + if (useWebSocket) return; + + this.popoupTimeouts[name] = setTimeout(function () { + this.checkPopupNotifications(name, isNotFirstCheck); + }.bind(this), interval * 1000); + }.bind(this) + ); }, showPopupNotification: function (name, data, isNotFirstCheck) {