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
83
gaia/shared/js/contacts/contacts_datastore.js
Executable file
83
gaia/shared/js/contacts/contacts_datastore.js
Executable file
|
|
@ -0,0 +1,83 @@
|
|||
'use strict';
|
||||
|
||||
/* exported ContactsDatastore */
|
||||
|
||||
/**
|
||||
* This object will be useful for contact providers. It provides convenient
|
||||
* access to a contacts datastore
|
||||
*
|
||||
*/
|
||||
|
||||
var ContactsDatastore = (function() {
|
||||
function ContactsDatastore(provider) {
|
||||
this.provider = provider;
|
||||
|
||||
this._datastoreLoaded = false;
|
||||
this._datastoreLoading = false;
|
||||
}
|
||||
|
||||
function promiseResolution (resolve, reject) {
|
||||
/*jshint validthis:true */
|
||||
this._datastoreLoading = false;
|
||||
this._datastoreLoaded = (this.datastore !== null);
|
||||
|
||||
if (!this.datastore) {
|
||||
reject({
|
||||
name: 'DatastoreNotFound'
|
||||
});
|
||||
}
|
||||
else {
|
||||
resolve(this.datastore);
|
||||
}
|
||||
}
|
||||
|
||||
ContactsDatastore.prototype = {
|
||||
_DS_LOADED_EVENT: 'datastore_loaded',
|
||||
_DS_NAME: 'contacts',
|
||||
|
||||
getStore: function() {
|
||||
var self = this;
|
||||
|
||||
return new Promise(function(resolve, reject) {
|
||||
if (!navigator.getDataStores) {
|
||||
reject({
|
||||
name: 'DatastoreNotEnabled'
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if (self._datastoreLoaded) {
|
||||
resolve(self.datastore);
|
||||
return;
|
||||
}
|
||||
|
||||
if (self._datastoreLoading) {
|
||||
document.addEventListener(self._DS_LOADED_EVENT, function loaded() {
|
||||
document.removeEventListener(self._DS_LOADED_EVENT, loaded);
|
||||
promiseResolution.bind(self)(resolve, reject);
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
self._datastoreLoading = true;
|
||||
navigator.getDataStores(self._DS_NAME).then(function(stores) {
|
||||
var targetOwner = self.provider;
|
||||
|
||||
for (var j = 0; j < stores.length; j++) {
|
||||
if (stores[j].owner === targetOwner) {
|
||||
self.datastore = stores[j];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
document.dispatchEvent(new CustomEvent(self._DS_LOADED_EVENT));
|
||||
promiseResolution.bind(self)(resolve, reject);
|
||||
|
||||
}, reject);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
return ContactsDatastore;
|
||||
|
||||
}());
|
||||
Loading…
Reference in a new issue