diff options
| -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 |
