formatting - template js admin side

v1.18.x
psychobunny 12 years ago
parent 221b9bc149
commit c44461e33f

@ -1,4 +1,3 @@
var modified_categories = {}; var modified_categories = {};
function modified(el) { function modified(el) {
@ -16,7 +15,7 @@ function save() {
function select_icon(el) { function select_icon(el) {
var selected = el.attr('class').replace(' icon-2x', ''); var selected = el.attr('class').replace(' icon-2x', '');
jQuery('#icons .selected').removeClass('selected'); jQuery('#icons .selected').removeClass('selected');
if(selected) if (selected)
jQuery('#icons .' + selected).parent().addClass('selected'); jQuery('#icons .' + selected).parent().addClass('selected');
@ -57,14 +56,14 @@ jQuery('.blockclass').each(function() {
function createNewCategory() { function createNewCategory() {
var category = { var category = {
name:$('#inputName').val(), name: $('#inputName').val(),
description:$('#inputDescription').val(), description: $('#inputDescription').val(),
icon:$('#new-category-modal i').attr('value'), icon: $('#new-category-modal i').attr('value'),
blockclass:$('#inputBlockclass').val() blockclass: $('#inputBlockclass').val()
}; };
socket.emit('api:admin.categories.create', category, function(err, data) { socket.emit('api:admin.categories.create', category, function(err, data) {
if(!err) { if (!err) {
app.alert({ app.alert({
alert_id: 'category_created', alert_id: 'category_created',
title: 'Created', title: 'Created',
@ -73,7 +72,9 @@ jQuery('.blockclass').each(function() {
timeout: 2000 timeout: 2000
}); });
var html = templates.prepare(templates['admin/categories'].blocks['categories']).parse({categories:[data]}); var html = templates.prepare(templates['admin/categories'].blocks['categories']).parse({
categories: [data]
});
$('#entry-container').append(html); $('#entry-container').append(html);
$('#new-category-modal').modal('hide'); $('#new-category-modal').modal('hide');
@ -84,7 +85,7 @@ jQuery('.blockclass').each(function() {
jQuery('document').ready(function() { jQuery('document').ready(function() {
var url = window.location.href, var url = window.location.href,
parts = url.split('/'), parts = url.split('/'),
active = parts[parts.length-1]; active = parts[parts.length - 1];
jQuery('.nav-pills li').removeClass('active'); jQuery('.nav-pills li').removeClass('active');
jQuery('.nav-pills li a').each(function() { jQuery('.nav-pills li a').each(function() {
@ -112,7 +113,7 @@ jQuery('.blockclass').each(function() {
jQuery('.entry-row button').each(function(index, element) { jQuery('.entry-row button').each(function(index, element) {
var disabled = $(element).attr('data-disabled'); var disabled = $(element).attr('data-disabled');
if(disabled == "0" || disabled == "") if (disabled == "0" || disabled == "")
$(element).html('Disable'); $(element).html('Disable');
else else
$(element).html('Enable'); $(element).html('Enable');
@ -124,7 +125,7 @@ jQuery('.blockclass').each(function() {
var categoryRow = btn.parents('li'); var categoryRow = btn.parents('li');
var cid = categoryRow.attr('data-cid'); var cid = categoryRow.attr('data-cid');
var disabled = btn.html() == "Disable" ? "1":"0"; var disabled = btn.html() == "Disable" ? "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;

@ -1,6 +1,3 @@
var nodebb_admin = (function(nodebb_admin) { var nodebb_admin = (function(nodebb_admin) {
nodebb_admin.config = undefined; nodebb_admin.config = undefined;
@ -19,21 +16,21 @@ var nodebb_admin = (function(nodebb_admin) {
numFields = fields.length, numFields = fields.length,
saveBtn = document.getElementById('save'), saveBtn = document.getElementById('save'),
x, key, inputType; x, key, inputType;
for(x=0;x<numFields;x++) { for (x = 0; x < numFields; x++) {
key = fields[x].getAttribute('data-field'); key = fields[x].getAttribute('data-field');
inputType = fields[x].getAttribute('type'); inputType = fields[x].getAttribute('type');
if (fields[x].nodeName === 'INPUT') { if (fields[x].nodeName === 'INPUT') {
if (nodebb_admin.config[key]) { if (nodebb_admin.config[key]) {
switch(inputType) { switch (inputType) {
case 'text': case 'text':
case 'textarea': case 'textarea':
case 'number': case 'number':
fields[x].value = nodebb_admin.config[key]; fields[x].value = nodebb_admin.config[key];
break; break;
case 'checkbox': case 'checkbox':
fields[x].checked = nodebb_admin.config[key] === '1' ? true : false; fields[x].checked = nodebb_admin.config[key] === '1' ? true : false;
break; break;
} }
} }
} else if (fields[x].nodeName === 'TEXTAREA') { } else if (fields[x].nodeName === 'TEXTAREA') {
@ -45,25 +42,28 @@ var nodebb_admin = (function(nodebb_admin) {
var key, value; var key, value;
e.preventDefault(); e.preventDefault();
for(x=0;x<numFields;x++) { for (x = 0; x < numFields; x++) {
key = fields[x].getAttribute('data-field'); key = fields[x].getAttribute('data-field');
if (fields[x].nodeName === 'INPUT') { if (fields[x].nodeName === 'INPUT') {
inputType = fields[x].getAttribute('type'); inputType = fields[x].getAttribute('type');
switch(inputType) { switch (inputType) {
case 'text': case 'text':
case 'number': case 'number':
value = fields[x].value; value = fields[x].value;
break; break;
case 'checkbox': case 'checkbox':
value = fields[x].checked ? '1' : '0'; value = fields[x].checked ? '1' : '0';
break; break;
} }
} else if (fields[x].nodeName === 'TEXTAREA') { } else if (fields[x].nodeName === 'TEXTAREA') {
value = fields[x].value; value = fields[x].value;
} }
socket.emit('api:config.set', { key: key, value: value }); socket.emit('api:config.set', {
key: key,
value: value
});
} }
}); });
} }
@ -82,7 +82,7 @@ var nodebb_admin = (function(nodebb_admin) {
menuEl.addEventListener('click', function(e) { menuEl.addEventListener('click', function(e) {
parentEl = e.target.parentNode; parentEl = e.target.parentNode;
if (parentEl.nodeName === 'LI') { if (parentEl.nodeName === 'LI') {
for(var x=0,numLis=liEls.length;x<numLis;x++) { for (var x = 0, numLis = liEls.length; x < numLis; x++) {
if (liEls[x] !== parentEl) jQuery(liEls[x]).removeClass('active'); if (liEls[x] !== parentEl) jQuery(liEls[x]).removeClass('active');
else jQuery(parentEl).addClass('active'); else jQuery(parentEl).addClass('active');
} }
@ -119,4 +119,3 @@ var nodebb_admin = (function(nodebb_admin) {
return nodebb_admin; return nodebb_admin;
}(nodebb_admin || {})); }(nodebb_admin || {}));

@ -1,5 +1,5 @@
$(document).ready(function() { $(document).ready(function() {
var createEl = document.getElementById('create'), var createEl = document.getElementById('create'),
createModal = $('#create-modal'), createModal = $('#create-modal'),
createSubmitBtn = document.getElementById('create-modal-go'), createSubmitBtn = document.getElementById('create-modal-go'),
createNameEl = $('#create-group-name'), createNameEl = $('#create-group-name'),
@ -19,25 +19,25 @@ $(document).ready(function() {
}, false); }, false);
createSubmitBtn.addEventListener('click', function() { createSubmitBtn.addEventListener('click', function() {
var submitObj = { var submitObj = {
name: createNameEl.val(), name: createNameEl.val(),
description: $('#create-group-desc').val() description: $('#create-group-desc').val()
}, },
errorEl = $('#create-modal-error'), errorEl = $('#create-modal-error'),
errorText; errorText;
socket.emit('api:groups.create', submitObj, function(err, data) { socket.emit('api:groups.create', submitObj, function(err, data) {
if (err) { if (err) {
switch(err) { switch (err) {
case 'group-exists': case 'group-exists':
errorText = '<strong>Please choose another name</strong><p>There seems to be a group with this name already.</p>'; errorText = '<strong>Please choose another name</strong><p>There seems to be a group with this name already.</p>';
break; break;
case 'name-too-short': case 'name-too-short':
errorText = '<strong>Please specify a grou name</strong><p>A group name is required for administrative purposes.</p>'; errorText = '<strong>Please specify a grou name</strong><p>A group name is required for administrative purposes.</p>';
break; break;
default: default:
errorText = '<strong>Uh-Oh</strong><p>There was a problem creating your group. Please try again later!</p>'; errorText = '<strong>Uh-Oh</strong><p>There was a problem creating your group. Please try again later!</p>';
break; break;
} }
errorEl.html(errorText).removeClass('hide'); errorEl.html(errorText).removeClass('hide');
@ -51,10 +51,10 @@ $(document).ready(function() {
}); });
listEl.on('click', 'button[data-action]', function() { listEl.on('click', 'button[data-action]', function() {
var action = this.getAttribute('data-action'), var action = this.getAttribute('data-action'),
gid = $(this).parents('li[data-gid]').attr('data-gid'); gid = $(this).parents('li[data-gid]').attr('data-gid');
switch(action) { switch (action) {
case 'delete': case 'delete':
bootbox.confirm('Are you sure you wish to delete this group?', function(confirm) { bootbox.confirm('Are you sure you wish to delete this group?', function(confirm) {
if (confirm) { if (confirm) {
@ -63,10 +63,10 @@ $(document).ready(function() {
}); });
} }
}); });
break; break;
case 'members': case 'members':
socket.emit('api:groups.get', gid, function(err, groupObj) { socket.emit('api:groups.get', gid, function(err, groupObj) {
var formEl = detailsModal.find('form'), var formEl = detailsModal.find('form'),
nameEl = formEl.find('#change-group-name'), nameEl = formEl.find('#change-group-name'),
descEl = formEl.find('#change-group-desc'), descEl = formEl.find('#change-group-desc'),
memberIcon = document.createElement('li'), memberIcon = document.createElement('li'),
@ -83,7 +83,7 @@ $(document).ready(function() {
memberIconImg = memberIcon.querySelector('img'); memberIconImg = memberIcon.querySelector('img');
memberIconLabel = memberIcon.querySelector('span'); memberIconLabel = memberIcon.querySelector('span');
if (numMembers > 0) { if (numMembers > 0) {
for(x=0;x<numMembers;x++) { for (x = 0; x < numMembers; x++) {
memberIconImg.src = groupObj.members[x].picture; memberIconImg.src = groupObj.members[x].picture;
memberIconLabel.innerHTML = groupObj.members[x].username; memberIconLabel.innerHTML = groupObj.members[x].username;
memberIcon.setAttribute('data-uid', groupObj.members[x].uid); memberIcon.setAttribute('data-uid', groupObj.members[x].uid);
@ -96,17 +96,17 @@ $(document).ready(function() {
detailsModal.attr('data-gid', groupObj.gid); detailsModal.attr('data-gid', groupObj.gid);
detailsModal.modal('show'); detailsModal.modal('show');
}); });
break; break;
} }
}); });
detailsSearch.on('keyup', function() { detailsSearch.on('keyup', function() {
var searchEl = this; var searchEl = this;
if (searchDelay) clearTimeout(searchDelay); if (searchDelay) clearTimeout(searchDelay);
searchDelay = setTimeout(function() { searchDelay = setTimeout(function() {
var searchText = searchEl.value, var searchText = searchEl.value,
resultsEl = document.getElementById('group-details-search-results'), resultsEl = document.getElementById('group-details-search-results'),
foundUser = document.createElement('li'), foundUser = document.createElement('li'),
foundUserImg, foundUserLabel; foundUserImg, foundUserLabel;
@ -117,11 +117,11 @@ $(document).ready(function() {
socket.emit('api:admin.user.search', searchText, function(err, results) { socket.emit('api:admin.user.search', searchText, function(err, results) {
if (!err && results && results.length > 0) { if (!err && results && results.length > 0) {
var numResults = results.length, var numResults = results.length,
resultsSlug = document.createDocumentFragment(), resultsSlug = document.createDocumentFragment(),
x; x;
if (numResults > 4) numResults = 4; if (numResults > 4) numResults = 4;
for(x=0;x<numResults;x++) { for (x = 0; x < numResults; x++) {
foundUserImg.src = results[x].picture; foundUserImg.src = results[x].picture;
foundUserLabel.innerHTML = results[x].username; foundUserLabel.innerHTML = results[x].username;
foundUser.setAttribute('title', results[x].username); foundUser.setAttribute('title', results[x].username);
@ -137,7 +137,7 @@ $(document).ready(function() {
}); });
searchResults.on('click', 'li[data-uid]', function() { searchResults.on('click', 'li[data-uid]', function() {
var userLabel = this, var userLabel = this,
uid = parseInt(this.getAttribute('data-uid')), uid = parseInt(this.getAttribute('data-uid')),
gid = detailsModal.attr('data-gid'), gid = detailsModal.attr('data-gid'),
members = []; members = [];
@ -159,7 +159,7 @@ $(document).ready(function() {
}); });
groupMembersEl.on('click', 'li[data-uid]', function() { groupMembersEl.on('click', 'li[data-uid]', function() {
var uid = this.getAttribute('data-uid'), var uid = this.getAttribute('data-uid'),
gid = detailsModal.attr('data-gid'); gid = detailsModal.attr('data-gid');
socket.emit('api:groups.leave', { socket.emit('api:groups.leave', {
@ -173,7 +173,7 @@ $(document).ready(function() {
}); });
detailsModalSave.on('click', function() { detailsModalSave.on('click', function() {
var formEl = detailsModal.find('form'), var formEl = detailsModal.find('form'),
nameEl = formEl.find('#change-group-name'), nameEl = formEl.find('#change-group-name'),
descEl = formEl.find('#change-group-desc'), descEl = formEl.find('#change-group-desc'),
gid = detailsModal.attr('data-gid'); gid = detailsModal.attr('data-gid');

@ -8,7 +8,7 @@
total = 0; total = 0;
active_users.innerHTML = ''; active_users.innerHTML = '';
for(var room in data) { for (var room in data) {
if (room !== '') { if (room !== '') {
var count = data[room].length; var count = data[room].length;
total += count; total += count;

@ -1,35 +1,35 @@
var nodebb_admin = nodebb_admin || {}; var nodebb_admin = nodebb_admin || {};
(function() { (function() {
var plugins = { var plugins = {
init: function() { init: function() {
var pluginsList = $('.plugins'), var pluginsList = $('.plugins'),
numPlugins = pluginsList[0].querySelectorAll('li').length, numPlugins = pluginsList[0].querySelectorAll('li').length,
pluginID, pluginTgl; pluginID, pluginTgl;
if (numPlugins > 0) { if (numPlugins > 0) {
pluginsList.on('click', 'button[data-action="toggleActive"]', function() { pluginsList.on('click', 'button[data-action="toggleActive"]', function() {
pluginID = $(this).parents('li').attr('data-plugin-id'); pluginID = $(this).parents('li').attr('data-plugin-id');
socket.emit('api:admin.plugins.toggle', pluginID); socket.emit('api:admin.plugins.toggle', pluginID);
}); });
socket.on('api:admin.plugins.toggle', function(status) { socket.on('api:admin.plugins.toggle', function(status) {
pluginTgl = document.querySelector('.plugins li[data-plugin-id="' + status.id + '"] button'); pluginTgl = document.querySelector('.plugins li[data-plugin-id="' + status.id + '"] button');
pluginTgl.innerHTML = '<i class="icon-off"></i> ' + (status.active ? 'Dea' : 'A') + 'ctivate'; pluginTgl.innerHTML = '<i class="icon-off"></i> ' + (status.active ? 'Dea' : 'A') + 'ctivate';
app.alert({ app.alert({
alert_id: 'plugin_toggled_' + status.id, alert_id: 'plugin_toggled_' + status.id,
title: 'Plugin Enabled', title: 'Plugin Enabled',
message: 'You may need to restart NodeBB in order for these changes to be reflected.', message: 'You may need to restart NodeBB in order for these changes to be reflected.',
type: 'warning', type: 'warning',
timeout: 5000 timeout: 5000
}) })
}); });
} else { } else {
pluginsList.append('<li><p><i>No plugins found.</i></p></li>'); pluginsList.append('<li><p><i>No plugins found.</i></p></li>');
}
} }
}; }
};
jQuery(document).ready(function() { jQuery(document).ready(function() {
nodebb_admin.plugins = plugins; nodebb_admin.plugins = plugins;

@ -1,5 +1,3 @@
var nodebb_admin = (function(nodebb_admin) { var nodebb_admin = (function(nodebb_admin) {
var themes = {}; var themes = {};
@ -10,20 +8,20 @@ var nodebb_admin = (function(nodebb_admin) {
themeContainer = document.querySelector('#bootstrap_themes'), themeContainer = document.querySelector('#bootstrap_themes'),
numThemes = bootswatch.themes.length; numThemes = bootswatch.themes.length;
for(var x=0;x<numThemes;x++) { for (var x = 0; x < numThemes; x++) {
var theme = bootswatch.themes[x]; var theme = bootswatch.themes[x];
themeEl.setAttribute('data-css', theme.cssMin); themeEl.setAttribute('data-css', theme.cssMin);
themeEl.setAttribute('data-theme', theme.name); themeEl.setAttribute('data-theme', theme.name);
themeEl.innerHTML = '<img src="' + theme.thumbnail + '" />' + themeEl.innerHTML = '<img src="' + theme.thumbnail + '" />' +
'<div>' + '<div>' +
'<div class="pull-right">' + '<div class="pull-right">' +
'<button class="btn btn-primary" data-action="use">Use</button> ' + '<button class="btn btn-primary" data-action="use">Use</button> ' +
'<button class="btn btn-default" data-action="preview">Preview</button>' + '<button class="btn btn-default" data-action="preview">Preview</button>' +
'</div>' + '</div>' +
'<h4>' + theme.name + '</h4>' + '<h4>' + theme.name + '</h4>' +
'<p>' + theme.description + '</p>' + '<p>' + theme.description + '</p>' +
'</div>' + '</div>' +
'<div class="clear">'; '<div class="clear">';
themeFrag.appendChild(themeEl.cloneNode(true)); themeFrag.appendChild(themeEl.cloneNode(true));
} }
themeContainer.innerHTML = ''; themeContainer.innerHTML = '';
@ -42,28 +40,30 @@ var nodebb_admin = (function(nodebb_admin) {
scriptEl.src = 'http://api.bootswatch.com/3/?callback=nodebb_admin.themes.render'; scriptEl.src = 'http://api.bootswatch.com/3/?callback=nodebb_admin.themes.render';
document.body.appendChild(scriptEl); document.body.appendChild(scriptEl);
var bootstrapThemeContainer = document.querySelector('#bootstrap_themes'), var bootstrapThemeContainer = document.querySelector('#bootstrap_themes'),
installedThemeContainer = document.querySelector('#installed_themes'), installedThemeContainer = document.querySelector('#installed_themes'),
themeEvent = function(e) { themeEvent = function(e) {
if (e.target.hasAttribute('data-action')) { if (e.target.hasAttribute('data-action')) {
switch(e.target.getAttribute('data-action')) { switch (e.target.getAttribute('data-action')) {
case 'preview': case 'preview':
var cssSrc = $(e.target).parents('li').attr('data-css'), var cssSrc = $(e.target).parents('li').attr('data-css'),
cssEl = document.getElementById('base-theme'); cssEl = document.getElementById('base-theme');
cssEl.href = cssSrc; cssEl.href = cssSrc;
break; break;
case 'use': case 'use':
var parentEl = $(e.target).parents('li'), var parentEl = $(e.target).parents('li'),
cssSrc = parentEl.attr('data-css'), cssSrc = parentEl.attr('data-css'),
cssName = parentEl.attr('data-theme'); cssName = parentEl.attr('data-theme');
socket.emit('api:config.set', { socket.emit('api:config.set', {
key: 'theme:id', value: 'bootswatch:' + cssName key: 'theme:id',
value: 'bootswatch:' + cssName
}); });
socket.emit('api:config.set', { socket.emit('api:config.set', {
key: 'theme:src', value: cssSrc key: 'theme:src',
value: cssSrc
}); });
break; break;
} }
} }
}; };
@ -82,27 +82,27 @@ var nodebb_admin = (function(nodebb_admin) {
// Installed Themes // Installed Themes
socket.emit('api:admin.themes.getInstalled', function(themes) { socket.emit('api:admin.themes.getInstalled', function(themes) {
var instListEl = document.getElementById('installed_themes'), var instListEl = document.getElementById('installed_themes'),
themeFrag = document.createDocumentFragment(), themeFrag = document.createDocumentFragment(),
liEl = document.createElement('li'); liEl = document.createElement('li');
if (themes.length > 0) { if (themes.length > 0) {
for(var x=0,numThemes=themes.length;x<numThemes;x++) { for (var x = 0, numThemes = themes.length; x < numThemes; x++) {
liEl.setAttribute('data-theme', themes[x].id); liEl.setAttribute('data-theme', themes[x].id);
liEl.setAttribute('data-css', themes[x].src); liEl.setAttribute('data-css', themes[x].src);
liEl.innerHTML = '<img src="' + themes[x].screenshot + '" />' + liEl.innerHTML = '<img src="' + themes[x].screenshot + '" />' +
'<div>' + '<div>' +
'<div class="pull-right">' + '<div class="pull-right">' +
'<button class="btn btn-primary" data-action="use">Use</button> ' + '<button class="btn btn-primary" data-action="use">Use</button> ' +
'<button class="btn btn-default" data-action="preview">Preview</button>' + '<button class="btn btn-default" data-action="preview">Preview</button>' +
'</div>' + '</div>' +
'<h4>' + themes[x].name + '</h4>' + '<h4>' + themes[x].name + '</h4>' +
'<p>' + '<p>' +
themes[x].description + themes[x].description +
(themes[x].url ? ' (<a href="' + themes[x].url + '">Homepage</a>)' : '') + (themes[x].url ? ' (<a href="' + themes[x].url + '">Homepage</a>)' : '') +
'</p>' + '</p>' +
'</div>' + '</div>' +
'<div class="clear">'; '<div class="clear">';
themeFrag.appendChild(liEl.cloneNode(true)); themeFrag.appendChild(liEl.cloneNode(true));
} }
} else { } else {

@ -7,25 +7,37 @@ $(document).ready(function() {
action = this.getAttribute('data-action'), action = this.getAttribute('data-action'),
tid = $this.parents('[data-tid]').attr('data-tid'); tid = $this.parents('[data-tid]').attr('data-tid');
switch(action) { switch (action) {
case 'pin': case 'pin':
if (!$this.hasClass('active')) socket.emit('api:topic.pin', { tid: tid }); if (!$this.hasClass('active')) socket.emit('api:topic.pin', {
else socket.emit('api:topic.unpin', { tid: tid }); tid: tid
break; });
else socket.emit('api:topic.unpin', {
tid: tid
});
break;
case 'lock': case 'lock':
if (!$this.hasClass('active')) socket.emit('api:topic.lock', { tid: tid }); if (!$this.hasClass('active')) socket.emit('api:topic.lock', {
else socket.emit('api:topic.unlock', { tid: tid }); tid: tid
break; });
else socket.emit('api:topic.unlock', {
tid: tid
});
break;
case 'delete': case 'delete':
if (!$this.hasClass('active')) socket.emit('api:topic.delete', { tid: tid }); if (!$this.hasClass('active')) socket.emit('api:topic.delete', {
else socket.emit('api:topic.restore', { tid: tid }); tid: tid
break; });
else socket.emit('api:topic.restore', {
tid: tid
});
break;
} }
}); });
loadMoreEl.addEventListener('click', function() { loadMoreEl.addEventListener('click', function() {
if (this.className.indexOf('disabled') === -1) { if (this.className.indexOf('disabled') === -1) {
var topics = document.querySelectorAll('.topics li[data-tid]'), var topics = document.querySelectorAll('.topics li[data-tid]'),
lastTid = parseInt(topics[topics.length - 1].getAttribute('data-tid')); lastTid = parseInt(topics[topics.length - 1].getAttribute('data-tid'));
this.innerHTML = '<i class="icon-refresh icon-spin"></i> Retrieving topics'; this.innerHTML = '<i class="icon-refresh icon-spin"></i> Retrieving topics';
@ -37,9 +49,9 @@ $(document).ready(function() {
topics = JSON.parse(topics); topics = JSON.parse(topics);
if (topics.length > 0) { if (topics.length > 0) {
var html = templates.prepare(templates['admin/topics'].blocks['topics']).parse({ var html = templates.prepare(templates['admin/topics'].blocks['topics']).parse({
topics: topics topics: topics
}), }),
topicsListEl = document.querySelector('.topics'); topicsListEl = document.querySelector('.topics');
topicsListEl.innerHTML += html; topicsListEl.innerHTML += html;
@ -54,9 +66,9 @@ $(document).ready(function() {
}, false); }, false);
// Resolve proper button state for all topics // Resolve proper button state for all topics
var topicEls = topicsListEl.querySelectorAll('li'), var topicEls = topicsListEl.querySelectorAll('li'),
numTopics = topicEls.length; numTopics = topicEls.length;
for(var x=0;x<numTopics;x++) { for (var x = 0; x < numTopics; x++) {
if (topicEls[x].getAttribute('data-pinned') === '1') topicEls[x].querySelector('[data-action="pin"]').className += ' active'; if (topicEls[x].getAttribute('data-pinned') === '1') topicEls[x].querySelector('[data-action="pin"]').className += ' active';
if (topicEls[x].getAttribute('data-locked') === '1') topicEls[x].querySelector('[data-action="lock"]').className += ' active'; if (topicEls[x].getAttribute('data-locked') === '1') topicEls[x].querySelector('[data-action="lock"]').className += ' active';
if (topicEls[x].getAttribute('data-deleted') === '1') topicEls[x].querySelector('[data-action="delete"]').className += ' active'; if (topicEls[x].getAttribute('data-deleted') === '1') topicEls[x].querySelector('[data-action="delete"]').className += ' active';

@ -1,4 +1,3 @@
(function() { (function() {
var yourid = templates.get('yourid'); var yourid = templates.get('yourid');
@ -24,19 +23,19 @@
var adminBtn = $(element); var adminBtn = $(element);
var uid = getUID(adminBtn); var uid = getUID(adminBtn);
if(isUserAdmin(adminBtn)) if (isUserAdmin(adminBtn))
adminBtn.addClass('btn-success'); adminBtn.addClass('btn-success');
else else
adminBtn.removeClass('btn-success'); adminBtn.removeClass('btn-success');
if(uid === yourid) if (uid === yourid)
adminBtn.addClass('disabled'); adminBtn.addClass('disabled');
}); });
jQuery('.delete-btn').each(function(index, element) { jQuery('.delete-btn').each(function(index, element) {
var deleteBtn = $(element); var deleteBtn = $(element);
if(isUserAdmin(deleteBtn)) if (isUserAdmin(deleteBtn))
deleteBtn.addClass('disabled'); deleteBtn.addClass('disabled');
else else
deleteBtn.show(); deleteBtn.show();
@ -45,9 +44,9 @@
jQuery('.ban-btn').each(function(index, element) { jQuery('.ban-btn').each(function(index, element) {
var banBtn = $(element); var banBtn = $(element);
if(isUserAdmin(banBtn)) if (isUserAdmin(banBtn))
banBtn.addClass('disabled'); banBtn.addClass('disabled');
else if(isUserBanned(banBtn)) else if (isUserBanned(banBtn))
banBtn.addClass('btn-warning'); banBtn.addClass('btn-warning');
else else
banBtn.removeClass('btn-warning'); banBtn.removeClass('btn-warning');
@ -65,14 +64,14 @@
var parent = adminBtn.parents('.users-box'); var parent = adminBtn.parents('.users-box');
var uid = getUID(adminBtn); var uid = getUID(adminBtn);
if(isAdmin && uid != yourid) { if (isAdmin && uid != yourid) {
socket.emit('api:admin.user.removeAdmin', uid); socket.emit('api:admin.user.removeAdmin', uid);
adminBtn.removeClass('btn-success'); adminBtn.removeClass('btn-success');
parent.find('.delete-btn').removeClass('disabled'); parent.find('.delete-btn').removeClass('disabled');
parent.attr('data-admin', 0); parent.attr('data-admin', 0);
} else if(uid != yourid) { } else if (uid != yourid) {
bootbox.confirm('Do you really want to make "' + parent.attr('data-username') +'" an admin?', function(confirm) { bootbox.confirm('Do you really want to make "' + parent.attr('data-username') + '" an admin?', function(confirm) {
if(confirm) { if (confirm) {
socket.emit('api:admin.user.makeAdmin', uid); socket.emit('api:admin.user.makeAdmin', uid);
adminBtn.addClass('btn-success'); adminBtn.addClass('btn-success');
parent.find('.delete-btn').addClass('disabled'); parent.find('.delete-btn').addClass('disabled');
@ -90,8 +89,8 @@
var parent = deleteBtn.parents('.users-box'); var parent = deleteBtn.parents('.users-box');
var uid = getUID(deleteBtn); var uid = getUID(deleteBtn);
if(!isAdmin) { if (!isAdmin) {
bootbox.confirm('Do you really want to delete "' + parent.attr('data-username') +'"?', function(confirm) { bootbox.confirm('Do you really want to delete "' + parent.attr('data-username') + '"?', function(confirm) {
if (confirm) { if (confirm) {
socket.emit('api:admin.user.deleteUser', uid); socket.emit('api:admin.user.deleteUser', uid);
} }
@ -108,13 +107,13 @@
var parent = banBtn.parents('.users-box'); var parent = banBtn.parents('.users-box');
var uid = getUID(banBtn); var uid = getUID(banBtn);
if(!isAdmin) { if (!isAdmin) {
if(isBanned) { if (isBanned) {
socket.emit('api:admin.user.unbanUser', uid); socket.emit('api:admin.user.unbanUser', uid);
banBtn.removeClass('btn-warning'); banBtn.removeClass('btn-warning');
parent.attr('data-banned', 0); parent.attr('data-banned', 0);
} else { } else {
bootbox.confirm('Do you really want to ban "' + parent.attr('data-username') +'"?', function(confirm) { bootbox.confirm('Do you really want to ban "' + parent.attr('data-username') + '"?', function(confirm) {
if (confirm) { if (confirm) {
socket.emit('api:admin.user.banUser', uid); socket.emit('api:admin.user.banUser', uid);
banBtn.addClass('btn-warning'); banBtn.addClass('btn-warning');
@ -136,7 +135,7 @@
var url = window.location.href, var url = window.location.href,
parts = url.split('/'), parts = url.split('/'),
active = parts[parts.length-1]; active = parts[parts.length - 1];
jQuery('.nav-pills li').removeClass('active'); jQuery('.nav-pills li').removeClass('active');
jQuery('.nav-pills li a').each(function() { jQuery('.nav-pills li a').each(function() {
@ -146,8 +145,8 @@
} }
}); });
jQuery('#search-user').on('keyup', function () { jQuery('#search-user').on('keyup', function() {
if(timeoutId !== 0) { if (timeoutId !== 0) {
clearTimeout(timeoutId); clearTimeout(timeoutId);
timeoutId = 0; timeoutId = 0;
} }
@ -167,21 +166,20 @@
socket.on('api:admin.user.search', function(data) { socket.on('api:admin.user.search', function(data) {
var html = templates.prepare(templates['admin/users'].blocks['users']).parse({ var html = templates.prepare(templates['admin/users'].blocks['users']).parse({
users: data users: data
}), }),
userListEl = document.querySelector('.users'); userListEl = document.querySelector('.users');
userListEl.innerHTML = html; userListEl.innerHTML = html;
jQuery('.icon-spinner').addClass('none'); jQuery('.icon-spinner').addClass('none');
if(data && data.length === 0) { if (data && data.length === 0) {
$('#user-notfound-notify').html('User not found!') $('#user-notfound-notify').html('User not found!')
.show() .show()
.addClass('label-danger') .addClass('label-danger')
.removeClass('label-success'); .removeClass('label-success');
} } else {
else { $('#user-notfound-notify').html(data.length + ' user' + (data.length > 1 ? 's' : '') + ' found!')
$('#user-notfound-notify').html(data.length + ' user'+(data.length>1?'s':'') + ' found!')
.show() .show()
.addClass('label-success') .addClass('label-success')
.removeClass('label-danger'); .removeClass('label-danger');
@ -191,28 +189,30 @@
}); });
function onUsersLoaded(users) { function onUsersLoaded(users) {
var html = templates.prepare(templates['admin/users'].blocks['users']).parse({ users: users }); var html = templates.prepare(templates['admin/users'].blocks['users']).parse({
users: users
});
$('#users-container').append(html); $('#users-container').append(html);
updateUserButtons(); updateUserButtons();
} }
function loadMoreUsers() { function loadMoreUsers() {
var set = ''; var set = '';
if(active === 'latest') { if (active === 'latest') {
set = 'users:joindate'; set = 'users:joindate';
} else if(active === 'sort-posts') { } else if (active === 'sort-posts') {
set = 'users:postcount'; set = 'users:postcount';
} else if(active === 'sort-reputation') { } else if (active === 'sort-reputation') {
set = 'users:reputation'; set = 'users:reputation';
} }
if(set) { if (set) {
loadingMoreUsers = true; loadingMoreUsers = true;
socket.emit('api:users.loadMore', { socket.emit('api:users.loadMore', {
set: set, set: set,
after: $('#users-container').children().length after: $('#users-container').children().length
}, function(data) { }, function(data) {
if(data.users.length) { if (data.users.length) {
onUsersLoaded(data.users); onUsersLoaded(data.users);
} }
loadingMoreUsers = false; loadingMoreUsers = false;

Loading…
Cancel
Save