fireEvent reflection socket call, tweaks to Sounds page in ACP

v1.18.x
Julian Lam 11 years ago
parent 14a0b45ae8
commit 16f1db4f5d

@ -214,8 +214,11 @@ var socket,
alert = $('<div id="' + alert_id + '" class="alert alert-dismissable alert-' + params.type +'"></div>');
alert.append($('<button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>'))
.append($('<strong>' + title + '</strong>'))
.append($('<p>' + params.message + '</p>'));
.append($('<strong>' + title + '</strong>'));
if (params.message) {
alert.append($('<p>' + params.message + '</p>'));
}
if (!params.location) {
params.location = 'alert_window';

@ -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'
});
});
});
};

@ -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');
}
}

@ -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 <i class="fa fa-spin fa-refresh"></i>',
type: 'success',
timeout: 2500
});
socket.emit('admin.restart');
if (typeof callback === 'function') {
callback();
}
});
} else {
console.log('[settings] Form not found.');

@ -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;
});

@ -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 = {

@ -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);
};

Loading…
Cancel
Save