Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 6 additions & 22 deletions www/addons/files/controllers/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ angular.module('mm.addons.files')

var path = $stateParams.path,
root = $stateParams.root,
title,
promise;

// We're loading the files.
Expand All @@ -32,40 +31,25 @@ angular.module('mm.addons.files')
// The path is unknown, the user must be requesting a root.
if (root === 'site') {
promise = $mmaFiles.getSiteFiles();
title = $translate('mma.files.sitefiles');
$scope.title = $translate.instant('mma.files.sitefiles');
} else if (root === 'my') {
promise = $mmaFiles.getMyFiles();
title = $translate('mma.files.myprivatefiles');
$scope.title = $translate.instant('mma.files.myprivatefiles');
} else {
// Upon error we create a fake promise that is rejected.
promise = $q.reject();
title = (function() {
var q = $q.defer();
q.resolve('');
return q.promise;
})();
}
} else {
// Serve the files the user requested.
pathdata = JSON.parse(path);
promise = $mmaFiles.getFiles(pathdata);

// Put the title in a promise to act like translate does.
title = (function() {
var q = $q.defer();
q.resolve($stateParams.title);
return q.promise;
})();
$scope.title = $stateParams.title;
}

return $q.all([promise, title]).then(function(data) {
var files = data[0],
title = data[1];

return promise.then(function(files) {
$scope.files = files.entries;
$scope.count = files.count;
$scope.title = title;
}, function() {
}).catch(function() {
$mmUtil.showErrorModal('mma.files.couldnotloadfiles', true);
});
}
Expand All @@ -84,7 +68,7 @@ angular.module('mm.addons.files')

// Update list if we come from upload page (we don't know if user upoaded a file or not).
// List is invalidated in upload state after uploading a file.
$scope.$on('$ionicView.enter', function(e) {
$scope.$on('$ionicView.enter', function() {
var forwardView = $ionicHistory.forwardView();
if (forwardView && forwardView.stateName === mmaFilesUploadStateName) {
$scope.filesLoaded = false;
Expand Down
14 changes: 7 additions & 7 deletions www/addons/files/controllers/upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ angular.module('mm.addons.files')
.controller('mmaFilesUploadCtrl', function($scope, $stateParams, $mmUtil, $mmaFilesHelper, $ionicHistory, $mmaFiles, $mmApp) {

var uploadMethods = {
album: $mmaFilesHelper.uploadImageFromAlbum,
camera: $mmaFilesHelper.uploadImageFromCamera,
audio: $mmaFilesHelper.uploadAudio,
video: $mmaFilesHelper.uploadVideo
album: $mmaFilesHelper.uploadImage,
camera: $mmaFilesHelper.uploadImage,
audio: $mmaFilesHelper.uploadAudioOrVideo,
video: $mmaFilesHelper.uploadAudioOrVideo
},
path = $stateParams.path,
root = $stateParams.root;
Expand All @@ -49,12 +49,12 @@ angular.module('mm.addons.files')
}
}

$scope.upload = function(type) {
$scope.upload = function(type, param) {
if (!$mmApp.isOnline()) {
$mmUtil.showErrorModal('mma.files.errormustbeonlinetoupload', true);
} else {
if (typeof(uploadMethods[type]) !== 'undefined') {
uploadMethods[type]().then(successUploading, errorUploading);
uploadMethods[type](param).then(successUploading, errorUploading);
}
}
};
Expand All @@ -69,5 +69,5 @@ angular.module('mm.addons.files')
$mmaFilesHelper.copyAndUploadFile(file).then(successUploading, errorUploading);
}, errorUploading);
}
}
};
});
21 changes: 15 additions & 6 deletions www/addons/files/services/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -414,8 +414,7 @@ angular.module('mm.addons.files')
*/
self.uploadImage = function(uri, isFromAlbum) {
$log.debug('Uploading an image');
var d = new Date(),
options = {};
var options = {};

if (typeof(uri) === 'undefined' || uri === ''){
// In Node-Webkit, if you successfully upload a picture and then you open the file picker again
Expand All @@ -426,7 +425,7 @@ angular.module('mm.addons.files')

options.deleteAfterUpload = !isFromAlbum;
options.fileKey = "file";
options.fileName = "image_" + d.getTime() + ".jpg";
options.fileName = "image_" + new Date().getTime() + ".jpg";
options.mimeType = "image/jpeg";

return self.uploadFile(uri, options);
Expand All @@ -444,10 +443,20 @@ angular.module('mm.addons.files')
self.uploadMedia = function(mediaFiles) {
$log.debug('Uploading media');
var promises = [];
angular.forEach(mediaFiles, function(mediaFile, index) {
var options = {};
angular.forEach(mediaFiles, function(mediaFile) {
var options = {},
filename = mediaFile.name,
split;

if (ionic.Platform.isIOS()) {
// In iOS we'll add a timestamp to the filename to make it unique.
split = filename.split('.');
split[0] += '_' + new Date().getTime();
filename = split.join('.');
}

options.fileKey = null;
options.fileName = mediaFile.name;
options.fileName = filename;
options.mimeType = null;
options.deleteAfterUpload = true;
promises.push(self.uploadFile(mediaFile.fullPath, options));
Expand Down
Loading