2013-11-02 09:56:20 +01:00
|
|
|
(function (root, factory) {
|
2013-11-02 12:37:38 +01:00
|
|
|
define("utils", [
|
|
|
|
'jquery',
|
|
|
|
'mock'
|
|
|
|
],
|
|
|
|
function($, mock) {
|
|
|
|
return factory($, mock);
|
2013-11-02 09:56:20 +01:00
|
|
|
});
|
2013-11-02 12:37:38 +01:00
|
|
|
}(this, function ($, mock) {
|
2013-11-02 09:56:20 +01:00
|
|
|
var utils = {};
|
|
|
|
|
|
|
|
utils.closeAllChatBoxes = function () {
|
2013-11-03 11:02:25 +01:00
|
|
|
var i, chatbox;
|
|
|
|
for (i=converse.chatboxes.models.length-1; i>-1; i--) {
|
2013-11-02 09:56:20 +01:00
|
|
|
chatbox = converse.chatboxes.models[i];
|
|
|
|
converse.chatboxesview.views[chatbox.get('id')].closeChat();
|
|
|
|
}
|
|
|
|
return this;
|
|
|
|
};
|
|
|
|
|
|
|
|
utils.removeAllChatBoxes = function () {
|
|
|
|
var i, chatbox, num_chatboxes = converse.chatboxes.models.length;
|
|
|
|
for (i=num_chatboxes-1; i>-1; i--) {
|
|
|
|
chatbox = converse.chatboxes.models[i];
|
|
|
|
converse.chatboxesview.views[chatbox.get('id')].closeChat();
|
|
|
|
converse.chatboxesview.views[chatbox.get('id')].$el.remove();
|
|
|
|
}
|
|
|
|
converse.chatboxesview.views.controlbox.closeChat();
|
|
|
|
converse.chatboxesview.views.controlbox.$el.remove();
|
|
|
|
return this;
|
|
|
|
};
|
|
|
|
|
2013-11-03 10:38:48 +01:00
|
|
|
utils.initConverse = function () {
|
|
|
|
converse.chatboxes = new converse.ChatBoxes();
|
|
|
|
converse.chatboxesview = new converse.ChatBoxesView({model: converse.chatboxes});
|
|
|
|
converse.onConnected();
|
|
|
|
};
|
|
|
|
|
2013-11-02 09:56:20 +01:00
|
|
|
utils.initRoster = function () {
|
|
|
|
converse.roster.localStorage._clear();
|
|
|
|
converse.initRoster();
|
|
|
|
};
|
|
|
|
|
|
|
|
utils.openControlBox = function () {
|
|
|
|
if (!$("#controlbox").is(':visible')) {
|
|
|
|
$('.toggle-online-users').click();
|
|
|
|
}
|
|
|
|
return this;
|
|
|
|
};
|
|
|
|
|
2013-11-03 10:38:48 +01:00
|
|
|
utils.closeControlBox = function () {
|
|
|
|
if ($("#controlbox").is(':visible')) {
|
|
|
|
$('.toggle-online-users').click();
|
|
|
|
}
|
|
|
|
return this;
|
|
|
|
};
|
|
|
|
|
|
|
|
utils.removeControlBox = function () {
|
|
|
|
$('#controlbox').remove();
|
|
|
|
};
|
|
|
|
|
2013-11-02 09:56:20 +01:00
|
|
|
utils.openContactsPanel = function () {
|
|
|
|
var cbview = converse.chatboxesview.views.controlbox;
|
|
|
|
var $tabs = cbview.$el.find('#controlbox-tabs');
|
|
|
|
$tabs.find('li').first().find('a').click();
|
|
|
|
};
|
|
|
|
|
2013-11-02 12:37:38 +01:00
|
|
|
utils.openRoomsPanel = function () {
|
|
|
|
var cbview = converse.chatboxesview.views.controlbox;
|
|
|
|
var $tabs = cbview.$el.find('#controlbox-tabs');
|
|
|
|
$tabs.find('li').last().find('a').click();
|
|
|
|
};
|
|
|
|
|
2013-11-03 10:38:48 +01:00
|
|
|
utils.openChatBoxes = function (amount) {
|
|
|
|
var i = 0, jid;
|
|
|
|
for (i; i<amount; i++) {
|
|
|
|
jid = mock.cur_names[i].replace(' ','.').toLowerCase() + '@localhost';
|
|
|
|
converse.rosterview.rosteritemviews[jid].openChat(mock.event);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
utils.openChatBoxFor = function (jid) {
|
|
|
|
converse.rosterview.rosteritemviews[jid].openChat(mock.event);
|
|
|
|
};
|
|
|
|
|
2013-11-03 12:24:18 +01:00
|
|
|
utils.clearChatBoxMessages = function (jid) {
|
|
|
|
var view = converse.chatboxesview.views[jid];
|
|
|
|
view.$el.find('.chat-content').empty();
|
|
|
|
view.model.messages.reset().localStorage._clear();
|
|
|
|
};
|
|
|
|
|
2013-11-03 11:02:25 +01:00
|
|
|
utils.createNewChatRoom = function (room, nick) {
|
|
|
|
var controlbox_was_visible = $("#controlbox").is(':visible');
|
|
|
|
utils.openControlBox();
|
|
|
|
utils.openRoomsPanel();
|
|
|
|
var roomspanel = converse.chatboxesview.views.controlbox.roomspanel;
|
|
|
|
var $input = roomspanel.$el.find('input.new-chatroom-name');
|
|
|
|
var $nick = roomspanel.$el.find('input.new-chatroom-nick');
|
|
|
|
var $server = roomspanel.$el.find('input.new-chatroom-server');
|
|
|
|
$input.val('lounge');
|
|
|
|
$nick.val('dummy');
|
|
|
|
$server.val('muc.localhost');
|
|
|
|
roomspanel.$el.find('form').submit();
|
|
|
|
if (!controlbox_was_visible) {
|
|
|
|
utils.closeControlBox();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-11-02 12:37:38 +01:00
|
|
|
utils.createCurrentContacts = function () {
|
|
|
|
// Create current (as opposed to requesting or pending) contacts
|
|
|
|
// for the user's roster.
|
|
|
|
for (i=0; i<mock.cur_names.length; i++) {
|
|
|
|
converse.roster.create({
|
|
|
|
jid: mock.cur_names[i].replace(' ','.').toLowerCase() + '@localhost',
|
2013-11-02 09:56:20 +01:00
|
|
|
subscription: 'both',
|
|
|
|
ask: null,
|
2013-11-02 12:37:38 +01:00
|
|
|
fullname: mock.cur_names[i],
|
|
|
|
is_last: i===(mock.cur_names.length-1)
|
2013-11-02 09:56:20 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
return this;
|
|
|
|
};
|
|
|
|
return utils;
|
|
|
|
}));
|