diff options
-rw-r--r-- | src/js/files.js | 38 | ||||
-rw-r--r-- | src/js/views/photo.js | 14 |
2 files changed, 51 insertions, 1 deletions
diff --git a/src/js/files.js b/src/js/files.js index a3a6458..583011a 100644 --- a/src/js/files.js +++ b/src/js/files.js @@ -26,6 +26,25 @@ }); }, + copyURI: function (srcURI, dest ) { + + var fileEntry; + return getFileFromURI(srcURI) + .pipe( function (file) { + fileEntry = file; + + return getFileSystem(); + }) + .pipe( function (filesystem) { + console.log('Filesystem returned: ' + filesystem); + + return getDirectory(filesystem.root, CONFIG.FILES_DIR, {create: true}); + }) + .pipe( function(directory) { + return copyFile( fileEntry, directory ); + }); + }, + deleteURI: function (uri) { console.log('Deleting URI: ' + uri); @@ -122,6 +141,25 @@ return move.promise(); } + function copyFile (src, dest, options) { + + console.log( 'copying file ' + src.fullPath + ' to ' + dest.fullPath ); + + var copy = $.Deferred(); + + var destPath = dest.fullPath + '/' + src.name; + var srcPath = src.fullPath + ''; + if ( srcPath === destPath ) { + console.log('not copying because files are the same'); + copy.resolve( src ); + } else { + console.log('paths differ so copying'); + src.copyTo( dest, null, copy.resolve, copy.reject); + } + + return copy.promise(); + } + function getFileFromURI(uri) { console.log( 'getting file from uri ' + uri ); diff --git a/src/js/views/photo.js b/src/js/views/photo.js index 74f3933..0c308a8 100644 --- a/src/js/views/photo.js +++ b/src/js/views/photo.js @@ -40,7 +40,19 @@ }, addPhotoSuccess: function(imgURI) { - var move = FMS.files.moveURI( imgURI ); + console.log(imgURI); + var move; + // on iOS the photos go into a temp folder in the apps own filespace so we + // can move them, and indeed have to as the tmp space is cleaned out by the OS + // so draft reports might have their images removed. on android you access the + // images where they are stored on the filesystem so if you move, and then delete + // them, you are moving and deleting the only copy of them which is likely to be + // surprising and unwelcome so we copy them instead. + if ( FMS.isAndroid ) { + move = FMS.files.copyURI( imgURI ); + } else { + move = FMS.files.moveURI( imgURI ); + } var that = this; move.done( function( file ) { |