Skip to content

Commit

Permalink
Display a cancel button if the server-side validation failed. Fixes b…
Browse files Browse the repository at this point in the history
…lueimp#2538

Replace label-important with label-danger (Bootstrap 3 change).
  • Loading branch information
blueimp committed Aug 26, 2013
1 parent 04954d5 commit 5754b98
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 25 deletions.
4 changes: 2 additions & 2 deletions angularjs.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<!DOCTYPE HTML>
<!--
/*
* jQuery File Upload Plugin AngularJS Demo 1.6.2
* jQuery File Upload Plugin AngularJS Demo 1.6.3
* https://github.com/blueimp/jQuery-File-Upload
*
* Copyright 2013, Sebastian Tschan
Expand Down Expand Up @@ -125,7 +125,7 @@ <h2 class="lead">AngularJS version</h2>
</span>
<span data-ng-switch-default>{{file.name}}</span>
</p>
<div data-ng-show="file.error"><span class="label label-important">Error</span> {{file.error}}</div>
<div data-ng-show="file.error"><span class="label label-danger">Error</span> {{file.error}}</div>
</td>
<td>
<p class="size">{{file.size | formatFileSize}}</p>
Expand Down
29 changes: 20 additions & 9 deletions index.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<!DOCTYPE HTML>
<!--
/*
* jQuery File Upload Plugin Demo 8.8.2
* jQuery File Upload Plugin Demo 8.8.3
* https://github.com/blueimp/jQuery-File-Upload
*
* Copyright 2010, Sebastian Tschan
Expand Down Expand Up @@ -149,7 +149,7 @@ <h3 class="title"></h3>
<td>
<p class="name">{%=file.name%}</p>
{% if (file.error) { %}
<div><span class="label label-important">Error</span> {%=file.error%}</div>
<div><span class="label label-danger">Error</span> {%=file.error%}</div>
{% } %}
</td>
<td>
Expand Down Expand Up @@ -188,21 +188,32 @@ <h3 class="title"></h3>
</td>
<td>
<p class="name">
<a href="{%=file.url%}" title="{%=file.name%}" download="{%=file.name%}" {%=file.thumbnailUrl?'data-gallery':''%}>{%=file.name%}</a>
{% if (file.url) { %}
<a href="{%=file.url%}" title="{%=file.name%}" download="{%=file.name%}" {%=file.thumbnailUrl?'data-gallery':''%}>{%=file.name%}</a>
{% } else { %}
<span>{%=file.name%}</span>
{% } %}
</p>
{% if (file.error) { %}
<div><span class="label label-important">Error</span> {%=file.error%}</div>
<div><span class="label label-danger">Error</span> {%=file.error%}</div>
{% } %}
</td>
<td>
<span class="size">{%=o.formatFileSize(file.size)%}</span>
</td>
<td>
<button class="btn btn-danger delete" data-type="{%=file.deleteType%}" data-url="{%=file.deleteUrl%}"{% if (file.deleteWithCredentials) { %} data-xhr-fields='{"withCredentials":true}'{% } %}>
<i class="glyphicon glyphicon-trash"></i>
<span>Delete</span>
</button>
<input type="checkbox" name="delete" value="1" class="toggle">
{% if (file.deleteUrl) { %}
<button class="btn btn-danger delete" data-type="{%=file.deleteType%}" data-url="{%=file.deleteUrl%}"{% if (file.deleteWithCredentials) { %} data-xhr-fields='{"withCredentials":true}'{% } %}>
<i class="glyphicon glyphicon-trash"></i>
<span>Delete</span>
</button>
<input type="checkbox" name="delete" value="1" class="toggle">
{% } else { %}
<button class="btn btn-warning cancel">
<i class="glyphicon glyphicon-ban-circle"></i>
<span>Cancel</span>
</button>
{% } %}
</td>
</tr>
{% } %}
Expand Down
6 changes: 4 additions & 2 deletions js/jquery.fileupload-ui.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* jQuery File Upload User Interface Plugin 8.8.1
* jQuery File Upload User Interface Plugin 8.8.3
* https://github.com/blueimp/jQuery-File-Upload
*
* Copyright 2010, Sebastian Tschan
Expand Down Expand Up @@ -460,9 +460,11 @@

_cancelHandler: function (e) {
e.preventDefault();
var template = $(e.currentTarget).closest('.template-upload'),
var template = $(e.currentTarget)
.closest('.template-upload,.template-download'),
data = template.data('data') || {};
if (!data.jqXHR) {
data.context = data.context || template;
data.errorThrown = 'abort';
this._trigger('fail', e, data);
} else {
Expand Down
33 changes: 22 additions & 11 deletions test/index.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<!DOCTYPE HTML>
<!--
/*
* jQuery File Upload Plugin Test 8.8.0
* jQuery File Upload Plugin Test 8.8.3
* https://github.com/blueimp/jQuery-File-Upload
*
* Copyright 2010, Sebastian Tschan
Expand All @@ -20,7 +20,7 @@
<meta charset="utf-8">
<title>jQuery File Upload Plugin Test</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="http://code.jquery.com/qunit/git/qunit.css">
<link rel="stylesheet" href="http://codeorigin.jquery.com/qunit/qunit-1.12.0.css">
</head>
<body>
<h1 id="qunit-header">jQuery File Upload Plugin Test</h1>
Expand Down Expand Up @@ -80,7 +80,7 @@ <h2 id="qunit-userAgent"></h2>
<td>
<p class="name">{%=file.name%}</p>
{% if (file.error) { %}
<div><span class="label label-important">Error</span> {%=file.error%}</div>
<div><span class="label label-danger">Error</span> {%=file.error%}</div>
{% } %}
</td>
<td>
Expand Down Expand Up @@ -119,21 +119,32 @@ <h2 id="qunit-userAgent"></h2>
</td>
<td>
<p class="name">
<a href="{%=file.url%}" title="{%=file.name%}" download="{%=file.name%}" {%=file.thumbnailUrl?'data-gallery':''%}>{%=file.name%}</a>
{% if (file.url) { %}
<a href="{%=file.url%}" title="{%=file.name%}" download="{%=file.name%}" {%=file.thumbnailUrl?'data-gallery':''%}>{%=file.name%}</a>
{% } else { %}
<span>{%=file.name%}</span>
{% } %}
</p>
{% if (file.error) { %}
<div><span class="label label-important">Error</span> {%=file.error%}</div>
<div><span class="label label-danger">Error</span> {%=file.error%}</div>
{% } %}
</td>
<td>
<span class="size">{%=o.formatFileSize(file.size)%}</span>
</td>
<td>
<button class="btn btn-danger delete" data-type="{%=file.deleteType%}" data-url="{%=file.deleteUrl%}"{% if (file.deleteWithCredentials) { %} data-xhr-fields='{"withCredentials":true}'{% } %}>
<i class="icon-trash icon-white"></i>
<span>Delete</span>
</button>
<input type="checkbox" name="delete" value="1" class="toggle">
{% if (file.deleteUrl) { %}
<button class="btn btn-danger delete" data-type="{%=file.deleteType%}" data-url="{%=file.deleteUrl%}"{% if (file.deleteWithCredentials) { %} data-xhr-fields='{"withCredentials":true}'{% } %}>
<i class="glyphicon glyphicon-trash"></i>
<span>Delete</span>
</button>
<input type="checkbox" name="delete" value="1" class="toggle">
{% } else { %}
<button class="btn btn-warning cancel">
<i class="glyphicon glyphicon-ban-circle"></i>
<span>Cancel</span>
</button>
{% } %}
</td>
</tr>
{% } %}
Expand All @@ -153,7 +164,7 @@ <h2 id="qunit-userAgent"></h2>
<script src="../js/jquery.fileupload-validate.js"></script>
<script src="../js/jquery.fileupload-ui.js"></script>
<script>window.testUIWidget = $.blueimp.fileupload;</script>
<script src="http://code.jquery.com/qunit/git/qunit.js"></script>
<script src="http://codeorigin.jquery.com/qunit/qunit-1.12.0.js"></script>
<script src="test.js"></script>
</body>
</html>
3 changes: 2 additions & 1 deletion test/test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* jQuery File Upload Plugin Test 8.6.0
* jQuery File Upload Plugin Test 8.8.3
* https://github.com/blueimp/jQuery-File-Upload
*
* Copyright 2010, Sebastian Tschan
Expand Down Expand Up @@ -891,6 +891,7 @@ $(function () {
$('#fileupload').fileupload('add', {files: files});
buttonbar.find('.start').click();
buttonbar.find('.cancel').click();
files[0].deleteUrl = 'http://example.org/banana.jpg';
($('#fileupload').data('blueimp-fileupload') ||
$('#fileupload').data('fileupload'))
._renderDownload(files)
Expand Down

0 comments on commit 5754b98

Please sign in to comment.