From ed4b5caf2cae7e83e96e483cd377f34b8189ec44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Wed, 24 Jun 2020 16:02:01 -0400 Subject: [PATCH] fix: copy settings showing empty category selection --- public/src/admin/manage/category.js | 78 ++++++++++++++++------------- 1 file changed, 42 insertions(+), 36 deletions(-) diff --git a/public/src/admin/manage/category.js b/public/src/admin/manage/category.js index 15c70655e0..f4c75c38e6 100644 --- a/public/src/admin/manage/category.js +++ b/public/src/admin/manage/category.js @@ -124,49 +124,55 @@ define('admin/manage/category', [ }); $('.copy-settings').on('click', function () { - Benchpress.parse('admin/partials/categories/copy-settings', { - categories: ajaxify.data.allCategories, - }, function (html) { - var selectedCid; - var modal = bootbox.dialog({ - title: '[[modules:composer.select_category]]', - message: html, - buttons: { - save: { - label: '[[modules:bootbox.confirm]]', - className: 'btn-primary', - callback: function () { - if (!selectedCid) { - return; - } + socket.emit('categories.getSelectCategories', {}, function (err, allCategories) { + if (err) { + return app.alertError(err.message); + } - socket.emit('admin.categories.copySettingsFrom', { - fromCid: selectedCid, - toCid: ajaxify.data.category.cid, - copyParent: modal.find('#copyParent').prop('checked'), - }, function (err) { - if (err) { - return app.alertError(err.message); + Benchpress.parse('admin/partials/categories/copy-settings', { + categories: allCategories, + }, function (html) { + var selectedCid; + var modal = bootbox.dialog({ + title: '[[modules:composer.select_category]]', + message: html, + buttons: { + save: { + label: '[[modules:bootbox.confirm]]', + className: 'btn-primary', + callback: function () { + if (!selectedCid || parseInt(selectedCid, 10) === parseInt(ajaxify.data.category.cid, 10)) { + return; } - modal.modal('hide'); - app.alertSuccess('[[admin/manage/categories:alert.copy-success]]'); - ajaxify.refresh(); - }); - return false; + socket.emit('admin.categories.copySettingsFrom', { + fromCid: selectedCid, + toCid: ajaxify.data.category.cid, + copyParent: modal.find('#copyParent').prop('checked'), + }, function (err) { + if (err) { + return app.alertError(err.message); + } + + modal.modal('hide'); + app.alertSuccess('[[admin/manage/categories:alert.copy-success]]'); + ajaxify.refresh(); + }); + return false; + }, }, }, - }, - }); - modal.find('.modal-footer button').prop('disabled', true); - categorySelector.init(modal.find('[component="category-selector"]'), function (selectedCategory) { - selectedCid = selectedCategory && selectedCategory.cid; - if (selectedCid) { - modal.find('.modal-footer button').prop('disabled', false); - } + }); + modal.find('.modal-footer button').prop('disabled', true); + categorySelector.init(modal.find('[component="category-selector"]'), function (selectedCategory) { + selectedCid = selectedCategory && selectedCategory.cid; + if (selectedCid) { + modal.find('.modal-footer button').prop('disabled', false); + } + }); }); + return false; }); - return false; }); $('.upload-button').on('click', function () {