mirror of https://github.com/nextcloud/contacts
52 lines
999 B
JavaScript
52 lines
999 B
JavaScript
angular.module('contactsApp')
|
|
.service('SearchService', function() {
|
|
var searchTerm = '';
|
|
|
|
var observerCallbacks = [];
|
|
|
|
this.registerObserverCallback = function(callback) {
|
|
observerCallbacks.push(callback);
|
|
};
|
|
|
|
var notifyObservers = function(eventName) {
|
|
var ev = {
|
|
event:eventName,
|
|
searchTerm:searchTerm
|
|
};
|
|
angular.forEach(observerCallbacks, function(callback) {
|
|
callback(ev);
|
|
});
|
|
};
|
|
|
|
var SearchProxy = {
|
|
attach: function(search) {
|
|
search.setFilter('contacts', this.filterProxy);
|
|
},
|
|
filterProxy: function(query) {
|
|
searchTerm = query;
|
|
notifyObservers('changeSearch');
|
|
}
|
|
};
|
|
|
|
this.getSearchTerm = function() {
|
|
return searchTerm;
|
|
};
|
|
|
|
this.cleanSearch = function() {
|
|
if (!_.isUndefined($('.searchbox'))) {
|
|
$('.searchbox')[0].reset();
|
|
}
|
|
searchTerm = '';
|
|
};
|
|
|
|
|
|
|
|
if (!_.isUndefined($('.searchbox'))) {
|
|
$('.searchbox')[0].addEventListener('keypress', function(e) {
|
|
if(e.keyCode === 13) {
|
|
notifyObservers('submitSearch');
|
|
}
|
|
});
|
|
}
|
|
});
|