1
0
mirror of https://github.com/moparisthebest/kaiwa synced 2024-11-24 10:12:18 -05:00
kaiwa/clientapp/views/main.js

160 lines
4.9 KiB
JavaScript
Raw Permalink Normal View History

2013-09-16 14:16:47 -04:00
/*global $, app, me, client*/
2013-08-29 23:38:28 -04:00
"use strict";
var HumanView = require('human-view');
2013-08-29 23:38:28 -04:00
var templates = require('../templates');
var ContactListItem = require('../views/contactListItem');
2013-09-16 19:12:00 -04:00
var MUCListItem = require('../views/mucListItem');
var CallView = require('../views/call');
2013-08-29 23:38:28 -04:00
var ContactRequestItem = require('../views/contactRequest');
2013-08-29 23:38:28 -04:00
module.exports = HumanView.extend({
2013-08-29 23:38:28 -04:00
template: templates.body,
initialize: function () {
this.listenTo(app.state, 'change:title', this.handleTitle);
2013-10-14 17:02:05 -04:00
app.desktop.updateBadge('');
2014-01-23 14:11:56 -05:00
app.state.on('change:deviceID', function () {
console.log('DEVICE ID>>>', app.state.deviceID);
});
2015-02-22 17:43:49 -05:00
app.state.bind('change:connected', this.connectionChange, this);
},
2013-09-03 18:25:14 -04:00
events: {
2013-09-16 14:16:47 -04:00
'click a[href]': 'handleLinkClick',
2014-01-02 03:52:26 -05:00
'click .embed': 'handleEmbedClick',
2013-12-20 06:39:06 -05:00
'click .reconnect': 'handleReconnect',
2013-12-31 20:20:32 -05:00
'click .logout': 'handleLogout',
2014-11-17 18:40:08 -05:00
'keydown #addcontact': 'keyDownAddContact',
'keydown #joinmuc': 'keyDownJoinMUC',
2014-11-17 18:44:39 -05:00
'blur #me .status': 'handleStatusChange',
'keydown .status': 'keyDownStatus'
2013-09-03 18:25:14 -04:00
},
classBindings: {
2015-02-22 17:43:49 -05:00
connected: '#topbar',
cacheStatus: '#updateBar',
2015-02-23 12:24:16 -05:00
hasActiveCall: '#wrapper',
currentPageIsSettings: '.settings'
},
2013-08-29 23:38:28 -04:00
render: function () {
$('head').append(templates.head());
$('body').removeClass('aux');
2013-08-29 23:38:28 -04:00
this.renderAndBind();
2013-09-16 05:19:07 -04:00
this.renderCollection(me.contacts, ContactListItem, this.$('#roster nav'));
2013-09-16 19:12:00 -04:00
this.renderCollection(me.mucs, MUCListItem, this.$('#bookmarks nav'));
this.renderCollection(me.contactRequests, ContactRequestItem, this.$('#contactrequests'));
2013-12-20 06:39:06 -05:00
2015-02-22 17:43:49 -05:00
this.$joinmuc = this.$('#joinmuc');
this.$addcontact = this.$('#addcontact');
this.$meStatus = this.$('#footer .status');
2013-12-20 06:39:06 -05:00
this.registerBindings(me, {
textBindings: {
displayName: '#me .name',
2015-02-09 10:20:28 -05:00
status: '#me .status',
organization: '#organization #orga_name',
2013-12-20 06:39:06 -05:00
},
srcBindings: {
avatar: '#me .avatar'
}
});
2013-08-29 23:38:28 -04:00
return this;
2013-09-03 18:25:14 -04:00
},
2013-09-16 14:16:47 -04:00
handleReconnect: function (e) {
client.connect();
},
2013-09-03 18:25:14 -04:00
handleLinkClick: function (e) {
var t = $(e.target);
var aEl = t.is('a') ? t[0] : t.closest('a')[0];
var local = window.location.host === aEl.host;
var path = aEl.pathname.slice(1);
if (local) {
e.preventDefault();
app.navigate(path);
return false;
}
},
2014-01-01 19:24:11 -05:00
handleEmbedClick: function (e) {
if (e.shiftKey) {
e.preventDefault();
2014-01-02 03:52:26 -05:00
$(e.currentTarget).toggleClass('collapsed');
2014-01-01 19:24:11 -05:00
}
},
handleTitle: function (e) {
document.title = app.state.title;
2013-10-14 17:02:05 -04:00
app.desktop.updateBadge(app.state.badge);
2013-12-20 06:39:06 -05:00
},
handleStatusChange: function (e) {
var text = e.target.textContent;
me.status = text;
client.sendPresence({
status: text,
caps: client.disco.caps
});
2013-12-31 20:20:32 -05:00
},
2014-11-17 18:44:39 -05:00
keyDownStatus: function (e) {
if (e.which === 13 && !e.shiftKey) {
e.target.blur();
return false;
}
},
2013-12-31 20:20:32 -05:00
handleLogout: function (e) {
app.navigate('/logout');
},
handleAddContact: function (e) {
e.preventDefault();
var contact = this.$('#addcontact').val();
if (contact.indexOf('@') == -1 && SERVER_CONFIG.domain)
contact += '@' + SERVER_CONFIG.domain;
if (contact) {
app.api.sendPresence({to: contact, type: 'subscribe'});
}
this.$('#addcontact').val('');
return false;
},
2014-11-17 18:40:08 -05:00
keyDownAddContact: function (e) {
if (e.which === 13 && !e.shiftKey) {
this.handleAddContact(e);
return false;
}
},
handleJoinMUC: function (e) {
e.preventDefault();
var mucjid = this.$('#joinmuc').val();
this.$('#joinmuc').val('');
if (mucjid.indexOf('@') == -1 && SERVER_CONFIG.muc)
mucjid += '@' + SERVER_CONFIG.muc;
me.mucs.add({
id: mucjid,
name: mucjid,
jid: new client.JID(mucjid),
nick: me.nick,
autoJoin: true
});
me.mucs.save();
2015-02-27 13:39:48 -05:00
me.mucs.get(mucjid).join(true);
2014-11-17 18:40:08 -05:00
},
keyDownJoinMUC: function (e) {
if (e.which === 13 && !e.shiftKey) {
this.handleJoinMUC(e);
return false;
}
2015-02-22 17:43:49 -05:00
},
connectionChange: function () {
if (app.state.connected) {
this.$joinmuc.attr("disabled", false);
this.$addcontact.attr("disabled", false);
this.$meStatus.attr("contenteditable", true);
} else {
this.$joinmuc.attr("disabled", "disabled");
this.$addcontact.attr("disabled", "disabled");
this.$meStatus.attr("contenteditable", false);
}
2013-08-29 23:38:28 -04:00
}
});