diff options
| author | Guillaume Horel <guillaume.horel@gmail.com> | 2012-04-20 00:23:18 -0400 |
|---|---|---|
| committer | Guillaume Horel <guillaume.horel@gmail.com> | 2012-04-20 00:23:18 -0400 |
| commit | 3febf7cab87edf7045097a0cb9a06e5343ac5f6e (patch) | |
| tree | e7d5143bc2c18fcb56bf72b98f3cd8924566db4d | |
| parent | 1cb203c4e3d2114fca928729f049b259d4b05a66 (diff) | |
| download | alias-3febf7cab87edf7045097a0cb9a06e5343ac5f6e.tar.gz | |
filter the offline contacts
| -rw-r--r-- | alias-angular/app/index.html | 6 | ||||
| -rw-r--r-- | alias-angular/app/js/filters.js | 31 |
2 files changed, 27 insertions, 10 deletions
diff --git a/alias-angular/app/index.html b/alias-angular/app/index.html index cffa822..be7a664 100644 --- a/alias-angular/app/index.html +++ b/alias-angular/app/index.html @@ -23,11 +23,13 @@ <form class="form-inline"> <div class="input-prepend"> <span class="add-on"><i class="icon-search"></i></span><!-- - --><input class="span2" type="text" placeholder="Search" ng-model="query.jid"/> + --><input class="span2" type="text" placeholder="Search" ng-model="query"/> </div> </form> + <input type="checkbox" ng-model="checkoffline"/> + <span>Show offline contacts</span> <ul> - <li ng-repeat="contact in get_contacts() | filter:query |orderBy:'status'">{{contact.name}} <small>{{contact.jid}} {{contact.status}}</small></li> + <li ng-repeat="contact in get_contacts() | hideoffline:checkoffline | rosterFilter:query|orderBy:'status'">{{contact.name}} <small>{{contact.jid}} {{contact.status}}</small></li> </ul> </div> <script src="lib/angular/angular.js"></script> diff --git a/alias-angular/app/js/filters.js b/alias-angular/app/js/filters.js index ec78870..3321999 100644 --- a/alias-angular/app/js/filters.js +++ b/alias-angular/app/js/filters.js @@ -4,16 +4,31 @@ angular.module('Alias.filters', []). filter('rosterFilter', function (){ return function(contacts, query) { - if(!query || query.length == 0) { - return contacts + if(!query) { + return contacts; } else { - var filtered = {}; - $.each( contacts, function(k,v) { - if(k.indexOf(query) > -1) { - filtered[k] = v; + return _.filter(contacts, function(contact) { + if ( contact.jid.indexOf(query) > -1) { + return true; + } else { + if (_.has(contact, 'name') && + contact.name.indexOf(query) >-1) { + return true; + } else { + return false; + } } }); - return filtered; } - } + }; + }).filter('hideoffline', function() { + return function(contacts, checkoffline) { + if(checkoffline) { + return contacts; + } else { + return _.filter(contacts, function(contact) { + return contact.status != "offline"; + }); + }; + }; });
\ No newline at end of file |
