mirror of
https://github.com/owncloudarchive/contacts.git
synced 2025-01-30 19:52:17 +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() {
|
buildGroupSelect: function() {
|
||||||
// If a contact is open we know which categories it's in
|
// If a contact is open we know which categories it's in
|
||||||
if(this.currentid) {
|
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();
|
this.$groups.find('optgroup,option:not([value="-1"])').remove();
|
||||||
var addopts = '', rmopts = '';
|
var addopts = '', rmopts = '';
|
||||||
$.each(this.groups.categories, function(i, category) {
|
$.each(this.groups.categories, function(i, category) {
|
||||||
@ -487,7 +490,11 @@ OC.Contacts = OC.Contacts || {
|
|||||||
|
|
||||||
$(document).bind('status.group.contactadded', function(e, result) {
|
$(document).bind('status.group.contactadded', function(e, result) {
|
||||||
console.log('status.group.contactadded', 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
|
// Group sorted, save the sort order
|
||||||
@ -643,7 +650,11 @@ OC.Contacts = OC.Contacts || {
|
|||||||
// Delay each contact to not trigger too many ajax calls
|
// Delay each contact to not trigger too many ajax calls
|
||||||
// at a time.
|
// at a time.
|
||||||
setTimeout(function() {
|
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...
|
// I don't think this is used...
|
||||||
if(buildnow) {
|
if(buildnow) {
|
||||||
self.buildGroupSelect();
|
self.buildGroupSelect();
|
||||||
@ -679,7 +690,11 @@ OC.Contacts = OC.Contacts || {
|
|||||||
// at a time.
|
// at a time.
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
console.log('adding', id, 'to', groupName);
|
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...
|
// I don't think this is used...
|
||||||
if(buildnow) {
|
if(buildnow) {
|
||||||
self.buildGroupSelect();
|
self.buildGroupSelect();
|
||||||
@ -705,7 +720,11 @@ OC.Contacts = OC.Contacts || {
|
|||||||
if(result.status === 'success') {
|
if(result.status === 'success') {
|
||||||
var groupname = $opt.text(), groupid = $opt.val();
|
var groupname = $opt.text(), groupid = $opt.val();
|
||||||
$.each(result.ids, function(idx, id) {
|
$.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) {
|
if(buildnow) {
|
||||||
self.buildGroupSelect();
|
self.buildGroupSelect();
|
||||||
}
|
}
|
||||||
|
@ -1407,32 +1407,44 @@ OC.Contacts = OC.Contacts || {};
|
|||||||
$('tr.contact:not(:visible)').show();
|
$('tr.contact:not(:visible)').show();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
for(var contact in this.contacts) {
|
for(var id in this.contacts) {
|
||||||
contact = parseInt(contact);
|
var contact = this.findById(id);
|
||||||
if(contacts.indexOf(contact) === -1) {
|
if(contact === null) {
|
||||||
this.contacts[contact].getListItemElement().hide();
|
continue;
|
||||||
|
}
|
||||||
|
if(contacts.indexOf(id) === -1) {
|
||||||
|
contact.getListItemElement().hide();
|
||||||
} else {
|
} else {
|
||||||
this.contacts[contact].getListItemElement().show();
|
contact.getListItemElement().show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
ContactList.prototype.contactPos = function(id) {
|
ContactList.prototype.contactPos = function(id) {
|
||||||
if(!id) {
|
var contact = this.findById(id);
|
||||||
console.warn('id missing');
|
if(contact === null) {
|
||||||
return false;
|
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();
|
var pos = $elem.offset().top - this.$contactList.offset().top + this.$contactList.scrollTop();
|
||||||
return pos;
|
return pos;
|
||||||
};
|
};
|
||||||
|
|
||||||
ContactList.prototype.hideContact = function(id) {
|
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) {
|
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.
|
* to load the requested contact if not in list.
|
||||||
*/
|
*/
|
||||||
ContactList.prototype.findById = function(id) {
|
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)];
|
return this.contacts[parseInt(id)];
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -1519,7 +1542,11 @@ OC.Contacts = OC.Contacts || {};
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Let contact remove itself.
|
// 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);
|
console.log('deleteContact', response);
|
||||||
if(response.status === 'success') {
|
if(response.status === 'success') {
|
||||||
delete self.contacts[id];
|
delete self.contacts[id];
|
||||||
@ -1542,10 +1569,13 @@ OC.Contacts = OC.Contacts || {};
|
|||||||
* @returns A jquery object to be inserted in the DOM.
|
* @returns A jquery object to be inserted in the DOM.
|
||||||
*/
|
*/
|
||||||
ContactList.prototype.showContact = function(id, props) {
|
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;
|
this.currentContact = id;
|
||||||
console.log('Contacts.showContact', id, this.contacts[this.currentContact], this.contacts);
|
console.log('Contacts.showContact', id, contact, this.contacts);
|
||||||
return this.contacts[this.currentContact].renderContact(props);
|
return contact.renderContact(props);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user