Skip to content

Commit

Permalink
materized
Browse files Browse the repository at this point in the history
  • Loading branch information
Mirco Cipriani committed Jul 12, 2017
2 parents 54fa3fd + 3d35be5 commit 4a98a0a
Show file tree
Hide file tree
Showing 6 changed files with 445 additions and 15 deletions.
68 changes: 66 additions & 2 deletions dist/bower/stargate.js
Original file line number Diff line number Diff line change
Expand Up @@ -3002,6 +3002,42 @@ function getManifest() {
return Promise.resolve({});
}

var getCountryPromise = function(stargateConfCountries) {

return new Promise(function(resolve,reject){

window.aja()
.method('GET')
.url(stargateConfCountries.apiGetCountry)
.cache(false)
.timeout(10000) // ten seconds
.on('success', function(result){
resolve(result.realCountry);
})
.on('error', function(error){
err("getCountryPromise() api call "+stargateConfCountries.apiGetCountry+
" failed: "+JSON.stringify(error));
reject(new Error(error));
})
.on('4xx', function(error){
err("getCountryPromise() api call "+stargateConfCountries.apiGetCountry+
" failed: "+JSON.stringify(error));
reject(new Error(error));
})
.on('5xx', function(error){
err("getCountryPromise() api call "+stargateConfCountries.apiGetCountry+
" failed: "+JSON.stringify(error));
reject(new Error(error));
})
.on('timeout', function(){
err("getCountryPromise() api call "+stargateConfCountries.apiGetCountry+
" failed: Timeout 10s!");
reject(new Error("Timeout 10s!"));
})
.go();
});
};

var launchUrl = function (url) {
log("launchUrl: "+url);
document.location.href = url;
Expand Down Expand Up @@ -3362,6 +3398,8 @@ var onDeviceReady = function (resolve, reject) {
// get connection information
initializeConnectionStatus();

var manifest = '';

getManifest()
.then(function(resultManifest){
log("onDeviceReady() [1/4] got manifest");
Expand All @@ -3371,6 +3409,7 @@ var onDeviceReady = function (resolve, reject) {

// save stargateConf got from manifest.json
stargateConf = resultManifest.stargateConf;
manifest = resultManifest;

// execute next promise
return cordova.getAppVersion.getVersionNumber();
Expand All @@ -3393,8 +3432,33 @@ var onDeviceReady = function (resolve, reject) {
log("onDeviceReady() [4/4] got appPackageName");
appBuild = resultAppVersionCode;

// execute remaining initialization
onPluginReady(resolve, reject);
// multi country support ?
if (manifest.stargateConfCountries) {

getCountryPromise(manifest.stargateConfCountries)
.then(function(countryFromApi) {
log("onDeviceReady() [5/4] got user country");

// check if there is a configuration available
if (manifest.stargateConfCountries[countryFromApi]) {
// overwrite stargateConf
stargateConf = manifest.stargateConfCountries[countryFromApi];

} else if (manifest.stargateConfCountries.defaultCountry &&
manifest.stargateConfCountries[manifest.stargateConfCountries.defaultCountry]) {

// overwrite stargateConf with conf of default country
stargateConf = manifest.stargateConfCountries[manifest.stargateConfCountries.defaultCountry];
}

// execute remaining initialization
onPluginReady(resolve, reject);
});

} else {
// execute remaining initialization
onPluginReady(resolve, reject);
}
})
.catch(function (error) {
err("onDeviceReady() error: "+error);
Expand Down
6 changes: 3 additions & 3 deletions dist/bower/stargate.min.js

Large diffs are not rendered by default.

68 changes: 66 additions & 2 deletions dist/stargate.js
Original file line number Diff line number Diff line change
Expand Up @@ -6919,6 +6919,42 @@ function getManifest() {
return Promise.resolve({});
}

var getCountryPromise = function(stargateConfCountries) {

return new Promise(function(resolve,reject){

window.aja()
.method('GET')
.url(stargateConfCountries.apiGetCountry)
.cache(false)
.timeout(10000) // ten seconds
.on('success', function(result){
resolve(result.realCountry);
})
.on('error', function(error){
err("getCountryPromise() api call "+stargateConfCountries.apiGetCountry+
" failed: "+JSON.stringify(error));
reject(new Error(error));
})
.on('4xx', function(error){
err("getCountryPromise() api call "+stargateConfCountries.apiGetCountry+
" failed: "+JSON.stringify(error));
reject(new Error(error));
})
.on('5xx', function(error){
err("getCountryPromise() api call "+stargateConfCountries.apiGetCountry+
" failed: "+JSON.stringify(error));
reject(new Error(error));
})
.on('timeout', function(){
err("getCountryPromise() api call "+stargateConfCountries.apiGetCountry+
" failed: Timeout 10s!");
reject(new Error("Timeout 10s!"));
})
.go();
});
};

var launchUrl = function (url) {
log("launchUrl: "+url);
document.location.href = url;
Expand Down Expand Up @@ -7279,6 +7315,8 @@ var onDeviceReady = function (resolve, reject) {
// get connection information
initializeConnectionStatus();

var manifest = '';

getManifest()
.then(function(resultManifest){
log("onDeviceReady() [1/4] got manifest");
Expand All @@ -7288,6 +7326,7 @@ var onDeviceReady = function (resolve, reject) {

// save stargateConf got from manifest.json
stargateConf = resultManifest.stargateConf;
manifest = resultManifest;

// execute next promise
return cordova.getAppVersion.getVersionNumber();
Expand All @@ -7310,8 +7349,33 @@ var onDeviceReady = function (resolve, reject) {
log("onDeviceReady() [4/4] got appPackageName");
appBuild = resultAppVersionCode;

// execute remaining initialization
onPluginReady(resolve, reject);
// multi country support ?
if (manifest.stargateConfCountries) {

getCountryPromise(manifest.stargateConfCountries)
.then(function(countryFromApi) {
log("onDeviceReady() [5/4] got user country");

// check if there is a configuration available
if (manifest.stargateConfCountries[countryFromApi]) {
// overwrite stargateConf
stargateConf = manifest.stargateConfCountries[countryFromApi];

} else if (manifest.stargateConfCountries.defaultCountry &&
manifest.stargateConfCountries[manifest.stargateConfCountries.defaultCountry]) {

// overwrite stargateConf with conf of default country
stargateConf = manifest.stargateConfCountries[manifest.stargateConfCountries.defaultCountry];
}

// execute remaining initialization
onPluginReady(resolve, reject);
});

} else {
// execute remaining initialization
onPluginReady(resolve, reject);
}
})
.catch(function (error) {
err("onDeviceReady() error: "+error);
Expand Down
6 changes: 3 additions & 3 deletions dist/stargate.min.js

Large diffs are not rendered by default.

Loading

0 comments on commit 4a98a0a

Please sign in to comment.