formatting - template js admin side

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

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

@ -1,6 +1,3 @@
var nodebb_admin = (function(nodebb_admin) {
nodebb_admin.config = undefined;
@ -19,12 +16,12 @@ var nodebb_admin = (function(nodebb_admin) {
numFields = fields.length,
saveBtn = document.getElementById('save'),
x, key, inputType;
for(x=0;x<numFields;x++) {
for (x = 0; x < numFields; x++) {
key = fields[x].getAttribute('data-field');
inputType = fields[x].getAttribute('type');
if (fields[x].nodeName === 'INPUT') {
if (nodebb_admin.config[key]) {
switch(inputType) {
switch (inputType) {
case 'text':
case 'textarea':
case 'number':
@ -45,11 +42,11 @@ var nodebb_admin = (function(nodebb_admin) {
var key, value;
e.preventDefault();
for(x=0;x<numFields;x++) {
for (x = 0; x < numFields; x++) {
key = fields[x].getAttribute('data-field');
if (fields[x].nodeName === 'INPUT') {
inputType = fields[x].getAttribute('type');
switch(inputType) {
switch (inputType) {
case 'text':
case 'number':
value = fields[x].value;
@ -63,7 +60,10 @@ var nodebb_admin = (function(nodebb_admin) {
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) {
parentEl = e.target.parentNode;
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');
else jQuery(parentEl).addClass('active');
}
@ -119,4 +119,3 @@ var nodebb_admin = (function(nodebb_admin) {
return nodebb_admin;
}(nodebb_admin || {}));

@ -28,7 +28,7 @@ $(document).ready(function() {
socket.emit('api:groups.create', submitObj, function(err, data) {
if (err) {
switch(err) {
switch (err) {
case 'group-exists':
errorText = '<strong>Please choose another name</strong><p>There seems to be a group with this name already.</p>';
break;
@ -54,7 +54,7 @@ $(document).ready(function() {
var action = this.getAttribute('data-action'),
gid = $(this).parents('li[data-gid]').attr('data-gid');
switch(action) {
switch (action) {
case 'delete':
bootbox.confirm('Are you sure you wish to delete this group?', function(confirm) {
if (confirm) {
@ -83,7 +83,7 @@ $(document).ready(function() {
memberIconImg = memberIcon.querySelector('img');
memberIconLabel = memberIcon.querySelector('span');
if (numMembers > 0) {
for(x=0;x<numMembers;x++) {
for (x = 0; x < numMembers; x++) {
memberIconImg.src = groupObj.members[x].picture;
memberIconLabel.innerHTML = groupObj.members[x].username;
memberIcon.setAttribute('data-uid', groupObj.members[x].uid);
@ -121,7 +121,7 @@ $(document).ready(function() {
resultsSlug = document.createDocumentFragment(),
x;
if (numResults > 4) numResults = 4;
for(x=0;x<numResults;x++) {
for (x = 0; x < numResults; x++) {
foundUserImg.src = results[x].picture;
foundUserLabel.innerHTML = results[x].username;
foundUser.setAttribute('title', results[x].username);

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

@ -1,5 +1,3 @@
var nodebb_admin = (function(nodebb_admin) {
var themes = {};
@ -10,7 +8,7 @@ var nodebb_admin = (function(nodebb_admin) {
themeContainer = document.querySelector('#bootstrap_themes'),
numThemes = bootswatch.themes.length;
for(var x=0;x<numThemes;x++) {
for (var x = 0; x < numThemes; x++) {
var theme = bootswatch.themes[x];
themeEl.setAttribute('data-css', theme.cssMin);
themeEl.setAttribute('data-theme', theme.name);
@ -46,7 +44,7 @@ var nodebb_admin = (function(nodebb_admin) {
installedThemeContainer = document.querySelector('#installed_themes'),
themeEvent = function(e) {
if (e.target.hasAttribute('data-action')) {
switch(e.target.getAttribute('data-action')) {
switch (e.target.getAttribute('data-action')) {
case 'preview':
var cssSrc = $(e.target).parents('li').attr('data-css'),
cssEl = document.getElementById('base-theme');
@ -58,10 +56,12 @@ var nodebb_admin = (function(nodebb_admin) {
cssSrc = parentEl.attr('data-css'),
cssName = parentEl.attr('data-theme');
socket.emit('api:config.set', {
key: 'theme:id', value: 'bootswatch:' + cssName
key: 'theme:id',
value: 'bootswatch:' + cssName
});
socket.emit('api:config.set', {
key: 'theme:src', value: cssSrc
key: 'theme:src',
value: cssSrc
});
break;
}
@ -87,7 +87,7 @@ var nodebb_admin = (function(nodebb_admin) {
liEl = document.createElement('li');
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-css', themes[x].src);
liEl.innerHTML = '<img src="' + themes[x].screenshot + '" />' +

@ -7,18 +7,30 @@ $(document).ready(function() {
action = this.getAttribute('data-action'),
tid = $this.parents('[data-tid]').attr('data-tid');
switch(action) {
switch (action) {
case 'pin':
if (!$this.hasClass('active')) socket.emit('api:topic.pin', { tid: tid });
else socket.emit('api:topic.unpin', { tid: tid });
if (!$this.hasClass('active')) socket.emit('api:topic.pin', {
tid: tid
});
else socket.emit('api:topic.unpin', {
tid: tid
});
break;
case 'lock':
if (!$this.hasClass('active')) socket.emit('api:topic.lock', { tid: tid });
else socket.emit('api:topic.unlock', { tid: tid });
if (!$this.hasClass('active')) socket.emit('api:topic.lock', {
tid: tid
});
else socket.emit('api:topic.unlock', {
tid: tid
});
break;
case 'delete':
if (!$this.hasClass('active')) socket.emit('api:topic.delete', { tid: tid });
else socket.emit('api:topic.restore', { tid: tid });
if (!$this.hasClass('active')) socket.emit('api:topic.delete', {
tid: tid
});
else socket.emit('api:topic.restore', {
tid: tid
});
break;
}
});
@ -56,7 +68,7 @@ $(document).ready(function() {
// Resolve proper button state for all topics
var topicEls = topicsListEl.querySelectorAll('li'),
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-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';

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

Loading…
Cancel
Save