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