mirror of
https://github.com/owncloudarchive/contacts.git
synced 2025-01-18 07:52:21 +01:00
Contacts: Some more error checking
This commit is contained in:
parent
df92b31a51
commit
9aeec46945
29
js/app.js
29
js/app.js
@ -250,7 +250,10 @@ OC.Contacts = OC.Contacts || {
|
||||
buildGroupSelect: function() {
|
||||
// If a contact is open we know which categories it's in
|
||||
if(this.currentid) {
|
||||
var contact = this.contacts.contacts[this.currentid];
|
||||
var contact = this.contacts.findById(this.currentid);
|
||||
if(contact === null) {
|
||||
return false;
|
||||
}
|
||||
this.$groups.find('optgroup,option:not([value="-1"])').remove();
|
||||
var addopts = '', rmopts = '';
|
||||
$.each(this.groups.categories, function(i, category) {
|
||||
@ -487,7 +490,11 @@ OC.Contacts = OC.Contacts || {
|
||||
|
||||
$(document).bind('status.group.contactadded', function(e, result) {
|
||||
console.log('status.group.contactadded', result);
|
||||
self.contacts.contacts[parseInt(result.contactid)].addToGroup(result.groupname);
|
||||
var contact = self.contacts.findById(self.currentid);
|
||||
if(contact === null) {
|
||||
return false;
|
||||
}
|
||||
contact.addToGroup(result.groupname);
|
||||
});
|
||||
|
||||
// Group sorted, save the sort order
|
||||
@ -643,7 +650,11 @@ OC.Contacts = OC.Contacts || {
|
||||
// Delay each contact to not trigger too many ajax calls
|
||||
// at a time.
|
||||
setTimeout(function() {
|
||||
self.contacts.contacts[id].addToGroup(groupName);
|
||||
var contact = self.contacts.findById(id);
|
||||
if(contact === null) {
|
||||
return true;
|
||||
}
|
||||
contact.addToGroup(groupName);
|
||||
// I don't think this is used...
|
||||
if(buildnow) {
|
||||
self.buildGroupSelect();
|
||||
@ -679,7 +690,11 @@ OC.Contacts = OC.Contacts || {
|
||||
// at a time.
|
||||
setTimeout(function() {
|
||||
console.log('adding', id, 'to', groupName);
|
||||
self.contacts.contacts[id].addToGroup(groupName);
|
||||
var contact = self.contacts.findById(id);
|
||||
if(contact === null) {
|
||||
return true;
|
||||
}
|
||||
contact.addToGroup(groupName);
|
||||
// I don't think this is used...
|
||||
if(buildnow) {
|
||||
self.buildGroupSelect();
|
||||
@ -705,7 +720,11 @@ OC.Contacts = OC.Contacts || {
|
||||
if(result.status === 'success') {
|
||||
var groupname = $opt.text(), groupid = $opt.val();
|
||||
$.each(result.ids, function(idx, id) {
|
||||
self.contacts.contacts[id].removeFromGroup(groupname);
|
||||
var contact = self.contacts.findById(id);
|
||||
if(contact === null) {
|
||||
return true;
|
||||
}
|
||||
contact.removeFromGroup(groupname);
|
||||
if(buildnow) {
|
||||
self.buildGroupSelect();
|
||||
}
|
||||
|
@ -1407,32 +1407,44 @@ OC.Contacts = OC.Contacts || {};
|
||||
$('tr.contact:not(:visible)').show();
|
||||
return;
|
||||
}
|
||||
for(var contact in this.contacts) {
|
||||
contact = parseInt(contact);
|
||||
if(contacts.indexOf(contact) === -1) {
|
||||
this.contacts[contact].getListItemElement().hide();
|
||||
for(var id in this.contacts) {
|
||||
var contact = this.findById(id);
|
||||
if(contact === null) {
|
||||
continue;
|
||||
}
|
||||
if(contacts.indexOf(id) === -1) {
|
||||
contact.getListItemElement().hide();
|
||||
} else {
|
||||
this.contacts[contact].getListItemElement().show();
|
||||
contact.getListItemElement().show();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
ContactList.prototype.contactPos = function(id) {
|
||||
if(!id) {
|
||||
console.warn('id missing');
|
||||
return false;
|
||||
var contact = this.findById(id);
|
||||
if(contact === null) {
|
||||
return 0;
|
||||
}
|
||||
var $elem = this.contacts[parseInt(id)].getListItemElement();
|
||||
|
||||
var $elem = contact.getListItemElement();
|
||||
var pos = $elem.offset().top - this.$contactList.offset().top + this.$contactList.scrollTop();
|
||||
return pos;
|
||||
};
|
||||
|
||||
ContactList.prototype.hideContact = function(id) {
|
||||
this.contacts[parseInt(id)].hide();
|
||||
var contact = this.findById(id);
|
||||
if(contact === null) {
|
||||
return false;
|
||||
}
|
||||
contact.hide();
|
||||
};
|
||||
|
||||
ContactList.prototype.closeContact = function(id) {
|
||||
this.contacts[parseInt(id)].close();
|
||||
var contact = this.findById(id);
|
||||
if(contact === null) {
|
||||
return false;
|
||||
}
|
||||
contact.close();
|
||||
};
|
||||
|
||||
/**
|
||||
@ -1443,6 +1455,17 @@ OC.Contacts = OC.Contacts || {};
|
||||
* to load the requested contact if not in list.
|
||||
*/
|
||||
ContactList.prototype.findById = function(id) {
|
||||
if(!id) {
|
||||
console.warn('id missing');
|
||||
console.trace();
|
||||
return false;
|
||||
}
|
||||
id = parseInt(id);
|
||||
if(typeof this.contacts[id] === 'undefined') {
|
||||
console.warn('Could not find contact with id', id);
|
||||
console.trace();
|
||||
return null;
|
||||
}
|
||||
return this.contacts[parseInt(id)];
|
||||
};
|
||||
|
||||
@ -1519,7 +1542,11 @@ OC.Contacts = OC.Contacts || {};
|
||||
}
|
||||
|
||||
// Let contact remove itself.
|
||||
self.contacts[id].destroy(function(response) {
|
||||
var contact = this.findById(id);
|
||||
if(contact === null) {
|
||||
return false;
|
||||
}
|
||||
contact.destroy(function(response) {
|
||||
console.log('deleteContact', response);
|
||||
if(response.status === 'success') {
|
||||
delete self.contacts[id];
|
||||
@ -1542,10 +1569,13 @@ OC.Contacts = OC.Contacts || {};
|
||||
* @returns A jquery object to be inserted in the DOM.
|
||||
*/
|
||||
ContactList.prototype.showContact = function(id, props) {
|
||||
console.assert(typeof id === 'number', 'ContactList.showContact called with a non-number');
|
||||
var contact = this.findById(id);
|
||||
if(contact === null) {
|
||||
return false;
|
||||
}
|
||||
this.currentContact = id;
|
||||
console.log('Contacts.showContact', id, this.contacts[this.currentContact], this.contacts);
|
||||
return this.contacts[this.currentContact].renderContact(props);
|
||||
console.log('Contacts.showContact', id, contact, this.contacts);
|
||||
return contact.renderContact(props);
|
||||
};
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user