2 /*******************************************************************************
3 * Copyright (c) 2012-2013 University of Stuttgart.
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * and the Apache License 2.0 which both accompany this distribution,
7 * and are available at http://www.eclipse.org/legal/epl-v10.html
8 * and http://www.apache.org/licenses/LICENSE-2.0
11 * Oliver Kopp - initial API and implementation and/or initial documentation
12 *******************************************************************************/
14 <%@tag description="HTML + JavaScript enabling the full jQuery file upload as shown at http://blueimp.github.com/jQuery-File-Upload/" pageEncoding="UTF-8"%>
16 <%-- Original Source https://raw.github.com/blueimp/jQuery-File-Upload/9.5.4/jquery-ui.html, License: MIT; See also CQ 8006 --%>
18 <%@attribute name="action" required="false" description="custom action for the upload"%>
19 <%@attribute name="loadexistingfiles" type="java.lang.Boolean" required="true" description="load existing files from files/ url. false if that should not happen"%>
22 !! USES HARD-CODED URL "files/" for data !!
23 It is OK since it is currently only used in "files.jsp"
24 If it will be used in other places, there has to be a parameter "url" introduced
25 (and this jsp updated to a tag file)
28 <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
30 <%-- The File Upload user interface plugin --%>
32 <!-- The file upload form used as target for the file upload widget -->
33 <form id="fileupload" method="POST" enctype="multipart/form-data" <c:if test="${not empty action}">action="${action}"</c:if>>
34 <!-- The fileupload-buttonbar contains buttons to add/delete files and start/cancel the upload -->
35 <div class="row fileupload-buttonbar">
36 <div class="span7"> <!-- should be col-lg-7, but then the add button does not work any more -->
37 <!-- The fileinput-button span is used to style the file input field as button -->
38 <span class="btn btn-success fileinput-button">
39 <i class="glyphicon glyphicon-plus"></i>
40 <span>Add files...</span>
41 <input type="file" name="files[]" multiple>
44 <!-- The global progress information -->
45 <div class="span5 fileupload-progress fade">
46 <!-- The global progress bar -->
47 <div class="progress progress-success progress-striped active" role="progressbar" aria-valuemin="0" aria-valuemax="100">
48 <div class="bar" style="width:0%;"></div>
50 <!-- The extended global progress information -->
51 <div class="progress-extended"> </div>
54 <!-- The loading indicator is shown during file processing -->
55 <div class="fileupload-loading"></div>
57 <!-- The table listing the files available for upload/download -->
58 <table role="presentation" class="table table-striped"><tbody class="files" data-toggle="modal-gallery" data-target="#modal-gallery"></tbody></table>
61 <!-- The template to display files available for upload -->
62 <script id="template-upload" type="text/x-tmpl">
63 {% for (var i=0, file; file=o.files[i]; i++) { %}
64 <tr class="template-upload fade">
66 <span class="preview"></span>
69 <p class="name">{%=file.name%}</p>
70 <strong class="error text-danger"></strong>
73 <p class="size">Processing...</p>
74 <div class="progress progress-striped active" role="progressbar" aria-valuemin="0" aria-valuemax="100" aria-valuenow="0"><div class="progress-bar progress-bar-success" style="width:0%;"></div></div>
77 {% if (!i && !o.options.autoUpload) { %}
78 <button class="btn btn-primary start" disabled>
79 <i class="glyphicon glyphicon-upload"></i>
84 <button class="btn btn-warning cancel">
85 <i class="glyphicon glyphicon-ban-circle"></i>
93 <!-- The template to display files available for download -->
94 <script id="template-download" type="text/x-tmpl">
95 {% for (var i=0, file; file=o.files[i]; i++) { %}
96 <tr class="template-download fade">
98 <span class="preview">
99 {% if (file.thumbnailUrl) { %}
100 <a href="{%=file.url%}" title="{%=file.name%}" download="{%=file.name%}" data-gallery><img src="{%=file.thumbnailUrl%}"></a>
106 {% if (file.url) { %}
107 <a href="{%=file.url%}" title="{%=file.name%}" download="{%=file.name%}" {%=file.thumbnailUrl?'data-gallery':''%}>{%=file.name%}</a>
109 <span>{%=file.name%}</span>
112 {% if (file.error) { %}
113 <div><span class="label label-danger">Error</span> {%=file.error%}</div>
117 <span class="size">{%=o.formatFileSize(file.size)%}</span>
120 {% if (file.deleteUrl) { %}
121 <button class="btn btn-danger btn-sm delete" data-type="{%=file.deleteType%}" data-url="{%=file.deleteUrl%}"{% if (file.deleteWithCredentials) { %} data-xhr-fields='{"withCredentials":true}'{% } %}>
122 <i class="glyphicon glyphicon-trash"></i>
126 <button class="btn btn-warning cancel">
127 <i class="glyphicon glyphicon-ban-circle"></i>
138 * Based on jQuery File Upload Plugin JS Example
139 * https://github.com/blueimp/jQuery-File-Upload
141 * Copyright 2010, Sebastian Tschan
142 * https://blueimp.net
144 * Licensed under the MIT license:
145 * http://www.opensource.org/licenses/MIT
148 /*jslint nomen: true, unparam: true, regexp: true */
149 /*global $, window, document */
154 // jquery.fileupload.process for image resizing capabilities
155 // has to be included in all cases as jquery.ui.widget depends on it without specifying the depencency explicitly
156 requirejs(['tmpl', 'jquery.ui.widget', 'jquery.fileupload', 'jquery.fileupload-ui', 'jquery.fileupload-process'], function() {
157 // Initialize the jQuery File Upload widget:
158 $('#fileupload').fileupload( {
163 <c:if test="${loadexistingfiles}">
164 // Load existing files
165 $('#fileupload').addClass('fileupload-processing');
167 url: $('#fileupload').fileupload('option', 'url'),
169 context: $('#fileupload')[0]
170 }).always(function () {
171 $(this).removeClass('fileupload-processing');
172 }).done(function (result) {
173 $(this).fileupload('option', 'done')
174 .call(this, $.Event('done'), {result: result});
175 }).fail(function(jqXHR, textStatus, errorThrown) {
176 vShowAJAXError("Could not add upload file", jqXHR, errorThrown);