From 2ee2cd528f4dad9052ce9442205f6fc4296f76a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Tue, 2 Apr 2019 11:56:03 -0400 Subject: [PATCH] feat: #7501 --- .../en-GB/admin/manage/categories.json | 1 + public/src/admin/manage/category.js | 49 +++++++++++++++---- src/socket.io/admin/categories.js | 2 +- .../partials/categories/copy-settings.tpl | 7 +++ test/categories.js | 2 +- 5 files changed, 50 insertions(+), 11 deletions(-) create mode 100644 src/views/admin/partials/categories/copy-settings.tpl diff --git a/public/language/en-GB/admin/manage/categories.json b/public/language/en-GB/admin/manage/categories.json index 60524dd329..7e49aef36b 100644 --- a/public/language/en-GB/admin/manage/categories.json +++ b/public/language/en-GB/admin/manage/categories.json @@ -17,6 +17,7 @@ "parent-category": "Parent Category", "optional-parent-category": "(Optional) Parent Category", "parent-category-none": "(None)", + "copy-parent": "Copy Parent", "copy-settings": "Copy Settings From", "optional-clone-settings": "(Optional) Clone Settings From Category", "clone-children": "Clone Children Categories And Settings", diff --git a/public/src/admin/manage/category.js b/public/src/admin/manage/category.js index 3617ed04b3..05ee5daef9 100644 --- a/public/src/admin/manage/category.js +++ b/public/src/admin/manage/category.js @@ -4,11 +4,9 @@ define('admin/manage/category', [ 'uploader', 'iconSelect', 'admin/modules/colorpicker', - 'autocomplete', - 'translator', 'categorySelector', 'benchpress', -], function (uploader, iconSelect, colorpicker, autocomplete, translator, categorySelector, Benchpress) { +], function (uploader, iconSelect, colorpicker, categorySelector, Benchpress) { var Category = {}; var modified_categories = {}; @@ -126,13 +124,46 @@ define('admin/manage/category', [ }); $('.copy-settings').on('click', function () { - categorySelector.modal(function (cid) { - socket.emit('admin.categories.copySettingsFrom', { fromCid: cid, toCid: ajaxify.data.category.cid }, function (err) { - if (err) { - return app.alertError(err.message); + 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('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); } - app.alertSuccess('[[admin/manage/categories:alert.copy-success]]'); - ajaxify.refresh(); }); }); return false; diff --git a/src/socket.io/admin/categories.js b/src/socket.io/admin/categories.js index 3d9f0346fd..d585318f17 100644 --- a/src/socket.io/admin/categories.js +++ b/src/socket.io/admin/categories.js @@ -130,7 +130,7 @@ function copyPrivilegesToChildrenRecursive(parentCid, category, callback) { } Categories.copySettingsFrom = function (socket, data, callback) { - categories.copySettingsFrom(data.fromCid, data.toCid, true, callback); + categories.copySettingsFrom(data.fromCid, data.toCid, data.copyParent, callback); }; Categories.copyPrivilegesFrom = function (socket, data, callback) { diff --git a/src/views/admin/partials/categories/copy-settings.tpl b/src/views/admin/partials/categories/copy-settings.tpl new file mode 100644 index 0000000000..ab1f13c36a --- /dev/null +++ b/src/views/admin/partials/categories/copy-settings.tpl @@ -0,0 +1,7 @@ + +
+ +
\ No newline at end of file diff --git a/test/categories.js b/test/categories.js index 2d2412a6b1..69e5fddbee 100644 --- a/test/categories.js +++ b/test/categories.js @@ -549,7 +549,7 @@ describe('Categories', function () { }, function (category, next) { child1Cid = category.cid; - socketCategories.copySettingsFrom({ uid: adminUid }, { fromCid: parentCid, toCid: child1Cid }, next); + socketCategories.copySettingsFrom({ uid: adminUid }, { fromCid: parentCid, toCid: child1Cid, copyParent: true }, next); }, function (destinationCategory, next) { Categories.getCategoryField(child1Cid, 'description', next);