2014-10-08 15:36:47 -04:00
|
|
|
"use strict";
|
|
|
|
|
/*global define, socket, app, bootbox, templates, ajaxify, RELATIVE_PATH*/
|
|
|
|
|
|
2015-01-01 15:35:22 -05:00
|
|
|
define('admin/manage/categories', function() {
|
2014-10-08 15:36:47 -04:00
|
|
|
var Categories = {};
|
|
|
|
|
|
|
|
|
|
Categories.init = function() {
|
2014-12-30 12:25:39 -05:00
|
|
|
var bothEl = $('#active-categories, #disabled-categories');
|
|
|
|
|
|
2014-12-29 21:20:43 -05:00
|
|
|
function updateCategoryOrders(evt, ui) {
|
|
|
|
|
var categories = $(evt.target).children(),
|
|
|
|
|
modified = {},
|
|
|
|
|
cid;
|
2014-10-08 15:36:47 -04:00
|
|
|
|
2014-12-29 21:20:43 -05:00
|
|
|
for(var i=0;i<categories.length;i++) {
|
|
|
|
|
cid = $(categories[i]).attr('data-cid');
|
|
|
|
|
modified[cid] = {
|
|
|
|
|
order: i+1
|
|
|
|
|
};
|
2014-10-08 15:36:47 -04:00
|
|
|
}
|
2014-12-29 21:20:43 -05:00
|
|
|
|
|
|
|
|
socket.emit('admin.categories.update', modified);
|
2014-10-08 15:36:47 -04:00
|
|
|
}
|
|
|
|
|
|
2014-12-30 12:25:39 -05:00
|
|
|
bothEl.sortable({
|
2014-12-29 21:20:43 -05:00
|
|
|
stop: updateCategoryOrders,
|
2014-12-30 12:25:39 -05:00
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
});
|
2014-10-08 15:36:47 -04:00
|
|
|
});
|
|
|
|
|
|
2015-03-25 18:08:11 -04:00
|
|
|
$('button[data-action="create"]').on('click', Categories.create);
|
|
|
|
|
};
|
2014-10-08 15:36:47 -04:00
|
|
|
|
2015-03-25 18:08:11 -04:00
|
|
|
Categories.create = function() {
|
|
|
|
|
bootbox.prompt('Category Name', function(name) {
|
|
|
|
|
if (!name) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2015-02-25 18:29:15 -05:00
|
|
|
|
2015-03-25 18:08:11 -04:00
|
|
|
socket.emit('admin.categories.create', {
|
|
|
|
|
name: name,
|
|
|
|
|
description: '',
|
|
|
|
|
icon: 'fa-comments'
|
|
|
|
|
}, function(err, data) {
|
2014-10-08 15:36:47 -04:00
|
|
|
if(err) {
|
|
|
|
|
return app.alertError(err.message);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
app.alert({
|
|
|
|
|
alert_id: 'category_created',
|
|
|
|
|
title: 'Created',
|
|
|
|
|
message: 'Category successfully created!',
|
|
|
|
|
type: 'success',
|
|
|
|
|
timeout: 2000
|
|
|
|
|
});
|
|
|
|
|
|
2015-03-25 18:08:11 -04:00
|
|
|
ajaxify.go('admin/manage/categories/' + data.cid);
|
2014-10-08 15:36:47 -04:00
|
|
|
});
|
2015-03-25 18:08:11 -04:00
|
|
|
});
|
2014-10-08 15:36:47 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return Categories;
|
|
|
|
|
});
|