diff --git a/package.json b/package.json index e89a43d75c..5b7ce98aa4 100644 --- a/package.json +++ b/package.json @@ -66,8 +66,8 @@ "nodebb-plugin-spam-be-gone": "0.5.0", "nodebb-rewards-essentials": "0.0.9", "nodebb-theme-lavender": "4.0.1", - "nodebb-theme-persona": "5.0.4", - "nodebb-theme-vanilla": "6.0.3", + "nodebb-theme-persona": "5.0.5", + "nodebb-theme-vanilla": "6.0.4", "nodebb-widget-essentials": "3.0.0", "nodemailer": "2.6.4", "nodemailer-sendmail-transport": "1.0.0", diff --git a/public/language/en-GB/global.json b/public/language/en-GB/global.json index bb152e4561..08835e8386 100644 --- a/public/language/en-GB/global.json +++ b/public/language/en-GB/global.json @@ -130,6 +130,7 @@ "cookies.message": "This website uses cookies to ensure you get the best experience on our website.", "cookies.accept": "Got it!", "cookies.learn_more": "Learn More", - - "edited": "Edited" + + "edited": "Edited", + "disabled": "Disabled" } diff --git a/public/language/en-GB/topic.json b/public/language/en-GB/topic.json index 727417ca5f..e25ef4973c 100644 --- a/public/language/en-GB/topic.json +++ b/public/language/en-GB/topic.json @@ -70,6 +70,7 @@ "thread_tools.unlock": "Unlock Topic", "thread_tools.move": "Move Topic", "thread_tools.move_all": "Move All", + "thread_tools.select_category": "Select Category", "thread_tools.fork": "Fork Topic", "thread_tools.delete": "Delete Topic", "thread_tools.delete-posts": "Delete Posts", @@ -86,7 +87,6 @@ "post_purge_confirm": "Are you sure you want to purge this post?", "load_categories": "Loading Categories", - "disabled_categories_note": "Disabled Categories are greyed out", "confirm_move": "Move", "confirm_fork": "Fork", diff --git a/public/src/admin/manage/category.js b/public/src/admin/manage/category.js index c241dd8840..0373d3837a 100644 --- a/public/src/admin/manage/category.js +++ b/public/src/admin/manage/category.js @@ -297,47 +297,30 @@ define('admin/manage/category', [ }; Category.launchParentSelector = function () { - socket.emit('categories.get', function (err, categories) { - if (err) { - return app.alertError(err.message); - } - - categories = categories.filter(function (category) { - return category && !category.disabled && parseInt(category.cid, 10) !== parseInt(ajaxify.data.category.cid, 10); - }); - - templates.parse('partials/category_list', { - categories: categories, - }, function (html) { - var modal = bootbox.dialog({ - message: html, - title: '[[admin/manage/categories:alert.set-parent-category]]', - }); - - modal.find('li[data-cid]').on('click', function () { - var parentCid = $(this).attr('data-cid'); - var payload = {}; + var categories = ajaxify.data.allCategories.filter(function (category) { + return category && !category.disabled && parseInt(category.cid, 10) !== parseInt(ajaxify.data.category.cid, 10); + }); - payload[ajaxify.data.category.cid] = { - parentCid: parentCid, - }; + selectCategoryModal(categories, function (parentCid) { + var payload = {}; - socket.emit('admin.categories.update', payload, function (err) { - if (err) { - return app.alertError(err.message); - } - var parent = categories.filter(function (category) { - return category && parseInt(category.cid, 10) === parseInt(parentCid, 10); - }); - parent = parent[0]; + payload[ajaxify.data.category.cid] = { + parentCid: parentCid, + }; - modal.modal('hide'); - $('button[data-action="removeParent"]').parent().removeClass('hide'); - $('button[data-action="setParent"]').addClass('hide'); - var buttonHtml = '<i class="fa ' + parent.icon + '"></i> ' + parent.name; - $('button[data-action="changeParent"]').html(buttonHtml).parent().removeClass('hide'); - }); + socket.emit('admin.categories.update', payload, function (err) { + if (err) { + return app.alertError(err.message); + } + var parent = ajaxify.data.allCategories.filter(function (category) { + return category && parseInt(category.cid, 10) === parseInt(parentCid, 10); }); + parent = parent[0]; + + $('button[data-action="removeParent"]').parent().removeClass('hide'); + $('button[data-action="setParent"]').addClass('hide'); + var buttonHtml = '<i class="fa ' + parent.icon + '"></i> ' + parent.name; + $('button[data-action="changeParent"]').html(buttonHtml).parent().removeClass('hide'); }); }); }; @@ -418,37 +401,35 @@ define('admin/manage/category', [ }); }; - function selectCategoryModal(callback) { - socket.emit('admin.categories.getNames', function (err, categories) { - if (err) { - return app.alertError(err.message); - } - - templates.parse('admin/partials/categories/select-category', { - categories: categories, - }, function (html) { - translator.translate(html, function (html) { - var modal = bootbox.dialog({ - title: 'Select a Category', - message: html, - buttons: { - save: { - label: 'Copy', - className: 'btn-primary', - callback: submit, - }, + function selectCategoryModal(categories, callback) { + if (typeof categories === 'function') { + callback = categories; + categories = ajaxify.data.allCategories; + } + templates.parse('admin/partials/categories/select-category', { + categories: categories, + }, function (html) { + translator.translate(html, function (html) { + var modal = bootbox.dialog({ + title: 'Select a Category', + message: html, + buttons: { + save: { + label: 'Copy', + className: 'btn-primary', + callback: submit, }, - }); + }, + }); - function submit() { - var formData = modal.find('form').serializeObject(); - callback(formData['select-cid']); - modal.modal('hide'); - return false; - } + function submit() { + var formData = modal.find('form').serializeObject(); + callback(formData['select-cid']); + modal.modal('hide'); + return false; + } - modal.find('form').on('submit', submit); - }); + modal.find('form').on('submit', submit); }); }); } diff --git a/public/src/client/topic/move.js b/public/src/client/topic/move.js index 5ff9a02c49..e023d6822e 100644 --- a/public/src/client/topic/move.js +++ b/public/src/client/topic/move.js @@ -4,7 +4,7 @@ define('forum/topic/move', function () { var Move = {}; var modal; - var selectedEl; + var selectedCategory; Move.init = function (tids, currentCid, onComplete) { Move.tids = tids; @@ -31,8 +31,17 @@ define('forum/topic/move', function () { modal.find('.modal-header h3').translateText('[[topic:move_topics]]'); } - modal.on('click', '.category-list li[data-cid]', function () { - selectCategory($(this)); + modal.find('#select-cid').on('change', function () { + var cid = $(this).val(); + var optionEl = $(this).find('option[value="' + cid + '"]'); + + var selectedCategory = { + cid: cid, + name: optionEl.attr('data-name'), + text: optionEl.text(), + icon: optionEl.attr('data-icon'), + }; + selectCategory(selectedCategory); }); modal.find('#move_thread_commit').on('click', onCommitClicked); @@ -42,60 +51,25 @@ define('forum/topic/move', function () { } function parseModal(categories, callback) { - templates.parse('partials/move_thread_modal', { categories: [] }, function (html) { - require(['translator'], function (translator) { - translator.translate(html, function (html) { - modal = $(html); - categories.forEach(function (category) { - if (!category.link) { - buildRecursive(modal.find('.category-list'), category, ''); - } - }); - callback(); - }); - }); - }); - } - - function buildRecursive(parentEl, category, level) { - var categoryEl = $('<li/>'); + app.parseAndTranslate('partials/move_thread_modal', { categories: categories }, function (html) { + modal = $(html); - if (category.bgColor) { - categoryEl.css('background-color', category.bgColor); - } - if (category.color) { - categoryEl.css('color', category.color); - } - categoryEl.toggleClass('disabled', !!category.disabled); - categoryEl.attr('data-cid', category.cid); - categoryEl.attr('data-icon', category.icon); - categoryEl.attr('data-name', category.name); - categoryEl.html('<i class="fa fa-fw ' + category.icon + '"></i> ' + category.name); - - parentEl.append(level); - parentEl.append(categoryEl); - parentEl.append('<br/>'); - - var indent = ' '; - category.children.forEach(function (childCategory) { - if (!childCategory.link) { - buildRecursive(parentEl, childCategory, indent + level); - } + callback(); }); } function selectCategory(category) { - modal.find('#confirm-category-name').html(category.html()); + modal.find('#confirm-category-name').text(category.name); modal.find('#move-confirm').removeClass('hide'); - selectedEl = category; + selectedCategory = category; modal.find('#move_thread_commit').prop('disabled', false); } function onCommitClicked() { var commitEl = modal.find('#move_thread_commit'); - if (!commitEl.prop('disabled') && selectedEl.attr('data-cid')) { + if (!commitEl.prop('disabled') && selectedCategory && selectedCategory.cid) { commitEl.prop('disabled', true); moveTopics(); @@ -105,7 +79,7 @@ define('forum/topic/move', function () { function moveTopics() { socket.emit(Move.moveAll ? 'topics.moveAll' : 'topics.move', { tids: Move.tids, - cid: selectedEl.attr('data-cid'), + cid: selectedCategory.cid, currentCid: Move.currentCid, }, function (err) { modal.modal('hide'); @@ -114,7 +88,7 @@ define('forum/topic/move', function () { return app.alertError(err.message); } - app.alertSuccess('[[topic:topic_move_success, ' + selectedEl.attr('data-name') + ']] <i class="fa fa-fw ' + selectedEl.attr('data-icon') + '"></i>'); + app.alertSuccess('[[topic:topic_move_success, ' + selectedCategory.name + ']] <i class="fa fa-fw ' + selectedCategory.icon + '"></i>'); if (typeof Move.onComplete === 'function') { Move.onComplete(); } diff --git a/src/categories.js b/src/categories.js index 787853faa7..fbafad7e50 100644 --- a/src/categories.js +++ b/src/categories.js @@ -315,6 +315,17 @@ Categories.getTree = function (categories, parentCid) { }; Categories.buildForSelect = function (uid, callback) { + async.waterfall([ + function (next) { + Categories.getCategoriesByPrivilege('cid:0:children', uid, 'read', next); + }, + function (categories, next) { + Categories.buildForSelectCategories(categories, next); + }, + ], callback); +}; + +Categories.buildForSelectCategories = function (categories, callback) { function recursive(category, categoriesData, level) { if (category.link) { return; @@ -329,23 +340,17 @@ Categories.buildForSelect = function (uid, callback) { recursive(child, categoriesData, ' ' + level); }); } - async.waterfall([ - function (next) { - Categories.getCategoriesByPrivilege('cid:0:children', uid, 'read', next); - }, - function (categories, next) { - var categoriesData = []; - categories = categories.filter(function (category) { - return category && !category.link && !parseInt(category.parentCid, 10); - }); + var categoriesData = []; - categories.forEach(function (category) { - recursive(category, categoriesData, ''); - }); - next(null, categoriesData); - }, - ], callback); + categories = categories.filter(function (category) { + return category && !category.link && !parseInt(category.parentCid, 10); + }); + + categories.forEach(function (category) { + recursive(category, categoriesData, ''); + }); + callback(null, categoriesData); }; Categories.getIgnorers = function (cid, start, stop, callback) { diff --git a/src/socket.io/categories.js b/src/socket.io/categories.js index 3404fb3fee..db47d0e865 100644 --- a/src/socket.io/categories.js +++ b/src/socket.io/categories.js @@ -160,12 +160,12 @@ SocketCategories.getMoveCategories = function (socket, data, callback) { function (next) { db.getSortedSetRange('cid:0:children', 0, -1, next); }, - function (cids, next) { - privileges.categories.filterCids('read', cids, socket.uid, next); - }, function (cids, next) { categories.getCategories(cids, socket.uid, next); }, + function (categoriesData, next) { + categories.buildForSelectCategories(categoriesData, next); + }, ], next); }, }, next); diff --git a/src/views/admin/partials/categories/select-category.tpl b/src/views/admin/partials/categories/select-category.tpl index 8c93286507..b9b8e39e2e 100644 --- a/src/views/admin/partials/categories/select-category.tpl +++ b/src/views/admin/partials/categories/select-category.tpl @@ -3,7 +3,7 @@ <label for="select-cid">[[admin/manage/categories:select-category]]</label> <select class="form-control" name="select-cid" id="select-cid"> <!-- BEGIN categories --> - <option value="{categories.cid}">{categories.name}</option> + <option value="{categories.cid}">{categories.text}</option> <!-- END categories --> </select> </div> diff --git a/src/views/admin/partials/categories/setParent.tpl b/src/views/admin/partials/categories/setParent.tpl deleted file mode 100644 index e8e6b9f860..0000000000 --- a/src/views/admin/partials/categories/setParent.tpl +++ /dev/null @@ -1,23 +0,0 @@ -<div class="modal fade" id="setParent" tabindex="-1" role="dialog" aria-labelledby="setParentLabel" aria-hidden="true"> - <div class="modal-dialog"> - <div class="modal-content"> - <div class="modal-header"> - <button type="button" class="close" data-dismiss="modal"> - <span aria-hidden="true">×</span> - <span class="sr-only">[[global:buttons.close]]</span> - </button> - <h4 class="modal-title" id="setParentLabel"> - [[admin/manage/categories:set-parent-category]] - </h4> - </div> - <div class="modal-body"> - <!-- IMPORT partials/category_list.tpl --> - </div> - <div class="modal-footer"> - <button type="button" class="btn btn-default" data-dismiss="modal"> - [[global:buttons.close]] - </button> - </div> - </div> - </div> -</div> \ No newline at end of file