diff options
| author | Thibaut Horel <thibaut.horel@gmail.com> | 2012-03-29 22:56:21 -0700 |
|---|---|---|
| committer | Thibaut Horel <thibaut.horel@gmail.com> | 2012-03-29 22:56:21 -0700 |
| commit | 6ccfa0c2ad6c4cfc4a9be8fb25a69100f8fe3f14 (patch) | |
| tree | 9a3d38aeaf1bffe5ba723cb823f711d99d02edd6 | |
| parent | 6a6bf6f782b5c1f9c50735e77fa4cfbee7ec4fde (diff) | |
| download | alias-6ccfa0c2ad6c4cfc4a9be8fb25a69100f8fe3f14.tar.gz | |
Basic roster loading with JavascriptMVC
| -rw-r--r-- | webclient/alias/alias.html | 3 | ||||
| -rw-r--r-- | webclient/alias/models/contact.js | 29 |
2 files changed, 16 insertions, 16 deletions
diff --git a/webclient/alias/alias.html b/webclient/alias/alias.html index 01cae99..9e338a9 100644 --- a/webclient/alias/alias.html +++ b/webclient/alias/alias.html @@ -13,6 +13,9 @@ <div id="roster"> </div> + <script type='text/ejs' id='contactEJS'> +<li <%= this %> ><%= name %></li> +</script> <script type='text/javascript' src='../steal/steal.js?alias'></script> </body> </html> diff --git a/webclient/alias/models/contact.js b/webclient/alias/models/contact.js index 53c11ed..924ccf0 100644 --- a/webclient/alias/models/contact.js +++ b/webclient/alias/models/contact.js @@ -1,38 +1,35 @@ steal('jquery/model/list', 'jquery/controller', + 'jquery/view/ejs', function(){ $.Model('Contact', { - - }, {}); + template: "contact.ejs", - $.Model.List('Contact.List', { - - }, {}); + findAll: function(params,success,error) { + var query = $iq({type : 'get'}).c('query', {xmlns : Strophe.NS.ROSTER}); + params.connection.sendIQ(query, success); + } + }, {} ); - $.Controller('Roster', { + $.Controller('Roster', {}, { onRoster: function(iq) { var elems = iq.getElementsByTagName('query'); var query = elems[0]; Strophe.forEachChild(query, 'item', function(item){ var jid = item.getAttribute('jid'); var name = item.getAttribute('name') || jid; - var id = jid; - steal.dev.log("<li id='" + id + "' class='roster-contact offline'>" - + "<div class='roster-name'>" + name + "</div>" - + "<div class='roster-jid'>" + jid + "</div></li>"); + var contact = new Contact({jid: jid, name: name}); + $("#roster").append('contactEJS',contact); }); return true; }, - - }, { - + init: function() { - var roster = $iq({type : 'get'}).c('query', {xmlns : Strophe.NS.ROSTER}); - this.options.connection.sendIQ(roster, Roster.onRoster); + Contact.findAll({connection: this.options.connection},this.onRoster) }, - + }); |
