diff options
author | Thomas Tanghus <thomas@tanghus.net> | 2012-07-30 04:56:20 +0200 |
---|---|---|
committer | Thomas Tanghus <thomas@tanghus.net> | 2012-07-30 04:57:14 +0200 |
commit | 118d9e17b6afe5c3c763737226a90307f67a03b9 (patch) | |
tree | cd21b6333a5895d4345fab02c2baa7f138c1fe2f /apps/contacts | |
parent | b25b73b5b41618247e8a239a332a148b45d7f75b (diff) | |
download | nextcloud-server-118d9e17b6afe5c3c763737226a90307f67a03b9.tar.gz nextcloud-server-118d9e17b6afe5c3c763737226a90307f67a03b9.zip |
Check if the are contacts marked as deleted and warn if so.
Diffstat (limited to 'apps/contacts')
-rw-r--r-- | apps/contacts/js/contacts.js | 60 |
1 files changed, 55 insertions, 5 deletions
diff --git a/apps/contacts/js/contacts.js b/apps/contacts/js/contacts.js index 4c6c8bf3d93..34961360eea 100644 --- a/apps/contacts/js/contacts.js +++ b/apps/contacts/js/contacts.js @@ -14,17 +14,28 @@ Contacts={ UI:{ /** * Arguments: - * message: The text message to show. The only mandatory parameter. + * message: The text message to show. * timeout: The timeout in seconds before the notification disappears. Default 10. * timeouthandler: A function to run on timeout. * clickhandler: A function to run on click. If a timeouthandler is given it will be cancelled. * data: An object that will be passed as argument to the timeouthandler and clickhandler functions. + * cancel: If set cancel all ongoing timer events and hide the notification. */ notify:function(params) { self = this; if(!self.notifier) { self.notifier = $('#notification'); } + if(params.cancel) { + self.notifier.off('click'); + for(var id in self.notifier.data()) { + if($.isNumeric(id)) { + clearTimeout(parseInt(id)); + } + } + self.notifier.text('').fadeOut().removeData(); + return; + } self.notifier.text(params.message); self.notifier.fadeIn(); self.notifier.on('click', function() { $(this).fadeOut();}); @@ -460,6 +471,11 @@ Contacts={ } $('#rightcontent').data('id', newid); + Contacts.UI.Contacts.deletionQueue.push(this.id); + if(!window.onbeforeunload) { + window.onbeforeunload = Contacts.UI.Contacts.warnNotDeleted; + } + with(this) { delete id; delete fn; delete fullname; delete shortname; delete famname; delete givname; delete addname; delete honpre; delete honsuf; delete data; @@ -483,7 +499,7 @@ Contacts={ data:curlistitem, message:t('contacts','Click to undo deletion of "') + curlistitem.find('a').text() + '"', timeouthandler:function(contact) { - Contacts.UI.Card.doDelete(contact.data('id')); + Contacts.UI.Card.doDelete(contact.data('id'), true); delete contact; }, clickhandler:function(contact) { @@ -492,13 +508,21 @@ Contacts={ } }); }, - doDelete:function(id) { + doDelete:function(id, removeFromQueue) { + if(Contacts.UI.Contacts.deletionQueue.indexOf(id) == -1 && removeFromQueue) { + return; + } $.post(OC.filePath('contacts', 'ajax', 'deletecard.php'),{'id':id},function(jsondata) { if(jsondata.status == 'error'){ OC.dialogs.alert(jsondata.data.message, t('contacts', 'Error')); } + if(removeFromQueue) { + Contacts.UI.Contacts.deletionQueue.splice(Contacts.UI.Contacts.deletionQueue.indexOf(id), 1); + } + if(Contacts.UI.Contacts.deletionQueue.length == 0) { + window.onbeforeunload = null; + } }); - return false; }, loadContact:function(jsondata, bookid){ this.data = jsondata; @@ -1477,7 +1501,31 @@ Contacts={ }, Contacts:{ contacts:{}, + deletionQueue:[], batchnum:50, + warnNotDeleted:function(e) { + e = e || window.event; + var warn = t('contacts', 'Some contacts are marked for deletion, but not deleted yet. Please wait for them to be deleted.'); + if (e) { + e.returnValue = String(warn); + } + if(Contacts.UI.Contacts.deletionQueue.length > 0) { + setTimeout(Contacts.UI.Contacts.deleteFilesInQueue, 1); + } + return warn; + }, + deleteFilesInQueue:function() { + var queue = Contacts.UI.Contacts.deletionQueue; + if(queue.length > 0) { + Contacts.UI.notify({cancel:true}); + while(queue.length > 0) { + var id = queue.pop(); + if(id) { + Contacts.UI.Card.doDelete(id, false); + } + } + } + }, getContact:function(id) { if(!this.contacts[id]) { this.contacts[id] = $('#contacts li[data-id="'+id+'"]'); @@ -1774,7 +1822,9 @@ $(document).ready(function(){ }); - // Load a contact. + //$(window).on('beforeunload', Contacts.UI.Contacts.deleteFilesInQueue); + + // Load a contact. $('.contacts').keydown(function(event) { if(event.which == 13 || event.which == 32) { $('.contacts').click(); |