aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuillaume Horel <guillaume.horel@gmail.com>2012-04-06 19:17:54 -0400
committerGuillaume Horel <guillaume.horel@gmail.com>2012-04-06 19:17:54 -0400
commit0576a6276cfbf435fba4fd8d8b2e984ab91104b3 (patch)
tree4fea21d0dcdd9bfa1edad00143baa1b6e153bbd4
parent894f72e64e1557e74a9395682eeb200b63eea0d2 (diff)
downloadalias-0576a6276cfbf435fba4fd8d8b2e984ab91104b3.tar.gz
Finally fixed the angular code!
-rw-r--r--alias-angular/app/index.html18
-rw-r--r--alias-angular/app/js/controllers.js43
-rw-r--r--alias-angular/app/js/services.js25
3 files changed, 56 insertions, 30 deletions
diff --git a/alias-angular/app/index.html b/alias-angular/app/index.html
index 00909a1..f6f1e4f 100644
--- a/alias-angular/app/index.html
+++ b/alias-angular/app/index.html
@@ -6,11 +6,19 @@
<link rel="stylesheet" href="css/app.css"/>
</head>
<body>
- <div ng-controller="RosterCtl">
- <ul>
- <li ng-repeat="contact in contacts">{{contact}}</li>
- </ul>
- </div>
+ <!-- var query = $iq({type : 'get'}).c('query', {xmlns : Strophe.NS.ROSTER}); -->
+ <!-- connection.sendIQ(query, $scope.onRoster); -->
+ <form ng-submit="login()" ng-controller="ConnectCtl">
+ Username: <input type="text" ng-model="username"/>
+ Password: <input type="text" ng-model="password"/>
+ <input type="submit" value="Login"/> <!-- disabled="{{username=='' || password==''}}"> -->
+ </form>
+
+ <div ng-controller="RosterCtl">
+ <ul>
+ <li ng-repeat="contact in contacts">{{contact}}</li>
+ </ul>
+ </div>
<script src="lib/angular/angular.js"></script>
<script src="lib/config.js"></script>
<script src="js/alias.js"></script>
diff --git a/alias-angular/app/js/controllers.js b/alias-angular/app/js/controllers.js
index 7eb5cbd..5477e57 100644
--- a/alias-angular/app/js/controllers.js
+++ b/alias-angular/app/js/controllers.js
@@ -1,9 +1,34 @@
'use strict';
/* App Controllers */
-function RosterCtl($scope, connection, $log) {
+function ConnectCtl($scope, StropheSrv, $log, $rootScope) {
+ $scope.username = 'thrasibule@alias.im';
+ $scope.password = 'Jdiema;06';
+ $scope.connected = false;
+ function connect_callback(status){
+ if ( status == Strophe.Status.CONNECTING ) {
+ $log.log('Strophe is connecting.');
+ } else if ( status == Strophe.Status.CONNFAIL ) {
+ $log.log('Strophe failed to connect.');
+ } else if ( status == Strophe.Status.DISCONNECTING ) {
+ $log.log('Strophe is disconnecting.');
+ } else if ( status == Strophe.Status.DISCONNECTED ) {
+ $log.log('Strophe is disconnected.');
+ } else if ( status == Strophe.Status.CONNECTED ) {
+ $log.log('Strophe is connected.');
+ $rootScope.$broadcast('connected', true);
+ }
+ };
+ $scope.login = function () {
+ StropheSrv.login($scope.username, $scope.password, connect_callback);
+ };
+}
+
+ConnectCtl.$inject = ['$scope', 'StropheSrv', '$log', '$rootScope'];
+
+function RosterCtl($scope, StropheSrv, $log) {
$scope.contacts = [];
- $scope.onRoster = function(iq) {
+ function onRoster(iq) {
var elems = iq.getElementsByTagName('query');
var query = elems[0];
Strophe.forEachChild(query, 'item', function(item){
@@ -11,10 +36,12 @@ function RosterCtl($scope, connection, $log) {
var name = item.getAttribute('name') || jid;
$scope.contacts.push(name);
});
- return true;
};
- $log.log('sending the stanza');
- var query = $iq({type : 'get'}).c('query', {xmlns : Strophe.NS.ROSTER});
- $scope.$on('connected',function () {$log('caught connected event');connection.sendIQ(query, $scope.onRoster);});
- };
-RosterCtl.$inject = ['$scope','connection','$log']; \ No newline at end of file
+ $scope.$on('connected', function() {$scope.getRoster();});
+ $scope.getRoster = function () {
+ var query = $iq({type : 'get'}).c('query', {xmlns : Strophe.NS.ROSTER});
+ StropheSrv.sendIQ(query, onRoster);
+ };
+ }
+
+RosterCtl.$inject = ['$scope','StropheSrv','$log']; \ No newline at end of file
diff --git a/alias-angular/app/js/services.js b/alias-angular/app/js/services.js
index 1a3a96b..7b9e285 100644
--- a/alias-angular/app/js/services.js
+++ b/alias-angular/app/js/services.js
@@ -1,25 +1,16 @@
'use strict';
angular.module('Alias.services', [], function($provide) {
- $provide.factory('connection', ['$log', '$rootScope',
+ $provide.factory('StropheSrv', ['$log', '$rootScope',
function($log, $rootScope) {
- function connect_callback(status){
- if ( status == Strophe.Status.CONNECTING ) {
- $log.log('Strophe is connecting.');
- } else if ( status == Strophe.Status.CONNFAIL ) {
- $log.log('Strophe failed to connect.');
- } else if ( status == Strophe.Status.DISCONNECTING ) {
- $log.log('Strophe is disconnecting.');
- } else if ( status == Strophe.Status.DISCONNECTED ) {
- $log.log('Strophe is disconnected.');
- } else if ( status == Strophe.Status.CONNECTED ) {
- $log.log('Strophe is connected.');
- cb();
- }
- };
var connection = new Strophe.Connection(BOSH_SERVICE);
- return function(cb) {
- connection.connect(NAME, PASSWORD, connect_callback);
+ this.login = function(name, password, connect_callback) {
+ connection.connect(name, password, function(status){ $rootScope.$apply(connect_callback(status));});
+ };
+ this.sendIQ = function(query, callback) {
+ connection.sendIQ(query, function(data){
+ $rootScope.$apply(callback(data));});
};
+ return this;
}]);
}); \ No newline at end of file