This repository has been archived by the owner on Nov 3, 2021. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17523 from arcturus/multipledelete2
Bug_956219 Multiple Contact Delete
- Loading branch information
Showing
17 changed files
with
515 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
/* globals Contacts, _, utils, contactsRemover */ | ||
'use strict'; | ||
|
||
var contacts = window.contacts || {}; | ||
|
||
contacts.BulkDelete = (function() { | ||
|
||
var cancelled = false; | ||
|
||
/** | ||
* Loads the overlay class before showing | ||
*/ | ||
function requireOverlay(callback) { | ||
Contacts.utility('Overlay', callback); | ||
} | ||
|
||
// Shows a dialog to confirm the bulk delete | ||
var showConfirm = function showConfirm(n) { | ||
var response = confirm(_('ContactConfirmDel', {n: n})); | ||
return response; | ||
}; | ||
|
||
var doDelete = function doDelete(ids) { | ||
cancelled = false; | ||
var progress = utils.overlay.show(_('DeletingContacts'), 'progressBar'); | ||
progress.setTotal(ids.length); | ||
utils.overlay.showMenu(); | ||
|
||
utils.overlay.oncancel = function() { | ||
cancelled = true; | ||
contactsRemoverObj.finish(); | ||
}; | ||
|
||
var contactsRemoverObj = new contactsRemover(); | ||
contactsRemoverObj.init(ids, function onInitDone() { | ||
contactsRemoverObj.start(); | ||
}); | ||
|
||
contactsRemoverObj.onDeleted = function onDeleted(currentId) { | ||
if (contacts.Search && contacts.Search.isInSearchMode()) { | ||
contacts.Search.invalidateCache(); | ||
contacts.Search.removeContact(currentId); | ||
} | ||
contacts.List.remove(currentId); | ||
progress.update(); | ||
}; | ||
|
||
contactsRemoverObj.onCancelled = function onCancelled() { | ||
Contacts.hideOverlay(); | ||
Contacts.showStatus(_('DeletedTxt', | ||
{n: contactsRemoverObj.getDeletedCount()})); | ||
contacts.Settings.refresh(); | ||
}; | ||
|
||
contactsRemoverObj.onError = function onError() { | ||
Contacts.hideOverlay(); | ||
Contacts.showStatus(_('deleteError-general')); | ||
contacts.Settings.refresh(); | ||
}; | ||
|
||
contactsRemoverObj.onFinished = function onFinished() { | ||
Contacts.hideOverlay(); | ||
Contacts.showStatus(_('DeletedTxt', | ||
{n: contactsRemoverObj.getDeletedCount()})); | ||
contacts.Settings.refresh(); | ||
}; | ||
|
||
}; | ||
// Start the delete of the contacts | ||
var performDelete = function performDelete(promise) { | ||
requireOverlay(function onOverlay() { | ||
utils.overlay.show(_('preparing-contacts'), 'spinner'); | ||
promise.onsuccess = function onSucces(ids) { | ||
Contacts.hideOverlay(); | ||
var confirmDelete = showConfirm(ids.length); | ||
if (confirmDelete) { | ||
doDelete(ids); | ||
} else { | ||
Contacts.showStatus(_('BulkDelCancel')); | ||
} | ||
}; | ||
promise.onerror = function onError() { | ||
Contacts.hideOverlay(); | ||
}; | ||
}); | ||
}; | ||
|
||
return { | ||
'performDelete': performDelete, | ||
'doDelete': doDelete | ||
}; | ||
|
||
})(); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
/* globals mozContact, fb */ | ||
'use strict'; | ||
|
||
/* | ||
* Contacts Remover delete the contacts present in phone. | ||
* - start: To initiate the deleting process. | ||
* - finish: To cancel the deleting process. | ||
* - onDeleted: A Contact has been deleted | ||
* - onFinished: All Selected contacts have been deleted; | ||
* - onError: Error while deleting contacts. | ||
*/ | ||
|
||
function contactsRemover() { | ||
|
||
var totalRemoved = 0; | ||
var totalSelected = 0; | ||
var cancelled = false; | ||
/*jshint validthis:true */ | ||
var self = this; | ||
var ids; | ||
|
||
this.init = function(cIds, cb) { | ||
if (cIds === null || cIds.length === 0) { | ||
return; | ||
} | ||
ids = cIds; | ||
cb(); | ||
}; | ||
|
||
this.start = function() { | ||
totalRemoved = 0; | ||
cancelled = false; | ||
totalSelected = ids.length; | ||
continueCb(ids); | ||
}; | ||
|
||
this.finish = function() { | ||
cancelled = true; | ||
}; | ||
|
||
this.getDeletedCount = function() { | ||
return totalRemoved; | ||
}; | ||
|
||
function continueCb(ids) { | ||
var currentId = ids.shift(); | ||
if (!currentId || cancelled) { | ||
if (totalRemoved === totalSelected) { | ||
notifyFinished(); | ||
} | ||
else { | ||
notifyCancelled(); | ||
} | ||
return; | ||
} | ||
var request = deleteContact(currentId); | ||
request.onSuccess = function() { | ||
totalRemoved++; | ||
notifyDeleted(currentId); | ||
continueCb(ids); | ||
}; | ||
request.onError = function() { | ||
notifyError(); | ||
}; | ||
} | ||
|
||
function notifyError() { | ||
if (typeof self.onError === 'function') { | ||
self.onError(); | ||
} | ||
} | ||
|
||
function notifyCancelled() { | ||
if (typeof self.onCancelled === 'function') { | ||
window.setTimeout(self.onCancelled, 100); | ||
} | ||
} | ||
|
||
function notifyFinished() { | ||
if (typeof self.onFinished === 'function') { | ||
window.setTimeout(self.onFinished, 100); | ||
} | ||
} | ||
|
||
function notifyDeleted(currentId) { | ||
if (typeof self.onDeleted === 'function') { | ||
self.onDeleted(currentId); | ||
} | ||
} | ||
|
||
function deleteContact(currentID) { | ||
var request; | ||
var outreq = {onSuccess: null, onError: null}; | ||
var contact = new mozContact(); | ||
contact.id = currentID; | ||
|
||
if (fb.isFbContact(contact)) { | ||
var fbContact = new fb.Contact(contact); | ||
request = fbContact.remove(); | ||
} else { | ||
request = navigator.mozContacts.remove(contact); | ||
} | ||
request.onsuccess = function() { | ||
outreq.onSuccess(); | ||
}; | ||
request.onerror = function() { | ||
outreq.onError(); | ||
}; | ||
return outreq; | ||
} | ||
} | ||
|
||
window.contactsRemover = contactsRemover; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.