mirror of
https://github.com/owncloudarchive/contacts.git
synced 2024-12-01 13:24:10 +01:00
Contacts: Simplified delayed delete.
This commit is contained in:
parent
addd12c967
commit
7cf2974e0c
@ -1117,10 +1117,10 @@ OC.Contacts = OC.Contacts || {
|
|||||||
if(self.currentid) {
|
if(self.currentid) {
|
||||||
console.assert(utils.isUInt(self.currentid), 'self.currentid is not an integer');
|
console.assert(utils.isUInt(self.currentid), 'self.currentid is not an integer');
|
||||||
self.Contacts.delayedDelete(self.currentid);
|
self.Contacts.delayedDelete(self.currentid);
|
||||||
self.showActions(['addcontact']);
|
|
||||||
} else {
|
} else {
|
||||||
self.Contacts.delayedDelete(self.Contacts.getSelectedContacts());
|
self.Contacts.delayedDelete(self.Contacts.getSelectedContacts());
|
||||||
}
|
}
|
||||||
|
self.showActions(['addcontact']);
|
||||||
});
|
});
|
||||||
|
|
||||||
this.$header.on('click keydown', '.download', function(event) {
|
this.$header.on('click keydown', '.download', function(event) {
|
||||||
|
@ -282,14 +282,26 @@ OC.Contacts = OC.Contacts || {};
|
|||||||
/**
|
/**
|
||||||
* Remove any open contact from the DOM and detach it's list
|
* Remove any open contact from the DOM and detach it's list
|
||||||
* element from the DOM.
|
* element from the DOM.
|
||||||
* @returns The list item jquery object.
|
* @returns The contact object.
|
||||||
*/
|
*/
|
||||||
Contact.prototype.detach = function() {
|
Contact.prototype.detach = function() {
|
||||||
if(this.$fullelem) {
|
if(this.$fullelem) {
|
||||||
this.$fullelem.remove();
|
this.$fullelem.remove();
|
||||||
}
|
}
|
||||||
if(this.$listelem) {
|
if(this.$listelem) {
|
||||||
return this.$listelem.detach();
|
this.$listelem.detach();
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set a contacts list element as (un)checked
|
||||||
|
* @returns The contact object.
|
||||||
|
*/
|
||||||
|
Contact.prototype.setChecked = function(checked) {
|
||||||
|
if(this.$listelem) {
|
||||||
|
this.$listelem.find('input:checkbox').prop('checked', checked);
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -957,7 +969,7 @@ OC.Contacts = OC.Contacts || {};
|
|||||||
});
|
});
|
||||||
|
|
||||||
$(document).bind('status.contact.renamed', function(e, data) {
|
$(document).bind('status.contact.renamed', function(e, data) {
|
||||||
self.insertContact(data.contact.$listelem.detach());
|
self.insertContact(data.contact.getListItemElement().detach());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1068,10 +1080,9 @@ OC.Contacts = OC.Contacts || {};
|
|||||||
}
|
}
|
||||||
|
|
||||||
ContactList.prototype.delayedDelete = function(id) {
|
ContactList.prototype.delayedDelete = function(id) {
|
||||||
var self = this, $listelem;
|
var self = this;
|
||||||
if(utils.isUInt(id)) {
|
if(utils.isUInt(id)) {
|
||||||
this.currentContact = null;
|
this.currentContact = null;
|
||||||
$listelem = this.contacts[id].detach();
|
|
||||||
self.$contactList.show();
|
self.$contactList.show();
|
||||||
this.deletionQueue.push(id);
|
this.deletionQueue.push(id);
|
||||||
} else if(utils.isArray(id)) {
|
} else if(utils.isArray(id)) {
|
||||||
@ -1079,6 +1090,9 @@ OC.Contacts = OC.Contacts || {};
|
|||||||
} else {
|
} else {
|
||||||
throw { name: 'WrongParameterType', message: 'ContactList.delayedDelete only accept integers or arrays.'}
|
throw { name: 'WrongParameterType', message: 'ContactList.delayedDelete only accept integers or arrays.'}
|
||||||
}
|
}
|
||||||
|
$.each(this.deletionQueue, function(idx, id) {
|
||||||
|
self.contacts[id].detach().setChecked(false);
|
||||||
|
});
|
||||||
console.log('deletionQueue', this.deletionQueue);
|
console.log('deletionQueue', this.deletionQueue);
|
||||||
if(!window.onbeforeunload) {
|
if(!window.onbeforeunload) {
|
||||||
window.onbeforeunload = this.warnNotDeleted;
|
window.onbeforeunload = this.warnNotDeleted;
|
||||||
@ -1087,18 +1101,18 @@ OC.Contacts = OC.Contacts || {};
|
|||||||
$(document).trigger('status.visiblecontacts');
|
$(document).trigger('status.visiblecontacts');
|
||||||
}
|
}
|
||||||
OC.notify({
|
OC.notify({
|
||||||
data: $listelem,
|
|
||||||
message:t('contacts','Click to undo deletion of {num} contacts', {num: self.deletionQueue.length}),
|
message:t('contacts','Click to undo deletion of {num} contacts', {num: self.deletionQueue.length}),
|
||||||
//timeout:5,
|
//timeout:5,
|
||||||
timeouthandler:function($listelem) {
|
timeouthandler:function() {
|
||||||
console.log('timeout');
|
console.log('timeout');
|
||||||
self.deleteContacts();
|
// Don't fire all deletes at once
|
||||||
|
self.deletionTimer = setInterval('self.deleteContacts()', 500);
|
||||||
},
|
},
|
||||||
clickhandler:function($listelem) {
|
clickhandler:function() {
|
||||||
console.log('clickhandler');
|
console.log('clickhandler');
|
||||||
if($listelem) {
|
$.each(self.deletionQueue, function(idx, id) {
|
||||||
self.insertContact($listelem);
|
self.insertContact(self.contacts[id].getListItemElement());
|
||||||
}
|
});
|
||||||
OC.notify({cancel:true});
|
OC.notify({cancel:true});
|
||||||
OC.notify({message:t('contacts', 'Cancelled deletion of {num}', {num: self.deletionQueue.length})});
|
OC.notify({message:t('contacts', 'Cancelled deletion of {num}', {num: self.deletionQueue.length})});
|
||||||
self.deletionQueue = [];
|
self.deletionQueue = [];
|
||||||
@ -1114,43 +1128,35 @@ OC.Contacts = OC.Contacts || {};
|
|||||||
ContactList.prototype.deleteContacts = function() {
|
ContactList.prototype.deleteContacts = function() {
|
||||||
var self = this;
|
var self = this;
|
||||||
console.log('ContactList.deleteContacts, deletionQueue', this.deletionQueue);
|
console.log('ContactList.deleteContacts, deletionQueue', this.deletionQueue);
|
||||||
// Local function to update queue.
|
if(typeof this.deletionTimer === 'undefined') {
|
||||||
var updateQueue = function(id) {
|
console.log('No deletion timer!');
|
||||||
console.log('Removing', id, 'from deletionQueue');
|
window.onbeforeunload = null;
|
||||||
OC.Contacts.Contacts.deletionQueue.splice(OC.Contacts.Contacts.deletionQueue.indexOf(parseInt(id)), 1);
|
return;
|
||||||
|
|
||||||
if(OC.Contacts.Contacts.deletionQueue.length === 0) {
|
|
||||||
console.log('deletionQueue is empty');
|
|
||||||
window.onbeforeunload = null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$.each(this.deletionQueue, function(idx, id) {
|
var id = this.deletionQueue.shift();
|
||||||
// Remind me why I do this?
|
if(typeof id === 'undefined') {
|
||||||
if(OC.Contacts.Contacts.deletionQueue.indexOf(id) === -1) {
|
clearInterval(this.deletionTimer);
|
||||||
console.log('Already deleted, returning');
|
delete this.deletionTimer;
|
||||||
updateQueue(id);
|
window.onbeforeunload = null;
|
||||||
return true; // continue
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Let contact remove itself.
|
// Let contact remove itself.
|
||||||
self.contacts[id].destroy(function(response) {
|
self.contacts[id].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];
|
||||||
updateQueue(id);
|
$(document).trigger('status.contact.deleted', {
|
||||||
self.$contactList.show();
|
id: id,
|
||||||
$(document).trigger('status.contact.deleted', {
|
});
|
||||||
id: id,
|
self.length -= 1;
|
||||||
});
|
if(self.length === 0) {
|
||||||
self.length -= 1;
|
$(document).trigger('status.nomorecontacts');
|
||||||
if(self.length === 0) {
|
|
||||||
$(document).trigger('status.nomorecontacts');
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
OC.notify({message:response.message});
|
|
||||||
}
|
}
|
||||||
});
|
} else {
|
||||||
|
OC.notify({message:response.message});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user