2015-05-06 04:06:13 +02:00
|
|
|
/* -*- Mode: javascript; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
|
|
|
|
(function() {
|
2015-07-24 22:14:53 +02:00
|
|
|
/* jshint validthis: true */
|
2015-05-06 04:06:13 +02:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
/*
|
|
|
|
* sgSubscribe - Common subscription widget
|
2015-08-06 17:22:23 +02:00
|
|
|
* @restrict attribute
|
2015-05-06 04:06:13 +02:00
|
|
|
* @param {string} sgSubscribe - the folder type
|
|
|
|
* @param {function} sgSubscribeOnSelect - the function to call when subscribing to a folder.
|
|
|
|
* One variable is available: folderData.
|
|
|
|
* @ngInject
|
|
|
|
* @example:
|
|
|
|
|
2015-05-06 18:12:27 +02:00
|
|
|
<md-button sg-subscribe="contact" sg-subscribe-on-select="subscribeToFolder">Subscribe ..</md-button>
|
2015-05-06 04:06:13 +02:00
|
|
|
*/
|
|
|
|
sgSubscribe.$inject = ['User'];
|
|
|
|
function sgSubscribe(User) {
|
|
|
|
return {
|
|
|
|
restrict: 'A',
|
|
|
|
scope: {
|
|
|
|
folderType: '@sgSubscribe',
|
|
|
|
onFolderSelect: '&sgSubscribeOnSelect'
|
|
|
|
},
|
|
|
|
replace: false,
|
|
|
|
bindToController: true,
|
|
|
|
controller: sgSubscribeDialogController,
|
2015-08-06 17:22:23 +02:00
|
|
|
controllerAs: '$sgSubscribeDialogController',
|
2015-05-06 04:06:13 +02:00
|
|
|
link: link
|
2015-07-24 22:14:53 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function link(scope, element, attrs, controller) {
|
|
|
|
var inputEl = element.find('input');
|
|
|
|
element.on('click', controller.showDialog);
|
2015-05-06 18:12:27 +02:00
|
|
|
}
|
2015-05-06 04:06:13 +02:00
|
|
|
|
2015-05-06 18:12:27 +02:00
|
|
|
/**
|
|
|
|
* @ngInject
|
|
|
|
*/
|
|
|
|
sgSubscribeDialogController.$inject = ['$mdDialog'];
|
|
|
|
function sgSubscribeDialogController($mdDialog) {
|
|
|
|
var vm = this;
|
|
|
|
vm.showDialog = function() {
|
|
|
|
$mdDialog.show({
|
|
|
|
templateUrl: '../Contacts/UIxContactsUserFolders',
|
|
|
|
clickOutsideToClose: true,
|
|
|
|
locals: {
|
|
|
|
folderType: vm.folderType,
|
|
|
|
onFolderSelect: vm.onFolderSelect
|
|
|
|
},
|
|
|
|
controller: sgSubscribeController,
|
2015-08-06 17:22:23 +02:00
|
|
|
controllerAs: 'subscribe'
|
2015-05-06 18:12:27 +02:00
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
2015-05-06 04:06:13 +02:00
|
|
|
|
2015-05-06 18:12:27 +02:00
|
|
|
/**
|
|
|
|
* @ngInject
|
|
|
|
*/
|
2015-09-17 16:37:35 +02:00
|
|
|
sgSubscribeController.$inject = ['$mdDialog', 'folderType', 'onFolderSelect', 'User'];
|
|
|
|
function sgSubscribeController($mdDialog, folderType, onFolderSelect, User) {
|
2015-05-06 18:12:27 +02:00
|
|
|
var vm = this;
|
2015-08-06 17:22:23 +02:00
|
|
|
|
2015-05-06 18:12:27 +02:00
|
|
|
vm.selectedUser = null;
|
2016-02-29 21:13:09 +01:00
|
|
|
vm.users = [];
|
2015-05-06 04:06:13 +02:00
|
|
|
|
2015-05-06 18:12:27 +02:00
|
|
|
vm.searchTextOptions = {
|
|
|
|
updateOn: 'default blur',
|
|
|
|
debounce: {
|
|
|
|
default: 300,
|
|
|
|
blur: 0
|
|
|
|
}
|
|
|
|
};
|
2015-05-06 04:06:13 +02:00
|
|
|
|
2016-02-29 21:13:09 +01:00
|
|
|
vm.onChange = function(input) {
|
|
|
|
User.$filter(vm.searchText, null, { results: vm.users }).then(function(users) {
|
|
|
|
input.$setValidity('matches', users.length > 0);
|
|
|
|
input.$setTouched();
|
2015-08-06 17:22:23 +02:00
|
|
|
if (vm.selectedUser) {
|
|
|
|
// If selected user is no longer part of the matching users, unselect it
|
2016-02-29 21:13:09 +01:00
|
|
|
if (_.isUndefined(_.find(users, function(user) {
|
2015-08-06 17:22:23 +02:00
|
|
|
return user.uid == vm.selectedUser.uid;
|
|
|
|
}))) {
|
|
|
|
vm.selectedUser = null;
|
|
|
|
}
|
|
|
|
}
|
2015-05-06 18:12:27 +02:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
vm.selectUser = function(i) {
|
2015-08-06 17:22:23 +02:00
|
|
|
if (vm.selectedUser == vm.users[i]) {
|
|
|
|
vm.selectedUser = null;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Fetch folders of specific type for selected user
|
|
|
|
vm.users[i].$folders(folderType).then(function() {
|
|
|
|
vm.selectedUser = vm.users[i];
|
|
|
|
});
|
|
|
|
}
|
2015-05-06 18:12:27 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
// Callback upon subscription to a folder
|
|
|
|
vm.selectFolder = function(folder) {
|
|
|
|
onFolderSelect({folderData: folder});
|
|
|
|
};
|
2015-09-17 16:37:35 +02:00
|
|
|
|
|
|
|
vm.close = function() {
|
|
|
|
$mdDialog.hide();
|
|
|
|
};
|
2015-05-06 04:06:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
angular
|
|
|
|
.module('SOGo.Common')
|
|
|
|
.directive('sgSubscribe', sgSubscribe);
|
2015-05-06 18:12:27 +02:00
|
|
|
})();
|