2016-03-19 11:02:13 +00:00
|
|
|
angular.module('contactsApp')
|
|
|
|
.controller('grouplistCtrl', function($scope, ContactService, SearchService, $routeParams) {
|
2016-03-17 19:23:19 +00:00
|
|
|
var ctrl = this;
|
2016-02-12 12:48:46 +00:00
|
|
|
|
2016-03-17 19:23:19 +00:00
|
|
|
var initialGroups = [t('contacts', 'All contacts'), t('contacts', 'Not grouped')];
|
|
|
|
|
|
|
|
ctrl.groups = initialGroups;
|
2016-02-12 12:48:46 +00:00
|
|
|
|
|
|
|
ContactService.getGroups().then(function(groups) {
|
2016-03-17 19:23:19 +00:00
|
|
|
ctrl.groups = _.unique(initialGroups.concat(groups));
|
2016-02-12 12:48:46 +00:00
|
|
|
});
|
|
|
|
|
2016-03-17 19:23:19 +00:00
|
|
|
ctrl.getSelected = function() {
|
|
|
|
return $routeParams.gid;
|
|
|
|
};
|
|
|
|
|
2016-04-11 02:53:51 +00:00
|
|
|
// Update groupList on contact add/delete/update
|
|
|
|
ContactService.registerObserverCallback(function() {
|
|
|
|
$scope.$apply(function() {
|
|
|
|
ContactService.getGroups().then(function(groups) {
|
|
|
|
ctrl.groups = _.unique(initialGroups.concat(groups));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-03-17 19:23:19 +00:00
|
|
|
ctrl.setSelected = function (selectedGroup) {
|
2016-03-14 23:58:51 +00:00
|
|
|
SearchService.cleanSearch();
|
2016-03-17 19:23:19 +00:00
|
|
|
$routeParams.gid = selectedGroup;
|
2016-02-18 16:31:46 +00:00
|
|
|
};
|
2016-03-16 19:37:40 +00:00
|
|
|
});
|