From 9cbe9389f54cb9e0bb20312452610c7640e9481c Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Fri, 21 Aug 2020 12:02:53 -0400 Subject: [PATCH] fix: use promises in privilege save ... instead of jQuery Deferreds --- public/src/admin/manage/privileges.js | 30 +++++++++++++-------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/public/src/admin/manage/privileges.js b/public/src/admin/manage/privileges.js index e9e5bfb037..ecc61b8f00 100644 --- a/public/src/admin/manage/privileges.js +++ b/public/src/admin/manage/privileges.js @@ -115,7 +115,7 @@ define('admin/manage/privileges', [ return Privileges.setPrivilege(member, privilege, state); }); - $.when(requests).done(function () { + Promise.allSettled(requests).then(function () { Privileges.refreshPrivilegeTable(); app.alertSuccess('[[admin/manage/privileges:alert.saved]]'); }); @@ -180,23 +180,21 @@ define('admin/manage/privileges', [ }; Privileges.setPrivilege = function (member, privilege, state) { - var deferred = $.Deferred(); - - socket.emit('admin.categories.setPrivilege', { - cid: isNaN(cid) ? 0 : cid, - privilege: privilege, - set: state, - member: member, - }, function (err) { - if (err) { - deferred.reject(err); - return app.alertError(err.message); - } + return new Promise(function (resolve, reject) { + socket.emit('admin.categories.setPrivilege', { + cid: isNaN(cid) ? 0 : cid, + privilege: privilege, + set: state, + member: member, + }, function (err) { + if (err) { + reject(err); + return app.alertError(err.message); + } - deferred.resolve(); + resolve(); + }); }); - - return deferred.promise(); }; Privileges.addUserToPrivilegeTable = function () {