mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-07 22:45:46 +01:00
closed #2820
This commit is contained in:
@@ -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({
|
||||||
|
title: 'Create a Category',
|
||||||
|
message: html,
|
||||||
|
buttons: {
|
||||||
|
save: {
|
||||||
|
label: 'Save',
|
||||||
|
className: 'btn-primary',
|
||||||
|
callback: function() {
|
||||||
|
var formData = modal.find('form').serializeObject();
|
||||||
|
formData.description = '';
|
||||||
|
formData.icon = 'fa-comments';
|
||||||
|
|
||||||
|
Categories.create(formData);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
Categories.create = function(payload) {
|
||||||
|
socket.emit('admin.categories.create', payload, function(err, data) {
|
||||||
|
if(err) {
|
||||||
|
return app.alertError(err.message);
|
||||||
}
|
}
|
||||||
|
|
||||||
socket.emit('admin.categories.create', {
|
app.alert({
|
||||||
name: name,
|
alert_id: 'category_created',
|
||||||
description: '',
|
title: 'Created',
|
||||||
icon: 'fa-comments'
|
message: 'Category successfully created!',
|
||||||
}, function(err, data) {
|
type: 'success',
|
||||||
if(err) {
|
timeout: 2000
|
||||||
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);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
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);
|
||||||
};
|
};
|
||||||
|
|||||||
14
src/views/admin/partials/categories/create.tpl
Normal file
14
src/views/admin/partials/categories/create.tpl
Normal file
@@ -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>
|
||||||
Reference in New Issue
Block a user