From c44461e33f9ffb4d60f4256f1fd45ad16cb126cb Mon Sep 17 00:00:00 2001 From: psychobunny Date: Tue, 17 Sep 2013 13:07:30 -0400 Subject: [PATCH] formatting - template js admin side --- public/src/forum/admin/categories.js | 23 ++++----- public/src/forum/admin/footer.js | 29 ++++++----- public/src/forum/admin/groups.js | 44 ++++++++--------- public/src/forum/admin/index.js | 8 ++-- public/src/forum/admin/plugins.js | 52 ++++++++++---------- public/src/forum/admin/themes.js | 72 ++++++++++++++-------------- public/src/forum/admin/topics.js | 44 ++++++++++------- public/src/forum/admin/users.js | 62 ++++++++++++------------ 8 files changed, 173 insertions(+), 161 deletions(-) diff --git a/public/src/forum/admin/categories.js b/public/src/forum/admin/categories.js index 39efe81616..b9a4e2d5c5 100644 --- a/public/src/forum/admin/categories.js +++ b/public/src/forum/admin/categories.js @@ -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; diff --git a/public/src/forum/admin/footer.js b/public/src/forum/admin/footer.js index 9fc84c7325..9d1d3acd44 100644 --- a/public/src/forum/admin/footer.js +++ b/public/src/forum/admin/footer.js @@ -1,6 +1,3 @@ - - - var nodebb_admin = (function(nodebb_admin) { nodebb_admin.config = undefined; @@ -19,21 +16,21 @@ var nodebb_admin = (function(nodebb_admin) { numFields = fields.length, saveBtn = document.getElementById('save'), x, key, inputType; - for(x=0;x 0) { - for(x=0;x 0) { - var numResults = results.length, + var numResults = results.length, resultsSlug = document.createDocumentFragment(), x; if (numResults > 4) numResults = 4; - for(x=0;x" + room + " " + count + " active user" + (count > 1 ? "s" : "") + ""; + active_users.innerHTML = active_users.innerHTML + "
" + room + " " + count + " active user" + (count > 1 ? "s" : "") + "
"; } } diff --git a/public/src/forum/admin/plugins.js b/public/src/forum/admin/plugins.js index a913cc9fe9..297fc6eb3c 100644 --- a/public/src/forum/admin/plugins.js +++ b/public/src/forum/admin/plugins.js @@ -1,35 +1,35 @@ -var nodebb_admin = nodebb_admin || {}; +var nodebb_admin = nodebb_admin || {}; (function() { - var plugins = { - init: function() { - var pluginsList = $('.plugins'), - numPlugins = pluginsList[0].querySelectorAll('li').length, - pluginID, pluginTgl; + var plugins = { + init: function() { + var pluginsList = $('.plugins'), + numPlugins = pluginsList[0].querySelectorAll('li').length, + pluginID, pluginTgl; - if (numPlugins > 0) { - pluginsList.on('click', 'button[data-action="toggleActive"]', function() { - pluginID = $(this).parents('li').attr('data-plugin-id'); - socket.emit('api:admin.plugins.toggle', pluginID); - }); + if (numPlugins > 0) { + pluginsList.on('click', 'button[data-action="toggleActive"]', function() { + pluginID = $(this).parents('li').attr('data-plugin-id'); + socket.emit('api:admin.plugins.toggle', pluginID); + }); - socket.on('api:admin.plugins.toggle', function(status) { - pluginTgl = document.querySelector('.plugins li[data-plugin-id="' + status.id + '"] button'); - pluginTgl.innerHTML = ' ' + (status.active ? 'Dea' : 'A') + 'ctivate'; + socket.on('api:admin.plugins.toggle', function(status) { + pluginTgl = document.querySelector('.plugins li[data-plugin-id="' + status.id + '"] button'); + pluginTgl.innerHTML = ' ' + (status.active ? 'Dea' : 'A') + 'ctivate'; - app.alert({ - alert_id: 'plugin_toggled_' + status.id, - title: 'Plugin Enabled', - message: 'You may need to restart NodeBB in order for these changes to be reflected.', - type: 'warning', - timeout: 5000 - }) - }); - } else { - pluginsList.append('
  • No plugins found.

  • '); - } + app.alert({ + alert_id: 'plugin_toggled_' + status.id, + title: 'Plugin Enabled', + message: 'You may need to restart NodeBB in order for these changes to be reflected.', + type: 'warning', + timeout: 5000 + }) + }); + } else { + pluginsList.append('
  • No plugins found.

  • '); } - }; + } + }; jQuery(document).ready(function() { nodebb_admin.plugins = plugins; diff --git a/public/src/forum/admin/themes.js b/public/src/forum/admin/themes.js index de6396715b..05440189cb 100644 --- a/public/src/forum/admin/themes.js +++ b/public/src/forum/admin/themes.js @@ -1,5 +1,3 @@ - - var nodebb_admin = (function(nodebb_admin) { var themes = {}; @@ -10,20 +8,20 @@ var nodebb_admin = (function(nodebb_admin) { themeContainer = document.querySelector('#bootstrap_themes'), numThemes = bootswatch.themes.length; - for(var x=0;x' + - '
    ' + - '
    ' + - ' ' + - '' + - '
    ' + - '

    ' + theme.name + '

    ' + - '

    ' + theme.description + '

    ' + - '
    ' + - '
    '; + themeEl.innerHTML = '' + + '
    ' + + '
    ' + + ' ' + + '' + + '
    ' + + '

    ' + theme.name + '

    ' + + '

    ' + theme.description + '

    ' + + '
    ' + + '
    '; themeFrag.appendChild(themeEl.cloneNode(true)); } themeContainer.innerHTML = ''; @@ -42,28 +40,30 @@ var nodebb_admin = (function(nodebb_admin) { scriptEl.src = 'http://api.bootswatch.com/3/?callback=nodebb_admin.themes.render'; document.body.appendChild(scriptEl); - var bootstrapThemeContainer = document.querySelector('#bootstrap_themes'), + var bootstrapThemeContainer = document.querySelector('#bootstrap_themes'), 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'), + var cssSrc = $(e.target).parents('li').attr('data-css'), cssEl = document.getElementById('base-theme'); cssEl.href = cssSrc; - break; + break; case 'use': - var parentEl = $(e.target).parents('li'), + var parentEl = $(e.target).parents('li'), 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; + break; } } }; @@ -82,27 +82,27 @@ var nodebb_admin = (function(nodebb_admin) { // Installed Themes socket.emit('api:admin.themes.getInstalled', function(themes) { - var instListEl = document.getElementById('installed_themes'), + var instListEl = document.getElementById('installed_themes'), themeFrag = document.createDocumentFragment(), liEl = document.createElement('li'); if (themes.length > 0) { - for(var x=0,numThemes=themes.length;x' + - '
    ' + - '
    ' + - ' ' + - '' + - '
    ' + - '

    ' + themes[x].name + '

    ' + - '

    ' + - themes[x].description + - (themes[x].url ? ' (Homepage)' : '') + - '

    ' + - '
    ' + - '
    '; + liEl.innerHTML = '' + + '
    ' + + '
    ' + + ' ' + + '' + + '
    ' + + '

    ' + themes[x].name + '

    ' + + '

    ' + + themes[x].description + + (themes[x].url ? ' (Homepage)' : '') + + '

    ' + + '
    ' + + '
    '; themeFrag.appendChild(liEl.cloneNode(true)); } } else { diff --git a/public/src/forum/admin/topics.js b/public/src/forum/admin/topics.js index d0c6608fef..040197df82 100644 --- a/public/src/forum/admin/topics.js +++ b/public/src/forum/admin/topics.js @@ -7,25 +7,37 @@ $(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 }); - break; + 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 }); - break; + 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 }); - break; + if (!$this.hasClass('active')) socket.emit('api:topic.delete', { + tid: tid + }); + else socket.emit('api:topic.restore', { + tid: tid + }); + break; } }); loadMoreEl.addEventListener('click', function() { 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')); this.innerHTML = ' Retrieving topics'; @@ -37,9 +49,9 @@ $(document).ready(function() { topics = JSON.parse(topics); if (topics.length > 0) { - var html = templates.prepare(templates['admin/topics'].blocks['topics']).parse({ - topics: topics - }), + var html = templates.prepare(templates['admin/topics'].blocks['topics']).parse({ + topics: topics + }), topicsListEl = document.querySelector('.topics'); topicsListEl.innerHTML += html; @@ -54,9 +66,9 @@ $(document).ready(function() { }, false); // Resolve proper button state for all topics - var topicEls = topicsListEl.querySelectorAll('li'), + var topicEls = topicsListEl.querySelectorAll('li'), numTopics = topicEls.length; - for(var x=0;x1?'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;