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.",
"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) {
var Account = {};
@ -8,75 +12,52 @@ define(['forum/accountheader'], function(header) {
theirid = ajaxify.variables.get('theirid'),
isFollowing = ajaxify.variables.get('isFollowing');
$(document).ready(function() {
var username = $('.account-username').html();
app.enterRoom('user/' + theirid);
utils.addCommasToNumbers($('.account .formatted-number'));
utils.makeNumbersHumanReadable($('.account .human-readable-number'));
$('.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');
}
var username = $('.account-username').html();
app.enterRoom('user/' + theirid);
utils.addCommasToNumbers($('.account .formatted-number'));
utils.makeNumbersHumanReadable($('.account .human-readable-number'));
$('.user-recent-posts img').addClass('img-responsive');
var isSelfOrNotLoggedIn = yourid === theirid || yourid === '0';
$('#follow-btn').toggleClass('hide', isFollowing || isSelfOrNotLoggedIn);
$('#unfollow-btn').toggleClass('hide', !isFollowing || isSelfOrNotLoggedIn);
$('#chat-btn').toggleClass('hide', isSelfOrNotLoggedIn);
$('#follow-btn').on('click', function() {
return toggleFollow('follow');
});
followBtn.on('click', function() {
socket.emit('user.follow', {
uid: theirid
}, function(err) {
if(err) {
return app.alertError('There was an error following' + username + '!');
}
followBtn.addClass('hide');
unfollowBtn.removeClass('hide');
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');
unfollowBtn.addClass('hide');
app.alertSuccess('[[global:alert.unfollow, ' + username + ']]');
});
return false;
});
chatBtn.on('click', function() {
app.openChat(username, theirid);
});
socket.on('user.isOnline', Account.handleUserOnline);
socket.emit('user.isOnline', theirid, Account.handleUserOnline);
$('#unfollow-btn').on('click', function() {
return toggleFollow('unfollow');
});
$('#chat-btn').on('click', function() {
app.openChat(username, theirid);
});
socket.on('user.isOnline', handleUserOnline);
socket.emit('user.isOnline', theirid, handleUserOnline);
};
Account.handleUserOnline = function(err, data) {
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;
}
function handleUserOnline(err, data) {
var onlineStatus = $('.account-online-status');
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);
});
};
}
return Account;
});

@ -23,14 +23,14 @@ define(['forum/accountheader'], function(header) {
socket.emit('user.saveSettings', settings, function(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;
});
socket.emit('user.getSettings', function(err, settings) {
for (var setting in settings) {
if (settings.hasOwnProperty(setting)) {

Loading…
Cancel
Save