From bcfc6934191e913dcb78a9f06b6bbac1100b4461 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Guillaume=20Perr=C3=A9al?= <guillaume.perreal@irstea.fr>
Date: Thu, 22 Jan 2015 11:28:54 +0100
Subject: [PATCH] =?UTF-8?q?Affichage/cache=20le=20bouton=20d'upload=20lors?=
 =?UTF-8?q?qu'un=20g=C3=A8re=20un=20fichier=20unique.?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 Resources/js/widget/file_upload.js | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/Resources/js/widget/file_upload.js b/Resources/js/widget/file_upload.js
index 8b02e92e..6a6bbf90 100644
--- a/Resources/js/widget/file_upload.js
+++ b/Resources/js/widget/file_upload.js
@@ -9,6 +9,8 @@
     $.fn.irsteaFileUpload = function(options) {
 
         var $this             = $(this),
+            $button           = $this.find('.fileinput-button'),
+            $entries          = $this.find('.fileinput-entries'),
             prototype         = options.prototype,
             createUrl         = options.createUrl,
             uploadPrototype   = options.uploadPrototype,
@@ -33,11 +35,19 @@
             },
             formatBitrate = function(rate) {
                 return formatSize(rate) + '/s';
+            },
+            updateButtonVisibility = function() {
+                console.debug($entries.children());
+                if($entries.children().length > 0 && !options.multiple) {
+                    $button.hide();
+                } else {
+                    $button.show();
+                }
             };
 
         $this.find('.template-download .size').each(function() { $(this).html(formatSize($(this).text())); });
 
-        var formatBitrate = function(rate) { return formatSize(rate) + '/s'; };
+        updateButtonVisibility();
 
         // Activation
         $this.fileupload({
@@ -112,6 +122,9 @@
             fileuploadfailed: function (e, data) {
                 $.ajax(data.url, { type: 'DELETE' });
             },
+            fileuploadadded: updateButtonVisibility,
+            fileuploadfinished: updateButtonVisibility,
+            fileuploaddestroyed: updateButtonVisibility,
         });
 
     };
-- 
GitLab