diff --git a/UI/WebServerResources/js/Contacts/addressbook-model.js b/UI/WebServerResources/js/Contacts/addressbook-model.js
index 7e55be7a6..ebcccd659 100644
--- a/UI/WebServerResources/js/Contacts/addressbook-model.js
+++ b/UI/WebServerResources/js/Contacts/addressbook-model.js
@@ -1,114 +1,117 @@
(function() {
'use strict';
+ /* Constructor */
function AddressBook(futureAddressBookData) {
- /* DATA IS IMMEDIATELY AVAILABLE */
+ // Data is immediately available
if (typeof futureAddressBookData.then !== 'function') {
angular.extend(this, futureAddressBookData);
return;
}
- /* THE PROMISE WILL BE UNWRAPPED FIRST */
+ // The promise will be unwrapped first
this.$unwrap(futureAddressBookData);
}
- /* THE FACTORY WE'LL USE TO REGISTER WITH ANGULAR */
- AddressBook.$factory = ['$timeout', 'sgSettings', 'sgResource', 'sgContact', function($timeout, Settings, Resource, Contact) {
+ /* The factory we'll use to register with Angular */
+ AddressBook.$factory = ['$timeout', 'sgSettings', 'sgResource', 'sgCard', function($timeout, Settings, Resource, Card) {
angular.extend(AddressBook, {
$$resource: new Resource(Settings.baseURL),
$timeout: $timeout,
- $Contact: Contact
+ $Card: Card
});
return AddressBook; // return constructor
}];
- /* ANGULAR MODULE REGISTRATION */
- angular.module('SOGo').factory('sgAddressBook', AddressBook.$factory);
+ /* Factory registration in Angular module */
+ angular.module('SOGo.Contacts').factory('sgAddressBook', AddressBook.$factory);
- // AddressBook.$selectedId = function(addressbook_id) {
- // if (addressbook_id) angular.extend(AddressBook, { $selected_id: addressbook_id });
- // console.debug("selected id = " + AddressBook.$selected_id);
- // return AddressBook.$selected_id;
- // };
+ AddressBook.$all = function(data) {
+ if (data) {
+ this.$addressbooks = data;
+ }
+ return this.$addressbooks;
+ };
- /* Fetch list of contacts */
+ /* Fetch list of cards */
AddressBook.$find = function(addressbook_id) {
- var futureAddressBookData = this.$$resource.find(addressbook_id); // should return attributes of addressbook +
+ var futureAddressBookData = AddressBook.$$resource.find(addressbook_id); // should return attributes of addressbook +
// AddressBook.$selectedId(addressbook_id);
return new AddressBook(futureAddressBookData);
};
- // Instance methods
+ /* Instance methods */
AddressBook.prototype.$id = function() {
- var self = this;
return this.$futureAddressBookData.then(function(data) {
return data.id;
});
};
- AddressBook.prototype.$getContact = function(contact_id) {
+ AddressBook.prototype.$filter = function(search) {
var self = this;
- // return this.$futureAddressBookData.then(function(data) {
- // return data.id;
- // }).then(function(addressbook_id) {
+ var params = { 'search': 'name_or_address',
+ 'value': search,
+ 'sort': 'c_cn',
+ 'asc': 'true' };
+
return this.$id().then(function(addressbook_id) {
- var contact = AddressBook.$Contact.$find(addressbook_id, contact_id);
-
- AddressBook.$timeout(function() {
- self.contact = contact;
- });
-
- return contact.$futureContactData.then(function() {
- return self.contact;
+ var futureAddressBookData = AddressBook.$$resource.filter(addressbook_id, params);
+ return futureAddressBookData.then(function(data) {
+ return AddressBook.$timeout(function() {
+ self.cards = data.cards;
+ return self.cards;
+ });
});
});
};
- AddressBook.prototype.$resetContact = function() {
- this.$getContact(this.contact.id);
+ AddressBook.prototype.$getCard = function(card_id) {
+ var self = this;
+ return this.$id().then(function(addressbook_id) {
+ var card = AddressBook.$Card.$find(addressbook_id, card_id);
+
+ AddressBook.$timeout(function() {
+ self.card = card;
+ });
+
+ return card.$futureCardData.then(function() {
+ angular.forEach(self.cards, function(o, i) {
+ if (o.c_name == card_id) {
+ angular.extend(self.card, o);
+ }
+ });
+
+ return self.card;
+ });
+ });
+ };
+
+ AddressBook.prototype.$resetCard = function() {
+ this.$getCard(this.card.id);
};
AddressBook.prototype.$viewerIsActive = function(editMode) {
- return (typeof this.contact != "undefined" && !editMode);
+ return (!angular.isUndefined(this.card) && !editMode);
};
- // AddressBook.prototype.$getContacts = function() {
- // var self = this;
-
- // return AddressBook.$timeout(function() {
- // var contacts = [];
- // angular.forEach(self.contacts, function(addressBookContact, index) {
- // var contact = AddressBook.$Contact.$find(addressBookContact.c_name);
- // angular.extend(contact, addressBookContact); // useless?
- // this.push(contact);
- // }, contacts);
-
- // AddressBook.$timeout(function() {
- // self.contacts = contacts;
- // });
-
- // var futureContactData = [];
- // angular.forEach(contacts, function(contact, index) {
- // this.push(contact.$futureContactData);
- // }, futureContactData);
- // return this._q.all(futureContactData).then(function() {
- // //self.$$emitter.emit('update');
- // return self.contacts;
- // });
- // });
- // };
-
// Unwrap a promise
AddressBook.prototype.$unwrap = function(futureAddressBookData) {
var self = this;
this.$futureAddressBookData = futureAddressBookData;
this.$futureAddressBookData.then(function(data) {
- // The success callback. Calling _.extend from $timeout will wrap it into a try/catch call
- // and return a promise.
- AddressBook.$timeout(function() { angular.extend(self, data); });
+ AddressBook.$timeout(function() {
+ angular.extend(self, data);
+ self.$id().then(function(addressbook_id) {
+ angular.forEach(AddressBook.$all(), function(o, i) {
+ if (o.id == addressbook_id) {
+ angular.extend(self, o);
+ }
+ });
+ });
+ });
});
};
@@ -117,13 +120,12 @@
var addressbook = {};
angular.forEach(this, function(value, key) {
if (key != 'constructor' &&
- key != 'contact' &&
- key != 'contacts' &&
+ key != 'card' &&
+ key != 'cards' &&
key[0] != '$') {
addressbook[key] = value;
}
});
- console.debug(angular.toJson(addressbook));
return addressbook;
};
diff --git a/UI/WebServerResources/js/Contacts/contact-model.js b/UI/WebServerResources/js/Contacts/card-model.js
similarity index 61%
rename from UI/WebServerResources/js/Contacts/contact-model.js
rename to UI/WebServerResources/js/Contacts/card-model.js
index a2c605ece..56a7b6659 100644
--- a/UI/WebServerResources/js/Contacts/contact-model.js
+++ b/UI/WebServerResources/js/Contacts/card-model.js
@@ -3,51 +3,76 @@
/* Constructor */
- function Contact(futureContactData) {
+ function Card(futureCardData) {
/* DATA IS IMMEDIATELY AVAILABLE */
- // if (!futureContactData.inspect) {
- // angular.extend(this, futureContactData);
+ // if (!futureCardData.inspect) {
+ // angular.extend(this, futureCardData);
// return;
// }
/* THE PROMISE WILL BE UNWRAPPED FIRST */
- this.$unwrap(futureContactData);
+ this.$unwrap(futureCardData);
}
- Contact.$tel_types = [_('work'), 'home', 'cell', 'fax', 'pager'];
- Contact.$email_types = ['work', 'home', 'pref'];
- Contact.$url_types = ['work', 'home', 'pref'];
- Contact.$address_types = ['work', 'home'];
+ Card.$tel_types = ['work', 'home', 'cell', 'fax', 'pager'];
+ Card.$email_types = ['work', 'home', 'pref'];
+ Card.$url_types = ['work', 'home', 'pref'];
+ Card.$address_types = ['work', 'home'];
/* THE FACTORY WE'LL USE TO REGISTER WITH ANGULAR */
- Contact.$factory = ['$timeout', 'sgSettings', 'sgResource', function($timeout, Settings, Resource) {
- angular.extend(Contact, {
+ Card.$factory = ['$timeout', 'sgSettings', 'sgResource', function($timeout, Settings, Resource) {
+ angular.extend(Card, {
$$resource: new Resource(Settings.baseURL),
$timeout: $timeout
});
- return Contact; // return constructor
+ return Card; // return constructor
}];
/* ANGULAR MODULE REGISTRATION */
- angular.module('SOGo').factory('sgContact', Contact.$factory);
+ angular.module('SOGo.Contacts')
+ .factory('sgCard', Card.$factory)
+
+ .directive('sgAddress', function() {
+ return {
+ restrict: 'A',
+ replace: true,
+ scope: { data: '=sgAddress' },
+ controller: ['$scope', function($scope) {
+ $scope.addressLines = function(data) {
+ var lines = [];
+ if (data.street) lines.push(data.street);
+ if (data.street2) lines.push(data.street2);
+ var locality_region = [];
+ if (data.locality) locality_region.push(data.locality);
+ if (data.region) locality_region.push(data.region);
+ if (locality_region.length > 0) lines.push(locality_region.join(', '));
+ if (data.country) lines.push(data.country);
+ if (data.postalcode) lines.push(data.postalcode);
+ return lines.join('
');
+ };
+ }],
+ template: '
'
+ }
+ });
+
/* FETCH A UNIT */
- Contact.$find = function(addressbook_id, contact_id) {
+ Card.$find = function(addressbook_id, card_id) {
/* FALLS BACK ON AN INSTANCE OF RESOURCE */
// Fetch data over the wire.
- var futureContactData = this.$$resource.find([addressbook_id, contact_id].join('/'));
+ var futureCardData = this.$$resource.find([addressbook_id, card_id].join('/'));
- if (contact_id) return new Contact(futureContactData); // a single contact
+ if (card_id) return new Card(futureCardData); // a single card
- return Contact.$unwrapCollection(futureContactData); // a collection of contacts
+ return Card.$unwrapCollection(futureCardData); // a collection of cards
};
// Instance methods
- Contact.prototype.$id = function() {
+ Card.prototype.$id = function() {
//var self = this;
return this.$futureAddressBookData.then(function(data) {
return data.id;
@@ -55,20 +80,19 @@
};
// Unwrap a promise
- Contact.prototype.$unwrap = function(futureContactData) {
+ Card.prototype.$unwrap = function(futureCardData) {
var self = this;
- this.$futureContactData = futureContactData;
- this.$futureContactData.then(function(data) {
+ this.$futureCardData = futureCardData;
+ this.$futureCardData.then(function(data) {
// The success callback. Calling _.extend from $timeout will wrap it into a try/catch call.
- // I guess this is the only reason to do this.
- Contact.$timeout(function() {
+ Card.$timeout(function() {
angular.extend(self, data);
});
});
};
- Contact.prototype.$fullname = function() {
+ Card.prototype.$fullname = function() {
var fn = this.fn || '';
if (fn.length == 0) {
var names = [];
@@ -91,7 +115,7 @@
return fn;
};
- Contact.prototype.$description = function() {
+ Card.prototype.$description = function() {
var description = [];
if (this.title) description.push(this.title);
if (this.role) description.push(this.role);
@@ -106,30 +130,29 @@
return description.join(', ');
};
- Contact.prototype.$birthday = function() {
+ Card.prototype.$birthday = function() {
return new Date(this.birthday*1000);
};
- Contact.prototype.$isContact = function() {
+ Card.prototype.$isCard = function() {
return this.tag == 'VCARD';
};
- Contact.prototype.$isList = function() {
+ Card.prototype.$isList = function() {
return this.tag == 'VLIST';
};
- Contact.prototype.$delete = function(attribute, index) {
+ Card.prototype.$delete = function(attribute, index) {
if (index > -1 && this[attribute].length > index) {
this[attribute].splice(index, 1);
}
};
- Contact.prototype.$addOrgUnit = function(orgUnit) {
+ Card.prototype.$addOrgUnit = function(orgUnit) {
if (angular.isUndefined(this.orgUnits)) {
this.orgUnits = [{value: orgUnit}];
}
else {
- console.debug(angular.toJson(this.orgUnits));
for (var i = 0; i < this.orgUnits.length; i++) {
if (this.orgUnits[i].value == orgUnit) {
break;
@@ -141,7 +164,7 @@
return this.orgUnits.length - 1;
};
- Contact.prototype.$addCategory = function(category) {
+ Card.prototype.$addCategory = function(category) {
if (angular.isUndefined(this.categories)) {
this.categories = [{value: category}];
}
@@ -157,7 +180,7 @@
return this.categories.length - 1;
};
- Contact.prototype.$addEmail = function(type) {
+ Card.prototype.$addEmail = function(type) {
if (angular.isUndefined(this.emails)) {
this.emails = [{type: type, value: ''}];
}
@@ -167,7 +190,7 @@
return this.emails.length - 1;
};
- Contact.prototype.$addPhone = function(type) {
+ Card.prototype.$addPhone = function(type) {
if (angular.isUndefined(this.phones)) {
this.phones = [{type: type, value: ''}];
}
@@ -177,7 +200,7 @@
return this.phones.length - 1;
};
- Contact.prototype.$addUrl = function(type, url) {
+ Card.prototype.$addUrl = function(type, url) {
if (angular.isUndefined(this.urls)) {
this.urls = [{type: type, value: url}];
}
@@ -187,7 +210,7 @@
return this.urls.length - 1;
};
- Contact.prototype.$addAddress = function(type, postoffice, street, street2, locality, region, country, postalcode) {
+ Card.prototype.$addAddress = function(type, postoffice, street, street2, locality, region, country, postalcode) {
if (angular.isUndefined(this.addresses)) {
this.addresses = [{type: type, postoffice: postoffice, street: street, street2: street2, locality: locality, region: region, country: country, postalcode: postalcode}];
}
@@ -204,15 +227,15 @@
};
/* never call for now */
- Contact.$unwrapCollection = function(futureContactData) {
+ Card.$unwrapCollection = function(futureCardData) {
var collection = {};
- collection.$futureContactData = futureContactData;
+ collection.$futureCardData = futureCardData;
- futureContactData.then(function(contacts) {
- Contact.$timeout(function() {
- angular.forEach(contacts, function(data, index) {
- collection[data.id] = new Contact(data);
+ futureCardData.then(function(cards) {
+ Card.$timeout(function() {
+ angular.forEach(cards, function(data, index) {
+ collection[data.id] = new Card(data);
});
});
});
@@ -221,19 +244,18 @@
};
// $omit returns a sanitized object used to send to the server
- Contact.prototype.$omit = function() {
- var contact = {};
+ Card.prototype.$omit = function() {
+ var card = {};
angular.forEach(this, function(value, key) {
if (key != 'constructor' && key[0] != '$') {
- contact[key] = value;
+ card[key] = value;
}
});
- console.debug(angular.toJson(contact));
- return contact;
+ return card;
};
- Contact.prototype.$save = function() {
- return Contact.$$resource.set([this.pid, this.id].join('/'), this.$omit()).then(function (data) {
+ Card.prototype.$save = function() {
+ return Card.$$resource.set([this.pid, this.id].join('/'), this.$omit()).then(function (data) {
return data;
});
};
diff --git a/UI/WebServerResources/js/ContactsUI.js b/UI/WebServerResources/js/ContactsUI.js
index 6deb00ca1..ebbf53a33 100644
--- a/UI/WebServerResources/js/ContactsUI.js
+++ b/UI/WebServerResources/js/ContactsUI.js
@@ -4,206 +4,200 @@
(function() {
'use strict';
-angular.module('SOGo').config(['$routeProvider', function($routeProvider) {
- $routeProvider
- .when('/:addressbook_id', {
- controller: 'contactDisplayController',
- templateUrl: 'rightPanel.html'
- })
- .when('/:addressbook_id/:contact_id', {
- controller: 'contactDisplayController',
- templateUrl: 'rightPanel.html'
- })
- .otherwise({
- redirectTo: '/personal'
- });
-}]);
+ angular.module('SOGo.Common', []);
-angular.module('SOGo').directive('sgFocusOn', function() {
- return function(scope, elem, attr) {
- scope.$on('sgFocusOn', function(e, name) {
- if (name === attr.sgFocusOn) {
- elem[0].focus();
- }
- });
- };
-});
+ angular.module('SOGo.Contacts', ['ngSanitize', 'ui.router', 'mm.foundation', 'mm.foundation.offcanvas', 'SOGo.Common'])
-angular.module('SOGo').factory('sgFocus', ['$rootScope', '$timeout', function ($rootScope, $timeout) {
- return function(name) {
- $timeout(function (){
- $rootScope.$broadcast('sgFocusOn', name);
- });
- }
-}]);
+ .constant('sgSettings', {
+ 'baseURL': '/SOGo/so/francis/Contacts'
+ })
-// angular.module('SOGo').provider('Contact', function() {
-// var folders = contactFolders;
-// var selectedIndex;
-// this.$get = [function() {
-// var self = this;
-// var service = {
-// getFoldersList: function() {
-// return folders
-// },
-// selectFolder: function(index) {
-// selectedIndex = index;
-// },
-// currentFolder: function() {
-// return selectedIndex;
-// }
-// };
-// return service;
-// }];
-// });
-
-// angular.module('SOGo').controller('addressbookSharingModal', ['$scope', '$rootScope', '$modal', function($scope, $rootScope, $modal) {
-
-// }]);
-
-angular.module('SOGo').controller('addressbooksList', ['$scope', '$rootScope', '$timeout', '$modal', 'sgFocus', 'sgContact', 'sgAddressBook', function($scope, $rootScope, $timeout, $modal, focus, Contact, AddressBook) {
- // Initialize with data from template
- // $rootScope.addressbooks = new Array();
- // angular.forEach(contactFolders, function(folder, index) {
- // $rootScope.addressbooks.push(new AddressBook(folder));
- // // contactFolders[index].$omit();
- // });
- //$scope.contactFolders = contactFolders;
- $rootScope.addressbooks = contactFolders;
- $scope.select = function(rowIndex) {
- //$rootScope.selectedAddressBook = $scope.contactFolders[rowIndex];
- $scope.editMode = false;
- };
- // $rootScope.$on('AddressBook:selected', function(event, id) {
- // $rootScope.selectedAddressBook = id;
- // });
- $scope.rename = function() {
- console.debug("rename folder");
- $scope.editMode = $rootScope.addressbook.id;
- focus('folderName');
- };
- $scope.save = function() {
- console.debug("save addressbook");
- $rootScope.addressbook.$save()
- .then(function(data) {
- console.debug("saved!");
- $scope.editMode = false;
- }, function(data, status) {
- console.debug("failed");
+ .config(['$stateProvider', '$urlRouterProvider', function($stateProvider, $urlRouterProvider) {
+ $stateProvider
+ .state('addressbook', {
+ url: "/:addressbook_id",
+ views: {
+ 'addressbook': {
+ templateUrl: "addressbook.html",
+ controller: 'AddressBookCtrl'
+ }
+ }
+ })
+ .state('addressbook.card', {
+ url: "/:card_id",
+ views: {
+ 'card': {
+ templateUrl: "card.html",
+ controller: 'cardCtrl'
+ }
+ }
});
- };
- $scope.sharing = function() {
- var modal = $modal.open({
- templateUrl: 'addressbookSharing.html',
- //controller: 'addressbookSharingCtrl'
- controller: function($scope, $modalInstance) {
- $scope.closeModal = function() {
- console.debug('please close it');
- $modalInstance.close();
- };
- }
+
+ // if none of the above states are matched, use this as the fallback
+ $urlRouterProvider.otherwise('/personal');
+ }])
+
+ .directive('sgFocusOn', function() {
+ return function(scope, elem, attr) {
+ scope.$on('sgFocusOn', function(e, name) {
+ if (name === attr.sgFocusOn) {
+ elem[0].focus();
+ elem[0].select();
+ }
+ });
+ };
+ })
+
+ .factory('sgFocus', ['$rootScope', '$timeout', function ($rootScope, $timeout) {
+ return function(name) {
+ $timeout(function (){
+ $rootScope.$broadcast('sgFocusOn', name);
});
- // modal.result.then(function() {
- // console.debug('close');
- // }, function() {
- // console.debug('dismiss');
- // });
- };
- // $scope.rename = function(rowIndex) {
- // var folder = $scope.contactFolders[rowIndex];
- // if (folder.owner != "nobody") {
- // showPromptDialog(l("Properties"),
- // l("Address Book Name"),
- // onAddressBookModifyConfirm,
- // folder.name);
- // }
- // };
-}]);
+ }
+ }])
-// angular.module('SOGo').controller('addressbookSharingCtrl', ['$scope', '$modalInstance', function($scope, modal) {
-// $scope.closeModal = function() {
-// console.debug('please close it');
-// modal.close();
-// };
-// }]);
-
-
-angular.module('SOGo').controller('contactDisplayController', ['$scope', '$rootScope', 'sgAddressBook', 'sgContact', 'sgFocus', '$routeParams', function($scope, $rootScope, AddressBook, Contact, focus, $routeParams) {
- if ($routeParams.addressbook_id &&
- ($rootScope.addressbook == undefined || $routeParams.addressbook_id != $rootScope.addressbook.id)) {
- // Selected addressbook has changed
- console.debug("show addressbook " + $routeParams.addressbook_id);
- $rootScope.addressbook = AddressBook.$find($routeParams.addressbook_id);
- // Extend resulting model instance with parameters from addressbooks listing
- angular.forEach($rootScope.addressbooks, function(o, i) {
- if (o.id == $routeParams.addressbook_id) {
- angular.extend($rootScope.addressbook, o);
- $rootScope.addressbooks[i] = $rootScope.addressbook;
+ .controller('AddressBookCtrl', ['$state', '$scope', '$rootScope', '$stateParams', '$timeout', '$modal', 'sgFocus', 'sgCard', 'sgAddressBook', function($state, $scope, $rootScope, $stateParams, $timeout, $modal, focus, Card, AddressBook) {
+ $scope.search = { 'status': null, 'filter': null, 'last_filter': null };
+ if ($stateParams.addressbook_id &&
+ ($rootScope.addressbook == undefined || $stateParams.addressbook_id != $rootScope.addressbook.id)) {
+ // Selected addressbook has changed
+ $rootScope.addressbook = AddressBook.$find($stateParams.addressbook_id);
+ // Extend resulting model instance with parameters from addressbooks listing
+ var o = _.find($rootScope.addressbooks, function(o) {
+ return o.id == $stateParams.addressbook_id;
+ });
+ $scope.search.status = (o.isRemote)? 'remote-addressbook' : '';
+ }
+ // Initialize with data from template
+ $scope.init = function() {
+ $rootScope.addressbooks = AddressBook.$all(contactFolders);
+ };
+ $scope.select = function(rowIndex) {
+ $scope.editMode = false;
+ };
+ $scope.edit = function(i) {
+ if (angular.isUndefined(i)) {
+ i = _.indexOf(_.pluck($rootScope.addressbooks, 'id'), $rootScope.addressbook.id);
}
- });
- angular.extend($rootScope.addressbook, $rootScope.selectedAddressBook);
- }
-
- if ($routeParams.contact_id) {
- console.debug("show contact " + $routeParams.contact_id);
- $rootScope.addressbook.$getContact($routeParams.contact_id);
- $scope.editMode = false;
- }
- $scope.allEmailTypes = Contact.$email_types;
- $scope.allTelTypes = Contact.$tel_types;
- $scope.allUrlTypes = Contact.$url_types;
- $scope.allAddressTypes = Contact.$address_types;
- // $scope.select = function(cname) {
- // console.debug('show contact ' + cname);
- // };
- $scope.edit = function() {
- $rootScope.master_contact = angular.copy($rootScope.addressbook.contact);
- $scope.editMode = true;
- console.debug('edit');
- };
- $scope.addOrgUnit = function() {
- var i = $rootScope.addressbook.contact.$addOrgUnit('');
- focus('orgUnit_' + i);
- };
- $scope.addCategory = function() {
- var i = $rootScope.addressbook.contact.$addCategory($scope.new_category);
- focus('category_' + i);
- };
- $scope.addEmail = function() {
- var i = $rootScope.addressbook.contact.$addEmail($scope.new_email_type);
- focus('email_' + i);
- };
- $scope.addPhone = function() {
- var i = $rootScope.addressbook.contact.$addPhone($scope.new_phone_type);
- focus('phone_' + i);
- };
- $scope.addUrl = function() {
- var i = $rootScope.addressbook.contact.$addUrl('', '');
- focus('url_' + i);
- };
- $scope.addAddress = function() {
- var i = $rootScope.addressbook.contact.$addAddress('', '', '', '', '', '', '', '');
- focus('address_' + i);
- };
- $scope.save = function(contactForm) {
- console.debug("save");
- if (contactForm.$valid) {
- $rootScope.addressbook.contact.$save()
+ $scope.editMode = $rootScope.addressbook.id;
+ focus('addressBookName_' + i);
+ };
+ $scope.save = function(i) {
+ $rootScope.addressbook.name = $rootScope.addressbooks[i].name;
+ $rootScope.addressbook.$save()
.then(function(data) {
console.debug("saved!");
$scope.editMode = false;
}, function(data, status) {
console.debug("failed");
});
+ };
+ $scope.sharing = function() {
+ var modal = $modal.open({
+ templateUrl: 'addressbookSharing.html',
+ //controller: 'addressbookSharingCtrl'
+ controller: function($scope, $modalInstance) {
+ $scope.closeModal = function() {
+ $modalInstance.close();
+ };
+ }
+ });
+ };
+ $scope.doSearch = function(keyEvent) {
+ if ($scope.search.filter != $scope.search.last_filter) {
+ if ($scope.search.filter.length > 2) {
+ $rootScope.addressbook.$filter($scope.search.filter).then(function(data) {
+ if (data.length == 0)
+ $scope.search.status = 'no-result';
+ else
+ $scope.search.status = '';
+ });
+ }
+ else if ($scope.search.filter.length == 0) {
+ $rootScope.addressbook = AddressBook.$find($stateParams.addressbook_id);
+ // Extend resulting model instance with parameters from addressbooks listing
+ var o = _.find($rootScope.addressbooks, function(o) {
+ return o.id == $stateParams.addressbook_id;
+ });
+ $scope.search.status = (o.isRemote)? 'remote-addressbook' : '';
+ }
+ else {
+ $scope.search.status = 'min-char';
+ $rootScope.addressbook.cards = [];
+ }
+ }
+ $scope.search.last_filter = $scope.search.filter;
+ };
+ }])
+
+ // angular.module('SOGo').controller('addressbookSharingCtrl', ['$scope', '$modalInstance', function($scope, modal) {
+ // $scope.closeModal = function() {
+ // console.debug('please close it');
+ // modal.close();
+ // };
+ // }]);
+
+ .controller('cardCtrl', ['$scope', '$rootScope', 'sgAddressBook', 'sgCard', 'sgFocus', '$stateParams', function($scope, $rootScope, AddressBook, Card, focus, $stateParams) {
+ if ($stateParams.card_id) {
+ if ($rootScope.addressbook == null) {
+ // Card is directly access with URL fragment
+ $rootScope.addressbook = AddressBook.$find($stateParams.addressbook_id);
+ }
+ $rootScope.addressbook.$getCard($stateParams.card_id);
+ $scope.editMode = false;
}
- };
- $scope.cancel = function() {
- $scope.reset();
- $scope.editMode = false;
- };
- $scope.reset = function() {
- $rootScope.addressbook.contact = angular.copy($rootScope.master_contact);
- };
-}]);
+ $scope.allEmailTypes = Card.$email_types;
+ $scope.allTelTypes = Card.$tel_types;
+ $scope.allUrlTypes = Card.$url_types;
+ $scope.allAddressTypes = Card.$address_types;
+ $scope.edit = function() {
+ $rootScope.master_card = angular.copy($rootScope.addressbook.card);
+ $scope.editMode = true;
+ console.debug('edit');
+ };
+ $scope.addOrgUnit = function() {
+ var i = $rootScope.addressbook.card.$addOrgUnit('');
+ focus('orgUnit_' + i);
+ };
+ $scope.addCategory = function() {
+ var i = $rootScope.addressbook.card.$addCategory($scope.new_category);
+ focus('category_' + i);
+ };
+ $scope.addEmail = function() {
+ var i = $rootScope.addressbook.card.$addEmail($scope.new_email_type);
+ focus('email_' + i);
+ };
+ $scope.addPhone = function() {
+ var i = $rootScope.addressbook.card.$addPhone($scope.new_phone_type);
+ focus('phone_' + i);
+ };
+ $scope.addUrl = function() {
+ var i = $rootScope.addressbook.card.$addUrl('', '');
+ focus('url_' + i);
+ };
+ $scope.addAddress = function() {
+ var i = $rootScope.addressbook.card.$addAddress('', '', '', '', '', '', '', '');
+ focus('address_' + i);
+ };
+ $scope.save = function(cardForm) {
+ console.debug("save");
+ if (cardForm.$valid) {
+ $rootScope.addressbook.card.$save()
+ .then(function(data) {
+ console.debug("saved!");
+ $scope.editMode = false;
+ }, function(data, status) {
+ console.debug("failed");
+ });
+ }
+ };
+ $scope.cancel = function() {
+ $scope.reset();
+ $scope.editMode = false;
+ };
+ $scope.reset = function() {
+ $rootScope.addressbook.card = angular.copy($rootScope.master_card);
+ };
+ }]);
})();
diff --git a/UI/WebServerResources/js/SOGo.js b/UI/WebServerResources/js/SOGo.js
deleted file mode 100644
index b9c105cf4..000000000
--- a/UI/WebServerResources/js/SOGo.js
+++ /dev/null
@@ -1,8 +0,0 @@
-(function() {
- 'use strict';
-
- angular.module('SOGo', ['ngRoute', 'ngSanitize', 'mm.foundation', 'mm.foundation.offcanvas'])
- .constant('sgSettings', {
- 'baseURL': '/SOGo/so/francis/Contacts'
- });
-})();
diff --git a/UI/WebServerResources/js/app.js b/UI/WebServerResources/js/app.js
deleted file mode 100644
index 98ed014c7..000000000
--- a/UI/WebServerResources/js/app.js
+++ /dev/null
@@ -1,84 +0,0 @@
-//$(document).foundation();
-
-String.prototype.endsWith = function(suffix) {
- return this.indexOf(suffix, this.length - suffix.length) !== -1;
-};
-
-String.prototype.startsWith = function(pattern, position) {
- position = angular.isNumber(position) ? position : 0;
- return this.lastIndexOf(pattern, position) === position;
-};
-
-String.prototype._base64_keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
-String.prototype.base64encode = function () {
- var output = "";
- var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
- var i = 0;
-
- var input = this.utf8encode();
-
- while (i < input.length) {
- chr1 = input.charCodeAt(i++);
- chr2 = input.charCodeAt(i++);
- chr3 = input.charCodeAt(i++);
-
- enc1 = chr1 >> 2;
- enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
- enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
- enc4 = chr3 & 63;
-
- if (isNaN(chr2)) {
- enc3 = enc4 = 64;
- } else if (isNaN(chr3)) {
- enc4 = 64;
- }
-
- output = output +
- this._base64_keyStr.charAt(enc1) + this._base64_keyStr.charAt(enc2) +
- this._base64_keyStr.charAt(enc3) + this._base64_keyStr.charAt(enc4);
- }
-
- return output;
-};
-
-String.prototype.base64decode = function() {
- var output = "";
- var chr1, chr2, chr3;
- var enc1, enc2, enc3, enc4;
- var i = 0;
-
- var input = "" + this; // .replace(/[^A-Za-z0-9\+\/\=]/g, "")
- while (i < input.length) {
- enc1 = this._base64_keyStr.indexOf(input.charAt(i++));
- enc2 = this._base64_keyStr.indexOf(input.charAt(i++));
- enc3 = this._base64_keyStr.indexOf(input.charAt(i++));
- enc4 = this._base64_keyStr.indexOf(input.charAt(i++));
-
- chr1 = (enc1 << 2) | (enc2 >> 4);
- chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
- chr3 = ((enc3 & 3) << 6) | enc4;
-
- output = output + String.fromCharCode(chr1);
-
- if (enc3 != 64) {
- output = output + String.fromCharCode(chr2);
- }
- if (enc4 != 64) {
- output = output + String.fromCharCode(chr3);
- }
- }
-
- return output;
-};
-
-function l(key) {
- var value = key;
- if (labels[key]) {
- value = labels[key];
- }
- else if (clabels[key]) {
- value = clabels[key];
- }
-
- return value;
-}