Skip to content

Node.js based forum software built for the modern web

changed a bunch of whitespace back into tabs, and fixed issue where categories without a parentCid were not showing up at all in the ACP

Julian Lam6fedcca4eed5
diff --git a/public/less/admin/manage/categories.less b/public/less/admin/manage/categories.less
index a1238f9f23..acc730e081 100644
--- a/public/less/admin/manage/categories.less
+++ b/public/less/admin/manage/categories.less
@@ -11,7 +11,9 @@ div.categories {
}
}
- .fa-ul {
+ .stats {
+ display: inline-block;
+
li {
min-height: 0;
display: inline;
@@ -66,8 +68,4 @@ div.categories {
.description {
margin: 0;
}
-
- .stats, .btn-group {
- float: left;
- }
}
\ No newline at end of file
diff --git a/public/src/admin/manage/categories.js b/public/src/admin/manage/categories.js
index 27882cf1fb..ca26182388 100644
--- a/public/src/admin/manage/categories.js
+++ b/public/src/admin/manage/categories.js
@@ -2,10 +2,11 @@
/*global define, socket, app, bootbox, templates, ajaxify, RELATIVE_PATH, Sortable */
define('admin/manage/categories', function() {
- var Categories = {}, newCategoryId = -1, sortables, itemTemplate;
+ var Categories = {}, newCategoryId = -1, sortables;
Categories.init = function() {
socket.emit('admin.categories.getAll', function(error, payload){
+ console.log(payload);
if(error){
return app.alertError(error.message);
}
@@ -55,17 +56,17 @@ define('admin/manage/categories', function() {
};
Categories.render = function(categories){
- var container = $('.categories');
-
- if(!categories || categories.length == 0){
- $('<div></div>')
- .addClass('alert alert-info text-center')
- .text('You have no active categories.')
- .appendTo(container);
- }else{
- sortables = {};
- renderList(categories, container, 0);
- }
+ var container = $('.categories');
+
+ if (!categories || categories.length == 0) {
+ $('<div></div>')
+ .addClass('alert alert-info text-center')
+ .text('You have no active categories.')
+ .appendTo(container);
+ } else {
+ sortables = {};
+ renderList(categories, container, 0);
+ }
};
Categories.toggle = function(cid, state) {
@@ -85,40 +86,40 @@ define('admin/manage/categories', function() {
}
function itemDidAdd(e){
- newCategoryId = e.to.dataset.cid;
+ newCategoryId = e.to.dataset.cid;
}
function itemDragDidEnd(e){
- var isCategoryUpdate = (newCategoryId != -1);
+ var isCategoryUpdate = (newCategoryId != -1);
//Update needed?
if((e.newIndex != undefined && e.oldIndex != e.newIndex) || isCategoryUpdate){
- var parentCategory = isCategoryUpdate ? sortables[newCategoryId] : sortables[e.from.dataset.cid],
- modified = {}, i = 0, list = parentCategory.toArray(), len = list.length;
-
- for(i; i < len; ++i) {
- modified[list[i]] = {
- order: (i + 1)
- }
- }
-
- if(isCategoryUpdate){
- modified[e.item.dataset.cid]['parentCid'] = newCategoryId;
- }
-
- newCategoryId = -1
- socket.emit('admin.categories.update', modified);
- }
+ var parentCategory = isCategoryUpdate ? sortables[newCategoryId] : sortables[e.from.dataset.cid],
+ modified = {}, i = 0, list = parentCategory.toArray(), len = list.length;
+
+ for(i; i < len; ++i) {
+ modified[list[i]] = {
+ order: (i + 1)
+ }
+ }
+
+ if(isCategoryUpdate){
+ modified[e.item.dataset.cid]['parentCid'] = newCategoryId;
+ }
+
+ newCategoryId = -1
+ socket.emit('admin.categories.update', modified);
+ }
}
- /**
- * Render categories - recursively
- *
- * @param categories {array} categories tree
- * @param level {number} current sub-level of rendering
- * @param container {object} parent jquery element for the list
- * @param parentId {number} parent category identifier
- */
- function renderList(categories, container, parentId){
+ /**
+ * Render categories - recursively
+ *
+ * @param categories {array} categories tree
+ * @param level {number} current sub-level of rendering
+ * @param container {object} parent jquery element for the list
+ * @param parentId {number} parent category identifier
+ */
+ function renderList(categories, container, parentId){
templates.parse('admin/partials/categories/category-rows', {
cid: parentId,
categories: categories
@@ -137,13 +138,13 @@ define('admin/manage/categories', function() {
group: 'cross-categories',
animation: 150,
handle: '.icon',
- dataIdAttr: 'data-cid',
+ dataIdAttr: 'data-cid',
ghostClass: "placeholder",
onAdd: itemDidAdd,
onEnd: itemDragDidEnd
});
});
- }
+ }
return Categories;
});
\ No newline at end of file
diff --git a/src/categories.js b/src/categories.js
index 38cfa39c1e..1a51c192e6 100644
--- a/src/categories.js
+++ b/src/categories.js
@@ -319,16 +319,19 @@ var async = require('async'),
Categories.getTree = function(categories, parentCid) {
var tree = [], i = 0, len = categories.length, category;
- for(i; i < len; ++i){
- category = categories[i];
+ for(i; i < len; ++i) {
+ category = categories[i];
+ if (!category.hasOwnProperty('parentCid')) {
+ category.parentCid = 0;
+ }
- if(category.parentCid == parentCid){
- tree.push(category);
- category.children = Categories.getTree(categories, category.cid);
- }
- }
+ if(category.parentCid == parentCid){
+ tree.push(category);
+ category.children = Categories.getTree(categories, category.cid);
+ }
+ }
- return tree;
+ return tree;
};
}(exports));
diff --git a/src/views/admin/partials/categories/category-rows.tpl b/src/views/admin/partials/categories/category-rows.tpl
index b30059783d..599de8a5c5 100644
--- a/src/views/admin/partials/categories/category-rows.tpl
+++ b/src/views/admin/partials/categories/category-rows.tpl
@@ -2,7 +2,7 @@
<!-- BEGIN categories -->
<li data-cid="{categories.cid}" <!-- IF categories.disabled -->class="disabled"<!-- ENDIF categories.disabled -->>
<div class="row">
- <div class="col-md-9">
+ <div class="col-md-8">
<div class="clearfix">
<div class="icon" style="color: {categories.color}; background-color: {categories.bgColor};<!-- IF categories.backgroundImage --> background-image: url('{categories.backgroundImage}');<!-- ENDIF categories.backgroundImage -->">
<i data-name="icon" value="{categories.icon}" class="fa {categories.icon}"></i>
@@ -13,11 +13,11 @@
</div>
</div>
</div>
- <div class="col-md-3">
- <div class="clearfix pull-right">
- <ul class="fa-ul stats">
- <li class="fa-li"><i class="fa fa-book"></i> {categories.topic_count}</li>
- <li class="fa-li"><i class="fa fa-pencil"></i> {categories.post_count}</li>
+ <div class="col-md-4">
+ <div class="clearfix pull-right text-right">
+ <ul class="stats">
+ <li><i class="fa fa-book"></i> {categories.topic_count}</li>
+ <li><i class="fa fa-pencil"></i> {categories.post_count}</li>
</ul>
<div class="btn-group">
<button data-action="toggle" data-disabled="{categories.disabled}" class="btn btn-xs <!-- IF categories.disabled -->btn-primary<!-- ELSE -->btn-danger<!-- ENDIF categories.disabled -->">