some more language strings and account.js refactor

v1.18.x
barisusakli 11 years ago
parent 2ba767b499
commit 252e757185

@ -1,5 +1,5 @@
{ {
"topic-post": "You have successfully posted.", "topic-post": "You have successfully posted.",
"authentication-successful": "Authentication Successful" "authentication-successful": "Authentication Successful",
"settings-saved": "Settings saved!"
} }

@ -1,3 +1,7 @@
'use strict';
/* globals define, ajaxify, app, utils, socket, translator*/
define(['forum/accountheader'], function(header) { define(['forum/accountheader'], function(header) {
var Account = {}; var Account = {};
@ -8,7 +12,6 @@ define(['forum/accountheader'], function(header) {
theirid = ajaxify.variables.get('theirid'), theirid = ajaxify.variables.get('theirid'),
isFollowing = ajaxify.variables.get('isFollowing'); isFollowing = ajaxify.variables.get('isFollowing');
$(document).ready(function() {
var username = $('.account-username').html(); var username = $('.account-username').html();
app.enterRoom('user/' + theirid); app.enterRoom('user/' + theirid);
@ -16,67 +19,45 @@ define(['forum/accountheader'], function(header) {
utils.makeNumbersHumanReadable($('.account .human-readable-number')); utils.makeNumbersHumanReadable($('.account .human-readable-number'));
$('.user-recent-posts img').addClass('img-responsive'); $('.user-recent-posts img').addClass('img-responsive');
var followBtn = $('#follow-btn');
var unfollowBtn = $('#unfollow-btn');
var chatBtn = $('#chat-btn');
if (yourid !== theirid && yourid !== "0") {
if (isFollowing) {
followBtn.addClass('hide');
unfollowBtn.removeClass('hide');
} else {
followBtn.removeClass('hide');
unfollowBtn.addClass('hide');
}
chatBtn.removeClass('hide');
} else {
followBtn.addClass('hide');
unfollowBtn.addClass('hide');
chatBtn.addClass('hide');
}
followBtn.on('click', function() { var isSelfOrNotLoggedIn = yourid === theirid || yourid === '0';
socket.emit('user.follow', { $('#follow-btn').toggleClass('hide', isFollowing || isSelfOrNotLoggedIn);
uid: theirid $('#unfollow-btn').toggleClass('hide', !isFollowing || isSelfOrNotLoggedIn);
}, function(err) { $('#chat-btn').toggleClass('hide', isSelfOrNotLoggedIn);
if(err) {
return app.alertError('There was an error following' + username + '!');
}
followBtn.addClass('hide'); $('#follow-btn').on('click', function() {
unfollowBtn.removeClass('hide'); return toggleFollow('follow');
app.alertSuccess('[[global:alert.follow, ' + username + ']]');
}); });
return false;
});
unfollowBtn.on('click', function() {
socket.emit('user.unfollow', {
uid: theirid
}, function(err) {
if(err) {
return app.alertError('There was an error unfollowing ' + username + '!');
}
followBtn.removeClass('hide'); $('#unfollow-btn').on('click', function() {
unfollowBtn.addClass('hide'); return toggleFollow('unfollow');
app.alertSuccess('[[global:alert.unfollow, ' + username + ']]');
});
return false;
}); });
chatBtn.on('click', function() { $('#chat-btn').on('click', function() {
app.openChat(username, theirid); app.openChat(username, theirid);
}); });
socket.on('user.isOnline', Account.handleUserOnline); socket.on('user.isOnline', handleUserOnline);
socket.emit('user.isOnline', theirid, handleUserOnline);
};
socket.emit('user.isOnline', theirid, Account.handleUserOnline); function toggleFollow(type) {
socket.emit('user.' + type, {
uid: ajaxify.variables.get('theirid')
}, function(err) {
if(err) {
return app.alertError(err.message);
}
$('#follow-btn').toggleClass('hide', type === 'follow');
$('#unfollow-btn').toggleClass('hide', type === 'unfollow');
app.alertSuccess('[[global:alert.' + type + ', ' + $('.account-username').html() + ']]');
}); });
}; return false;
}
Account.handleUserOnline = function(err, data) { function handleUserOnline(err, data) {
var onlineStatus = $('.account-online-status'); var onlineStatus = $('.account-online-status');
if(parseInt(ajaxify.variables.get('theirid'), 10) !== parseInt(data.uid, 10)) { if(parseInt(ajaxify.variables.get('theirid'), 10) !== parseInt(data.uid, 10)) {
@ -89,7 +70,7 @@ define(['forum/accountheader'], function(header) {
.attr('data-original-title', translated); .attr('data-original-title', translated);
}); });
}; }
return Account; return Account;
}); });

@ -23,9 +23,9 @@ define(['forum/accountheader'], function(header) {
socket.emit('user.saveSettings', settings, function(err) { socket.emit('user.saveSettings', settings, function(err) {
if (err) { if (err) {
return app.alertError('There was an error saving settings!'); return app.alertError(err.message);
} }
app.alertSuccess('Settings saved!'); app.alertSuccess('[[success:settings-saved]]');
}); });
return false; return false;

Loading…
Cancel
Save