diff --git a/public/src/admin/extend/widgets.js b/public/src/admin/extend/widgets.js index 4394ee9a04..be7bf72e83 100644 --- a/public/src/admin/extend/widgets.js +++ b/public/src/admin/extend/widgets.js @@ -75,8 +75,7 @@ define('admin/extend/widgets', ['jqueryui'], function () { $('#save').on('click', saveWidgets); function saveWidgets() { - var total = $('#widgets [data-template][data-location]').length; - + var saveData = []; $('#widgets [data-template][data-location]').each(function (i, el) { el = $(el); @@ -112,26 +111,24 @@ define('admin/extend/widgets', ['jqueryui'], function () { }); }); - socket.emit('admin.widgets.set', { + saveData.push({ template: template, location: location, widgets: widgets, - }, function (err) { - total -= 1; + }); + }); - if (err) { - app.alertError(err.message); - } + socket.emit('admin.widgets.set', saveData, function (err) { + if (err) { + app.alertError(err.message); + } - if (total === 0) { - app.alert({ - alert_id: 'admin:widgets', - type: 'success', - title: '[[admin/extend/widgets:alert.updated]]', - message: '[[admin/extend/widgets:alert.update-success]]', - timeout: 2500, - }); - } + app.alert({ + alert_id: 'admin:widgets', + type: 'success', + title: '[[admin/extend/widgets:alert.updated]]', + message: '[[admin/extend/widgets:alert.update-success]]', + timeout: 2500, }); }); } diff --git a/src/socket.io/admin.js b/src/socket.io/admin.js index 322108330b..7e0eb64d98 100644 --- a/src/socket.io/admin.js +++ b/src/socket.io/admin.js @@ -149,11 +149,11 @@ SocketAdmin.plugins.upgrade = function (socket, data, callback) { }; SocketAdmin.widgets.set = function (socket, data, callback) { - if (!data) { + if (!Array.isArray(data)) { return callback(new Error('[[error:invalid-data]]')); } - widgets.setArea(data, callback); + async.eachSeries(data, widgets.setArea, callback); }; SocketAdmin.config.set = function (socket, data, callback) {