removed app.loadConfig

v1.18.x
barisusakli 10 years ago
parent da7dcd99a8
commit 04084807c2

@ -1,8 +1,7 @@
"use strict"; "use strict";
/*global io, templates, translator, ajaxify, utils, bootbox, RELATIVE_PATH*/ /*global io, templates, translator, ajaxify, utils, bootbox, RELATIVE_PATH, config*/
var socket, var socket,
config,
app = { app = {
'username': null, 'username': null,
'uid': null, 'uid': null,
@ -17,69 +16,12 @@ var socket,
var showWelcomeMessage = false; var showWelcomeMessage = false;
var reconnecting = false; var reconnecting = false;
function onSocketConnect(data) { function socketIOConnect() {
if (reconnecting) {
var reconnectEl = $('#reconnect');
reconnectEl.tooltip('destroy');
reconnectEl.html('<i class="fa fa-check"></i>');
reconnecting = false;
// Rejoin room that was left when we disconnected
var url_parts = window.location.pathname.slice(RELATIVE_PATH.length).split('/').slice(1);
var room;
switch(url_parts[0]) {
case 'user':
room = 'user/' + ajaxify.variables.get('theirid');
break;
case 'topic':
room = 'topic_' + url_parts[1];
break;
case 'category':
room = 'category_' + url_parts[1];
break;
case 'recent': // intentional fall-through
case 'unread':
room = 'recent_posts';
break;
case 'admin':
room = 'admin';
break;
case 'home':
room = 'home';
break;
}
app.currentRoom = '';
app.enterRoom(room);
socket.emit('meta.reconnected');
app.isConnected = true;
$(window).trigger('action:reconnected');
setTimeout(function() {
reconnectEl.removeClass('active').addClass('hide');
}, 3000);
}
}
function onConfigLoad(data) {
config = data;
exposeConfigToTemplates();
if(socket) {
socket.disconnect();
setTimeout(function() {
socket.connect();
}, 200);
} else {
var ioParams = { var ioParams = {
reconnectionAttempts: config.maxReconnectionAttempts, reconnectionAttempts: config.maxReconnectionAttempts,
reconnectionDelay : config.reconnectionDelay, reconnectionDelay : config.reconnectionDelay,
transports: config.socketioTransports, transports: config.socketioTransports,
path: RELATIVE_PATH + '/socket.io' path: config.relative_path + '/socket.io'
}; };
socket = io.connect(config.websocketAddress, ioParams); socket = io.connect(config.websocketAddress, ioParams);
@ -95,18 +37,12 @@ var socket,
app.user = data; app.user = data;
templates.setGlobal('loggedIn', parseInt(data.uid, 10) !== 0);
app.showLoginMessage(); app.showLoginMessage();
app.replaceSelfLinks(); app.replaceSelfLinks();
$(window).trigger('action:connected'); $(window).trigger('action:connected');
app.isConnected = true; app.isConnected = true;
}); });
socket.on('event:alert', function (data) {
app.alert(data);
});
socket.on('connect', onSocketConnect); socket.on('connect', onSocketConnect);
socket.on('event:disconnect', function() { socket.on('event:disconnect', function() {
@ -143,29 +79,57 @@ var socket,
}); });
setTimeout(function() { setTimeout(function() {
window.location.href = RELATIVE_PATH + '/'; window.location.href = config.relative_path + '/';
}, 1000); }, 1000);
}); });
}
app.cacheBuster = config['cache-buster']; function onSocketConnect(data) {
if (reconnecting) {
var reconnectEl = $('#reconnect');
require(['csrf'], function(csrf) { reconnectEl.tooltip('destroy');
csrf.set(data.csrf_token); reconnectEl.html('<i class="fa fa-check"></i>');
}); reconnecting = false;
bootbox.setDefaults({ // Rejoin room that was left when we disconnected
locale: config.userLang var url_parts = window.location.pathname.slice(RELATIVE_PATH.length).split('/').slice(1);
}); var room;
}
switch(url_parts[0]) {
case 'user':
room = 'user/' + ajaxify.variables.get('theirid');
break;
case 'topic':
room = 'topic_' + url_parts[1];
break;
case 'category':
room = 'category_' + url_parts[1];
break;
case 'recent': // intentional fall-through
case 'unread':
room = 'recent_posts';
break;
case 'admin':
room = 'admin';
break;
case 'home':
room = 'home';
break;
} }
app.currentRoom = '';
app.enterRoom(room);
app.loadConfig = function() { socket.emit('meta.reconnected');
$.ajax({
url: RELATIVE_PATH + '/api/config', app.isConnected = true;
success: onConfigLoad, $(window).trigger('action:reconnected');
async: false
}); setTimeout(function() {
}; reconnectEl.removeClass('active').addClass('hide');
}, 3000);
}
}
app.logout = function() { app.logout = function() {
require(['csrf'], function(csrf) { require(['csrf'], function(csrf) {
@ -402,6 +366,7 @@ var socket,
function exposeConfigToTemplates() { function exposeConfigToTemplates() {
$(document).ready(function() { $(document).ready(function() {
templates.setGlobal('loggedIn', config.loggedIn);
templates.setGlobal('relative_path', RELATIVE_PATH); templates.setGlobal('relative_path', RELATIVE_PATH);
for(var key in config) { for(var key in config) {
if (config.hasOwnProperty(key)) { if (config.hasOwnProperty(key)) {
@ -609,7 +574,20 @@ var socket,
showWelcomeMessage = window.location.href.indexOf('loggedin') !== -1; showWelcomeMessage = window.location.href.indexOf('loggedin') !== -1;
app.loadConfig(); exposeConfigToTemplates();
socketIOConnect();
app.cacheBuster = config['cache-buster'];
require(['csrf'], function(csrf) {
csrf.set(config.csrf_token);
});
bootbox.setDefaults({
locale: config.userLang
});
app.alternatingTitle(''); app.alternatingTitle('');
}()); }());

@ -1,3 +1,7 @@
'use strict';
/*global define, socket, app, ajaxify, config*/
define('forum/account/settings', ['forum/account/header'], function(header) { define('forum/account/settings', ['forum/account/header'], function(header) {
var AccountSettings = {}; var AccountSettings = {};
@ -26,13 +30,19 @@ define('forum/account/settings', ['forum/account/header'], function(header) {
} }
}); });
socket.emit('user.saveSettings', {uid: ajaxify.variables.get('theirid'), settings: settings}, function(err) { socket.emit('user.saveSettings', {uid: ajaxify.variables.get('theirid'), settings: settings}, function(err, newSettings) {
if (err) { if (err) {
return app.alertError(err.message); return app.alertError(err.message);
} }
app.alertSuccess('[[success:settings-saved]]'); app.alertSuccess('[[success:settings-saved]]');
app.loadConfig();
for (var key in newSettings) {
if (newSettings.hasOwnProperty(key)) {
config[key] = newSettings[key];
}
}
if (parseInt(app.uid, 10) === parseInt(ajaxify.variables.get('theirid'), 10)) { if (parseInt(app.uid, 10) === parseInt(ajaxify.variables.get('theirid'), 10)) {
ajaxify.refresh(); ajaxify.refresh();
} }

@ -216,6 +216,10 @@ middleware.renderHeader = function(req, res, callback) {
}; };
plugins.fireHook('filter:header.build', custom_header, function(err, custom_header) { plugins.fireHook('filter:header.build', custom_header, function(err, custom_header) {
if (err) {
return next(err);
}
var defaultMetaTags = [{ var defaultMetaTags = [{
name: 'viewport', name: 'viewport',
content: 'width=device-width, initial-scale=1.0, user-scalable=no' content: 'width=device-width, initial-scale=1.0, user-scalable=no'
@ -260,6 +264,8 @@ middleware.renderHeader = function(req, res, callback) {
} }
} }
templateValues.config = JSON.stringify(res.locals.config);
templateValues.metaTags = defaultMetaTags.concat(res.locals.metaTags || []).map(function(tag) { templateValues.metaTags = defaultMetaTags.concat(res.locals.metaTags || []).map(function(tag) {
if(!tag || typeof tag.content !== 'string') { if(!tag || typeof tag.content !== 'string') {
winston.warn('Invalid meta tag. ', tag); winston.warn('Invalid meta tag. ', tag);

@ -1,7 +1,8 @@
'use strict'; 'use strict';
var meta = require('../meta'), var async = require('async'),
meta = require('../meta'),
db = require('../database'), db = require('../database'),
plugins = require('../plugins'); plugins = require('../plugins');
@ -82,6 +83,9 @@ module.exports = function(User) {
data.language = data.language || meta.config.defaultLang; data.language = data.language || meta.config.defaultLang;
plugins.fireHook('action:user.saveSettings', {uid: uid, settings: data}); plugins.fireHook('action:user.saveSettings', {uid: uid, settings: data});
async.waterfall([
function(next) {
db.setObject('user:' + uid + ':settings', { db.setObject('user:' + uid + ':settings', {
showemail: data.showemail, showemail: data.showemail,
showfullname: data.showfullname, showfullname: data.showfullname,
@ -97,7 +101,12 @@ module.exports = function(User) {
sendChatNotifications: data.sendChatNotifications, sendChatNotifications: data.sendChatNotifications,
restrictChat: data.restrictChat, restrictChat: data.restrictChat,
topicSearchEnabled: data.topicSearchEnabled topicSearchEnabled: data.topicSearchEnabled
}, callback); }, next);
},
function(next) {
User.getSettings(uid, next);
}
], callback);
}; };
User.setSetting = function(uid, key, value, callback) { User.setSetting = function(uid, key, value, callback) {

Loading…
Cancel
Save