Improve JavaScript for Contacts module
This commit is contained in:
parent
fbe412db08
commit
2d6f8e4ea6
|
@ -1,114 +1,117 @@
|
||||||
(function() {
|
(function() {
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
/* Constructor */
|
||||||
function AddressBook(futureAddressBookData) {
|
function AddressBook(futureAddressBookData) {
|
||||||
/* DATA IS IMMEDIATELY AVAILABLE */
|
// Data is immediately available
|
||||||
if (typeof futureAddressBookData.then !== 'function') {
|
if (typeof futureAddressBookData.then !== 'function') {
|
||||||
angular.extend(this, futureAddressBookData);
|
angular.extend(this, futureAddressBookData);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* THE PROMISE WILL BE UNWRAPPED FIRST */
|
// The promise will be unwrapped first
|
||||||
this.$unwrap(futureAddressBookData);
|
this.$unwrap(futureAddressBookData);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* THE FACTORY WE'LL USE TO REGISTER WITH ANGULAR */
|
/* The factory we'll use to register with Angular */
|
||||||
AddressBook.$factory = ['$timeout', 'sgSettings', 'sgResource', 'sgContact', function($timeout, Settings, Resource, Contact) {
|
AddressBook.$factory = ['$timeout', 'sgSettings', 'sgResource', 'sgCard', function($timeout, Settings, Resource, Card) {
|
||||||
angular.extend(AddressBook, {
|
angular.extend(AddressBook, {
|
||||||
$$resource: new Resource(Settings.baseURL),
|
$$resource: new Resource(Settings.baseURL),
|
||||||
$timeout: $timeout,
|
$timeout: $timeout,
|
||||||
$Contact: Contact
|
$Card: Card
|
||||||
});
|
});
|
||||||
|
|
||||||
return AddressBook; // return constructor
|
return AddressBook; // return constructor
|
||||||
}];
|
}];
|
||||||
|
|
||||||
/* ANGULAR MODULE REGISTRATION */
|
/* Factory registration in Angular module */
|
||||||
angular.module('SOGo').factory('sgAddressBook', AddressBook.$factory);
|
angular.module('SOGo.Contacts').factory('sgAddressBook', AddressBook.$factory);
|
||||||
|
|
||||||
// AddressBook.$selectedId = function(addressbook_id) {
|
AddressBook.$all = function(data) {
|
||||||
// if (addressbook_id) angular.extend(AddressBook, { $selected_id: addressbook_id });
|
if (data) {
|
||||||
// console.debug("selected id = " + AddressBook.$selected_id);
|
this.$addressbooks = data;
|
||||||
// return AddressBook.$selected_id;
|
}
|
||||||
// };
|
return this.$addressbooks;
|
||||||
|
};
|
||||||
|
|
||||||
/* Fetch list of contacts */
|
/* Fetch list of cards */
|
||||||
AddressBook.$find = function(addressbook_id) {
|
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);
|
// AddressBook.$selectedId(addressbook_id);
|
||||||
return new AddressBook(futureAddressBookData);
|
return new AddressBook(futureAddressBookData);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Instance methods
|
/* Instance methods */
|
||||||
|
|
||||||
AddressBook.prototype.$id = function() {
|
AddressBook.prototype.$id = function() {
|
||||||
var self = this;
|
|
||||||
return this.$futureAddressBookData.then(function(data) {
|
return this.$futureAddressBookData.then(function(data) {
|
||||||
return data.id;
|
return data.id;
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
AddressBook.prototype.$getContact = function(contact_id) {
|
AddressBook.prototype.$filter = function(search) {
|
||||||
var self = this;
|
var self = this;
|
||||||
// return this.$futureAddressBookData.then(function(data) {
|
var params = { 'search': 'name_or_address',
|
||||||
// return data.id;
|
'value': search,
|
||||||
// }).then(function(addressbook_id) {
|
'sort': 'c_cn',
|
||||||
|
'asc': 'true' };
|
||||||
|
|
||||||
return this.$id().then(function(addressbook_id) {
|
return this.$id().then(function(addressbook_id) {
|
||||||
var contact = AddressBook.$Contact.$find(addressbook_id, contact_id);
|
var futureAddressBookData = AddressBook.$$resource.filter(addressbook_id, params);
|
||||||
|
return futureAddressBookData.then(function(data) {
|
||||||
AddressBook.$timeout(function() {
|
return AddressBook.$timeout(function() {
|
||||||
self.contact = contact;
|
self.cards = data.cards;
|
||||||
});
|
return self.cards;
|
||||||
|
});
|
||||||
return contact.$futureContactData.then(function() {
|
|
||||||
return self.contact;
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
AddressBook.prototype.$resetContact = function() {
|
AddressBook.prototype.$getCard = function(card_id) {
|
||||||
this.$getContact(this.contact.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) {
|
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
|
// Unwrap a promise
|
||||||
AddressBook.prototype.$unwrap = function(futureAddressBookData) {
|
AddressBook.prototype.$unwrap = function(futureAddressBookData) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
this.$futureAddressBookData = futureAddressBookData;
|
this.$futureAddressBookData = futureAddressBookData;
|
||||||
this.$futureAddressBookData.then(function(data) {
|
this.$futureAddressBookData.then(function(data) {
|
||||||
// The success callback. Calling _.extend from $timeout will wrap it into a try/catch call
|
AddressBook.$timeout(function() {
|
||||||
// and return a promise.
|
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 = {};
|
var addressbook = {};
|
||||||
angular.forEach(this, function(value, key) {
|
angular.forEach(this, function(value, key) {
|
||||||
if (key != 'constructor' &&
|
if (key != 'constructor' &&
|
||||||
key != 'contact' &&
|
key != 'card' &&
|
||||||
key != 'contacts' &&
|
key != 'cards' &&
|
||||||
key[0] != '$') {
|
key[0] != '$') {
|
||||||
addressbook[key] = value;
|
addressbook[key] = value;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
console.debug(angular.toJson(addressbook));
|
|
||||||
return addressbook;
|
return addressbook;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -3,51 +3,76 @@
|
||||||
|
|
||||||
/* Constructor */
|
/* Constructor */
|
||||||
|
|
||||||
function Contact(futureContactData) {
|
function Card(futureCardData) {
|
||||||
|
|
||||||
/* DATA IS IMMEDIATELY AVAILABLE */
|
/* DATA IS IMMEDIATELY AVAILABLE */
|
||||||
// if (!futureContactData.inspect) {
|
// if (!futureCardData.inspect) {
|
||||||
// angular.extend(this, futureContactData);
|
// angular.extend(this, futureCardData);
|
||||||
// return;
|
// return;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
/* THE PROMISE WILL BE UNWRAPPED FIRST */
|
/* THE PROMISE WILL BE UNWRAPPED FIRST */
|
||||||
this.$unwrap(futureContactData);
|
this.$unwrap(futureCardData);
|
||||||
}
|
}
|
||||||
|
|
||||||
Contact.$tel_types = [_('work'), 'home', 'cell', 'fax', 'pager'];
|
Card.$tel_types = ['work', 'home', 'cell', 'fax', 'pager'];
|
||||||
Contact.$email_types = ['work', 'home', 'pref'];
|
Card.$email_types = ['work', 'home', 'pref'];
|
||||||
Contact.$url_types = ['work', 'home', 'pref'];
|
Card.$url_types = ['work', 'home', 'pref'];
|
||||||
Contact.$address_types = ['work', 'home'];
|
Card.$address_types = ['work', 'home'];
|
||||||
|
|
||||||
/* THE FACTORY WE'LL USE TO REGISTER WITH ANGULAR */
|
/* THE FACTORY WE'LL USE TO REGISTER WITH ANGULAR */
|
||||||
Contact.$factory = ['$timeout', 'sgSettings', 'sgResource', function($timeout, Settings, Resource) {
|
Card.$factory = ['$timeout', 'sgSettings', 'sgResource', function($timeout, Settings, Resource) {
|
||||||
angular.extend(Contact, {
|
angular.extend(Card, {
|
||||||
$$resource: new Resource(Settings.baseURL),
|
$$resource: new Resource(Settings.baseURL),
|
||||||
$timeout: $timeout
|
$timeout: $timeout
|
||||||
});
|
});
|
||||||
|
|
||||||
return Contact; // return constructor
|
return Card; // return constructor
|
||||||
}];
|
}];
|
||||||
|
|
||||||
/* ANGULAR MODULE REGISTRATION */
|
/* 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('<br>');
|
||||||
|
};
|
||||||
|
}],
|
||||||
|
template: '<address ng-bind-html="addressLines(data)"></address>'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
/* FETCH A UNIT */
|
/* FETCH A UNIT */
|
||||||
Contact.$find = function(addressbook_id, contact_id) {
|
Card.$find = function(addressbook_id, card_id) {
|
||||||
|
|
||||||
/* FALLS BACK ON AN INSTANCE OF RESOURCE */
|
/* FALLS BACK ON AN INSTANCE OF RESOURCE */
|
||||||
// Fetch data over the wire.
|
// 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
|
// Instance methods
|
||||||
|
|
||||||
Contact.prototype.$id = function() {
|
Card.prototype.$id = function() {
|
||||||
//var self = this;
|
//var self = this;
|
||||||
return this.$futureAddressBookData.then(function(data) {
|
return this.$futureAddressBookData.then(function(data) {
|
||||||
return data.id;
|
return data.id;
|
||||||
|
@ -55,20 +80,19 @@
|
||||||
};
|
};
|
||||||
|
|
||||||
// Unwrap a promise
|
// Unwrap a promise
|
||||||
Contact.prototype.$unwrap = function(futureContactData) {
|
Card.prototype.$unwrap = function(futureCardData) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
this.$futureContactData = futureContactData;
|
this.$futureCardData = futureCardData;
|
||||||
this.$futureContactData.then(function(data) {
|
this.$futureCardData.then(function(data) {
|
||||||
// The success callback. Calling _.extend from $timeout will wrap it into a try/catch call.
|
// 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.
|
Card.$timeout(function() {
|
||||||
Contact.$timeout(function() {
|
|
||||||
angular.extend(self, data);
|
angular.extend(self, data);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
Contact.prototype.$fullname = function() {
|
Card.prototype.$fullname = function() {
|
||||||
var fn = this.fn || '';
|
var fn = this.fn || '';
|
||||||
if (fn.length == 0) {
|
if (fn.length == 0) {
|
||||||
var names = [];
|
var names = [];
|
||||||
|
@ -91,7 +115,7 @@
|
||||||
return fn;
|
return fn;
|
||||||
};
|
};
|
||||||
|
|
||||||
Contact.prototype.$description = function() {
|
Card.prototype.$description = function() {
|
||||||
var description = [];
|
var description = [];
|
||||||
if (this.title) description.push(this.title);
|
if (this.title) description.push(this.title);
|
||||||
if (this.role) description.push(this.role);
|
if (this.role) description.push(this.role);
|
||||||
|
@ -106,30 +130,29 @@
|
||||||
return description.join(', ');
|
return description.join(', ');
|
||||||
};
|
};
|
||||||
|
|
||||||
Contact.prototype.$birthday = function() {
|
Card.prototype.$birthday = function() {
|
||||||
return new Date(this.birthday*1000);
|
return new Date(this.birthday*1000);
|
||||||
};
|
};
|
||||||
|
|
||||||
Contact.prototype.$isContact = function() {
|
Card.prototype.$isCard = function() {
|
||||||
return this.tag == 'VCARD';
|
return this.tag == 'VCARD';
|
||||||
};
|
};
|
||||||
|
|
||||||
Contact.prototype.$isList = function() {
|
Card.prototype.$isList = function() {
|
||||||
return this.tag == 'VLIST';
|
return this.tag == 'VLIST';
|
||||||
};
|
};
|
||||||
|
|
||||||
Contact.prototype.$delete = function(attribute, index) {
|
Card.prototype.$delete = function(attribute, index) {
|
||||||
if (index > -1 && this[attribute].length > index) {
|
if (index > -1 && this[attribute].length > index) {
|
||||||
this[attribute].splice(index, 1);
|
this[attribute].splice(index, 1);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Contact.prototype.$addOrgUnit = function(orgUnit) {
|
Card.prototype.$addOrgUnit = function(orgUnit) {
|
||||||
if (angular.isUndefined(this.orgUnits)) {
|
if (angular.isUndefined(this.orgUnits)) {
|
||||||
this.orgUnits = [{value: orgUnit}];
|
this.orgUnits = [{value: orgUnit}];
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
console.debug(angular.toJson(this.orgUnits));
|
|
||||||
for (var i = 0; i < this.orgUnits.length; i++) {
|
for (var i = 0; i < this.orgUnits.length; i++) {
|
||||||
if (this.orgUnits[i].value == orgUnit) {
|
if (this.orgUnits[i].value == orgUnit) {
|
||||||
break;
|
break;
|
||||||
|
@ -141,7 +164,7 @@
|
||||||
return this.orgUnits.length - 1;
|
return this.orgUnits.length - 1;
|
||||||
};
|
};
|
||||||
|
|
||||||
Contact.prototype.$addCategory = function(category) {
|
Card.prototype.$addCategory = function(category) {
|
||||||
if (angular.isUndefined(this.categories)) {
|
if (angular.isUndefined(this.categories)) {
|
||||||
this.categories = [{value: category}];
|
this.categories = [{value: category}];
|
||||||
}
|
}
|
||||||
|
@ -157,7 +180,7 @@
|
||||||
return this.categories.length - 1;
|
return this.categories.length - 1;
|
||||||
};
|
};
|
||||||
|
|
||||||
Contact.prototype.$addEmail = function(type) {
|
Card.prototype.$addEmail = function(type) {
|
||||||
if (angular.isUndefined(this.emails)) {
|
if (angular.isUndefined(this.emails)) {
|
||||||
this.emails = [{type: type, value: ''}];
|
this.emails = [{type: type, value: ''}];
|
||||||
}
|
}
|
||||||
|
@ -167,7 +190,7 @@
|
||||||
return this.emails.length - 1;
|
return this.emails.length - 1;
|
||||||
};
|
};
|
||||||
|
|
||||||
Contact.prototype.$addPhone = function(type) {
|
Card.prototype.$addPhone = function(type) {
|
||||||
if (angular.isUndefined(this.phones)) {
|
if (angular.isUndefined(this.phones)) {
|
||||||
this.phones = [{type: type, value: ''}];
|
this.phones = [{type: type, value: ''}];
|
||||||
}
|
}
|
||||||
|
@ -177,7 +200,7 @@
|
||||||
return this.phones.length - 1;
|
return this.phones.length - 1;
|
||||||
};
|
};
|
||||||
|
|
||||||
Contact.prototype.$addUrl = function(type, url) {
|
Card.prototype.$addUrl = function(type, url) {
|
||||||
if (angular.isUndefined(this.urls)) {
|
if (angular.isUndefined(this.urls)) {
|
||||||
this.urls = [{type: type, value: url}];
|
this.urls = [{type: type, value: url}];
|
||||||
}
|
}
|
||||||
|
@ -187,7 +210,7 @@
|
||||||
return this.urls.length - 1;
|
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)) {
|
if (angular.isUndefined(this.addresses)) {
|
||||||
this.addresses = [{type: type, postoffice: postoffice, street: street, street2: street2, locality: locality, region: region, country: country, postalcode: postalcode}];
|
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 */
|
/* never call for now */
|
||||||
Contact.$unwrapCollection = function(futureContactData) {
|
Card.$unwrapCollection = function(futureCardData) {
|
||||||
var collection = {};
|
var collection = {};
|
||||||
|
|
||||||
collection.$futureContactData = futureContactData;
|
collection.$futureCardData = futureCardData;
|
||||||
|
|
||||||
futureContactData.then(function(contacts) {
|
futureCardData.then(function(cards) {
|
||||||
Contact.$timeout(function() {
|
Card.$timeout(function() {
|
||||||
angular.forEach(contacts, function(data, index) {
|
angular.forEach(cards, function(data, index) {
|
||||||
collection[data.id] = new Contact(data);
|
collection[data.id] = new Card(data);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -221,19 +244,18 @@
|
||||||
};
|
};
|
||||||
|
|
||||||
// $omit returns a sanitized object used to send to the server
|
// $omit returns a sanitized object used to send to the server
|
||||||
Contact.prototype.$omit = function() {
|
Card.prototype.$omit = function() {
|
||||||
var contact = {};
|
var card = {};
|
||||||
angular.forEach(this, function(value, key) {
|
angular.forEach(this, function(value, key) {
|
||||||
if (key != 'constructor' && key[0] != '$') {
|
if (key != 'constructor' && key[0] != '$') {
|
||||||
contact[key] = value;
|
card[key] = value;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
console.debug(angular.toJson(contact));
|
return card;
|
||||||
return contact;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Contact.prototype.$save = function() {
|
Card.prototype.$save = function() {
|
||||||
return Contact.$$resource.set([this.pid, this.id].join('/'), this.$omit()).then(function (data) {
|
return Card.$$resource.set([this.pid, this.id].join('/'), this.$omit()).then(function (data) {
|
||||||
return data;
|
return data;
|
||||||
});
|
});
|
||||||
};
|
};
|
|
@ -4,206 +4,200 @@
|
||||||
(function() {
|
(function() {
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
angular.module('SOGo').config(['$routeProvider', function($routeProvider) {
|
angular.module('SOGo.Common', []);
|
||||||
$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').directive('sgFocusOn', function() {
|
angular.module('SOGo.Contacts', ['ngSanitize', 'ui.router', 'mm.foundation', 'mm.foundation.offcanvas', 'SOGo.Common'])
|
||||||
return function(scope, elem, attr) {
|
|
||||||
scope.$on('sgFocusOn', function(e, name) {
|
|
||||||
if (name === attr.sgFocusOn) {
|
|
||||||
elem[0].focus();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
angular.module('SOGo').factory('sgFocus', ['$rootScope', '$timeout', function ($rootScope, $timeout) {
|
.constant('sgSettings', {
|
||||||
return function(name) {
|
'baseURL': '/SOGo/so/francis/Contacts'
|
||||||
$timeout(function (){
|
})
|
||||||
$rootScope.$broadcast('sgFocusOn', name);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}]);
|
|
||||||
|
|
||||||
// angular.module('SOGo').provider('Contact', function() {
|
.config(['$stateProvider', '$urlRouterProvider', function($stateProvider, $urlRouterProvider) {
|
||||||
// var folders = contactFolders;
|
$stateProvider
|
||||||
// var selectedIndex;
|
.state('addressbook', {
|
||||||
// this.$get = [function() {
|
url: "/:addressbook_id",
|
||||||
// var self = this;
|
views: {
|
||||||
// var service = {
|
'addressbook': {
|
||||||
// getFoldersList: function() {
|
templateUrl: "addressbook.html",
|
||||||
// return folders
|
controller: 'AddressBookCtrl'
|
||||||
// },
|
}
|
||||||
// selectFolder: function(index) {
|
}
|
||||||
// selectedIndex = index;
|
})
|
||||||
// },
|
.state('addressbook.card', {
|
||||||
// currentFolder: function() {
|
url: "/:card_id",
|
||||||
// return selectedIndex;
|
views: {
|
||||||
// }
|
'card': {
|
||||||
// };
|
templateUrl: "card.html",
|
||||||
// return service;
|
controller: 'cardCtrl'
|
||||||
// }];
|
}
|
||||||
// });
|
}
|
||||||
|
|
||||||
// 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");
|
|
||||||
});
|
});
|
||||||
};
|
|
||||||
$scope.sharing = function() {
|
// if none of the above states are matched, use this as the fallback
|
||||||
var modal = $modal.open({
|
$urlRouterProvider.otherwise('/personal');
|
||||||
templateUrl: 'addressbookSharing.html',
|
}])
|
||||||
//controller: 'addressbookSharingCtrl'
|
|
||||||
controller: function($scope, $modalInstance) {
|
.directive('sgFocusOn', function() {
|
||||||
$scope.closeModal = function() {
|
return function(scope, elem, attr) {
|
||||||
console.debug('please close it');
|
scope.$on('sgFocusOn', function(e, name) {
|
||||||
$modalInstance.close();
|
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) {
|
.controller('AddressBookCtrl', ['$state', '$scope', '$rootScope', '$stateParams', '$timeout', '$modal', 'sgFocus', 'sgCard', 'sgAddressBook', function($state, $scope, $rootScope, $stateParams, $timeout, $modal, focus, Card, AddressBook) {
|
||||||
// $scope.closeModal = function() {
|
$scope.search = { 'status': null, 'filter': null, 'last_filter': null };
|
||||||
// console.debug('please close it');
|
if ($stateParams.addressbook_id &&
|
||||||
// modal.close();
|
($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) {
|
||||||
angular.module('SOGo').controller('contactDisplayController', ['$scope', '$rootScope', 'sgAddressBook', 'sgContact', 'sgFocus', '$routeParams', function($scope, $rootScope, AddressBook, Contact, focus, $routeParams) {
|
return o.id == $stateParams.addressbook_id;
|
||||||
if ($routeParams.addressbook_id &&
|
});
|
||||||
($rootScope.addressbook == undefined || $routeParams.addressbook_id != $rootScope.addressbook.id)) {
|
$scope.search.status = (o.isRemote)? 'remote-addressbook' : '';
|
||||||
// Selected addressbook has changed
|
}
|
||||||
console.debug("show addressbook " + $routeParams.addressbook_id);
|
// Initialize with data from template
|
||||||
$rootScope.addressbook = AddressBook.$find($routeParams.addressbook_id);
|
$scope.init = function() {
|
||||||
// Extend resulting model instance with parameters from addressbooks listing
|
$rootScope.addressbooks = AddressBook.$all(contactFolders);
|
||||||
angular.forEach($rootScope.addressbooks, function(o, i) {
|
};
|
||||||
if (o.id == $routeParams.addressbook_id) {
|
$scope.select = function(rowIndex) {
|
||||||
angular.extend($rootScope.addressbook, o);
|
$scope.editMode = false;
|
||||||
$rootScope.addressbooks[i] = $rootScope.addressbook;
|
};
|
||||||
|
$scope.edit = function(i) {
|
||||||
|
if (angular.isUndefined(i)) {
|
||||||
|
i = _.indexOf(_.pluck($rootScope.addressbooks, 'id'), $rootScope.addressbook.id);
|
||||||
}
|
}
|
||||||
});
|
$scope.editMode = $rootScope.addressbook.id;
|
||||||
angular.extend($rootScope.addressbook, $rootScope.selectedAddressBook);
|
focus('addressBookName_' + i);
|
||||||
}
|
};
|
||||||
|
$scope.save = function(i) {
|
||||||
if ($routeParams.contact_id) {
|
$rootScope.addressbook.name = $rootScope.addressbooks[i].name;
|
||||||
console.debug("show contact " + $routeParams.contact_id);
|
$rootScope.addressbook.$save()
|
||||||
$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()
|
|
||||||
.then(function(data) {
|
.then(function(data) {
|
||||||
console.debug("saved!");
|
console.debug("saved!");
|
||||||
$scope.editMode = false;
|
$scope.editMode = false;
|
||||||
}, function(data, status) {
|
}, function(data, status) {
|
||||||
console.debug("failed");
|
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.allEmailTypes = Card.$email_types;
|
||||||
$scope.cancel = function() {
|
$scope.allTelTypes = Card.$tel_types;
|
||||||
$scope.reset();
|
$scope.allUrlTypes = Card.$url_types;
|
||||||
$scope.editMode = false;
|
$scope.allAddressTypes = Card.$address_types;
|
||||||
};
|
$scope.edit = function() {
|
||||||
$scope.reset = function() {
|
$rootScope.master_card = angular.copy($rootScope.addressbook.card);
|
||||||
$rootScope.addressbook.contact = angular.copy($rootScope.master_contact);
|
$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);
|
||||||
|
};
|
||||||
|
}]);
|
||||||
|
|
||||||
})();
|
})();
|
||||||
|
|
|
@ -1,8 +0,0 @@
|
||||||
(function() {
|
|
||||||
'use strict';
|
|
||||||
|
|
||||||
angular.module('SOGo', ['ngRoute', 'ngSanitize', 'mm.foundation', 'mm.foundation.offcanvas'])
|
|
||||||
.constant('sgSettings', {
|
|
||||||
'baseURL': '/SOGo/so/francis/Contacts'
|
|
||||||
});
|
|
||||||
})();
|
|
|
@ -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;
|
|
||||||
}
|
|
Loading…
Reference in a new issue