"use strict"; /*global define, socket, app, bootbox, templates, ajaxify, RELATIVE_PATH*/ define('admin/manage/categories', function() { var Categories = {}; Categories.init = function() { socket.emit('admin.categories.getAll', function(error, payload){ if(error){ return app.alertError(error.message); } Categories.render(payload); }); 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{ renderList(categories, 0, container); } }; function renderList(categories, level, parent){ var i = 0, len = categories.length, category, list = $(''), marginLeft = 48, listItem; for(i; i < len; ++i){ category = categories[i]; listItem = $('
  • ') .append(renderListItem(category)) .appendTo(list); if(level > 0){ listItem.css('margin-left', marginLeft); } if(category.disabled){ listItem.addClass('disabled'); } if(category.children.length > 0){ renderList(category.children, level + 1, listItem); } } list.appendTo(parent); } function renderListItem(categoryEntity){ var listItem = $(templates.parse( '
    ' + '
    ' + '
    ' + '
    ' + '' + '
    ' + '
    ' + '
    {name}
    ' + '

    {description}

    ' + '
    ' + '
    ' + '
    ' + '
    ' + '
    ' + '
      ' + '
    • {topic_count}
    • ' + '
    • {post_count}
    • ' + '
    ' + '
    ' + '' + 'Edit' + '
    ' + '
    ' + '
    ' + '
    ', categoryEntity )); var icon = listItem.find('.icon'), button = listItem.find('[data-action="toggle"]'); if(categoryEntity.backgroundImage){ icon.css('background-image', 'url(' + categoryEntity.backgroundImage + ')'); } icon .css('color', categoryEntity.color) .css('background-color', categoryEntity.bgColor); if(categoryEntity.disabled){ button.text('Enable').addClass('btn-success'); }else{ button.text('Disable').addClass('btn-danger'); } // Category enable/disable button.on('click', function(e) { var payload = {}; payload[categoryEntity.cid] = { disabled: !categoryEntity.disabled | 0 }; socket.emit('admin.categories.update', payload, function(err, result) { if (err) { return app.alertError(err.message); } else { ajaxify.refresh(); } }); }); return listItem; } return Categories; });