var app = {
fs: null,
datasDir = '/appname/another_folder_as_dictated_by_my_boss/datas/',
entities : ['one', 'two', 'three', 'bar', 'foo'],
onDeviceReady: function() {
app.handleDatas();
_.delay(function() {//underscore setimout
navigator.splashscreen.hide();
}, 1000);
startApp();// loads html tpl, backbone router start etc...
},
handleDatas: function(){
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, app.onFileSuccess, app.onFileFail);
},
onFileSuccess: function(fileSystem) {
app.fs = fileSystem;
var filePath = app.fs.root.fullPath + app.datasDir,
fileTransfer = new FileTransfer();
fileSystem.root.getDirectory( app.datasDir, {create: true, exclusive: false}); // Get the data directory, creating it if it doesn't exist.
// i'm not using the success and fail callback so maybe the issue is there but if using it, it always fails on first app build and maybe it is normal behaviour...
fileSystem.root.getFile( app.datasDir + "profile.json", {create:false, exclusive: false}, app.profileExist, app.firstLaunch);
_.each(app.entities, function(entity, index) {
fileTransfer.download(
encodeURI(app.uri + entity),
filePath + entity + ".json",
function(entry) {
//fetch my collections from the new json fils in app.datasDir
},
function(error) {
if(index == 0){
app.onFileFail();
return;
}
},
true
);// end fileTransfer function
});// end each
}
profileExist: function(fileSystem) {
// if profile.json exist that means it's not the first time it's opened
}
firstLaunch: function(fileSystem) {
// if profile.json does not exist that means it's the first time it's opened so we do something different
},
onFileFail: function(evt) {
// fallback if online files didn't get loaded
}
}
function startApp() {
// loads html tpl, backbone router start etc...