Commit 1801b876 authored by Thibaut Frain's avatar Thibaut Frain

Revised contactlist gadget

parent ecceec8e
...@@ -110,8 +110,6 @@ module.exports = function (grunt) { ...@@ -110,8 +110,6 @@ module.exports = function (grunt) {
"<%= global_config.src %>/jabberclient/jabberclient.css", "<%= global_config.src %>/jabberclient/jabberclient.css",
"<%= global_config.dest %>/jabberclient_connection/jabberclient_connection.css": "<%= global_config.dest %>/jabberclient_connection/jabberclient_connection.css":
"<%= global_config.src %>/jabberclient_connection/jabberclient_connection.css", "<%= global_config.src %>/jabberclient_connection/jabberclient_connection.css",
"<%= global_config.dest %>/jabberclient_contactlist/jabberclient_contactlist.css":
"<%= global_config.src %>/jabberclient_contactlist/jabberclient_contactlist.css",
"<%= global_config.dest %>/jabberclient_chatbox/jabberclient_chatbox.css": "<%= global_config.dest %>/jabberclient_chatbox/jabberclient_chatbox.css":
"<%= global_config.src %>/jabberclient_chatbox/jabberclient_chatbox.css" "<%= global_config.src %>/jabberclient_chatbox/jabberclient_chatbox.css"
} }
......
...@@ -108,32 +108,15 @@ ...@@ -108,32 +108,15 @@
.push(this.pleaseRedirectMyHash.bind(this)); .push(this.pleaseRedirectMyHash.bind(this));
}) })
.declareMethod('getConnectionJID', function () { .allowPublicAcquisition('getConnectionJID', function () {
return this.getDeclaredGadget('connection') return this.getDeclaredGadget('connection')
.push(function (connection_gadget) { .push(function (connection_gadget) {
return connection_gadget.getConnectionJID(); return connection_gadget.getConnectionJID();
}); });
}) })
.allowPublicAcquisition('getConnectionJID', function () { .allowPublicAcquisition('getHash', function (options) {
return this.getConnectionJid(); return this.aq_pleasePublishMyState(options[0]);
})
.allowPublicAcquisition('getJID', function () {
return this.login_gadget.getJID();
})
.allowPublicAcquisition('openChat', function (jid) {
var gadget = this;
return gadget.getConnectionJID()
.push(function (connection_jid) {
return gadget.aq_pleasePublishMyState({
page: 'chatbox',
current_contact_jid: jid[0],
jid: connection_jid
});
})
.push(this.pleaseRedirectMyHash.bind(this));
}) })
.declareAcquiredMethod("pleaseRedirectMyHash", "pleaseRedirectMyHash") .declareAcquiredMethod("pleaseRedirectMyHash", "pleaseRedirectMyHash")
......
...@@ -75,12 +75,22 @@ ...@@ -75,12 +75,22 @@
}) })
.declareMethod('render', function (options) { .declareMethod('render', function (options) {
var gadget = this; var gadget = this,
messages;
this.props.jid = options.jid; this.props.jid = options.jid;
this.props.current_contact_jid = options.current_contact_jid; this.props.current_contact_jid = options.current_contact_jid;
$('[data-role="page"]').height("100%"); $('[data-role="page"]').height("100%");
$('.gadget-container').height("93%"); $('.gadget-container').height("93%");
$(gadget.__element).find(".talk-box").html("");
if (this.props.talks[this.props.current_contact_jid]) {
messages = this.props.talks[this.props.current_contact_jid].messages;
messages.forEach(function (message) {
displayMessage(message);
});
}
$(this.__element).find(".send-button").click(function (e) { $(this.__element).find(".send-button").click(function (e) {
e.preventDefault(); e.preventDefault();
sendInput(gadget); sendInput(gadget);
......
...@@ -5,7 +5,6 @@ ...@@ -5,7 +5,6 @@
<title>Jabber client</title> <title>Jabber client</title>
<link rel="stylesheet" href="../<%= curl.jquerymobilecss.relative_dest %>"> <link rel="stylesheet" href="../<%= curl.jquerymobilecss.relative_dest %>">
<link rel="stylesheet" href="jabberclient_contactlist.css">
<script src="../<%= curl.jquery.relative_dest %>"></script> <script src="../<%= curl.jquery.relative_dest %>"></script>
<script src="../<%= curl.jquerymobilejs.relative_dest %>"></script> <script src="../<%= curl.jquerymobilejs.relative_dest %>"></script>
...@@ -18,23 +17,29 @@ ...@@ -18,23 +17,29 @@
<script class="offline-contact-template" type="text/x-handlebars-template"> <script class="offline-contact-template" type="text/x-handlebars-template">
<li> <li>
<img src="../jabberclient_contactlist/images/offline.png"> <img src="../jabberclient_contactlist/images/offline.png"
<h2>{{name}}&nbsp&nbsp{{jid}}</h2> alt="offline"
class="ui-li-icon ui-corner-none">
{{name}}&nbsp&nbsp{{jid}}
</li> </li>
</script> </script>
<script class="online-contact-template" type="text/x-handlebars-template"> <script class="online-contact-template" type="text/x-handlebars-template">
<li> <li><a href="{{hash}}">
<img src="../jabberclient_contactlist/images/online.png"> <img src="../jabberclient_contactlist/images/online.png"
<h2>{{name}}&nbsp&nbsp{{jid}}</h2> alt="online"
</li> class="ui-li-icon ui-corner-none">
{{name}}&nbsp&nbsp{{jid}}
</a></li>
</script> </script>
<script class="status-contact-template" type="text/x-handlebars-template"> <script class="status-contact-template" type="text/x-handlebars-template">
<li> <li><a href="{{hash}}">
<img src="../jabberclient_contactlist/images/status.png"> <img src="../jabberclient_contactlist/images/status.png"
<h2>{{name}}&nbsp&nbsp{{jid}}&nbsp&nbsp({{status}})</h2> alt="{{status}}"
</li> class="ui-li-icon ui-corner-none">
{{name}}&nbsp&nbsp{{jid}}&nbsp&nbsp({{status}})
</a></li>
</script> </script>
</head> </head>
......
#contact-list img {
float: left;
margin-right: 5px;
}
#contact-list li {
min-height: 0.625em;
padding-left: 3.25em;
}
#contact-list li > * {
cursor: pointer;
}
#contact-list h2 {
margin: -0.6em 0;
margin-top: -0.3em;
}
\ No newline at end of file
/*global window, rJS, Strophe, $, DOMParser, /*global window, rJS, Strophe, $, DOMParser, RSVP,
XMLSerializer, Handlebars, $iq, $pres*/ XMLSerializer, Handlebars, $iq, $pres*/
/*jslint nomen: true*/ /*jslint nomen: true*/
...@@ -25,7 +25,6 @@ ...@@ -25,7 +25,6 @@
function updateContactElement(gadget, contact) { function updateContactElement(gadget, contact) {
var template, var template,
options = {}; options = {};
if (contact.el) { contact.el.remove(); } if (contact.el) { contact.el.remove(); }
if (contact.offline) { if (contact.offline) {
template = offline_contact_template; template = offline_contact_template;
...@@ -37,10 +36,18 @@ ...@@ -37,10 +36,18 @@
} }
options.jid = contact.jid; options.jid = contact.jid;
options.name = contact.name; options.name = contact.name;
contact.el = $(template(options)); return gadget.getConnectionJID()
contact.el.click(function () { .push(function (connection_jid) {
gadget.openChat(contact.jid); return gadget.getHash({
}); page: "chatbox",
current_contact_jid: contact.jid,
jid: connection_jid
});
})
.push(function (hash) {
options.hash = hash;
contact.el = $(template(options));
});
} }
function updateContact(gadget, contact, presence) { function updateContact(gadget, contact, presence) {
...@@ -54,37 +61,49 @@ ...@@ -54,37 +61,49 @@
contact.status = show.text(); contact.status = show.text();
} }
} }
updateContactElement(gadget, contact); return updateContactElement(gadget, contact);
} }
function Contact(gadget, jid, options) { function createContact(gadget, jid, options) {
this.jid = jid; gadget.contactList.list[jid] = {};
this.offline = true; gadget.contactList.list[jid].jid = jid;
this.status = null; gadget.contactList.list[jid].offline = true;
gadget.contactList.list[jid].status = null;
if (typeof options === 'object') { if (typeof options === 'object') {
$.extend(this, options); $.extend(gadget.contactList.list[jid], options);
} }
updateContactElement(gadget, this); return updateContactElement(gadget, gadget.contactList.list[jid]);
} }
function ContactList(gadget, rosterIq) { function ContactList(gadget, rosterIq) {
var that = this, var that = this,
contactItems = rosterIq.childNodes[0].childNodes, contactItems = rosterIq.childNodes[0].childNodes,
jid, queue = new RSVP.Queue();
options;
this.list = {}; this.list = {};
this.el = $('#contact-list ul'); this.el = $('#contact-list ul');
//that.el.listview();
this.el.hide();
[].forEach.call(contactItems, function (item) { [].forEach.call(contactItems, function (item) {
jid = $(item).attr('jid'); queue
options = {}; .push(function () {
[].forEach.call(item.attributes, function (attr) { var options = {},
options[attr.name] = attr.value; jid = $(item).attr('jid');
}); [].forEach.call(item.attributes, function (attr) {
that.list[jid] = new Contact(gadget, jid, options); options[attr.name] = attr.value;
that.el.append(that.list[jid].el); });
return createContact(gadget, jid, options);
})
.push(function () {
var jid = $(item).attr('jid');
that.el.append(that.list[jid].el);
});
}); });
this.el.listview(); queue
gadget.send($pres().toString()); .push(function () {
that.el.listview();
that.el.show();
gadget.send($pres().toString());
});
} }
function updateContactList(gadget, presence) { function updateContactList(gadget, presence) {
...@@ -92,19 +111,26 @@ ...@@ -92,19 +111,26 @@
contact = gadget.contactList.list[jid]; contact = gadget.contactList.list[jid];
if (contact) { if (contact) {
updateContact(gadget, contact, presence); return updateContact(gadget, contact, presence)
if (contact.offline) { .push(function () {
gadget.contactList.el.append(contact.el); if (contact.offline) {
} else { gadget.contactList.el.append(contact.el);
gadget.contactList.el.prepend(contact.el); } else {
} gadget.contactList.el.prepend(contact.el);
gadget.contactList.el.listview('refresh'); }
gadget.contactList.el.listview('refresh');
});
} }
} }
gadget gadget
.declareAcquiredMethod('getHash', 'getHash')
.declareAcquiredMethod("getConnectionJID", "getConnectionJID")
.declareAcquiredMethod('send', 'send') .declareAcquiredMethod('send', 'send')
.declareAcquiredMethod('openChat', 'openChat') .declareAcquiredMethod('openChat', 'openChat')
.declareMethod('receiveRoster', function (roster) { .declareMethod('receiveRoster', function (roster) {
...@@ -112,7 +138,7 @@ ...@@ -112,7 +138,7 @@
}) })
.declareMethod('receivePresence', function (presence) { .declareMethod('receivePresence', function (presence) {
updateContactList(this, parseXML(presence)); return updateContactList(this, parseXML(presence));
}); });
}($, Strophe, rJS(window))); }($, 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