From c4ca67f33ff149c10f0f7b826226ded407502519 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guillaume=20Perr=C3=A9al?= <guillaume.perreal@irstea.fr> Date: Thu, 22 Jan 2015 14:44:50 +0100 Subject: [PATCH] =?UTF-8?q?FileUploadType:=20g=C3=A8re=20les=20param=C3=A8?= =?UTF-8?q?tres=20"disabled"=20et=20"read=5Fonly".?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Resources/js/widget/file_upload.js | 4 ++++ Resources/views/Form/file_upload.html.twig | 12 +++++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/Resources/js/widget/file_upload.js b/Resources/js/widget/file_upload.js index b612d134..4da6488e 100644 --- a/Resources/js/widget/file_upload.js +++ b/Resources/js/widget/file_upload.js @@ -141,6 +141,10 @@ fileuploadprocessalways: updateButtonVisibility }); + if(options.disabled || options.readonly) { + $button.fileupload('disable'); + } + }; })(jQuery); diff --git a/Resources/views/Form/file_upload.html.twig b/Resources/views/Form/file_upload.html.twig index f398994f..53f72846 100644 --- a/Resources/views/Form/file_upload.html.twig +++ b/Resources/views/Form/file_upload.html.twig @@ -17,7 +17,10 @@ {% block file_upload_widget %} <div id="{{ id }}" {{ block('widget_container_attributes') }} {{ block('widget_only_attributes') -}} data-download-prototype="{{ block('file_upload_entry_prototype')|e }}" - data-upload-prototype="{{ block('file_upload_progress_prototype')|e }}"> + data-upload-prototype="{{ block('file_upload_progress_prototype')|e }}" + {% if disabled %}data-disabled="disabled"{% endif -%} + {% if read_only %}data-readonly="readonly"{% endif -%} + > <div class="fileinput-entries"> {%- if value is not empty %} {%- if multiple %} @@ -30,7 +33,7 @@ {%- set file = file|default([]) %} <p class="template-download"> <input type="hidden" name="{{ full_name }}{% if multiple %}[]{% endif %}" value="{{ file.id|default }}"/> - <button class="btn btn-xs btn-danger delete" title="{% trans %}button.delete{% endtrans %}"> + <button class="btn btn-xs btn-danger delete" title="{% trans %}button.delete{% endtrans %}" {%- if disabled or read_only %} disabled="disabled"{% endif -%}> {{- irstea_icon('trash') -}} </button> <span class="name"> <a{% if file %} href="{{ path('file_upload_get', {id: file.id, token: csrfToken}) }}"{% endif %}>{{ file.originalFilename|default }}</a> @@ -45,7 +48,10 @@ </div> <span class="btn btn-primary fileinput-button"> <span>{{ irstea_icon('upload') }} {% trans %}button.upload{% endtrans %}</span> - <input type="file" name="_hack_{{ full_name }}"{% if multiple %} multiple="multiple"{% endif %}/> + <input type="file" name="_hack_{{ full_name }}" + {%- if multiple %} multiple="multiple"{% endif -%} + {%- if disabled or read_only %} disabled="disabled"{% endif -%} + /> </span> </div> {% endblock file_upload_widget %} -- GitLab