mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-09 15:35:47 +01:00
closes #228
This commit is contained in:
@@ -50,6 +50,33 @@ jQuery('.blockclass').each(function() {
|
||||
|
||||
//DRY Failure. this needs to go into an ajaxify onready style fn. Currently is copy pasted into every single function so after ACP is off the ground fix asap
|
||||
(function() {
|
||||
function showCreateCategoryModal() {
|
||||
$('#new-category-modal').modal();
|
||||
}
|
||||
|
||||
function createNewCategory() {
|
||||
var category = {
|
||||
name:$('#inputName').val(),
|
||||
description:$('#inputDescription').val(),
|
||||
icon:$('#new-category-modal i').val(),
|
||||
blockclass:$('#inputBlockclass').val()
|
||||
};
|
||||
|
||||
socket.emit('api:admin.categories.create', category, function(err, data) {
|
||||
if(!err) {
|
||||
app.alert({
|
||||
alert_id: 'category_created',
|
||||
title: 'Created',
|
||||
message: 'Category successfully created!',
|
||||
type: 'success',
|
||||
timeout: 2000
|
||||
});
|
||||
|
||||
$('#new-category-modal').modal('hide');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
jQuery('document').ready(function() {
|
||||
var url = window.location.href,
|
||||
parts = url.split('/'),
|
||||
@@ -64,6 +91,8 @@ jQuery('.blockclass').each(function() {
|
||||
});
|
||||
|
||||
jQuery('#save').on('click', save);
|
||||
jQuery('#addNew').on('click', showCreateCategoryModal);
|
||||
jQuery('#create-category-btn').on('click', createNewCategory);
|
||||
|
||||
jQuery('.icon').on('click', function(ev) {
|
||||
select_icon(ev.target);
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -5,27 +5,7 @@ var RDB = require('./../redis.js'),
|
||||
(function(CategoriesAdmin) {
|
||||
|
||||
CategoriesAdmin.create = function(data, callback) {
|
||||
RDB.incr('global:next_category_id', function(err, cid) {
|
||||
RDB.handle(err);
|
||||
|
||||
var slug = cid + '/' + utils.slugify(data.name);
|
||||
RDB.rpush('categories:cid', cid);
|
||||
|
||||
RDB.hmset('category:' + cid, {
|
||||
cid: cid,
|
||||
name: data.name,
|
||||
description: data.description,
|
||||
icon: data.icon,
|
||||
blockclass: data.blockclass,
|
||||
slug: slug,
|
||||
topic_count: 0,
|
||||
disabled: 0
|
||||
});
|
||||
|
||||
RDB.set('categoryslug:' + slug + ':cid', cid);
|
||||
|
||||
if (callback) callback(null);
|
||||
});
|
||||
categories.create(data, callback);
|
||||
};
|
||||
|
||||
CategoriesAdmin.update = function(modified, socket) {
|
||||
|
||||
@@ -8,6 +8,32 @@ var RDB = require('./redis.js'),
|
||||
|
||||
(function(Categories) {
|
||||
|
||||
Categories.create = function(data, callback) {
|
||||
RDB.incr('global:next_category_id', function(err, cid) {
|
||||
if(err)
|
||||
return callback(err, null);
|
||||
|
||||
var slug = cid + '/' + utils.slugify(data.name);
|
||||
RDB.rpush('categories:cid', cid);
|
||||
|
||||
var category = {
|
||||
cid: cid,
|
||||
name: data.name,
|
||||
description: data.description,
|
||||
icon: data.icon,
|
||||
blockclass: data.blockclass,
|
||||
slug: slug,
|
||||
topic_count: 0,
|
||||
disabled: 0
|
||||
};
|
||||
RDB.hmset('category:' + cid, category);
|
||||
|
||||
RDB.set('categoryslug:' + slug + ':cid', cid);
|
||||
|
||||
callback(null, category);
|
||||
});
|
||||
}
|
||||
|
||||
Categories.getCategoryById = function(category_id, current_user, callback) {
|
||||
|
||||
Categories.getCategoryData(category_id, function(err, categoryData) {
|
||||
|
||||
@@ -742,6 +742,12 @@ var SocketIO = require('socket.io').listen(global.server, {
|
||||
});
|
||||
});
|
||||
|
||||
socket.on('api:admin.categories.create', function(data, callback) {
|
||||
admin.categories.create(data, function(err, data) {
|
||||
callback(err, data);
|
||||
});
|
||||
});
|
||||
|
||||
socket.on('api:admin.categories.update', function(data) {
|
||||
admin.categories.update(data, socket);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user