summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.gitignore2
-rw-r--r--.travis.yml1
-rw-r--r--js/public/script.js1627
3 files changed, 2 insertions, 1628 deletions
diff --git a/.gitignore b/.gitignore
index bb64915a..a99acd51 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,3 @@
node_modules
build
-
+js/public
diff --git a/.travis.yml b/.travis.yml
index 661efadd..a1b3fc6f 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -9,6 +9,7 @@ branches:
script:
- node_modules/.bin/gulp eslint
+ - node_modules/.bin/gulp
- make appstore_package
deploy:
diff --git a/js/public/script.js b/js/public/script.js
deleted file mode 100644
index 4391d777..00000000
--- a/js/public/script.js
+++ /dev/null
@@ -1,1627 +0,0 @@
-/**
- * ownCloud - contacts
- *
- * This file is licensed under the Affero General Public License version 3 or
- * later. See the COPYING file.
- *
- * @author Hendrik Leppelsack <hendrik@leppelsack.de>
- * @copyright Hendrik Leppelsack 2015
- */
-
-var app = angular.module('contactsApp', ['uuid4', 'angular-cache', 'ngRoute', 'ui.bootstrap', 'ui.select', 'ngSanitize']);
-
-app.config(['$routeProvider', function($routeProvider) {
-
- $routeProvider.when('/:gid', {
- template: '<contactdetails></contactdetails>'
- });
-
- $routeProvider.when('/:gid/:uid', {
- template: '<contactdetails></contactdetails>'
- });
-
- $routeProvider.otherwise('/' + t('contacts', 'All contacts'));
-
-}]);
-
-app.directive('datepicker', function() {
- return {
- restrict: 'A',
- require : 'ngModel',
- link : function (scope, element, attrs, ngModelCtrl) {
- $(function() {
- element.datepicker({
- dateFormat:'yy-mm-dd',
- minDate: null,
- maxDate: null,
- onSelect:function (date) {
- ngModelCtrl.$setViewValue(date);
- scope.$apply();
- }
- });
- });
- }
- };
-});
-
-app.directive('focusExpression', ['$timeout', function ($timeout) {
- return {
- restrict: 'A',
- link: {
- post: function postLink(scope, element, attrs) {
- scope.$watch(attrs.focusExpression, function (value) {
-
- if (attrs.focusExpression) {
- if (scope.$eval(attrs.focusExpression)) {
- $timeout(function () {
- if (element.is('input')) {
- element.focus();
- } else {
- element.find('input').focus();
- }
- }, 100); //need some delay to work with ng-disabled
- }
- }
- });
- }
- }
- };
-}]);
-
-app.controller('addressbookCtrl', ['$scope', 'AddressBookService', function($scope, AddressBookService) {
- var ctrl = this;
-
- ctrl.urlBase = window.location.protocol + '//' + window.location.host;
- ctrl.showUrl = false;
-
- ctrl.toggleShowUrl = function() {
- ctrl.showUrl = !ctrl.showUrl;
- };
-
- ctrl.toggleSharesEditor = function(addressBook) {
- addressBook.editingShares = !addressBook.editingShares;
- addressBook.selectedSharee = null;
- };
-
- /* From Calendar-Rework - js/app/controllers/calendarlistcontroller.js */
- ctrl.findSharee = function (val, addressBook) {
- return $.get(
- OC.linkToOCS('apps/files_sharing/api/v1') + 'sharees',
- {
- format: 'json',
- search: val.trim(),
- perPage: 200,
- itemType: 'principals'
- }
- ).then(function(result) {
- // Todo - filter out current user, existing sharees
- var users = result.ocs.data.exact.users.concat(result.ocs.data.users);
- var groups = result.ocs.data.exact.groups.concat(result.ocs.data.groups);
-
- var userShares = addressBook.sharedWith.users;
- var groupShares = addressBook.sharedWith.groups;
- var userSharesLength = userShares.length;
- var groupSharesLength = groupShares.length;
- var i, j;
-
- // Filter out current user
- var usersLength = users.length;
- for (i = 0 ; i < usersLength; i++) {
- if (users[i].value.shareWith === OC.currentUser) {
- users.splice(i, 1);
- break;
- }
- }
-
- // Now filter out all sharees that are already shared with
- for (i = 0; i < userSharesLength; i++) {
- var share = userShares[i];
- usersLength = users.length;
- for (j = 0; j < usersLength; j++) {
- if (users[j].value.shareWith === share.id) {
- users.splice(j, 1);
- break;
- }
- }
- }
-
- // Combine users and groups
- users = users.map(function(item) {
- return {
- display: item.value.shareWith,
- type: OC.Share.SHARE_TYPE_USER,
- identifier: item.value.shareWith
- };
- });
-
- groups = groups.map(function(item) {
- return {
- display: item.value.shareWith + ' (group)',
- type: OC.Share.SHARE_TYPE_GROUP,
- identifier: item.value.shareWith
- };
- });
-
- return groups.concat(users);
- });
- };
-
- ctrl.onSelectSharee = function (item, model, label, addressBook) {
- ctrl.addressBook.selectedSharee = null;
- AddressBookService.share(addressBook, item.type, item.identifier, false, false).then(function() {
- $scope.$apply();
- });
-
- };
-
- ctrl.updateExistingUserShare = function(addressBook, userId, writable) {
- AddressBookService.share(addressBook, OC.Share.SHARE_TYPE_USER, userId, writable, true).then(function() {
- $scope.$apply();
- });
- };
-
- ctrl.updateExistingGroupShare = function(addressBook, groupId, writable) {
- AddressBookService.share(addressBook, OC.Share.SHARE_TYPE_GROUP, groupId, writable, true).then(function() {
- $scope.$apply();
- });
- };
-
- ctrl.unshareFromUser = function(addressBook, userId) {
- AddressBookService.unshare(addressBook, OC.Share.SHARE_TYPE_USER, userId).then(function() {
- $scope.$apply();
- });
- };
-
- ctrl.unshareFromGroup = function(addressBook, groupId) {
- AddressBookService.unshare(addressBook, OC.Share.SHARE_TYPE_GROUP, groupId).then(function() {
- $scope.$apply();
- });
- };
-
- ctrl.deleteAddressBook = function(addressBook) {
- AddressBookService.delete(addressBook).then(function() {
- $scope.$apply();
- });
- };
-
-}]);
-
-app.directive('addressbook', function() {
- return {
- restrict: 'A', // has to be an attribute to work with core css
- scope: {},
- controller: 'addressbookCtrl',
- controllerAs: 'ctrl',
- bindToController: {
- addressBook: '=data'
- },
- templateUrl: OC.linkTo('contacts', 'templates/addressBook.html')
- };
-});
-
-app.controller('addressbooklistCtrl', ['$scope', 'AddressBookService', 'SettingsService', function($scope, AddressBookService, SettingsService) {
- var ctrl = this;
-
- AddressBookService.getAll().then(function(addressBooks) {
- ctrl.addressBooks = addressBooks;
- });
-
- ctrl.createAddressBook = function() {
- if(ctrl.newAddressBookName) {
- AddressBookService.create(ctrl.newAddressBookName).then(function() {
- AddressBookService.getAddressBook(ctrl.newAddressBookName).then(function(addressBook) {
- ctrl.addressBooks.push(addressBook);
- $scope.$apply();
- });
- });
- }
- };
-}]);
-
-app.directive('addressbooklist', function() {
- return {
- restrict: 'EA', // has to be an attribute to work with core css
- scope: {},
- controller: 'addressbooklistCtrl',
- controllerAs: 'ctrl',
- bindToController: {},
- templateUrl: OC.linkTo('contacts', 'templates/addressBookList.html')
- };
-});
-
-app.controller('contactCtrl', ['$route', '$routeParams', function($route, $routeParams) {
- var ctrl = this;
-
- ctrl.openContact = function() {
- $route.updateParams({
- gid: $routeParams.gid,
- uid: ctrl.contact.uid()});
- };
-}]);
-
-app.directive('contact', function() {
- return {
- scope: {},
- controller: 'contactCtrl',
- controllerAs: 'ctrl',
- bindToController: {
- contact: '=data'
- },
- templateUrl: OC.linkTo('contacts', 'templates/contact.html')
- };
-});
-
-app.controller('contactdetailsCtrl', ['ContactService', 'AddressBookService', 'vCardPropertiesService', '$routeParams', '$scope', function(ContactService, AddressBookService, vCardPropertiesService, $routeParams, $scope) {
- var ctrl = this;
-
- ctrl.uid = $routeParams.uid;
- ctrl.t = {
- noContacts : t('contacts', 'No contacts in here'),
- placeholderName : t('contacts', 'Name'),
- placeholderOrg : t('contacts', 'Organization'),
- placeholderTitle : t('contacts', 'Title'),
- selectField : t('contacts', 'Add field ...')
- };
-
- ctrl.fieldDefinitions = vCardPropertiesService.fieldDefinitions;
- ctrl.focus = undefined;
- ctrl.field = undefined;
- $scope.addressBooks = [];
- ctrl.addressBooks = [];
-
- AddressBookService.getAll().then(function(addressBooks) {
- ctrl.addressBooks = addressBooks;
- $scope.addressBooks = addressBooks.map(function (element) {
- return {
- id: element.displayName,
- name: element.displayName
- };
- });
- if (!_.isUndefined(ctrl.contact)) {
- $scope.addressBook = _.find($scope.addressBooks, function(book) {
- return book.id === ctrl.contact.addressBookId;
- });
- }
- });
-
- $scope.$watch('ctrl.uid', function(newValue, oldValue) {
- ctrl.changeContact(newValue);
- });
-
- ctrl.changeContact = function(uid) {
- if (typeof uid === 'undefined') {
- return;
- }
- ContactService.getById(uid).then(function(contact) {
- ctrl.contact = contact;
- ctrl.photo = ctrl.contact.photo();
- $scope.addressBook = _.find($scope.addressBooks, function(book) {
- return book.id === ctrl.contact.addressBookId;
- });
- });
- };
-
- ctrl.updateContact = function() {
- ContactService.update(ctrl.contact);
- };
-
- ctrl.deleteContact = function() {
- ContactService.delete(ctrl.contact);
- };
-
- ctrl.addField = function(field) {
- var defaultValue = vCardPropertiesService.getMeta(field).defaultValue || {value: ''};
- ctrl.contact.addProperty(field, defaultValue);
- ctrl.focus = field;
- ctrl.field = '';
- };
-
- ctrl.deleteField = function (field, prop) {
- ctrl.contact.removeProperty(field, prop);
- ctrl.focus = undefined;
- };
-
- ctrl.changeAddressBook = function (addressBook) {
- addressBook = _.find(ctrl.addressBooks, function(book) {
- return book.displayName === addressBook.id;
- });
- ContactService.moveContact(ctrl.contact, addressBook);
- };
-}]);
-
-app.directive('contactdetails', function() {
- return {
- priority: 1,
- scope: {},
- controller: 'contactdetailsCtrl',
- controllerAs: 'ctrl',
- bindToController: {},
- templateUrl: OC.linkTo('contacts', 'templates/contactDetails.html')
- };
-});
-
-app.controller('contactlistCtrl', ['$scope', '$filter', '$route', '$routeParams', 'ContactService', 'vCardPropertiesService', 'SearchService', function($scope, $filter, $route, $routeParams, ContactService, vCardPropertiesService, SearchService) {
- var ctrl = this;
-
- ctrl.routeParams = $routeParams;
-
- ctrl.contactList = [];
- ctrl.selectedContactId = undefined;
- ctrl.searchTerm = '';
-
- ctrl.t = {
- addContact : t('contacts', 'Add contact'),
- emptySearch : t('contacts', 'No search result for {query}', {query: ctrl.searchTerm})
- };
-
-
- $scope.query = function(contact) {
- return contact.matches(SearchService.getSearchTerm());
- };
-
- SearchService.registerObserverCallback(function(ev) {
- if (ev.event === 'submitSearch') {
- var uid = !_.isEmpty(ctrl.contactList) ? ctrl.contactList[0].uid() : undefined;
- $route.updateParams({
- uid: uid
- });
- ctrl.selectedContactId = uid;
- $scope.$apply();
- }
- if (ev.event === 'changeSearch') {
- ctrl.searchTerm = ev.searchTerm;
- ctrl.t.emptySearch;
- ctrl.t.emptySearch = t('contacts',
- 'No search result for {query}',
- {query: ctrl.searchTerm}
- );
- $scope.$apply();
- }
- });
-
- ContactService.registerObserverCallback(function(ev) {
- $scope.$apply(function() {
- if (ev.event === 'delete') {
- if (ctrl.contactList.length === 1) {
- $route.updateParams({
- gid: $routeParams.gid,
- uid: undefined
- });
- } else {
- for (var i = 0, length = ctrl.contactList.length; i < length; i++) {
- if (ctrl.contactList[i].uid() === ev.uid) {
- $route.updateParams({
- gid: $routeParams.gid,
- uid: (ctrl.contactList[i+1]) ? ctrl.contactList[i+1].uid() : ctrl.contactList[i-1].uid()
- });
- break;
- }
- }
- }
- }
- else if (ev.event === 'create') {
- $route.updateParams({
- gid: $routeParams.gid,
- uid: ev.uid
- });
- }
- ctrl.contacts = ev.contacts;
- });
- });
-
- ContactService.getAll().then(function(contacts) {
- $scope.$apply(function() {
- ctrl.contacts = contacts;
- });
- });
-
- $scope.$watch('ctrl.routeParams.uid', function(newValue) {
- if(newValue === undefined) {
- // we might have to wait until ng-repeat filled the contactList
- if(ctrl.contactList && ctrl.contactList.length > 0) {
- $route.updateParams({
- gid: $routeParams.gid,
- uid: ctrl.contactList[0].uid()
- });
- } else {
- // watch for next contactList update
- var unbindWatch = $scope.$watch('ctrl.contactList', function() {
- if(ctrl.contactList && ctrl.contactList.length > 0) {
- $route.updateParams({
- gid: $routeParams.gid,
- uid: ctrl.contactList[0].uid()
- });
- }
- unbindWatch(); // unbind as we only want one update
- });
- }
- }
- });
-
- $scope.$watch('ctrl.routeParams.gid', function() {
- // we might have to wait until ng-repeat filled the contactList
- ctrl.contactList = [];
- // watch for next contactList update
- var unbindWatch = $scope.$watch('ctrl.contactList', function() {
- if(ctrl.contactList && ctrl.contactList.length > 0) {
- $route.updateParams({
- gid: $routeParams.gid,
- uid: ctrl.contactList[0].uid()
- });
- }
- unbindWatch(); // unbind as we only want one update
- });
- });
-
- ctrl.createContact = function() {
- ContactService.create().then(function(contact) {
- ['tel', 'adr', 'email'].forEach(function(field) {
- var defaultValue = vCardPropertiesService.getMeta(field).defaultValue || {value: ''};
- contact.addProperty(field, defaultValue);
- } );
- if ($routeParams.gid !== t('contacts', 'All contacts')) {
- contact.categories($routeParams.gid);
- } else {
- contact.categories('');
- }
- $('#details-fullName').focus();
- });
- };
-
- ctrl.hasContacts = function () {
- if (!ctrl.contacts) {
- return false;
- }
- return ctrl.contacts.length > 0;
- };
-
- $scope.selectedContactId = $routeParams.uid;
- $scope.setSelected = function (selectedContactId) {
- $scope.selectedContactId = selectedContactId;
- };
-
-}]);
-
-app.directive('contactlist', function() {
- return {
- priority: 1,
- scope: {},
- controller: 'contactlistCtrl',
- controllerAs: 'ctrl',
- bindToController: {
- addressbook: '=adrbook'
- },
- templateUrl: OC.linkTo('contacts', 'templates/contactList.html')
- };
-});
-
-app.controller('detailsItemCtrl', ['$templateRequest', 'vCardPropertiesService', 'ContactService', function($templateRequest, vCardPropertiesService, ContactService) {
- var ctrl = this;
-
- ctrl.meta = vCardPropertiesService.getMeta(ctrl.name);
- ctrl.type = undefined;
- ctrl.t = {
- poBox : t('contacts', 'Post Office Box'),
- postalCode : t('contacts', 'Postal Code'),
- city : t('contacts', 'City'),
- state : t('contacts', 'State or province'),
- country : t('contacts', 'Country'),
- address: t('contacts', 'Address'),
- newGroup: t('contacts', '(new group)')
- };
-
- ctrl.availableOptions = ctrl.meta.options || [];
- if (!_.isUndefined(ctrl.data) && !_.isUndefined(ctrl.data.meta) && !_.isUndefined(ctrl.data.meta.type)) {
- ctrl.type = ctrl.data.meta.type[0];
- if (!ctrl.availableOptions.some(function(e) { return e.id === ctrl.data.meta.type[0]; } )) {
- ctrl.availableOptions = ctrl.availableOptions.concat([{id: ctrl.data.meta.type[0], name: ctrl.data.meta.type[0]}]);
- }
- }
- ctrl.availableGroups = [];
-
- ContactService.getGroups().then(function(groups) {
- ctrl.availableGroups = _.unique(groups);
- });
-
- ctrl.changeType = function (val) {
- ctrl.data.meta = ctrl.data.meta || {};
- ctrl.data.meta.type = ctrl.data.meta.type || [];
- ctrl.data.meta.type[0] = val;
- ctrl.model.updateContact();
- };
-
- ctrl.getTemplate = function() {
- var templateUrl = OC.linkTo('contacts', 'templates/detailItems/' + ctrl.meta.template + '.html');
- return $templateRequest(templateUrl);
- };
-
- ctrl.deleteField = function () {
- ctrl.model.deleteField(ctrl.name, ctrl.data);
- ctrl.model.updateContact();
- };
-}]);
-
-app.directive('detailsitem', ['$compile', function($compile) {
- return {
- scope: {},
- controller: 'detailsItemCtrl',
- controllerAs: 'ctrl',
- bindToController: {
- name: '=',
- data: '=',
- model: '='
- },
- link: function(scope, element, attrs, ctrl) {
- ctrl.getTemplate().then(function(html) {
- var template = angular.element(html);
- element.append(template);
- $compile(template)(scope);
- });
- }
- };
-}]);
-
-app.controller('detailsPhotoCtrl', function() {
- var ctrl = this;
-});
-
-app.directive('detailsphoto', function() {
- return {
- scope: {},
- controller: 'detailsPhotoCtrl',
- controllerAs: 'ctrl',
- bindToController: {
- contact: '=data'
- },
- templateUrl: OC.linkTo('contacts', 'templates/detailsPhoto.html')
- };
-});
-
-app.controller('groupCtrl', function() {
- var ctrl = this;
-});
-
-app.directive('group', function() {
- return {
- restrict: 'A', // has to be an attribute to work with core css
- scope: {},
- controller: 'groupCtrl',
- controllerAs: 'ctrl',
- bindToController: {
- group: '=data'
- },
- templateUrl: OC.linkTo('contacts', 'templates/group.html')
- };
-});
-
-app.controller('grouplistCtrl', ['$scope', 'ContactService', 'SearchService', '$routeParams', function($scope, ContactService, SearchService, $routeParams) {
-
- $scope.groups = [t('contacts', 'All contacts'), t('contacts', 'Not grouped')];
-
- ContactService.getGroups().then(function(groups) {
- $scope.groups = _.unique([t('contacts', 'All contacts'), t('contacts', 'Not grouped')].concat(groups));
- });
-
- $scope.selectedGroup = $routeParams.gid;
- $scope.setSelected = function (selectedGroup) {
- SearchService.cleanSearch();
- $scope.selectedGroup = selectedGroup;
- };
-}]);
-
-app.directive('grouplist', function() {
- return {
- restrict: 'EA', // has to be an attribute to work with core css
- scope: {},
- controller: 'grouplistCtrl',
- controllerAs: 'ctrl',
- bindToController: {},
- templateUrl: OC.linkTo('contacts', 'templates/groupList.html')
- };
-});
-
-app.controller('imagePreviewCtrl', ['$scope', function($scope) {
- var ctrl = this;
-
- ctrl.loadImage = function(file) {
- var reader = new FileReader();
-
- reader.addEventListener('load', function () {
- $scope.$apply(function() {
- $scope.imagepreview = reader.result;
- });
- }, false);
-
- if (file) {
- reader.readAsDataURL(file);
- }
- };
-}]);
-
-app.directive('imagepreview', function() {
- return {
- scope: {
- photoCallback: '&imagepreview'
- },
- link: function(scope, element, attrs, ctrl) {
- element.bind('change', function() {
- var file = element.get(0).files[0];
- var reader = new FileReader();
-
- reader.addEventListener('load', function () {
- console.log('hi', scope.photoCallback() + '');
- scope.$apply(function() {
- scope.photoCallback()(reader.result);
- });
- }, false);
-
- if (file) {
- reader.readAsDataURL(file);
- }
- });
- }
- };
-});
-
-app.directive('groupModel', ['$filter', function($filter) {
- return{
- restrict: 'A',
- require: 'ngModel',
- link: function(scope, element, attr, ngModel) {
- ngModel.$formatters.push(function(value) {
- if (value.trim().length === 0) {
- return [];
- }
- return value.split(',');
- });
- ngModel.$parsers.push(function(value) {
- return value.join(',');
- });
- }
- };
-}]);
-
-app.directive('telModel', function() {
- return{
- restrict: 'A',
- require: 'ngModel',
- link: function(scope, element, attr, ngModel) {
- ngModel.$formatters.push(function(value) {
- return value;
- });
- ngModel.$parsers.push(function(value) {
- return value;
- });
- }
- };
-});
-
-app.factory('AddressBook', function()
-{
- return function AddressBook(data) {
- angular.extend(this, {
-
- displayName: '',
- contacts: [],
- groups: data.data.props.groups,
-
- getContact: function(uid) {
- for(var i in this.contacts) {
- if(this.contacts[i].uid() === uid) {
- return this.contacts[i];
- }
- }
- return undefined;
- },
-
- sharedWith: {
- users: [],
- groups: []
- }
-
- });
- angular.extend(this, data);
- angular.extend(this, {
- owner: data.url.split('/').slice(-3, -2)[0]
- });
-
- var shares = this.data.props.invite;
- if (typeof shares !== 'undefined') {
- for (var j = 0; j < shares.length; j++) {
- var href = shares[j].href;
- if (href.length === 0) {
- continue;
- }
- var access = shares[j].access;
- if (access.length === 0) {
- continue;
- }
-
- var readWrite = (typeof access.readWrite !== 'undefined');
-
- if (href.startsWith('principal:principals/users/')) {
- this.sharedWith.users.push({
- id: href.substr(27),
- displayname: href.substr(27),
- writable: readWrite
- });
- } else if (href.startsWith('principal:principals/groups/')) {
- this.sharedWith.groups.push({
- id: href.substr(28),
- displayname: href.substr(28),
- writable: readWrite
- });
- }
- }
- }
-
- //var owner = this.data.props.owner;
- //if (typeof owner !== 'undefined' && owner.length !== 0) {
- // owner = owner.trim();
- // if (owner.startsWith('/remote.php/dav/principals/users/')) {
- // this._properties.owner = owner.substr(33);
- // }
- //}
-
- };
-});
-
-app.factory('Contact', ['$filter', function($filter) {
- return function Contact(addressBook, vCard) {
- angular.extend(this, {
-
- data: {},
- props: {},
-
- addressBookId: addressBook.displayName,
-
- uid: function(value) {
- if (angular.isDefined(value)) {
- // setter
- return this.setProperty('uid', { value: value });
- } else {
- // getter
- return this.getProperty('uid').value;
- }
- },
-
- fullName: function(value) {
- if (angular.isDefined(value)) {
- // setter
- return this.setProperty('fn', { value: value });
- } else {
- // getter
- var property = this.getProperty('fn');
- if(property) {
- return property.value;
- } else {
- return undefined;
- }
- }
- },
-
- title: function(value) {
- if (angular.isDefined(value)) {
- // setter
- return this.setProperty('title', { value: value });
- } else {
- // getter
- var property = this.getProperty('title');
- if(property) {
- return property.value;
- } else {
- return undefined;
- }
- }
- },
-
- org: function(value) {
- var property = this.getProperty('org');
- if (angular.isDefined(value)) {
- var val = value;
- // setter
- if(property && Array.isArray(property.value)) {
- val = property.value;
- val[0] = value;
- }
- return this.setProperty('org', { value: val });
- } else {
- // getter
- if(property) {
- if (Array.isArray(property.value)) {
- return property.value[0];
- }
- return property.value;
- } else {
- return undefined;
- }
- }
- },
-
- email: function() {
- // getter
- var property = this.getProperty('email');
- if(property) {
- return property.value;
- } else {
- return undefined;
- }
- },
-
- photo: function() {
- var property = this.getProperty('photo');
- if(property) {
- return property.value;
- } else {
- return undefined;
- }
- },
-
- categories: function(value) {
- if (angular.isDefined(value)) {
- // setter
- return this.setProperty('categories', { value: value });
- } else {
- // getter
- var property = this.getProperty('categories');
- if(property && property.value.length > 0) {
- return property.value.split(',');
- } else {
- return [];
- }
- }
- },
-
- getProperty: function(name) {
- if (this.props[name]) {
- return this.props[name][0];
- } else {
- return undefined;
- }
- },
- addProperty: function(name, data) {
- data = angular.copy(data);
- if(!this.props[name]) {
- this.props[name] = [];
- }
- var idx = this.props[name].length;
- this.props[name][idx] = data;
-
- // keep vCard in sync
- this.data.addressData = $filter('JSON2vCard')(this.props);
- return idx;
- },
- setProperty: function(name, data) {
- if(!this.props[name]) {
- this.props[name] = [];
- }
- this.props[name][0] = data;
-
- // keep vCard in sync
- this.data.addressData = $filter('JSON2vCard')(this.props);
- },
- removeProperty: function (name, prop) {
- angular.copy(_.without(this.props[name], prop), this.props[name]);
- this.data.addressData = $filter('JSON2vCard')(this.props);
- },
- setETag: function(etag) {
- this.data.etag = etag;
- },
- setUrl: function(addressBook, uid) {
- this.data.url = addressBook.url + uid + '.vcf';
- },
-
- syncVCard: function() {
- // keep vCard in sync
- this.data.addressData = $filter('JSON2vCard')(this.props);
- },
-
- matches: function(pattern) {
- if (_.isUndefined(pattern) || pattern.length === 0) {
- return true;
- }
- return this.data.addressData.toLowerCase().indexOf(pattern.toLowerCase()) !== -1;
- }
-
- });
-
- if(angular.isDefined(vCard)) {
- angular.extend(this.data, vCard);
- angular.extend(this.props, $filter('vCard2JSON')(this.data.addressData));
- } else {
- angular.extend(this.props, {
- version: [{value: '3.0'}],
- fn: [{value: ''}]
- });
- this.data.addressData = $filter('JSON2vCard')(this.props);
- }
-
- var property = this.getProperty('categories');
- if(!property) {
- this.categories('');
- }
- };
-}]);
-
-app.factory('AddressBookService', ['DavClient', 'DavService', 'SettingsService', 'AddressBook', 'Contact', function(DavClient, DavService, SettingsService, AddressBook, Contact) {
-
- var addressBooks = [];
-
- var loadAll = function() {
- return DavService.then(function(account) {
- addressBooks = account.addressBooks.map(function(addressBook) {
- return new AddressBook(addressBook);
- });
- });
- };
-
- return {
- getAll: function() {
- return loadAll().then(function() {
- return addressBooks;
- });
- },
-
- getGroups: function () {
- return this.getAll().then(function(addressBooks) {
- return addressBooks.map(function (element) {
- return element.groups;
- }).reduce(function(a, b) {
- return a.concat(b);
- });
- });
- },
-
- getEnabled: function() {
- return DavService.then(function(account) {
- return account.addressBooks.map(function(addressBook) {
- return new AddressBook(addressBook);
- });
- });
- },
-
- getDefaultAddressBook: function() {
- return addressBooks[0];
- },
-
- getAddressBook: function(displayName) {
- return DavService.then(function(account) {
- return DavClient.getAddressBook({displayName:displayName, url:account.homeUrl}).then(function(addressBook) {
- addressBook = new AddressBook({
- url: addressBook[0].href,
- data: addressBook[0]
- });
- addressBook.displayName = displayName;
- return addressBook;
- });
- });
- },
-
- create: function(displayName) {
- return DavService.then(function(account) {
- return DavClient.createAddressBook({displayName:displayName, url:account.homeUrl});
- });
- },
-
- delete: function(addressBook) {
- return DavService.then(function(account) {
- return DavClient.deleteAddressBook(addressBook).then(function() {
- angular.copy(_.without(addressBooks, addressBook), addressBooks);
- });
- });
- },
-
- rename: function(addressBook, displayName) {
- return DavService.then(function(account) {
- return DavClient.renameAddressBook(addressBook, {displayName:displayName, url:account.homeUrl});
- });
- },
-
- get: function(displayName) {
- return this.getAll().then(function(addressBooks) {
- return addressBooks.filter(function (element) {
- return element.displayName === displayName;
- })[0];
- });
- },
-
- sync: function(addressBook) {
- return DavClient.syncAddressBook(addressBook);
- },
-
- share: function(addressBook, shareType, shareWith, writable, existingShare) {
- var xmlDoc = document.implementation.createDocument('', '', null);
- var oShare = xmlDoc.createElement('o:share');
- oShare.setAttribute('xmlns:d', 'DAV:');
- oShare.setAttribute('xmlns:o', 'http://owncloud.org/ns');
- xmlDoc.appendChild(oShare);
-
- var oSet = xmlDoc.createElement('o:set');
- oShare.appendChild(oSet);
-
- var dHref = xmlDoc.createElement('d:href');
- if (shareType === OC.Share.SHARE_TYPE_USER) {
- dHref.textContent = 'principal:principals/users/';
- } else if (shareType === OC.Share.SHARE_TYPE_GROUP) {
- dHref.textContent = 'principal:principals/groups/';
- }
- dHref.textContent += shareWith;
- oSet.appendChild(dHref);
-
- var oSummary = xmlDoc.createElement('o:summary');
- oSummary.textContent = t('contacts', '{addressbook} shared by {owner}', {
- addressbook: addressBook.displayName,
- owner: addressBook.owner
- });
- oSet.appendChild(oSummary);
-
- if (writable) {
- var oRW = xmlDoc.createElement('o:read-write');
- oSet.appendChild(oRW);
- }
-
- var body = oShare.outerHTML;
-
- return DavClient.xhr.send(
- dav.request.basic({method: 'POST', data: b