Skip to content

Node.js based forum software built for the modern web

ACP setting and API return for subcats

Julian Lamb7c7dd98c34a
diff --git a/public/src/forum/admin/categories.js b/public/src/forum/admin/categories.js
index cc1627fdf6..c7851c1e7e 100644
--- a/public/src/forum/admin/categories.js
+++ b/public/src/forum/admin/categories.js
@@ -231,6 +231,30 @@ define('forum/admin/categories', ['uploader', 'forum/admin/iconSelect'], functio
});
setupEditTargets();
+
+ $('button[data-action="setParent"]').on('click', function() {
+ var cid = $(this).parents('[data-cid]').attr('data-cid'),
+ modal = $('#setParent');
+
+ modal.find('select').val($(this).attr('data-parentCid'));
+ modal.attr('data-cid', cid).modal();
+ });
+ $('#setParent [data-cid]').on('click', function() {
+ var modalEl = $('#setParent'),
+ parentCid = $(this).attr('data-cid'),
+ payload = {};
+
+ payload[modalEl.attr('data-cid')] = {
+ parentCid: parentCid
+ };
+
+ socket.emit('admin.categories.update', payload, function(err) {
+ modalEl.one('hidden.bs.modal', function() {
+ ajaxify.go('admin/categories/active');
+ });
+ modalEl.modal('hide');
+ });
+ });
});
};
diff --git a/src/categories.js b/src/categories.js
index eae19b4595..e3f17e96e5 100644
--- a/src/categories.js
+++ b/src/categories.js
@@ -263,7 +263,13 @@ var db = require('./database'),
});
};
- Categories.getCategoriesData = function(cids, callback) {
+ Categories.getCategoriesData = function(cids, expandParent, callback) {
+ // expandParent is optional, default: true
+ if (typeof expandParent === 'function' && !callback) {
+ callback = expandParent;
+ expandParent = undefined;
+ }
+
var keys = cids.map(function(cid) {
return 'category:' + cid;
});
@@ -285,7 +291,18 @@ var db = require('./database'),
category.description = validator.escape(category.description);
category.backgroundImage = category.image ? nconf.get('relative_path') + category.image : '';
category.disabled = category.disabled ? parseInt(category.disabled, 10) !== 0 : false;
- next(null, category);
+
+ if (expandParent !== false && category.parentCid) {
+ Categories.getCategoriesData([category.parentCid], false, function(err, categories) {
+ if (!err && categories.length) {
+ category.parent = categories[0];
+ }
+
+ next(null, category);
+ });
+ } else {
+ next(null, category);
+ }
}, callback);
});
};
diff --git a/src/categories/update.js b/src/categories/update.js
index 002628d723..fa04d99deb 100644
--- a/src/categories/update.js
+++ b/src/categories/update.js
@@ -13,6 +13,7 @@ module.exports = function(Categories) {
function updateCategory(cid, next) {
var category = modified[cid];
var fields = Object.keys(category);
+ console.log('updating', cid, 'fields:', fields);
async.each(fields, function(key, next) {
updateCategoryField(cid, key, category[key], next);
diff --git a/src/controllers/categories.js b/src/controllers/categories.js
index 25a4bf3255..f7557210fb 100644
--- a/src/controllers/categories.js
+++ b/src/controllers/categories.js
@@ -8,7 +8,7 @@ var categoriesController = {},
user = require('../user'),
categories = require('../categories'),
topics = require('../topics'),
- meta = require('../meta');
+ meta = require('../meta'),
plugins = require('../plugins');
categoriesController.recent = function(req, res, next) {