Commit 30e80411c9870c4f1ba8efc7fc55369d08112e7d
1 parent
92f8d2d5
Exists in
master
and in
2 other branches
Change restore to require a file
Showing
1 changed file
with
27 additions
and
4 deletions
Show diff stats
subjects/templates/subjects/restore.html
| ... | ... | @@ -72,10 +72,10 @@ |
| 72 | 72 | {% csrf_token %} |
| 73 | 73 | |
| 74 | 74 | <div class="form-group is-fileinput"> |
| 75 | - <input type="file" id="zip_file" name="zip_file" class="form-control" accept=".zip" /> | |
| 75 | + <input type="file" id="zip_file" name="zip_file" class="form-control" accept=".zip" data-mimetypes="['application/zip', 'application/octet-stream']" required /> | |
| 76 | 76 | |
| 77 | 77 | <div class="input-group common-file-input"> |
| 78 | - <input type="text" readonly="" class="form-control" placeholder="{% trans 'Choose your file...' %}"> | |
| 78 | + <input type="text" readonly="" class="form-control" placeholder="{% trans 'Choose your file...' %}" required> | |
| 79 | 79 | <span class="input-group-btn input-group-sm"> |
| 80 | 80 | <button type="button" class="btn btn-fab btn-fab-mini"> |
| 81 | 81 | <i class="material-icons">attach_file</i> |
| ... | ... | @@ -88,8 +88,18 @@ |
| 88 | 88 | </div> |
| 89 | 89 | </div> |
| 90 | 90 | |
| 91 | + <div class="col-lg-12 col-md-12 col-sm-12 alert alert-danger alert-dismissible client-file-errors" style="display:none" role="alert"> | |
| 92 | + <button type="button" class="close" data-dismiss="alert" aria-label="Close"> | |
| 93 | + <span aria-hidden="true">×</span> | |
| 94 | + </button> | |
| 95 | + <ul> | |
| 96 | + <li class="format">{% trans 'File not supported.' %}</li> | |
| 97 | + </ul> | |
| 98 | + </div> | |
| 99 | + | |
| 100 | + | |
| 91 | 101 | <div class="row text-center"> |
| 92 | - <input type="submit" value="{% trans 'Restore' %}" class="btn btn-success btn-raised" /> | |
| 102 | + <input type="submit" value="{% trans 'Restore' %}" disabled class="btn btn-success btn-raised" /> | |
| 93 | 103 | </div> |
| 94 | 104 | </form> |
| 95 | 105 | </div> |
| ... | ... | @@ -127,10 +137,23 @@ |
| 127 | 137 | // file selection |
| 128 | 138 | function FileSelectHandler(e) { |
| 129 | 139 | var files = e.target.files || e.dataTransfer.files, |
| 130 | - parent = $(e.target.offsetParent); | |
| 140 | + parent = $(e.target.offsetParent), | |
| 141 | + mimeTypes = $(e.target).data('mimetypes'), | |
| 142 | + submit_btn = $(e.target).closest("form").find("input[type='submit']"); | |
| 143 | + | |
| 144 | + $(".client-file-errors").hide(); | |
| 145 | + $(submit_btn).prop('disable', false); | |
| 146 | + $(submit_btn).prop('disabled', false); | |
| 131 | 147 | |
| 132 | 148 | // process all File objects |
| 133 | 149 | for (var i = 0, f; f = files[i]; i++) { |
| 150 | + if (!mimeTypes.includes(f.type)) { | |
| 151 | + $(submit_btn).prop('disable', true); | |
| 152 | + $(submit_btn).prop('disabled', true); | |
| 153 | + | |
| 154 | + $(".client-file-errors").show(); | |
| 155 | + } | |
| 156 | + | |
| 134 | 157 | parent.find('.filedrag').html(f.name); |
| 135 | 158 | } |
| 136 | 159 | } | ... | ... |