v1.18.x
Julian Lam 10 years ago
parent 9e63aaebb8
commit 5340537631

@ -1,7 +1,7 @@
"use strict"; "use strict";
/*global define, socket, app, bootbox, templates, ajaxify, RELATIVE_PATH, Sortable */ /*global define, socket, app, bootbox, templates, ajaxify, RELATIVE_PATH, Sortable */
define('admin/manage/categories', function() { define('admin/manage/categories', ['vendor/jquery/serializeObject/jquery.ba-serializeobject.min'], function() {
var Categories = {}, newCategoryId = -1, sortables; var Categories = {}, newCategoryId = -1, sortables;
Categories.init = function() { Categories.init = function() {
@ -13,7 +13,7 @@ define('admin/manage/categories', function() {
Categories.render(payload); Categories.render(payload);
}); });
$('button[data-action="create"]').on('click', Categories.create); $('button[data-action="create"]').on('click', Categories.throwCreateModal);
// Enable/Disable toggle events // Enable/Disable toggle events
$('.categories').on('click', 'button[data-action="toggle"]', function() { $('.categories').on('click', 'button[data-action="toggle"]', function() {
@ -26,31 +26,47 @@ define('admin/manage/categories', function() {
}); });
}; };
Categories.create = function() { Categories.throwCreateModal = function() {
bootbox.prompt('Category Name', function(name) { socket.emit('admin.categories.getNames', {}, function(err, categories) {
if (!name) { templates.parse('admin/partials/categories/create', {
return; categories: categories
} }, function(html) {
var modal = bootbox.dialog({
socket.emit('admin.categories.create', { title: 'Create a Category',
name: name, message: html,
description: '', buttons: {
icon: 'fa-comments' save: {
}, function(err, data) { label: 'Save',
if(err) { className: 'btn-primary',
return app.alertError(err.message); callback: function() {
} var formData = modal.find('form').serializeObject();
formData.description = '';
app.alert({ formData.icon = 'fa-comments';
alert_id: 'category_created',
title: 'Created', Categories.create(formData);
message: 'Category successfully created!', }
type: 'success', }
timeout: 2000 }
}); });
});
});
};
ajaxify.go('admin/manage/categories/' + data.cid); Categories.create = function(payload) {
socket.emit('admin.categories.create', payload, function(err, data) {
if(err) {
return app.alertError(err.message);
}
app.alert({
alert_id: 'category_created',
title: 'Created',
message: 'Category successfully created!',
type: 'success',
timeout: 2000
}); });
ajaxify.go('admin/manage/categories/' + data.cid);
}); });
}; };

@ -198,6 +198,15 @@ var async = require('async'),
}); });
}; };
Categories.getAllCategoryFields = function(fields, callback) {
async.waterfall([
async.apply(db.getSortedSetRange, 'categories:cid', 0, -1),
function(cids, next) {
Categories.getMultipleCategoryFields(cids, fields, next);
}
], callback);
};
Categories.getCategoryFields = function(cid, fields, callback) { Categories.getCategoryFields = function(cid, fields, callback) {
db.getObjectFields('category:' + cid, fields, callback); db.getObjectFields('category:' + cid, fields, callback);
}; };

@ -38,6 +38,10 @@ Categories.getAll = function(socket, data, callback) {
}); });
}; };
Categories.getNames = function(socket, data, callback) {
categories.getAllCategoryFields(['cid', 'name'], callback);
};
Categories.purge = function(socket, cid, callback) { Categories.purge = function(socket, cid, callback) {
categories.purge(cid, callback); categories.purge(cid, callback);
}; };

@ -0,0 +1,14 @@
<form type="form">
<div class="form-group">
<label for="name">Category Name</label>
<input type="text" class="form-control" name="name" id="name" />
</div>
<div class="form-group">
<label for="parentCid">(Optional) Parent Category</label>
<select class="form-control" name="parentCid" id="parentCid">
<!-- BEGIN categories -->
<option value="{categories.cid}">{categories.name}</option>
<!-- END categories -->
</select>
</div>
</form>
Loading…
Cancel
Save