Skip to content

Commit

Permalink
feat: #7501
Browse files Browse the repository at this point in the history
  • Loading branch information
barisusakli committed Apr 2, 2019
1 parent b52dba5 commit 2ee2cd5
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 11 deletions.
1 change: 1 addition & 0 deletions public/language/en-GB/admin/manage/categories.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
49 changes: 40 additions & 9 deletions public/src/admin/manage/category.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {};

Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/socket.io/admin/categories.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
7 changes: 7 additions & 0 deletions src/views/admin/partials/categories/copy-settings.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<!-- IMPORT admin/partials/categories/select-category.tpl -->
<div class="form-group">
<label for="copyParent">
<input id="copyParent" name="copyParent" type="checkbox">
<strong>[[admin/manage/categories:copy-parent]]</strong>
</label>
</div>
2 changes: 1 addition & 1 deletion test/categories.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 2ee2cd5

Please sign in to comment.