From 9e97958f60e9bf96d20333cb8624b5244d993946 Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Thu, 22 Jun 2017 12:00:52 +0200 Subject: [PATCH] Errores subida multiple de fotos solucionados --- debian/changelog | 2 +- forms/admin/photos/locale/ca.json | 4 + forms/admin/photos/locale/en.json | 4 + forms/admin/photos/locale/es.json | 4 + forms/admin/photos/locale/fr.json | 4 + forms/admin/photos/locale/mn.json | 4 + forms/admin/photos/locale/pt.json | 4 + forms/admin/photos/photos.js | 107 ++++++++++++++-------- image/icon/dark/cloud-upload.svg | 62 +++++++++++++ image/icon/dark/upload.svg | 62 +++++++++++++ image/icon/light/clean_backup.svg | 143 ++++++++++++++++++++++++++++++ image/icon/light/cloud-upload.svg | 62 +++++++++++++ image/icon/light/upload.svg | 62 +++++++++++++ 13 files changed, 485 insertions(+), 39 deletions(-) create mode 100644 image/icon/dark/cloud-upload.svg create mode 100644 image/icon/dark/upload.svg create mode 100644 image/icon/light/clean_backup.svg create mode 100644 image/icon/light/cloud-upload.svg create mode 100644 image/icon/light/upload.svg diff --git a/debian/changelog b/debian/changelog index 83a072b0..761b70b3 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,4 +1,4 @@ -hedera-web (1.405.6) stable; urgency=low +hedera-web (1.405.8) stable; urgency=low * Initial Release. diff --git a/forms/admin/photos/locale/ca.json b/forms/admin/photos/locale/ca.json index 704fe00c..60d2a788 100755 --- a/forms/admin/photos/locale/ca.json +++ b/forms/admin/photos/locale/ca.json @@ -7,6 +7,10 @@ ,"Clear all": "Netejar tot" ,"Upload files": "Pujar arxius" + ,"Waiting for upload": "Esperant per pujar" + ,"Uploading file": "Pujant fitxer" + ,"Image uploaded": "Imatge pujada" + ,"Upload finished successfully": "Imatges pujades correctament" ,"Some errors happened on upload": "Van ocórrer errors en pujar alguna de les imatges" ,"There are no files to upload": "No s'ha seleccionat arxius per pujar" diff --git a/forms/admin/photos/locale/en.json b/forms/admin/photos/locale/en.json index c160093c..dd46d4af 100755 --- a/forms/admin/photos/locale/en.json +++ b/forms/admin/photos/locale/en.json @@ -7,6 +7,10 @@ ,"Clear all": "Clear all" ,"Upload files": "Upload files" + ,"Waiting for upload": "Waiting for upload" + ,"Uploading file": "Uploading file" + ,"Image uploaded": "Image uploaded" + ,"Upload finished successfully": "Upload finished successfully" ,"Some errors happened on upload": "Some errors happened on upload" ,"There are no files to upload": "There are no files to upload" diff --git a/forms/admin/photos/locale/es.json b/forms/admin/photos/locale/es.json index 841acff0..57a426a5 100755 --- a/forms/admin/photos/locale/es.json +++ b/forms/admin/photos/locale/es.json @@ -7,6 +7,10 @@ ,"Clear all": "Limpiar todo" ,"Upload files": "Subir archivos" + ,"Waiting for upload": "Esperando para subir" + ,"Uploading file": "Subiendo fichero" + ,"Image uploaded": "Imagen subida" + ,"Upload finished successfully": "Imágenes subidas correctamente" ,"Some errors happened on upload": "Ocurrieron errores al subir alguna de las imágenes" ,"There are no files to upload": "No se han seleccionado archivos para subir" diff --git a/forms/admin/photos/locale/fr.json b/forms/admin/photos/locale/fr.json index c2b17151..4242b592 100755 --- a/forms/admin/photos/locale/fr.json +++ b/forms/admin/photos/locale/fr.json @@ -7,6 +7,10 @@ ,"Clear all": "Tout effacer" ,"Upload files": "Upload Files" + ,"Waiting for upload": "En attente de télécharger" + ,"Uploading file": "Uploader des fichiers" + ,"Image uploaded": "Fichier uploadé" + ,"Upload finished successfully": "Les images téléchargées correctement" ,"Some errors happened on upload": "Des erreurs sont survenues lors du téléchargement des images" ,"There are no files to upload": "Aucun fichier sélectionné pour télécharger" diff --git a/forms/admin/photos/locale/mn.json b/forms/admin/photos/locale/mn.json index c160093c..dd46d4af 100755 --- a/forms/admin/photos/locale/mn.json +++ b/forms/admin/photos/locale/mn.json @@ -7,6 +7,10 @@ ,"Clear all": "Clear all" ,"Upload files": "Upload files" + ,"Waiting for upload": "Waiting for upload" + ,"Uploading file": "Uploading file" + ,"Image uploaded": "Image uploaded" + ,"Upload finished successfully": "Upload finished successfully" ,"Some errors happened on upload": "Some errors happened on upload" ,"There are no files to upload": "There are no files to upload" diff --git a/forms/admin/photos/locale/pt.json b/forms/admin/photos/locale/pt.json index 728f208e..0b96d036 100644 --- a/forms/admin/photos/locale/pt.json +++ b/forms/admin/photos/locale/pt.json @@ -7,6 +7,10 @@ ,"Clear all": "Clear All" ,"Upload files": "Fazer upload de arquivos" + ,"Waiting for upload": "Esperando para enviar" + ,"Uploading file": "Enviando arquivo" + ,"Image uploaded": "Arquivo enviado" + ,"Upload finished successfully": "Upload concluído com sucesso" ,"Some errors happened on upload": "Ocurrieron erros ao subir alguma das imagens" ,"There are no files to upload": "Não há arquivos selecionados para upload" diff --git a/forms/admin/photos/photos.js b/forms/admin/photos/photos.js index 7fab2c61..6cde6ddd 100644 --- a/forms/admin/photos/photos.js +++ b/forms/admin/photos/photos.js @@ -1,3 +1,11 @@ +(function() { + +var Status = { + NONE : 0 + ,WAITING : 1 + ,UPLOADING : 2 + ,UPLOADED : 3 +}; Hedera.Photos = new Class ({ @@ -5,6 +13,8 @@ Hedera.Photos = new Class ,filesData: [] ,uploadCount: 0 ,errors: false + ,uploadQueue: [] + ,isUploading: false ,activate: function () { @@ -46,17 +56,16 @@ Hedera.Photos = new Class name.value = getFileName (file.name); div.appendChild (name); - var status = doc.createElement ('span'); - status.className = 'status'; - div.appendChild (status); + var statusNode = doc.createElement ('span'); + statusNode.className = 'status'; + div.appendChild (statusNode); var fileData = { div: div, file: file, name: name, - status: status, - sent: false, - loading : false + statusNode: statusNode, + status: Status.NONE }; this.filesData.push (fileData); button.value = fileData; @@ -67,68 +76,88 @@ Hedera.Photos = new Class ,onUploadClick: function () { var filesData = this.filesData; - var formData = new FormData(); var count = 0; for (var i = 0; i < filesData.length; i++) { var fileData = filesData[i]; - - if (!(fileData.sent || fileData.loading)) - { - formData.append ('image', fileData.file); - formData.append ('name', fileData.name.value); - formData.append ('schema', this.$('schema').value); - formData.append ('srv', 'json:image/upload'); - this.conn.sendFormData (formData, - this.onFileUpload.bind (this, fileData)); - fileData.loading = true; - this.uploadCount++; + if (fileData.status === Status.NONE) + { + this.setImageStatus ( + fileData, Status.WAITING, 'cloud-upload', _('Waiting for upload')); + fileData.name.disabled = true; + this.uploadQueue.push (fileData); count++; } } if (count === 0) Htk.Toast.showWarning (_('There are no files to upload')); + else + this.uploadNextFile (); + } + + ,uploadNextFile: function () + { + if (this.isUploading) + return; + + this.isUploading = true; + + var fileData = this.uploadQueue.shift (); + this.setImageStatus ( + fileData, Status.UPLOADING, 'upload', _('Uploading file')); + + var formData = new FormData(); + formData.append ('image', fileData.file); + formData.append ('name', fileData.name.value); + formData.append ('schema', this.$('schema').value); + formData.append ('srv', 'json:image/upload'); + this.conn.sendFormData (formData, + this.onFileUpload.bind (this, fileData)); } ,onFileUpload: function (fileData, data, error) { - fileData.loading = false; + this.isUploading = false; if (data) { - var iconName = 'ok'; - var title = _('ImageAdded'); - fileData.sent = true; - fileData.name.disabled = true; + this.setImageStatus ( + fileData, Status.UPLOADED, 'ok', _('Image uploaded')); } else { - var iconName = 'error'; - var title = error.message; + this.setImageStatus ( + fileData, Status.NONE, 'error', error.message); + fileData.name.disabled = false; this.errors = true; } - var status = fileData.status; - Vn.Node.removeChilds (status); - - var icon = new Htk.Icon ({icon: iconName}); - status.appendChild (icon.node); - status.title = title; - - this.uploadCount--; - - if (this.uploadCount === 0) + if (this.uploadQueue.length === 0) { - if (!this.errors) - Htk.Toast.showMessage (_('Upload finished successfully')); - else + if (this.errors) Htk.Toast.showError (_('Some errors happened on upload')); + else + Htk.Toast.showMessage (_('Upload finished successfully')); this.errors = false; } + else + this.uploadNextFile (); + } + + ,setImageStatus: function (fileData, status, icon, title) + { + fileData.status = status; + + var statusNode = fileData.statusNode; + Vn.Node.removeChilds (statusNode); + + var iconNode = new Htk.Icon ({icon: icon}); + statusNode.appendChild (iconNode.node); + statusNode.title = title ? title : ''; } ,onFileRemove: function (button) @@ -202,3 +231,5 @@ function getFileName (path) return path.substr (barIndex, dotIndex); } + +})(); diff --git a/image/icon/dark/cloud-upload.svg b/image/icon/dark/cloud-upload.svg new file mode 100644 index 00000000..3a6da283 --- /dev/null +++ b/image/icon/dark/cloud-upload.svg @@ -0,0 +1,62 @@ + + + + + + image/svg+xml + + + + + + + + + + diff --git a/image/icon/dark/upload.svg b/image/icon/dark/upload.svg new file mode 100644 index 00000000..7521267b --- /dev/null +++ b/image/icon/dark/upload.svg @@ -0,0 +1,62 @@ + + + + + + image/svg+xml + + + + + + + + + + diff --git a/image/icon/light/clean_backup.svg b/image/icon/light/clean_backup.svg new file mode 100644 index 00000000..17bb5fae --- /dev/null +++ b/image/icon/light/clean_backup.svg @@ -0,0 +1,143 @@ + + + + + + + + image/svg+xml + + Gnome Symbolic Icon Theme + + + + + + + Gnome Symbolic Icon Theme + + + + + + + + + + + + + diff --git a/image/icon/light/cloud-upload.svg b/image/icon/light/cloud-upload.svg new file mode 100644 index 00000000..56b71d60 --- /dev/null +++ b/image/icon/light/cloud-upload.svg @@ -0,0 +1,62 @@ + + + + + + image/svg+xml + + + + + + + + + + diff --git a/image/icon/light/upload.svg b/image/icon/light/upload.svg new file mode 100644 index 00000000..13835b13 --- /dev/null +++ b/image/icon/light/upload.svg @@ -0,0 +1,62 @@ + + + + + + image/svg+xml + + + + + + + + + +