diff --git a/public/src/forum/accountedit.js b/public/src/forum/accountedit.js index 912bb29b37..5e4eb0fcc3 100644 --- a/public/src/forum/accountedit.js +++ b/public/src/forum/accountedit.js @@ -99,6 +99,22 @@ define(['forum/accountheader', 'uploader'], function(header, uploader) { return false; }); + function showError(element, msg) { + element.html(msg); + element.parent() + .removeClass('alert-success') + .addClass('alert-danger'); + element.show(); + validationError = true; + } + + function showSuccess(element, msg) { + element.html(msg); + element.parent() + .removeClass('alert-danger') + .addClass('alert-success'); + element.show(); + } (function handlePasswordChange() { var currentPassword = $('#inputCurrentPassword'); @@ -108,42 +124,29 @@ define(['forum/accountheader', 'uploader'], function(header, uploader) { var password_confirm = $('#inputNewPasswordAgain'); var passwordvalid = false; var passwordsmatch = false; + var successIcon = ''; function onPasswordChanged() { passwordvalid = utils.isPasswordValid(password.val()); if (password.val().length < config.minimumPasswordLength) { - password_notify.html('Password too short'); - password_notify.attr('class', 'alert alert-danger'); - password_notify.removeClass('hide'); + showError(password_notify, 'Password too short!'); } else if (!passwordvalid) { - password_notify.html('Invalid password'); - password_notify.attr('class', 'alert alert-danger'); - password_notify.removeClass('hide'); + showError(password_notify, 'Invalid password!'); } else { - password_notify.html('OK!'); - password_notify.attr('class', 'alert alert-success'); - password_notify.removeClass('hide'); + showSuccess(password_notify, successIcon); } - - onPasswordConfirmChanged(); } function onPasswordConfirmChanged() { - if (password_notify.hasClass('alert-danger') || !password_confirm.val()) { - password_confirm_notify.addClass('hide'); - return; - } - if (password.val() !== password_confirm.val()) { - password_confirm_notify.html('Passwords must match!'); - password_confirm_notify.attr('class', 'alert alert-danger'); - password_confirm_notify.removeClass('hide'); - passwordsmatch = false; - } else { - password_confirm_notify.html('OK!'); - password_confirm_notify.attr('class', 'alert alert-success'); - password_confirm_notify.removeClass('hide'); - passwordsmatch = true; + if(password.val()) { + if (password.val() !== password_confirm.val()) { + showError(password_confirm_notify, 'Passwords must match!') + passwordsmatch = false; + } else { + showSuccess(password_confirm_notify, successIcon); + passwordsmatch = true; + } } } @@ -161,8 +164,6 @@ define(['forum/accountheader', 'uploader'], function(header, uploader) { currentPassword.val(''); password.val(''); password_confirm.val(''); - password_notify.addClass('hide'); - password_confirm_notify.addClass('hide'); passwordsmatch = false; passwordvalid = false; diff --git a/public/src/forum/topic.js b/public/src/forum/topic.js index e7706df99d..fd77d2084f 100644 --- a/public/src/forum/topic.js +++ b/public/src/forum/topic.js @@ -1,7 +1,7 @@ define(function() { var Topic = {}, - infiniteLoaderActive = false; - + infiniteLoaderActive = false, + pagination; function showBottomPostBar() { if($('#post-container .post-row').length > 1) { @@ -775,74 +775,75 @@ define(function() { - var pagination; - Topic.postCount = templates.get('postcount'); - - function updateHeader() { - if (pagination == null) { - jQuery('.pagination-block i:first').on('click', function() { - app.scrollToTop(); - }); - jQuery('.pagination-block i:last').on('click', function() { - app.scrollToBottom(); - }); - } - pagination = pagination || document.getElementById('pagination'); - - var windowHeight = jQuery(window).height(); - var scrollTop = jQuery(window).scrollTop(); - var scrollBottom = scrollTop + windowHeight; - var progressBar = $('.progress-bar'); - var progressBarContainer = $('.progress-container'); - pagination.parentNode.style.display = 'block'; - progressBarContainer.css('display', ''); + Topic.postCount = templates.get('postcount'); - if (scrollTop < 50 && Topic.postCount > 1) { - localStorage.removeItem("topic:" + tid + ":bookmark"); - pagination.innerHTML = '1 out of ' + Topic.postCount; - progressBar.width(0); - return; - } + window.onscroll = updateHeader; + window.onload = updateHeader; + }; + function updateHeader() { + if (pagination == null) { + jQuery('.pagination-block i:first').on('click', function() { + app.scrollToTop(); + }); + jQuery('.pagination-block i:last').on('click', function() { + app.scrollToBottom(); + }); + } + pagination = pagination || document.getElementById('pagination'); + + var windowHeight = jQuery(window).height(); + var scrollTop = jQuery(window).scrollTop(); + var scrollBottom = scrollTop + windowHeight; + var progressBar = $('.progress-bar'); + var progressBarContainer = $('.progress-container'); + var tid = templates.get('topic_id'); + + pagination.parentNode.style.display = 'block'; + progressBarContainer.css('display', ''); + + if (scrollTop < 50 && Topic.postCount > 1) { + localStorage.removeItem("topic:" + tid + ":bookmark"); + pagination.innerHTML = '1 out of ' + Topic.postCount; + progressBar.width(0); + return; + } - var count = 0, smallestNonNegative = 0; - jQuery('.posts > .post-row:not(".deleted")').each(function() { - count++; - this.postnumber = count; + var count = 0, smallestNonNegative = 0; + jQuery('.posts > .post-row:not(".deleted")').each(function() { + count++; + this.postnumber = count; - var el = jQuery(this); - var elTop = el.offset().top; - var height = Math.floor(el.height()); - var elBottom = elTop + (height < 300 ? height : 300); - var inView = ((elBottom >= scrollTop) && (elTop <= scrollBottom) && (elBottom <= scrollBottom) && (elTop >= scrollTop)); + var el = jQuery(this); + var elTop = el.offset().top; + var height = Math.floor(el.height()); + var elBottom = elTop + (height < 300 ? height : 300); + var inView = ((elBottom >= scrollTop) && (elTop <= scrollBottom) && (elBottom <= scrollBottom) && (elTop >= scrollTop)); - if (inView) { - if(elTop - scrollTop > smallestNonNegative) { - localStorage.setItem("topic:" + tid + ":bookmark", el.attr('data-pid')); - smallestNonNegative = Number.MAX_VALUE; - } - pagination.innerHTML = (this.postnumber-1) + ' out of ' + Topic.postCount; - progressBar.width(((this.postnumber-1) / Topic.postCount * 100) + '%'); + if (inView) { + if(elTop - scrollTop > smallestNonNegative) { + localStorage.setItem("topic:" + tid + ":bookmark", el.attr('data-pid')); + smallestNonNegative = Number.MAX_VALUE; } - }); - setTimeout(function() { - if (scrollTop + windowHeight == jQuery(document).height()) { - pagination.innerHTML = Topic.postCount + ' out of ' + Topic.postCount; - progressBar.width('100%'); - } - }, 100); - } + pagination.innerHTML = (this.postnumber-1) + ' out of ' + Topic.postCount; + progressBar.width(((this.postnumber-1) / Topic.postCount * 100) + '%'); + } + }); - window.onscroll = updateHeader; - window.onload = updateHeader; - }; + setTimeout(function() { + if (scrollTop + windowHeight == jQuery(document).height()) { + pagination.innerHTML = Topic.postCount + ' out of ' + Topic.postCount; + progressBar.width('100%'); + } + }, 100); + } Topic.scrollToPost = function(pid) { if (!pid) { @@ -944,8 +945,13 @@ define(function() { } function updatePostCount() { - Topic.postCount = $('#post-container li[data-pid]:not(.deleted)').length; - $('#topic-post-count').html(Topic.postCount); + socket.emit('api:topics.postcount', templates.get('topic_id'), function(err, postcount) { + if(!err) { + Topic.postCount = postcount; + $('#topic-post-count').html(Topic.postCount); + updateHeader(); + } + }) } function loadMorePosts(tid, callback) { diff --git a/public/templates/accountedit.tpl b/public/templates/accountedit.tpl index ebff456b22..c6594343db 100644 --- a/public/templates/accountedit.tpl +++ b/public/templates/accountedit.tpl @@ -115,17 +115,21 @@
-
+
-
+ + +
-
+
-
+ + +

diff --git a/src/user.js b/src/user.js index 090f4d3758..01f4914bd2 100644 --- a/src/user.js +++ b/src/user.js @@ -7,7 +7,7 @@ var bcrypt = require('bcrypt'), userSearch = require('reds').createSearch('nodebbusersearch'), check = require('validator').check, sanitize = require('validator').sanitize, - + utils = require('./../public/src/utils'), RDB = require('./redis'), meta = require('./meta'), diff --git a/src/websockets.js b/src/websockets.js index af9a9136b0..9fdbd43e34 100644 --- a/src/websockets.js +++ b/src/websockets.js @@ -340,8 +340,8 @@ module.exports.init = function(io) { if (uid) { user.setUserFields(uid, { showemail: data.showemail - }, function(err) { - callback(err ? err.message : null); + }, function(err, result) { + callback(err); }); } }); @@ -403,6 +403,10 @@ module.exports.init = function(io) { }); + socket.on('api:topics.postcount', function(tid, callback) { + topics.getTopicField(tid, 'postcount', callback); + }); + socket.on('api:topics.markAllRead', function(data, callback) { topics.markAllRead(uid, function(err, success) { if (!err && success) {