diff --git a/public/src/app.js b/public/src/app.js index 2270bc0968..16c60dbe41 100644 --- a/public/src/app.js +++ b/public/src/app.js @@ -214,8 +214,11 @@ var socket, alert = $('
'); alert.append($('')) - .append($('' + title + '')) - .append($('' + params.message + '
')); + .append($('' + title + '')); + + if (params.message) { + alert.append($('' + params.message + '
')); + } if (!params.location) { params.location = 'alert_window'; diff --git a/public/src/forum/admin/sounds.js b/public/src/forum/admin/sounds.js index b56436163e..b58acc6ac2 100644 --- a/public/src/forum/admin/sounds.js +++ b/public/src/forum/admin/sounds.js @@ -1,5 +1,5 @@ "use strict"; -/* global define */ +/* global define, socket */ define(['sounds', 'settings'], function(Sounds, Settings) { var SoundsAdmin = {}; @@ -19,7 +19,11 @@ define(['sounds', 'settings'], function(Sounds, Settings) { // Saving of Form Values var saveEl = $('#save'); saveEl.on('click', function() { - Settings.save('sounds', $('.sounds form')); + Settings.save('sounds', $('.sounds form'), function() { + socket.emit('admin.fireEvent', { + name: 'event:sounds.reloadMapping' + }); + }); }); }; diff --git a/public/src/modules/chat.js b/public/src/modules/chat.js index 38ecf7974f..9670258ec6 100644 --- a/public/src/modules/chat.js +++ b/public/src/modules/chat.js @@ -229,7 +229,6 @@ define(['taskbar', 'string', 'sounds'], function(taskbar, S, sounds) { msg = msg +'\n'; socket.emit('modules.chats.send', { touid:chatModal.touid, message:msg}); chatModal.find('#chat-message-input').val(''); - console.log('outgoing'); sounds.play('chat-outgoing'); } } diff --git a/public/src/modules/settings.js b/public/src/modules/settings.js index cc4daafe77..55f15df705 100644 --- a/public/src/modules/settings.js +++ b/public/src/modules/settings.js @@ -28,8 +28,9 @@ define(function() { }); }; - Settings.save = function(hash, formEl) { - var formEl = $(formEl); + Settings.save = function(hash, formEl, callback) { + formEl = $(formEl); + if (formEl.length) { var values = formEl.serializeObject(); @@ -39,12 +40,13 @@ define(function() { }, function(err) { app.alert({ title: 'Settings Saved', - message: 'Restarting NodeBB ', type: 'success', timeout: 2500 }); - socket.emit('admin.restart'); + if (typeof callback === 'function') { + callback(); + } }); } else { console.log('[settings] Form not found.'); diff --git a/public/src/modules/sounds.js b/public/src/modules/sounds.js index 6bce66ce73..1ddb752def 100644 --- a/public/src/modules/sounds.js +++ b/public/src/modules/sounds.js @@ -1,5 +1,5 @@ "use strict"; -/* global socket */ +/* global define, socket */ define(['buzz'], function(buzz) { var Sounds = {}; @@ -11,7 +11,10 @@ define(['buzz'], function(buzz) { Sounds.init = function(callback) { var ready = false, onComplete = function() { - callback(); + Sounds.initialised = true; + if (typeof callback === 'function') { + callback(); + } }; loadFiles(function() { @@ -29,6 +32,11 @@ define(['buzz'], function(buzz) { ready = true; } }); + + // Listen for reload message + socket.on('event:sounds.reloadMapping', function() { + loadMapping(); + }); }; var loadFiles = function(callback) { @@ -45,8 +53,6 @@ define(['buzz'], function(buzz) { } } - this.initialised = true; - callback(); }); }; @@ -54,7 +60,9 @@ define(['buzz'], function(buzz) { var loadMapping = function(callback) { socket.emit('modules.sounds.getMapping', function(err, mapping) { Sounds.mapping = mapping; - callback(); + if (typeof callback === 'function') { + callback(); + } }); }; @@ -67,8 +75,11 @@ define(['buzz'], function(buzz) { } }; - if (!this.initialised) this.init(ready); - else ready(); + if (!this.initialised) { + this.init(ready); + } else { + ready(); + } }; Sounds.playFile = function(fileName) { @@ -80,9 +91,13 @@ define(['buzz'], function(buzz) { } }; - if (!this.initialised) this.init(ready); - else ready(); - } + if (!this.initialised) { + this.init(ready); + } else { + ready(); + } + }; + Sounds.init(); return Sounds; }); \ No newline at end of file diff --git a/src/meta.js b/src/meta.js index f38a777e68..b45fa18704 100644 --- a/src/meta.js +++ b/src/meta.js @@ -349,7 +349,7 @@ var fs = require('fs'), }; Meta.sounds.getMapping = function(callback) { - db.getObject('sounds', function(err, sounds) { + db.getObject('settings:sounds', function(err, sounds) { if (err || !sounds) { // Send default sounds var defaults = { diff --git a/src/socket.io/admin.js b/src/socket.io/admin.js index 6173ab7a04..67ce00ae3c 100644 --- a/src/socket.io/admin.js +++ b/src/socket.io/admin.js @@ -46,7 +46,6 @@ SocketAdmin.restart = function(socket, data, callback) { meta.restart(); }; - SocketAdmin.getVisitorCount = function(socket, data, callback) { var terms = { day: 86400000, @@ -68,7 +67,11 @@ SocketAdmin.getVisitorCount = function(socket, data, callback) { db.sortedSetCount('ip:recent', 0, now, next); } }, callback); -} +}; + +SocketAdmin.fireEvent = function(socket, data, callback) { + index.server.sockets.emit(data.name, data.payload || {}); +}; /* Topics */ SocketAdmin.topics.getMore = function(socket, data, callback) { @@ -405,7 +408,6 @@ SocketAdmin.settings.get = function(socket, data, callback) { }; SocketAdmin.settings.set = function(socket, data, callback) { - console.log('setting', data); meta.settings.set(data.hash, data.values, callback); };