diff --git a/public/src/client/account/settings.js b/public/src/client/account/settings.js index f5f9ab4e32..848bf8c1ef 100644 --- a/public/src/client/account/settings.js +++ b/public/src/client/account/settings.js @@ -61,31 +61,6 @@ define('forum/account/settings', ['forum/account/header'], function(header) { return false; }); - - socket.emit('user.getSettings', {uid: ajaxify.variables.get('theirid')}, function(err, settings) { - var inputs = $('.account').find('input, textarea, select'); - - inputs.each(function(index, input) { - input = $(input); - var setting = input.attr('data-property'); - if (setting) { - if (input.is('select')) { - input.val(settings[setting] || ''); - return; - } - - switch (input.attr('type')) { - case 'text' : - case 'textarea' : - input.val(settings[setting]); - break; - case 'checkbox' : - input.prop('checked', !!settings[setting]); - break; - } - } - }); - }); }; return AccountSettings; diff --git a/src/controllers/accounts.js b/src/controllers/accounts.js index 5552fa53be..f159058586 100644 --- a/src/controllers/accounts.js +++ b/src/controllers/accounts.js @@ -375,38 +375,59 @@ accountsController.accountEdit = function(req, res, next) { }; accountsController.accountSettings = function(req, res, next) { - accountsController.getBaseUser(req.params.userslug, req.uid, function(err, userData) { + var userData; + async.waterfall([ + function(next) { + accountsController.getBaseUser(req.params.userslug, req.uid, next); + }, + function(_userData, next) { + userData = _userData; + if (!userData) { + return helpers.notFound(req, res); + } + async.parallel({ + settings: function(next) { + user.getSettings(userData.uid, next); + }, + userGroups: function(next) { + groups.getUserGroups([userData.uid], next); + }, + languages: function(next) { + languages.list(next); + } + }, next); + }, + function(results, next) { + userData.languages = results.languages; + userData.userGroups = results.userGroups[0]; + plugins.fireHook('filter:user.settings', {settings: results.settings, uid: req.uid}, next); + }, + function(data, next) { + userData.settings = data.settings; + userData.disableEmailSubscriptions = parseInt(meta.config.disableEmailSubscriptions, 10) === 1; + next(); + } + ], function(err) { if (err) { return next(err); } - if (!userData) { - return helpers.notFound(req, res); - } + userData.dailyDigestFreqOptions = [ + {value: 'off', name: '[[user:digest_off]]', selected: 'off' === userData.settings.dailyDigestFreq}, + {value: 'day', name: '[[user:digest_daily]]', selected: 'day' === userData.settings.dailyDigestFreq}, + {value: 'week', name: '[[user:digest_weekly]]', selected: 'week' === userData.settings.dailyDigestFreq}, + {value: 'month', name: '[[user:digest_monthly]]', selected: 'month' === userData.settings.dailyDigestFreq} + ]; - async.parallel({ - settings: function(next) { - plugins.fireHook('filter:user.settings', [], next); - }, - userGroups: function(next) { - groups.getUserGroups([userData.uid], next); - }, - languages: function(next) { - languages.list(next); - } - }, function(err, results) { - if (err) { - return next(err); - } - - userData.settings = results.settings; - userData.languages = results.languages; - userData.userGroups = results.userGroups[0]; - - userData.disableEmailSubscriptions = parseInt(meta.config.disableEmailSubscriptions, 10) === 1; + userData.userGroups.forEach(function(group) { + group.selected = group.name === userData.settings.groupTitle; + }); - res.render('account/settings', userData); + userData.languages.forEach(function(language) { + language.selected = language.code === userData.settings.language; }); + + res.render('account/settings', userData); }); }; diff --git a/src/socket.io/user.js b/src/socket.io/user.js index 0df36121e8..65af901b08 100644 --- a/src/socket.io/user.js +++ b/src/socket.io/user.js @@ -340,26 +340,6 @@ function toggleFollow(method, uid, theiruid, callback) { }); } -SocketUser.getSettings = function(socket, data, callback) { - if (socket.uid) { - if (socket.uid === parseInt(data.uid, 10)) { - return user.getSettings(socket.uid, callback); - } - - user.isAdministrator(socket.uid, function(err, isAdmin) { - if (err) { - return callback(err); - } - - if (!isAdmin) { - return callback(new Error('[[error:no-privileges]]')); - } - - user.getSettings(data.uid, callback); - }); - } -}; - SocketUser.saveSettings = function(socket, data, callback) { if (!socket.uid || !data) { return callback(new Error('[[error:invalid-data]]'));