diff --git a/public/js/blue-twilight.js b/public/js/blue-twilight.js index 9a96d9d..65ccc09 100644 --- a/public/js/blue-twilight.js +++ b/public/js/blue-twilight.js @@ -22961,3 +22961,131 @@ var Popover = function ($) { }(jQuery); }(); + +/** + * This model is used by admin/show_album.blade.php to handle photo uploads. + * @param album_id ID of the album the photos are being uploaded to + * @param queue_token Unique token of the upload queue to save the photos to + * @param language Array containing language strings + * @param urls Array containing URLs + * @constructor + */ +function UploadPhotosViewModel(album_id, queue_token, language, urls) { + this.el = '#upload-tab'; + this.data = { + currentStatus: '', + imagesFailed: 0, + imagesTotal: 0, + isBulkUploadInProgress: false, + isUploadInProgress: false, + statusMessages: [] + }; + this.computed = { + // a computed getter + failedPercentage: function () { + return ((this.imagesFailed() / this.imagesTotal()) * 100).toFixed(2) + '%'; + }, + successfulPercentage: function () { + return ((self.imagesUploaded() / self.imagesTotal()) * 100).toFixed(2) + '%'; + } + }; + this.methods = { + // This method is called when an image is uploaded - regardless if it fails or not + onUploadCompleted: function () { + this.currentStatus = language.upload_status + .replace(':current', (self.imagesUploaded + self.imagesFailed)) + .replace(':total', self.imagesTotal); + + if ((this.imagesFailed + this.imagesUploaded) >= this.imagesTotal) { + this.isUploadInProgress = false; + + if (this.imagesFailed == 0 && this.imagesUploaded > 0) { + window.location = urls.analyse; + } + } + }, + // This method is called when an uploaded image fails + onUploadFailed: function (data, file_name) { + this.imagesFailed++; + this.statusMessages.push({ + 'message_class': 'text-danger', + 'message_text': language.image_failed.replace(':file_name', file_name) + }); + this.onUploadCompleted(); + }, + // This method is called when an uploaded image succeeds + onUploadSuccessful: function (data, file_name) { + if (data.is_successful) { + self.imagesUploaded++; + // Don't add to statusMessages() array so user only sees errors + /*self.statusMessages.push({ + 'message_class': 'text-success', + 'message_text': language.image_uploaded.replace(':file_name', file_name) + });*/ + self.onUploadCompleted(); + } + else { + self.onUploadFailed(data, file_name); + } + }, + uploadFile: function uploadImageFile(formObject, imageFile) { + var self = this; + var formData = new FormData(); + formData.append('album_id', album_id); + formData.append('queue_token', queue_token); + formData.append('photo[]', imageFile, imageFile.name); + + $.ajax( + { + contentType: false, + data: formData, + error: function (data) { + self.onUploadFailed(data, imageFile.name); + }, + method: $(formObject).attr('method'), + processData: false, + success: function (data) { + self.onUploadSuccessful(data, imageFile.name); + }, + url: $(formObject).attr('action') + } + ); + this.isUploadInProgress = true; + }, + uploadIndividualFiles: function(event) { + var fileSelect = $('input[type=file]', event.target); + + // Get the selected files + var files = fileSelect[0].files; + + // Reset statistics + this.currentStatus = ''; + this.statusMessages = []; + this.imagesUploaded = 0; + this.imagesFailed = 0; + this.imagesTotal = files.length; + this.isUploadInProgress = true; + + // Loop through each of the selected files and upload them individually + for (var i = 0; i < files.length; i++) + { + var file = files[i]; + + // We're only interested in image files + if (!file.type.match('image.*')) + { + alert(language.not_an_image_file.replace(':file_name', file.name)); + this.onUploadFailed(null, file.name); + continue; + } + + // Upload the file + this.uploadFile($(this), file); + } + + // Prevent standard form upload + event.preventDefault(); + return false; + } + }; +} \ No newline at end of file diff --git a/resources/assets/js/albums.js b/resources/assets/js/albums.js new file mode 100644 index 0000000..d0e191e --- /dev/null +++ b/resources/assets/js/albums.js @@ -0,0 +1,127 @@ +/** + * This model is used by admin/show_album.blade.php to handle photo uploads. + * @param album_id ID of the album the photos are being uploaded to + * @param queue_token Unique token of the upload queue to save the photos to + * @param language Array containing language strings + * @param urls Array containing URLs + * @constructor + */ +function UploadPhotosViewModel(album_id, queue_token, language, urls) { + this.el = '#upload-tab'; + this.data = { + currentStatus: '', + imagesFailed: 0, + imagesTotal: 0, + isBulkUploadInProgress: false, + isUploadInProgress: false, + statusMessages: [] + }; + this.computed = { + // a computed getter + failedPercentage: function () { + return ((this.imagesFailed() / this.imagesTotal()) * 100).toFixed(2) + '%'; + }, + successfulPercentage: function () { + return ((self.imagesUploaded() / self.imagesTotal()) * 100).toFixed(2) + '%'; + } + }; + this.methods = { + // This method is called when an image is uploaded - regardless if it fails or not + onUploadCompleted: function () { + this.currentStatus = language.upload_status + .replace(':current', (self.imagesUploaded + self.imagesFailed)) + .replace(':total', self.imagesTotal); + + if ((this.imagesFailed + this.imagesUploaded) >= this.imagesTotal) { + this.isUploadInProgress = false; + + if (this.imagesFailed == 0 && this.imagesUploaded > 0) { + window.location = urls.analyse; + } + } + }, + // This method is called when an uploaded image fails + onUploadFailed: function (data, file_name) { + this.imagesFailed++; + this.statusMessages.push({ + 'message_class': 'text-danger', + 'message_text': language.image_failed.replace(':file_name', file_name) + }); + this.onUploadCompleted(); + }, + // This method is called when an uploaded image succeeds + onUploadSuccessful: function (data, file_name) { + if (data.is_successful) { + self.imagesUploaded++; + // Don't add to statusMessages() array so user only sees errors + /*self.statusMessages.push({ + 'message_class': 'text-success', + 'message_text': language.image_uploaded.replace(':file_name', file_name) + });*/ + self.onUploadCompleted(); + } + else { + self.onUploadFailed(data, file_name); + } + }, + uploadFile: function uploadImageFile(formObject, imageFile) { + var self = this; + var formData = new FormData(); + formData.append('album_id', album_id); + formData.append('queue_token', queue_token); + formData.append('photo[]', imageFile, imageFile.name); + + $.ajax( + { + contentType: false, + data: formData, + error: function (data) { + self.onUploadFailed(data, imageFile.name); + }, + method: $(formObject).attr('method'), + processData: false, + success: function (data) { + self.onUploadSuccessful(data, imageFile.name); + }, + url: $(formObject).attr('action') + } + ); + this.isUploadInProgress = true; + }, + uploadIndividualFiles: function(event) { + var fileSelect = $('input[type=file]', event.target); + + // Get the selected files + var files = fileSelect[0].files; + + // Reset statistics + this.currentStatus = ''; + this.statusMessages = []; + this.imagesUploaded = 0; + this.imagesFailed = 0; + this.imagesTotal = files.length; + this.isUploadInProgress = true; + + // Loop through each of the selected files and upload them individually + for (var i = 0; i < files.length; i++) + { + var file = files[i]; + + // We're only interested in image files + if (!file.type.match('image.*')) + { + alert(language.not_an_image_file.replace(':file_name', file.name)); + this.onUploadFailed(null, file.name); + continue; + } + + // Upload the file + this.uploadFile($(this), file); + } + + // Prevent standard form upload + event.preventDefault(); + return false; + } + }; +} \ No newline at end of file diff --git a/resources/views/themes/base/admin/create_album.blade.php b/resources/views/themes/base/admin/create_album.blade.php index 69fa3a2..718b0e1 100644 --- a/resources/views/themes/base/admin/create_album.blade.php +++ b/resources/views/themes/base/admin/create_album.blade.php @@ -2,61 +2,60 @@ @section('title', 'Gallery Admin') @section('breadcrumb') -
+@lang('admin.create_album_intro')
@lang('admin.create_album_intro2')
@lang('admin.list_albums_intro')
+ @lang('admin.list_albums_intro'){{ $album->photos_count }} {{ trans_choice('admin.stats_widget.photos', $album->photos_count) }}
@lang('admin.list_groups_intro')
+ @lang('admin.list_groups_intro')@lang('admin.list_users_intro')
+ @lang('admin.list_users_intro')