This commit is contained in:
unkelpehr 2014-09-27 14:44:41 +02:00
parent 276220eaf4
commit cb37d41502
2 changed files with 28 additions and 21 deletions

View File

@ -12,16 +12,12 @@
*/ */
define( define({
{
compiles: ['$'], compiles: ['$'],
requires: ['castrato','settings','templates'] requires: ['castrato','settings','templates']
}, function ($, requires, data) { }, function ($, requires) {
var // Private properties
var room = false,
// Private properties
room=false,
// Require shortcuts // Require shortcuts
mediator = requires.castrato, mediator = requires.castrato,
@ -30,30 +26,43 @@ define(
join = function(payload) { join = function(payload) {
if (room !== false) { if (room !== false) {
mediator.emit('console:error',$.template(templates.messages.already_in_room, { room: room })); mediator.emit('console:error',
$.template(templates.messages.already_in_room, {
room: room
})
);
} else if (payload.length >= settings.room.maxLen) { } else if (payload.length >= settings.room.maxLen) {
mediator.emit('console:error',$.template(templates.messages.room_name_too_long)); mediator.emit('console:error', $.template(templates.messages.room_name_too_long));
} else if (payload.length < settings.room.minLen) { } else if (payload.length < settings.room.minLen) {
mediator.emit('console:error',$.template(templates.messages.room_name_too_short)); mediator.emit('console:error', $.template(templates.messages.room_name_too_short));
} else { } else {
room = payload; room = payload;
mediator.emit('room:changed', room );
mediator.emit('socket:emit',{ data: 'room:join' , payload: $.SHA1(room) } ); mediator
.emit('room:changed', room)
.emit('socket:emit', {
data: 'room:join',
payload: $.SHA1(room)
});
} }
}, },
leave = function() { leave = function() {
if (room !== false) { if (room !== false) {
mediator.emit('socket:emit',{ data: 'room:leave' , payload: $.SHA1(room) } ); mediator.emit('socket:emit', {
data: 'room:leave',
payload: $.SHA1(room)
});
room = false; room = false;
} else { } else {
mediator.emit('console:error',templates.messages.leave_from_nowhere); mediator.emit('console:error', templates.messages.leave_from_nowhere);
} }
}, },
count = function() { count = function() {
if (room) { if (room) {
mediator.emit('socket:emit','room:count'); mediator.emit('socket:emit', 'room:count');
} else { } else {
mediator.emit('console:error', templates.messages.not_in_room); mediator.emit('console:error', templates.messages.not_in_room);
} }
@ -63,5 +72,4 @@ define(
mediator.on('command:join', join); mediator.on('command:join', join);
mediator.on('command:leave', leave); mediator.on('command:leave', leave);
mediator.on('command:count', count); mediator.on('command:count', count);
}); });

View File

@ -36,6 +36,5 @@ define({
notifications: { notifications: {
maxOnePerMs: 3000 maxOnePerMs: 3000
}, }
}); });