mirror of
https://github.com/inverse-inc/sogo.git
synced 2026-03-22 23:02:43 +00:00
Desktop list editor, mobile contact editor
This commit is contained in:
@@ -25,7 +25,7 @@
|
||||
}];
|
||||
|
||||
/* Factory registration in Angular module */
|
||||
angular.module('SOGo.Contacts').factory('sgAddressBook', AddressBook.$factory);
|
||||
angular.module('SOGo.ContactsUI').factory('sgAddressBook', AddressBook.$factory);
|
||||
|
||||
/* Set or get the list of addressbooks */
|
||||
AddressBook.$all = function(data) {
|
||||
@@ -50,22 +50,35 @@
|
||||
});
|
||||
};
|
||||
|
||||
AddressBook.prototype.$filter = function(search) {
|
||||
/**
|
||||
* @param {} [options]
|
||||
*/
|
||||
AddressBook.prototype.$filter = function(search, options) {
|
||||
var self = this;
|
||||
var params = { 'search': 'name_or_address',
|
||||
'value': search,
|
||||
'sort': 'c_cn',
|
||||
'asc': 'true' };
|
||||
if (options && options.excludeLists) {
|
||||
params.excludeLists = true;
|
||||
}
|
||||
|
||||
return this.$id().then(function(addressbook_id) {
|
||||
var futureAddressBookData = AddressBook.$$resource.filter(addressbook_id, params);
|
||||
return futureAddressBookData.then(function(data) {
|
||||
self.cards = data.cards;
|
||||
var cards;
|
||||
if (options && options.dry) {
|
||||
cards = data.cards;
|
||||
}
|
||||
else {
|
||||
self.cards = data.cards;
|
||||
cards = self.cards;
|
||||
}
|
||||
// Instanciate Card objects
|
||||
angular.forEach(self.cards, function(o, i) {
|
||||
self.cards[i] = new AddressBook.$Card(o);
|
||||
angular.forEach(cards, function(o, i) {
|
||||
cards[i] = new AddressBook.$Card(o);
|
||||
});
|
||||
return self.cards;
|
||||
return cards;
|
||||
});
|
||||
});
|
||||
};
|
||||
@@ -84,10 +97,6 @@
|
||||
var self = this;
|
||||
return this.$id().then(function(addressbook_id) {
|
||||
self.card = AddressBook.$Card.$find(addressbook_id, card_id);
|
||||
self.card.$id().catch(function() {
|
||||
// Card not found
|
||||
self.card = null;
|
||||
});
|
||||
return self.card;
|
||||
});
|
||||
};
|
||||
|
||||
@@ -13,11 +13,10 @@
|
||||
var newCardData = Card.$$resource.newguid(this.pid);
|
||||
this.$unwrap(newCardData);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// The promise will be unwrapped first
|
||||
this.$unwrap(futureCardData);
|
||||
else
|
||||
// The promise will be unwrapped first
|
||||
this.$unwrap(futureCardData);
|
||||
}
|
||||
|
||||
Card.$tel_types = ['work', 'home', 'cell', 'fax', 'pager'];
|
||||
@@ -36,7 +35,7 @@
|
||||
}];
|
||||
|
||||
/* Factory registration in Angular module */
|
||||
angular.module('SOGo.Contacts')
|
||||
angular.module('SOGo.ContactsUI')
|
||||
.factory('sgCard', Card.$factory)
|
||||
|
||||
// Directive to format a postal address
|
||||
@@ -99,7 +98,7 @@
|
||||
|
||||
Card.prototype.$save = function() {
|
||||
var action = 'saveAsContact';
|
||||
if (this.tag == 'VLIST') action = 'saveAsList';
|
||||
if (this.tag == 'vlist') action = 'saveAsList';
|
||||
//var action = 'saveAs' + this.tag.substring(1).capitalize();
|
||||
return Card.$$resource.set([this.pid, this.id || '_new_'].join('/'),
|
||||
this.$omit(),
|
||||
@@ -162,20 +161,51 @@
|
||||
return description.join(', ');
|
||||
};
|
||||
|
||||
Card.prototype.$preferredEmail = function() {
|
||||
var email = _.find(this.emails, function(o) {
|
||||
return o.type == 'pref';
|
||||
});
|
||||
/**
|
||||
* @name $preferredEmail
|
||||
* @desc Returns the first email address of type "pref" or the first address if none found.
|
||||
* @param {string} [partial] - a partial string that the email must match
|
||||
*/
|
||||
Card.prototype.$preferredEmail = function(partial) {
|
||||
var email;
|
||||
if (partial) {
|
||||
var re = new RegExp(partial);
|
||||
email = _.find(this.emails, function(o) {
|
||||
return re.test(o.value);
|
||||
});
|
||||
}
|
||||
if (email) {
|
||||
email = email.value;
|
||||
}
|
||||
else if (this.emails && this.emails.length) {
|
||||
email = this.emails[0].value;
|
||||
else {
|
||||
email = _.find(this.emails, function(o) {
|
||||
return o.type == 'pref';
|
||||
});
|
||||
if (email) {
|
||||
email = email.value;
|
||||
}
|
||||
else if (this.emails && this.emails.length) {
|
||||
email = this.emails[0].value;
|
||||
}
|
||||
else {
|
||||
email = '';
|
||||
}
|
||||
}
|
||||
|
||||
return email;
|
||||
};
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
Card.prototype.$shortFormat = function(partial) {
|
||||
var fullname = this.$fullname();
|
||||
var email = this.$preferredEmail(partial);
|
||||
if (email && email != fullname)
|
||||
fullname += ' (' + email + ')';
|
||||
return fullname;
|
||||
};
|
||||
|
||||
Card.prototype.$birthday = function() {
|
||||
return new Date(this.birthday*1000);
|
||||
};
|
||||
@@ -266,6 +296,35 @@
|
||||
return this.addresses.length - 1;
|
||||
};
|
||||
|
||||
Card.prototype.$addMember = function(email) {
|
||||
if (angular.isUndefined(this.refs)) {
|
||||
this.refs = [{email: email}];
|
||||
}
|
||||
else {
|
||||
for (var i = 0; i < this.refs.length; i++) {
|
||||
if (this.refs[i].email == email) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (i == this.refs.length)
|
||||
this.refs.push({email: email});
|
||||
}
|
||||
return this.refs.length - 1;
|
||||
};
|
||||
|
||||
/**
|
||||
* @name $updateMember
|
||||
* @desc Update an existing list member from a Card instance.
|
||||
* A list member has the following attribtues:
|
||||
* - email
|
||||
* - reference
|
||||
* - fn
|
||||
*/
|
||||
Card.prototype.$updateMember = function(index, email, card) {
|
||||
var ref = {'email': email, 'reference': card.c_name, 'fn': card.$fullname()};
|
||||
this.refs[index] = ref;
|
||||
};
|
||||
|
||||
// Unwrap a promise
|
||||
Card.prototype.$unwrap = function(futureCardData) {
|
||||
var self = this;
|
||||
|
||||
Reference in New Issue
Block a user