diff --git a/public/src/admin/manage/categories.js b/public/src/admin/manage/categories.js index 4124cbf423..f28b9c52bf 100644 --- a/public/src/admin/manage/categories.js +++ b/public/src/admin/manage/categories.js @@ -9,6 +9,8 @@ define('admin/manage/categories', [ var Categories = {}; Categories.init = function() { + var bothEl = $('#active-categories, #disabled-categories'); + var modified_categories = {}; function modified(el) { @@ -55,9 +57,29 @@ define('admin/manage/categories', [ socket.emit('admin.categories.update', modified); } - $('#entry-container').sortable({ + bothEl.sortable({ stop: updateCategoryOrders, - distance: 10 + distance: 15 + }); + + // Category enable/disable + bothEl.on('click', '[data-action="toggle"]', function(ev) { + var btnEl = $(this), + cid = btnEl.parents('tr').attr('data-cid'), + disabled = btnEl.attr('data-disabled') === 'false' ? '1' : '0', + payload = {}; + + payload[cid] = { + disabled: disabled + }; + + socket.emit('admin.categories.update', payload, function(err, result) { + if (err) { + return app.alertError(err.message); + } else { + ajaxify.refresh(); + } + }); }); $('.blockclass, .admin-categories form select').each(function() { @@ -76,7 +98,7 @@ define('admin/manage/categories', [ icon: $('#new-category-modal i').attr('value'), bgColor: '#0059b2', color: '#fff', - order: $('.admin-categories #entry-container').children().length + 1 + order: $('#disabled-categories').children().length + 1 }; socket.emit('admin.categories.create', category, function(err, data) { @@ -145,7 +167,7 @@ define('admin/manage/categories', [ $('#addNew').on('click', showCreateCategoryModal); $('#create-category-btn').on('click', createNewCategory); - $('#entry-container, #new-category-modal').on('click', '.icon', function(ev) { + $('#active-categories, #disabled-categories, #new-category-modal').on('click', '.icon', function(ev) { iconSelect.init($(this).find('i'), modified); }); @@ -153,20 +175,6 @@ define('admin/manage/categories', [ modified(ev.target); }); - $('.dropdown').on('click', '[data-disabled]', function(ev) { - var btn = $(this), - categoryRow = btn.parents('li'), - cid = categoryRow.attr('data-cid'), - disabled = btn.attr('data-disabled') === 'false' ? '1' : '0'; - - categoryRow.remove(); - modified_categories[cid] = modified_categories[cid] || {}; - modified_categories[cid].disabled = disabled; - - save(); - return false; - }); - // Colour Picker $('[data-name="bgColor"], [data-name="color"]').each(enableColorPicker); diff --git a/src/views/admin/manage/categories.tpl b/src/views/admin/manage/categories.tpl index 0bec4891a7..210e323204 100644 --- a/src/views/admin/manage/categories.tpl +++ b/src/views/admin/manage/categories.tpl @@ -15,7 +15,7 @@