Commit 3bd308e0 authored by Thibaut Frain's avatar Thibaut Frain

Added jabber contactlist gadget

parent aefceeff
......@@ -100,7 +100,9 @@ module.exports = function (grunt) {
"<%= global_config.dest %>/presentation_viewer/presentation_viewer.css":
"<%= global_config.src %>/presentation_viewer/presentation_viewer.css",
"<%= global_config.dest %>/jabber_login/jabber_login.css":
"<%= global_config.src %>/jabber_login/jabber_login.css"
"<%= global_config.src %>/jabber_login/jabber_login.css",
"<%= global_config.dest %>/jabber_contactlist/jabber_contactlist.css":
"<%= global_config.src %>/jabber_contactlist/jabber_contactlist.css"
}
}
},
......@@ -182,6 +184,11 @@ module.exports = function (grunt) {
src: "<%= global_config.lib %>/URI.js",
relative_dest: "lib/URI.js",
dest: "<%= global_config.dest %>/<%= copy.uri.relative_dest %>"
},
handlebars: {
src: 'node_modules/handlebars/dist/handlebars.min.js',
relative_dest: 'lib/handlebars.min.js',
dest: "<%= global_config.dest %>/<%= copy.handlebars.relative_dest %>"
}
},
......
......@@ -4,10 +4,11 @@
"version": "0.2.0",
"description": "The Free HTML5 Cloud Office",
"dependencies": {
"rsvp": "git+http://git.erp5.org/repos/rsvp.js.git",
"handlebars": "^2.0.0-alpha.4",
"jio": "git+http://git.erp5.org/repos/jio.git",
"renderjs": "git+http://git.erp5.org/repos/renderjs.git",
"uritemplate": "git+http://git.erp5.org/repos/uritemplate-js.git",
"jio": "git+http://git.erp5.org/repos/jio.git"
"rsvp": "git+http://git.erp5.org/repos/rsvp.js.git",
"uritemplate": "git+http://git.erp5.org/repos/uritemplate-js.git"
},
"devDependencies": {
"grunt": "~0.4.1",
......
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Jabber client</title>
<link rel="stylesheet" href="../<%= curl.jquerymobilecss.relative_dest %>">
<link rel="stylesheet" href="jabber_contactlist.css">
<script src="../<%= curl.jquery.relative_dest %>"></script>
<script src="../<%= curl.jquerymobilejs.relative_dest %>"></script>
<script src="../<%= copy.rsvp.relative_dest %>"></script>
<script src="../<%= copy.renderjs.relative_dest %>"></script>
<script src="../<%= curl.strophejs.relative_dest %>"></script>
<script src="../<%= copy.handlebars.relative_dest %>"></script>
<script src="jabber_contactlist.js"></script>
</head>
<body>
<div id=contact-list><ul data-role="listview" data-inset="true"></ul></div>
<script id="contact-template" type="text/x-handlebars-template">
<li>
{{#if offline}}
<img src="images/offline.png">
{{else}}
{{#if status}}
<img src="images/misc.png">
{{else}}
<img src="images/online.png">
{{/if}}
{{/if}}
<h2>{{name}}&nbsp&nbsp{{#if status}}({{status}}){{/if}}</h2>
</li>
</script>
</body>
</html>
#contact-list img {
float: left;
margin-right: 5px;
}
#contact-list li {
min-height: 0.625em;
padding-left: 3.25em;
}
#contact-list h2 {
margin: -0.6em 0;
margin-top: -0.3em;
}
\ No newline at end of file
/*global window, rJS, Strophe, $, DOMParser,
XMLSerializer, Handlebars, $iq, $pres*/
(function ($, Strophe, gadget) {
"use strict";
var contactTemplate, main;
function parseXML(xmlString) {
return new DOMParser()
.parseFromString(xmlString, 'text/xml')
.children[0];
}
function Contact(jid, options) {
this.jid = jid;
this.offline = true;
this.status = null;
if (typeof options === 'object') {
$.extend(this, options);
}
this.updateElement();
}
Contact.prototype.update = function (presence) {
this.status = null;
if (presence.getAttribute('type') === 'unavailable') {
this.offline = true;
} else {
var show = $(presence).find('show');
this.offline = false;
if (show.length !== 0 && show.text() !== "online") {
this.status = show.text();
}
}
this.updateElement();
};
Contact.prototype.updateElement = function () {
var that = this;
if (this.el) { this.el.remove(); }
this.el = $(contactTemplate({
jid: this.jid,
name: this.name,
offline: this.offline,
status: this.status
}));
this.el.click(function () {
main.openChat(that.jid);
});
};
function ContactList(rosterIq) {
var that = this,
contactItems = rosterIq.childNodes[0].childNodes,
jid,
options;
this.list = {};
this.el = $('#contact-list ul');
[].forEach.call(contactItems, function (item) {
jid = $(item).attr('jid');
options = {};
[].forEach.call(item.attributes, function (attr) {
options[attr.name] = attr.value;
});
that.list[jid] = new Contact(jid, options);
that.el.append(that.list[jid].el);
that.el.listview('refresh');
});
main.send($pres().toString());
}
ContactList.prototype.update = function (presence) {
var jid = Strophe.getBareJidFromJid($(presence).attr('from')),
contact = this.list[jid];
if (contact) {
contact.update(presence);
if (contact.offline) {
this.el.append(contact.el);
} else {
this.el.prepend(contact.el);
}
this.el.listview('refresh');
}
};
gadget
.declareAcquiredMethod('send', 'send')
.declareAcquiredMethod('openChat', 'openChat')
.declareMethod('receiveRoster', function (roster) {
this.contactList = new ContactList(parseXML(roster));
})
.declareMethod('receivePresence', function (presence) {
this.contactList.update(parseXML(presence));
})
.declareMethod('receive', function (message) {
var that = this,
body = parseXML(message);
if ($(body).find('iq').length !== 0 &&
$(body).find('query').length !== 0 &&
$(body).find('query').attr('xmlns') === "jabber:iq:roster") {
this.contactList = new ContactList($(body).find('iq')[0]);
} else if ($(body).find('presence')) {
$(body).find('presence').each(function (index, elem) {
that.contactList.update(elem);
});
}
})
.declareMethod('updatePresence', function (presence) {
presence = parseXML(presence);
this.contactList.update(presence);
})
.ready(function (g) {
main = g;
contactTemplate = Handlebars.compile($('#contact-template').html());
});
}($, Strophe, rJS(window)));
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment