From dc5060263aba3980d8577463ef818477ad9f3cae Mon Sep 17 00:00:00 2001 From: Zaran Date: Tue, 7 Feb 2012 17:00:50 -0800 Subject: Beginning of the rewriting. Starting with the Roster. Using a controller for the Roster, a Model for each contact and a Model.List. --- webclient/alias/alias.html | 20 ++----- webclient/alias/alias.js | 36 +++++++++--- webclient/alias/fixtures/fixtures.js | 2 +- webclient/alias/models/contact.js | 40 +++++++++++++ webclient/alias/models/models.js | 2 +- webclient/alias/test/qunit/contact_test.js | 51 +++++++++++++++++ webclient/alias/test/qunit/qunit.js | 2 +- webclient/config.js.sample | 4 ++ webclient/index.html | 91 ------------------------------ 9 files changed, 132 insertions(+), 116 deletions(-) create mode 100644 webclient/alias/models/contact.js create mode 100644 webclient/alias/test/qunit/contact_test.js create mode 100644 webclient/config.js.sample delete mode 100644 webclient/index.html diff --git a/webclient/alias/alias.html b/webclient/alias/alias.html index 7d8da8d..01cae99 100644 --- a/webclient/alias/alias.html +++ b/webclient/alias/alias.html @@ -9,20 +9,10 @@
  • Steal plugins and files in alias/alias.js.
  • Change to production mode by changing steal.js to steal.production.js in this file.
  • -
    - Here are some links to get you started: - -
    - Join the community: - + +
    + +
    - \ No newline at end of file + diff --git a/webclient/alias/alias.js b/webclient/alias/alias.js index 77c001e..d07ece5 100644 --- a/webclient/alias/alias.js +++ b/webclient/alias/alias.js @@ -1,7 +1,29 @@ -steal( - './alias.css', // application CSS file - './models/models.js', // steals all your models - './fixtures/fixtures.js', // sets up fixtures for your models - function(){ // configure your application - - }) \ No newline at end of file +steal('./alias.css', + './models/models.js', + './fixtures/fixtures.js', + 'lib/strophe/src/md5.js', + 'lib/strophe/src/sha1.js', + 'lib/strophe/src/base64.js', + 'lib/strophe/src/core.js', + 'config.js', + function(){ + function connect_callback(status){ + if ( status == Strophe.Status.CONNECTING ) { + steal.dev.log('Strophe is connecting.'); + } else if ( status == Strophe.Status.CONNFAIL ) { + steal.dev.log('Strophe failed to connect.'); + } else if ( status == Strophe.Status.DISCONNECTING ) { + steal.dev.log('Strophe is disconnecting.'); + } else if ( status == Strophe.Status.DISCONNECTED ) { + steal.dev.log('Strophe is disconnected.'); + } else if ( status == Strophe.Status.CONNECTED ) { + steal.dev.log('Strophe is connected.'); + $("#roster").roster({connection: connection}); + } + }; + // configure your application + var connection = new Strophe.Connection(BOSH_SERVICE); + connection.connect(NAME, PASSWORD, connect_callback); + + + }) \ No newline at end of file diff --git a/webclient/alias/fixtures/fixtures.js b/webclient/alias/fixtures/fixtures.js index 1e662ac..636837a 100644 --- a/webclient/alias/fixtures/fixtures.js +++ b/webclient/alias/fixtures/fixtures.js @@ -2,4 +2,4 @@ steal("jquery/dom/fixture", function(){ -}) \ No newline at end of file +}) diff --git a/webclient/alias/models/contact.js b/webclient/alias/models/contact.js new file mode 100644 index 0000000..53c11ed --- /dev/null +++ b/webclient/alias/models/contact.js @@ -0,0 +1,40 @@ +steal('jquery/model/list', + 'jquery/controller', + +function(){ + + $.Model('Contact', { + + }, {}); + + $.Model.List('Contact.List', { + + }, {}); + + $.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("
  • " + + "
    " + name + "
    " + + "
    " + jid + "
  • "); + }); + return true; + }, + + }, { + + init: function() { + var roster = $iq({type : 'get'}).c('query', {xmlns : Strophe.NS.ROSTER}); + this.options.connection.sendIQ(roster, Roster.onRoster); + }, + + }); + + + +}) \ No newline at end of file diff --git a/webclient/alias/models/models.js b/webclient/alias/models/models.js index 9224b68..e0f0ec7 100644 --- a/webclient/alias/models/models.js +++ b/webclient/alias/models/models.js @@ -1,2 +1,2 @@ // steal model files -steal("jquery/model") \ No newline at end of file +steal("jquery/model", './contact.js') \ No newline at end of file diff --git a/webclient/alias/test/qunit/contact_test.js b/webclient/alias/test/qunit/contact_test.js new file mode 100644 index 0000000..e4c8b23 --- /dev/null +++ b/webclient/alias/test/qunit/contact_test.js @@ -0,0 +1,51 @@ +steal("funcunit/qunit", "alias/fixtures", "alias/models/contact.js", function(){ + module("Model: Alias.Models.Contact") + + test("findAll", function(){ + expect(4); + stop(); + Alias.Models.Contact.findAll({}, function(contacts){ + ok(contacts) + ok(contacts.length) + ok(contacts[0].name) + ok(contacts[0].description) + start(); + }); + + }) + + test("create", function(){ + expect(3) + stop(); + new Alias.Models.Contact({name: "dry cleaning", description: "take to street corner"}).save(function(contact){ + ok(contact); + ok(contact.id); + equals(contact.name,"dry cleaning") + contact.destroy() + start(); + }) + }) + test("update" , function(){ + expect(2); + stop(); + new Alias.Models.Contact({name: "cook dinner", description: "chicken"}). + save(function(contact){ + equals(contact.description,"chicken"); + contact.update({description: "steak"},function(contact){ + equals(contact.description,"steak"); + contact.destroy(); + start(); + }) + }) + + }); + test("destroy", function(){ + expect(1); + stop(); + new Alias.Models.Contact({name: "mow grass", description: "use riding mower"}). + destroy(function(contact){ + ok( true ,"Destroy called" ) + start(); + }) + }) +}) \ No newline at end of file diff --git a/webclient/alias/test/qunit/qunit.js b/webclient/alias/test/qunit/qunit.js index 91674b7..f025b68 100644 --- a/webclient/alias/test/qunit/qunit.js +++ b/webclient/alias/test/qunit/qunit.js @@ -1 +1 @@ -steal("funcunit/qunit", "./alias_test.js"); \ No newline at end of file +steal("funcunit/qunit", "./alias_test.js", './contact_test.js'); \ No newline at end of file diff --git a/webclient/config.js.sample b/webclient/config.js.sample new file mode 100644 index 0000000..3a0aae6 --- /dev/null +++ b/webclient/config.js.sample @@ -0,0 +1,4 @@ +var BOSH_SERVICE = 'http://alias.im/http-bind'; +var server_component = 'social.alias.im'; +var NAME = "zaran@alias.im"; +var PASSWORD = "xxxx"; \ No newline at end of file diff --git a/webclient/index.html b/webclient/index.html deleted file mode 100644 index 85ff64e..0000000 --- a/webclient/index.html +++ /dev/null @@ -1,91 +0,0 @@ - - - - - - Alias - - - - - - - - - - - - - - - - - - - - - - - -
    -
    -
    test
    -
    - - - -
    -

    Connection

    -
    -

    - You can register with any Jabber account. -
    No account? Then you can - register on this server. -

    -
    -

    - - -

    -

    - - -

    -

    - -

    -
    -
    - -
    -

    Contacts

    -
    - -
      -
    -
    -
    - -