mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-02 12:05:57 +01:00
closes #1038
This commit is contained in:
@@ -83,7 +83,7 @@ define(['uploader'], function(uploader) {
|
||||
var category = {
|
||||
name: $('#inputName').val(),
|
||||
description: $('#inputDescription').val(),
|
||||
icon: $('#new-category-modal i').val(),
|
||||
icon: $('#new-category-modal i').attr('value'),
|
||||
bgColor: '#0059b2',
|
||||
color: '#fff',
|
||||
order: $('.admin-categories #entry-container').children().length + 1
|
||||
@@ -105,10 +105,26 @@ define(['uploader'], function(uploader) {
|
||||
var html = templates.prepare(templates['admin/categories'].blocks['categories']).parse({
|
||||
categories: [data]
|
||||
});
|
||||
html = $(html);
|
||||
html.find('[data-name="bgColor"], [data-name="color"]').each(enableColorPicker);
|
||||
|
||||
$('#entry-container').append(html);
|
||||
$('#new-category-modal').modal('hide');
|
||||
});
|
||||
}
|
||||
|
||||
function enableColorPicker(idx, inputEl) {
|
||||
var jinputEl = $(inputEl),
|
||||
previewEl = jinputEl.parents('[data-cid]').find('.preview-box');
|
||||
|
||||
jinputEl.ColorPicker({
|
||||
color: jinputEl.val() || '#000',
|
||||
onChange: function(hsb, hex) {
|
||||
jinputEl.val('#' + hex);
|
||||
if (inputEl.getAttribute('data-name') === 'bgColor') previewEl.css('background', '#' + hex);
|
||||
else if (inputEl.getAttribute('data-name') === 'color') previewEl.css('color', '#' + hex);
|
||||
modified(inputEl);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -141,21 +157,12 @@ define(['uploader'], function(uploader) {
|
||||
modified(ev.target);
|
||||
});
|
||||
|
||||
$('.dropdown li[data-disabled]').each(function(index, element) {
|
||||
var disabled = $(element).attr('data-disabled');
|
||||
if (disabled == "0" || disabled == "") {
|
||||
$(element).html('<a href="#"><i class="fa fa-power-off"></i> Disable</a>');
|
||||
} else {
|
||||
$(element).html('<a href="#"><i class="fa fa-power-off"></i> Enable</a>');
|
||||
}
|
||||
});
|
||||
|
||||
$('.dropdown').on('click', '[data-disabled]', function(ev) {
|
||||
var btn = $(this);
|
||||
var categoryRow = btn.parents('li');
|
||||
var cid = categoryRow.attr('data-cid');
|
||||
|
||||
var disabled = this.getAttribute('data-disabled') === '0' ? '1' : '0';
|
||||
var disabled = this.getAttribute('data-disabled') === 'false' ? '1' : '0';
|
||||
categoryRow.remove();
|
||||
modified_categories[cid] = modified_categories[cid] || {};
|
||||
modified_categories[cid]['disabled'] = disabled;
|
||||
@@ -165,20 +172,7 @@ define(['uploader'], function(uploader) {
|
||||
});
|
||||
|
||||
// Colour Picker
|
||||
$('[data-name="bgColor"], [data-name="color"]').each(function(idx, inputEl) {
|
||||
var jinputEl = $(this),
|
||||
previewEl = jinputEl.parents('[data-cid]').find('.preview-box');
|
||||
|
||||
jinputEl.ColorPicker({
|
||||
color: this.value || '#000',
|
||||
onChange: function(hsb, hex) {
|
||||
jinputEl.val('#' + hex);
|
||||
if (inputEl.getAttribute('data-name') === 'bgColor') previewEl.css('background', '#' + hex);
|
||||
else if (inputEl.getAttribute('data-name') === 'color') previewEl.css('color', '#' + hex);
|
||||
modified(inputEl);
|
||||
}
|
||||
});
|
||||
});
|
||||
$('[data-name="bgColor"], [data-name="color"]').each(enableColorPicker);
|
||||
|
||||
$('.admin-categories').on('click', '.save', save);
|
||||
|
||||
|
||||
@@ -100,7 +100,13 @@
|
||||
<ul class="dropdown-menu" role="menu">
|
||||
<li class="permissions"><a href="#"><i class="fa fa-ban"></i> Access Control</a></li>
|
||||
<hr />
|
||||
<li data-disabled="{categories.disabled}"><a href="#"></a></li>
|
||||
<li data-disabled="{categories.disabled}">
|
||||
<!-- IF categories.disabled -->
|
||||
<a href="#"><i class="fa fa-power-off"></i> Enable</a>
|
||||
<!-- ELSE -->
|
||||
<a href="#"><i class="fa fa-power-off"></i> Disable</a>
|
||||
<!-- ENDIF categories.disabled -->
|
||||
</li>
|
||||
</ul>
|
||||
<button type="button" data-name="image" data-value="{categories.image}" class="btn btn-default upload-button"><i class="fa fa-upload"></i> Image</button>
|
||||
|
||||
|
||||
@@ -30,6 +30,7 @@ var db = require('./database'),
|
||||
description: data.description,
|
||||
icon: data.icon,
|
||||
bgColor: data.bgColor,
|
||||
background: data.bgColor,
|
||||
color: data.color,
|
||||
slug: slug,
|
||||
topic_count: 0,
|
||||
@@ -96,7 +97,7 @@ var db = require('./database'),
|
||||
'category_name': results.category.name,
|
||||
'category_description': results.category.description,
|
||||
'link': results.category.link,
|
||||
'disabled': results.category.disabled || '0',
|
||||
'disabled': results.category.disabled,
|
||||
'topic_row_size': 'col-md-9',
|
||||
'category_id': category_id,
|
||||
'active_users': results.active_users,
|
||||
@@ -167,6 +168,7 @@ var db = require('./database'),
|
||||
if(err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
if(cids && cids.length === 0) {
|
||||
return callback(null, {categories : []});
|
||||
}
|
||||
@@ -301,6 +303,7 @@ var db = require('./database'),
|
||||
if (exists) {
|
||||
db.getObject('category:' + cid, function(err, data) {
|
||||
data.background = data.image ? 'url(' + data.image + ')' : data.bgColor;
|
||||
data.disabled = data.disabled ? parseInt(data.disabled, 10) !== 0 : false;
|
||||
callback(err, data);
|
||||
});
|
||||
} else {
|
||||
|
||||
@@ -316,7 +316,7 @@ var nconf = require('nconf'),
|
||||
app.get('/categories/active', function (req, res) {
|
||||
categories.getAllCategories(0, function (err, data) {
|
||||
data.categories = data.categories.filter(function (category) {
|
||||
return (!category.disabled || parseInt(category.disabled, 10) === 0);
|
||||
return !category.disabled;
|
||||
});
|
||||
res.json(data);
|
||||
});
|
||||
@@ -325,7 +325,7 @@ var nconf = require('nconf'),
|
||||
app.get('/categories/disabled', function (req, res) {
|
||||
categories.getAllCategories(0, function (err, data) {
|
||||
data.categories = data.categories.filter(function (category) {
|
||||
return parseInt(category.disabled, 10) === 1;
|
||||
return category.disabled;
|
||||
});
|
||||
res.json(data);
|
||||
});
|
||||
|
||||
@@ -87,7 +87,7 @@ var path = require('path'),
|
||||
categories.getAllCategories(uid, function (err, data) {
|
||||
|
||||
data.categories = data.categories.filter(function (category) {
|
||||
return (!category.disabled || parseInt(category.disabled, 10) === 0);
|
||||
return !category.disabled;
|
||||
});
|
||||
|
||||
function canSee(category, next) {
|
||||
@@ -279,7 +279,7 @@ var path = require('path'),
|
||||
data.currentPage = page;
|
||||
data.privileges = privileges;
|
||||
|
||||
if (data && parseInt(data.disabled, 10) === 0) {
|
||||
if (data && !data.disabled) {
|
||||
res.json(data);
|
||||
} else {
|
||||
next();
|
||||
|
||||
@@ -504,7 +504,7 @@ module.exports.server = server;
|
||||
|
||||
categories.getAllCategories(0, function (err, returnData) {
|
||||
returnData.categories = returnData.categories.filter(function (category) {
|
||||
return parseInt(category.disabled, 10) !== 1;
|
||||
return !category.disabled;
|
||||
});
|
||||
|
||||
async.filter(returnData.categories, canSee, function(visibleCategories) {
|
||||
|
||||
Reference in New Issue
Block a user