Publish Vulpes Preview 15 sources for desktop, Android and Tundra
Share Gaia assets and adapters, keep private profiles and development documents local, and update both public READMEs.
This commit is contained in:
parent
93e3a48004
commit
b38dea0597
25901 changed files with 9982925 additions and 369 deletions
200
gaia/apps/communications/contacts/js/export/bt.js
Executable file
200
gaia/apps/communications/contacts/js/export/bt.js
Executable file
|
|
@ -0,0 +1,200 @@
|
|||
/* global getStorageIfAvailable, getUnusedFilename, ContactToVcardBlob,
|
||||
MozActivity, utils */
|
||||
|
||||
/* exported ContactsBTExport */
|
||||
'use strict';
|
||||
|
||||
var ContactsBTExport = function ContactsBTExport() {
|
||||
var contacts;
|
||||
var progressStep;
|
||||
var cancelled = false;
|
||||
var _ = navigator.mozL10n.get;
|
||||
|
||||
var _setContactsToExport = function btex_setContactsToExport(cts) {
|
||||
contacts = cts;
|
||||
};
|
||||
|
||||
var _hasDeterminativeProgress = function btex_hasDeterminativeProgress() {
|
||||
return false;
|
||||
};
|
||||
|
||||
var _getExportTitle = function btex_getExportTitle() {
|
||||
return 'btExport-title';
|
||||
};
|
||||
|
||||
var _setProgressStep = function btex_setProgressStep(p) {
|
||||
progressStep = p;
|
||||
};
|
||||
|
||||
var _getGivenName = function _getGivenName(contact) {
|
||||
return (Array.isArray(contact.givenName) && contact.givenName[0] &&
|
||||
contact.givenName[0].trim());
|
||||
};
|
||||
var _getLastName = function _getLastName(contact) {
|
||||
return (Array.isArray(contact.familyName) && contact.familyName[0] &&
|
||||
contact.familyName[0].trim());
|
||||
};
|
||||
var _getFileName = function _getFileName() {
|
||||
var filename = [];
|
||||
if (contacts && contacts.length === 1) {
|
||||
var contact = contacts[0],
|
||||
givenName = _getGivenName(contact),
|
||||
lastName = _getLastName(contact);
|
||||
if (givenName) {
|
||||
filename.push(givenName);
|
||||
}
|
||||
if (lastName) {
|
||||
filename.push(lastName);
|
||||
}
|
||||
if (filename.length === 0) {
|
||||
if (contact.org && contact.org.length > 0) {
|
||||
filename.push(contact.org[0]);
|
||||
} else if (contact.tel && contact.tel.length > 0) {
|
||||
filename.push(contact.tel[0].value);
|
||||
} else if (contact.email && contact.email.length > 0) {
|
||||
filename.push(contact.email[0].value);
|
||||
} else {
|
||||
filename.push(_('noName'));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
var today = new Date();
|
||||
filename.push(
|
||||
today.getFullYear(),
|
||||
today.getMonth() + 1,
|
||||
today.getDate(),
|
||||
contacts.length
|
||||
);
|
||||
}
|
||||
|
||||
return filename.join('_')
|
||||
.replace(/[^a-z0-9]/gi, '_')
|
||||
.toLowerCase() +
|
||||
'.vcf';
|
||||
};
|
||||
var _getStorage = function _getStorage(fileName, blob, callback) {
|
||||
if (typeof callback !== 'function') {
|
||||
throw new Error('getStorage requires a callback function');
|
||||
}
|
||||
getStorageIfAvailable('sdcard', blob.size,
|
||||
function onSuccess(storage) {
|
||||
// Get the final version of the proposed file name
|
||||
getUnusedFilename(storage, fileName, function onfilename(name) {
|
||||
callback(null, storage, name);
|
||||
});
|
||||
},
|
||||
callback //onerror
|
||||
);
|
||||
};
|
||||
var _saveToSdcard = function _saveToSdcard(storage, name, blob, callback) {
|
||||
if (typeof callback !== 'function') {
|
||||
throw new Error('saveToSDcard requires a callback function');
|
||||
}
|
||||
|
||||
var request = storage.addNamed(blob, name);
|
||||
request.onsuccess = function(evt) {
|
||||
callback(null, evt.target.result); // returns the full filepath
|
||||
};
|
||||
request.onerror = callback;
|
||||
};
|
||||
var _getFile = function _getFile(storage, filename, callback) {
|
||||
if (typeof callback !== 'function') {
|
||||
throw new Error('getFile requires a callback function');
|
||||
}
|
||||
var request = storage.get(filename);
|
||||
request.onsuccess = function() {
|
||||
callback(null, request.result); // returns a File object
|
||||
};
|
||||
request.onerror = callback;
|
||||
};
|
||||
|
||||
var cancelExport = function cancelExport() {
|
||||
cancelled = true;
|
||||
};
|
||||
|
||||
var _doExport = function btex_doExport(finishCallback) {
|
||||
if (typeof finishCallback !== 'function') {
|
||||
throw new Error('BT export requires a callback function');
|
||||
}
|
||||
|
||||
var checkError = function checkError(error) {
|
||||
if (error === null) {
|
||||
return false;
|
||||
}
|
||||
var reason = error;
|
||||
// numeric error means not enough space available
|
||||
if (parseInt(error, 10) >= 0) {
|
||||
reason = 'noSpace';
|
||||
}
|
||||
finishCallback({ 'reason': reason }, 0, false);
|
||||
return true;
|
||||
};
|
||||
|
||||
ContactToVcardBlob(contacts, function onContacts(blob) {
|
||||
if (cancelled) {
|
||||
finishCallback(null, 0, false);
|
||||
return;
|
||||
}
|
||||
_getStorage(_getFileName(), blob,
|
||||
function onStorage(error, storage, filename) {
|
||||
if (checkError(error)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (cancelled) {
|
||||
finishCallback(null, 0, false);
|
||||
return;
|
||||
}
|
||||
|
||||
utils.overlay.hideMenu();
|
||||
_saveToSdcard(storage, filename, blob,
|
||||
function onVcardSaved(error, filepath) {
|
||||
if (checkError(error)) {
|
||||
return;
|
||||
}
|
||||
|
||||
_getFile(storage, filepath, function onFileRetrieved(error, file) {
|
||||
if (checkError(error)) {
|
||||
return;
|
||||
}
|
||||
|
||||
var a = new MozActivity({
|
||||
name: 'share-via-bluetooth-only',
|
||||
data: {
|
||||
type: 'text/vcard',
|
||||
number: 1,
|
||||
blobs: [file],
|
||||
filenames: [filename],
|
||||
filepaths: [filepath]
|
||||
}
|
||||
});
|
||||
|
||||
a.onsuccess = function() {
|
||||
finishCallback(null, contacts.length);
|
||||
};
|
||||
|
||||
a.onerror = function(e) {
|
||||
if (a.error.name === 'NO_PROVIDER') {
|
||||
alert(_('share-noprovider'));
|
||||
} else {
|
||||
console.warn('share activity error:', a.error.name);
|
||||
}
|
||||
finishCallback({'reason': a.error}, 0, a.error.name);
|
||||
};
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
return {
|
||||
'setContactsToExport': _setContactsToExport,
|
||||
'shouldShowProgress': function btex_shouldShowProgress() { return true; },
|
||||
'hasDeterminativeProgress': _hasDeterminativeProgress,
|
||||
'getExportTitle': _getExportTitle,
|
||||
'setProgressStep': _setProgressStep,
|
||||
'doExport': _doExport,
|
||||
'cancelExport' : cancelExport,
|
||||
get name() { return 'BT';} // handling error messages on contacts_exporter
|
||||
};
|
||||
};
|
||||
197
gaia/apps/communications/contacts/js/export/contacts_exporter.js
Executable file
197
gaia/apps/communications/contacts/js/export/contacts_exporter.js
Executable file
|
|
@ -0,0 +1,197 @@
|
|||
/* global utils, ConfirmDialog, Contacts, ContactsService, Loader */
|
||||
'use strict';
|
||||
|
||||
//
|
||||
// Generic module to do contacts export.
|
||||
//
|
||||
// Once passed to this module an array of mozContacts objects
|
||||
// and setup the strategy (mechanism to export), will perform
|
||||
// the common steps taken place during the process of exporting
|
||||
// the information.
|
||||
|
||||
// Those steps are:
|
||||
|
||||
// - Preparation: (optional), may launch extra UI to setup some configuration
|
||||
// and transform the mozcontacts object to any extra format
|
||||
// - Export: Here is where the real import happens, could provide three known
|
||||
// scenarios:
|
||||
// - External handling of the export (web activity, ect.)
|
||||
// - Progress of the import:
|
||||
// - Defined progress activity
|
||||
// - Undefined progress
|
||||
// - Result of the export
|
||||
|
||||
window.ContactsExporter = function ContactsExporter(theStrategy) {
|
||||
|
||||
var contacts;
|
||||
var strategy = theStrategy;
|
||||
var hasProgress = false;
|
||||
var determinativeProgress = false;
|
||||
var progress;
|
||||
|
||||
// XXX: Bug 904623 since we cannot fetch a list of contacts by
|
||||
// contact id, we will need to fetch them all and filter
|
||||
var _init = function _init(theContacts, cb) {
|
||||
if (theContacts === null || theContacts.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
ContactsService.getAll(function(e, contactsFromAPI) {
|
||||
if (e) {
|
||||
cb();
|
||||
return;
|
||||
}
|
||||
contacts = [];
|
||||
contactsFromAPI.forEach(function onContact(ct) {
|
||||
if (theContacts.indexOf(ct.id) !== -1) {
|
||||
contacts.push(ct);
|
||||
}
|
||||
});
|
||||
if (cb) {
|
||||
cb(contacts);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
//
|
||||
// Checks if the export module has been properly configured
|
||||
// and start the process of exporting.
|
||||
//
|
||||
var _start = function _start() {
|
||||
if (!contacts || !strategy) {
|
||||
throw new Error('Not properly configured');
|
||||
}
|
||||
|
||||
strategy.setContactsToExport(contacts);
|
||||
|
||||
// Check if we have a 'Preparation step'
|
||||
if (typeof strategy.prepare === 'function') {
|
||||
strategy.prepare(_doExport);
|
||||
} else {
|
||||
_doExport();
|
||||
}
|
||||
};
|
||||
|
||||
var _doExport = function _doExport() {
|
||||
if (typeof strategy.shouldShowProgress === 'function' &&
|
||||
strategy.shouldShowProgress()) {
|
||||
hasProgress = true;
|
||||
_configureProgress();
|
||||
_displayProgress();
|
||||
}
|
||||
|
||||
strategy.doExport(_doHandleResult);
|
||||
};
|
||||
|
||||
/**
|
||||
* Callback invoked when the exporting process finished.
|
||||
*
|
||||
* @param {Object} error Not null in case an error happened
|
||||
* @param {Number} exported Number of contacts successfuly exported
|
||||
* @param {Boolean} isRecoverable In case of error, whether it is recoverable
|
||||
*/
|
||||
var _doHandleResult = function _doHandleResult(error, exported,
|
||||
isRecoverable) {
|
||||
if (hasProgress && !error) {
|
||||
utils.overlay.hide();
|
||||
}
|
||||
|
||||
if (error) {
|
||||
// If it was cancelled by the user we don't show the error screen.
|
||||
if (error.reason && error.reason.name === 'cancelled') {
|
||||
utils.overlay.hide();
|
||||
} else {
|
||||
var cancel = {
|
||||
title: 'cancel',
|
||||
callback: function() {
|
||||
utils.overlay.hide();
|
||||
ConfirmDialog.hide();
|
||||
_showStatus(exported, contacts.length);
|
||||
}
|
||||
};
|
||||
|
||||
var retry = {
|
||||
title: 'retry',
|
||||
isRecommend: true,
|
||||
callback: function() {
|
||||
utils.overlay.hide();
|
||||
ConfirmDialog.hide();
|
||||
// And now the action is reproduced one more time
|
||||
window.setTimeout(_doExport, 0);
|
||||
}
|
||||
};
|
||||
|
||||
if (isRecoverable === false) {
|
||||
retry = null;
|
||||
}
|
||||
|
||||
var errorString = 'exportError-' + strategy.name + '-';
|
||||
ConfirmDialog.show('exportErrorTitle',
|
||||
errorString + error.reason, cancel, retry);
|
||||
|
||||
Contacts.hideOverlay();
|
||||
|
||||
console.error('An error occurred during the export: ',
|
||||
error.reason.name || error.reason);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
_showStatus(exported, contacts.length);
|
||||
};
|
||||
|
||||
var _showStatus = function(exported, total) {
|
||||
// TODO: Better mechanism to show result
|
||||
var msgId = {
|
||||
id: 'contactsExported2',
|
||||
args: {
|
||||
'exported': exported,
|
||||
'total': total
|
||||
}
|
||||
};
|
||||
|
||||
utils.status.show(msgId);
|
||||
};
|
||||
|
||||
//
|
||||
// Based on the strategy configure the progress display to show a
|
||||
// determinative or indeterminate ui depending on the strategy
|
||||
//
|
||||
var _configureProgress = function _configureProgress() {
|
||||
determinativeProgress =
|
||||
strategy.hasDeterminativeProgress !== undefined &&
|
||||
strategy.hasDeterminativeProgress();
|
||||
};
|
||||
|
||||
//
|
||||
// Shows the progress dialog based on the
|
||||
//
|
||||
var _displayProgress = function _displayProgress() {
|
||||
var progressClass = determinativeProgress ? 'progressBar' : 'spinner';
|
||||
|
||||
Loader.utility('Overlay', function _loaded() {
|
||||
progress = utils.overlay.show(
|
||||
strategy.getExportTitle(),
|
||||
progressClass,
|
||||
null
|
||||
);
|
||||
utils.overlay.showMenu();
|
||||
utils.overlay.oncancel = function() {
|
||||
strategy.cancelExport();
|
||||
utils.overlay.hide();
|
||||
};
|
||||
|
||||
// Allow the strategy to setup the progress bar
|
||||
if (determinativeProgress) {
|
||||
progress.setTotal(contacts.length);
|
||||
strategy.setProgressStep(progress.update);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
return {
|
||||
'init': _init,
|
||||
'start': _start
|
||||
};
|
||||
|
||||
};
|
||||
168
gaia/apps/communications/contacts/js/export/sd.js
Executable file
168
gaia/apps/communications/contacts/js/export/sd.js
Executable file
|
|
@ -0,0 +1,168 @@
|
|||
/* globals _, ContactToVcard, getStorageIfAvailable, getUnusedFilename
|
||||
*/
|
||||
|
||||
/* exported ContactsSDExport */
|
||||
|
||||
'use strict';
|
||||
|
||||
var ContactsSDExport = function ContactsSDExport() {
|
||||
|
||||
var contacts;
|
||||
var progressStep;
|
||||
var cancelled = false;
|
||||
|
||||
var setContactsToExport = function setContactsToExport(cts) {
|
||||
contacts = cts;
|
||||
};
|
||||
|
||||
var hasDeterminativeProgress = function hasDeterminativeProgress() {
|
||||
return false;
|
||||
};
|
||||
|
||||
var setProgressStep = function setProgressStep(p) {
|
||||
progressStep = p;
|
||||
};
|
||||
|
||||
var getExportTitle = function getExportTitle() {
|
||||
return 'memoryCardExport-title';
|
||||
};
|
||||
|
||||
var hasGivenName = function hasGivenName(contact) {
|
||||
return (Array.isArray(contact.givenName) && contact.givenName[0] &&
|
||||
contact.givenName[0].trim());
|
||||
};
|
||||
|
||||
var hasFamilyName = function hasFamilyName(contact) {
|
||||
return (Array.isArray(contact.familyName) && contact.familyName[0] &&
|
||||
contact.familyName[0].trim());
|
||||
};
|
||||
|
||||
var getFileName = function getFileName() {
|
||||
var filename = [];
|
||||
if (contacts && contacts.length === 1) {
|
||||
var contact = contacts[0],
|
||||
hasName = false;
|
||||
if (hasGivenName(contact)) {
|
||||
filename.push(contact.givenName[0]);
|
||||
hasName = true;
|
||||
}
|
||||
if (hasFamilyName(contact)) {
|
||||
filename.push(contact.familyName[0]);
|
||||
hasName = true;
|
||||
}
|
||||
if (!hasName) {
|
||||
if (contact.org && contact.org.length > 0) {
|
||||
filename.push(contact.org[0]);
|
||||
} else if (contact.tel && contact.tel.length > 0) {
|
||||
filename.push(contact.tel[0].value);
|
||||
} else if (contact.email && contact.email.length > 0) {
|
||||
filename.push(contact.email[0].value);
|
||||
} else {
|
||||
filename.push(_('noName'));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
var today = new Date();
|
||||
filename.push(
|
||||
today.getFullYear(),
|
||||
today.getMonth() + 1,
|
||||
today.getDate(),
|
||||
contacts.length
|
||||
);
|
||||
}
|
||||
|
||||
return filename.join('_')
|
||||
.replace(/[^a-z0-9]/gi, '_')
|
||||
.toLowerCase() +
|
||||
'.vcf';
|
||||
};
|
||||
|
||||
var getStorage = function getStorage(fileName, blob, callback) {
|
||||
getStorageIfAvailable('sdcard', blob.size,
|
||||
function onSuccess(storage) {
|
||||
// Get the final version of the proposed file name
|
||||
getUnusedFilename(storage, fileName, function onFinalName(name) {
|
||||
callback(null, storage, name);
|
||||
});
|
||||
},
|
||||
function onError(type) {
|
||||
callback(type);
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
var cancelExport = function cancelExport() {
|
||||
cancelled = true;
|
||||
};
|
||||
|
||||
var doExport = function doExport(finishCallback) {
|
||||
/* XXX: We use a batch-conversion size of 2MiB. This ensures that the
|
||||
* process won't go out of memory even on low-end devices. This should be
|
||||
* revisited once append-to-file functionality becomes available. */
|
||||
var batchSize = 2 * 1024 * 1024;
|
||||
var count = 0;
|
||||
var pendingBatches = 0;
|
||||
var done = false;
|
||||
var cancelButton = document.querySelector('#cancel-overlay');
|
||||
|
||||
if (typeof finishCallback !== 'function') {
|
||||
throw new Error('SD export requires a callback function');
|
||||
}
|
||||
|
||||
ContactToVcard(contacts, function onContacts(vcards, nCards) {
|
||||
if (cancelled) {
|
||||
finishCallback(null, 0);
|
||||
return;
|
||||
}
|
||||
var blob = new Blob([vcards], {'type': 'text/vcard'});
|
||||
|
||||
pendingBatches++;
|
||||
|
||||
getStorage(getFileName(), blob,
|
||||
function onStorage(error, storage, finalName) {
|
||||
if (error !== null) {
|
||||
var reason = error;
|
||||
// numeric error means not enough space available
|
||||
if (parseInt(error, 10) >= 0) {
|
||||
reason = 'noSpace';
|
||||
}
|
||||
finishCallback({
|
||||
'reason': reason
|
||||
}, count, true);
|
||||
return;
|
||||
}
|
||||
if (cancelled) {
|
||||
finishCallback(null, 0);
|
||||
return;
|
||||
}
|
||||
cancelButton.disabled = true;
|
||||
var request = storage.addNamed(blob, finalName);
|
||||
request.onsuccess = function onSuccess() {
|
||||
count += nCards;
|
||||
pendingBatches--;
|
||||
|
||||
if (done && (pendingBatches === 0)) {
|
||||
finishCallback(null, count, false);
|
||||
}
|
||||
};
|
||||
request.onerror = function onError(e) {
|
||||
finishCallback({ 'reason': e }, count, true);
|
||||
};
|
||||
});
|
||||
}, function finish() {
|
||||
done = true;
|
||||
}, batchSize);
|
||||
};
|
||||
|
||||
return {
|
||||
'setContactsToExport': setContactsToExport,
|
||||
'shouldShowProgress': function shouldShowProgress() { return true; },
|
||||
'hasDeterminativeProgress': hasDeterminativeProgress,
|
||||
'getExportTitle': getExportTitle,
|
||||
'doExport': doExport,
|
||||
'setProgressStep': setProgressStep,
|
||||
'cancelExport': cancelExport,
|
||||
get name() { return 'SD'; } // handling error messages on contacts_exporter
|
||||
};
|
||||
|
||||
};
|
||||
195
gaia/apps/communications/contacts/js/export/sim.js
Executable file
195
gaia/apps/communications/contacts/js/export/sim.js
Executable file
|
|
@ -0,0 +1,195 @@
|
|||
/* exported ContactsSIMExport */
|
||||
/* global ContactsService */
|
||||
'use strict';
|
||||
|
||||
var ContactsSIMExport = function ContactsSIMExport(icc) {
|
||||
|
||||
var contacts;
|
||||
var progressStep;
|
||||
var exported;
|
||||
var notExported;
|
||||
var cancelled = false;
|
||||
|
||||
var ERRORS = {
|
||||
'NoFreeRecordFound': false,
|
||||
'CannotAccessPhoneBook': true
|
||||
};
|
||||
|
||||
var setContactsToExport = function setContactsToExport(cts) {
|
||||
contacts = cts;
|
||||
};
|
||||
|
||||
var hasDeterminativeProgress = function hasDeterminativeProgress() {
|
||||
return contacts.length > 1;
|
||||
};
|
||||
|
||||
var setProgressStep = function setProgressStep(p) {
|
||||
progressStep = p;
|
||||
};
|
||||
|
||||
var getExportTitle = function getExportTitle() {
|
||||
return 'simExport-title';
|
||||
};
|
||||
|
||||
var doExport = function doExport(finishCallback) {
|
||||
if (typeof finishCallback !== 'function') {
|
||||
throw new Error('SIM export requires a callback function');
|
||||
}
|
||||
|
||||
exported = [];
|
||||
notExported = [];
|
||||
|
||||
// We should control this state before doing the export
|
||||
// but a second check is healthy
|
||||
if (!icc) {
|
||||
finishCallback({
|
||||
'reason': 'Unavailable'
|
||||
}, 0, false);
|
||||
return;
|
||||
}
|
||||
|
||||
_doExport(0, finishCallback);
|
||||
};
|
||||
|
||||
// Returns the iccContactId to be used for exporting this contact
|
||||
// undefined if not iccContactId is found
|
||||
// url content is urn:uuid:<iccid>-icccontactid
|
||||
var _getIccContactId = function _getIccContactId(theContact) {
|
||||
var out;
|
||||
var contactUrl = theContact.url;
|
||||
if (!Array.isArray(contactUrl)) {
|
||||
return out;
|
||||
}
|
||||
|
||||
for (var j = 0; j < contactUrl.length; j++) {
|
||||
var aUrl = contactUrl[j];
|
||||
if (aUrl.type.indexOf('source') !== -1 &&
|
||||
aUrl.type.indexOf('sim') !== -1) {
|
||||
var value = aUrl.value.split(':')[2];
|
||||
var iccInfo = value.split('-');
|
||||
if (iccInfo[0] === _getIccId()) {
|
||||
out = iccInfo[1];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return out;
|
||||
};
|
||||
|
||||
var _generateIccContactUrl = function _generateIccContactUrl(contactid,
|
||||
iccId) {
|
||||
var urlValue = 'urn:' + 'uuid:' + (iccId || 'iccId') + '-' + contactid;
|
||||
return {
|
||||
type: ['source', 'sim'],
|
||||
value: urlValue
|
||||
};
|
||||
};
|
||||
|
||||
var _getIccId = function _getIccId() {
|
||||
return icc.iccInfo && icc.iccInfo.iccid;
|
||||
};
|
||||
|
||||
var _updateContactSimSource = function _updateContactSimSource(theContact,
|
||||
iccContact, cb, errorCb) {
|
||||
if (!iccContact) {
|
||||
window.console.warn('No Icc Contact provided');
|
||||
cb();
|
||||
return;
|
||||
}
|
||||
|
||||
theContact.url = theContact.url || [];
|
||||
theContact.url.push(_generateIccContactUrl(iccContact.id, _getIccId()));
|
||||
|
||||
ContactsService.save(
|
||||
theContact,
|
||||
function(e) {
|
||||
if (e) {
|
||||
errorCb(e);
|
||||
return;
|
||||
}
|
||||
cb();
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
var cancelExport = function cancelExport() {
|
||||
cancelled = true;
|
||||
};
|
||||
|
||||
var _doExport = function _doExport(step, finishCallback) {
|
||||
if (step == contacts.length || cancelled) {
|
||||
finishCallback(null, exported.length);
|
||||
return;
|
||||
}
|
||||
|
||||
var next = function next(success, contact) {
|
||||
var resultArray = success ? exported : notExported;
|
||||
resultArray.push(contact);
|
||||
if (progressStep) {
|
||||
progressStep();
|
||||
}
|
||||
step++;
|
||||
_doExport(step, finishCallback);
|
||||
};
|
||||
|
||||
var theContact = contacts[step];
|
||||
var originalContactId = theContact.id;
|
||||
var idToUpdate = _getIccContactId(theContact);
|
||||
if (!idToUpdate) {
|
||||
theContact.id = null;
|
||||
}
|
||||
else {
|
||||
theContact.id = idToUpdate;
|
||||
}
|
||||
|
||||
var request = icc.updateContact('adn', theContact);
|
||||
request.onsuccess = function onsuccess() {
|
||||
// Restoring the original contact.id to avoid duplicating it
|
||||
theContact.id = originalContactId;
|
||||
|
||||
if (idToUpdate) {
|
||||
next(true, theContact);
|
||||
return;
|
||||
}
|
||||
// Now it is needed to save the provided id in case we don't have one
|
||||
var iccContact = request.result;
|
||||
_updateContactSimSource(theContact, iccContact,
|
||||
function export_update_success() {
|
||||
next(true, theContact);
|
||||
}, function export_update_error(err) {
|
||||
window.console.error('Error while updating: ', err.name);
|
||||
next(true, theContact);
|
||||
});
|
||||
};
|
||||
|
||||
request.onerror = function onerror(e) {
|
||||
var error = e.target.error;
|
||||
window.console.error('Error while exporting: ', originalContactId,
|
||||
error.name);
|
||||
|
||||
var errorName = typeof ERRORS[error.name] === 'boolean' ?
|
||||
error.name : 'GenericError';
|
||||
|
||||
if (errorName !== 'GenericError') {
|
||||
finishCallback({
|
||||
'reason': errorName
|
||||
}, exported.length, ERRORS[error.name]);
|
||||
}
|
||||
else {
|
||||
next(false, theContact);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
return {
|
||||
'setContactsToExport': setContactsToExport,
|
||||
'shouldShowProgress': function() { return true; },
|
||||
'hasDeterminativeProgress': hasDeterminativeProgress,
|
||||
'getExportTitle': getExportTitle,
|
||||
'doExport': doExport,
|
||||
'setProgressStep': setProgressStep,
|
||||
'cancelExport' : cancelExport,
|
||||
get name() { return 'SIM';} // handling error messages on contacts_exporter
|
||||
};
|
||||
|
||||
};
|
||||
Loading…
Reference in a new issue