diff --git a/public/less/admin/admin.less b/public/less/admin/admin.less index f92ce1d93b..5fa23efb0f 100644 --- a/public/less/admin/admin.less +++ b/public/less/admin/admin.less @@ -1,8 +1,10 @@ @import "./bootstrap/bootstrap"; @import "./mixins"; +@import "./vars"; @import "./general/dashboard"; @import "./general/navigation"; +@import "./manage/categories"; @import "./manage/tags"; @import "./manage/flags"; @import "./manage/users"; diff --git a/public/less/admin/manage/categories.less b/public/less/admin/manage/categories.less new file mode 100644 index 0000000000..020e618382 --- /dev/null +++ b/public/less/admin/manage/categories.less @@ -0,0 +1,68 @@ +div.categories { + + ul { + list-style-type: none; + margin: 0; + padding: 0; + } + + .fa-ul { + li { + min-height: 0; + display: inline; + margin: 0 @acp-margin 0 0; + left: 0; + } + } + + li { + min-height: @acp-line-height; + margin: @acp-base-line 0; + + &.placeholder { + border: 1px dashed #2196F3; + background-color: #E1F5FE; + } + } + + .disabled { + + .icon, .header, .description { + opacity: 0.5; + } + + .stats { + opacity: 0.3; + } + } + + .icon { + width: @acp-line-height; + height: @acp-line-height; + border-radius: 50%; + line-height: @acp-line-height; + text-align: center; + vertical-align: bottom; + background-size: cover; + float: left; + margin-right: @acp-margin; + cursor: move; + } + + .information { + float: left; + } + + .header { + margin-top: 0; + margin-bottom: @acp-base-line; + } + + .description { + margin: 0; + } + + .stats, .btn-group { + float: left; + } +} \ No newline at end of file diff --git a/public/less/admin/vars.less b/public/less/admin/vars.less new file mode 100644 index 0000000000..8e7bc2bb30 --- /dev/null +++ b/public/less/admin/vars.less @@ -0,0 +1,3 @@ +@acp-base-line: 8px; +@acp-line-height: @acp-base-line * 6; +@acp-margin: @acp-base-line * 2; \ No newline at end of file diff --git a/public/src/admin/manage/categories.js b/public/src/admin/manage/categories.js index 535d902dfe..bf087b3e8c 100644 --- a/public/src/admin/manage/categories.js +++ b/public/src/admin/manage/categories.js @@ -2,48 +2,18 @@ /*global define, socket, app, bootbox, templates, ajaxify, RELATIVE_PATH*/ define('admin/manage/categories', function() { - var Categories = {}; + var Categories = {}, newCategoryId = -1, sortables, itemTemplate; Categories.init = function() { - var bothEl = $('#active-categories, #disabled-categories'); - - function updateCategoryOrders(evt, ui) { - var categories = $(evt.target).children(), - modified = {}, - cid; - - for(var i=0;i') + .addClass('alert alert-info text-center') + .text('You have no active categories.') + .appendTo(container); + }else{ + sortables = {}; + renderList(categories, 0, container, 0); + } + }; + + function itemDidAdd(e){ + newCategoryId = e.to.dataset.cid; + } + + function itemDragDidEnd(e){ + 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); + } + } + + /** + * 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, level, container, parentId){ + var i = 0, len = categories.length, category, marginLeft = 48, listItem; + var list = $('