implement the view/route for updating existing files
This commit is contained in:
parent
da8a9e3c5e
commit
879229e4dd
|
@ -40,6 +40,16 @@
|
|||
(session/flash-put! :file-error "No file selected to upload."))
|
||||
(resp/redirect (str "/listfiles" path)))
|
||||
|
||||
(defn handle-update-file [id file]
|
||||
(if (valid-upload? file)
|
||||
(let [tempfile (:tempfile file)
|
||||
content-type (:content-type file)]
|
||||
(if-let [updatedfile (files/update-file id tempfile content-type)]
|
||||
(session/flash-put! :file-success (str "<strong>" id "</strong> was updated successfully."))
|
||||
(session/flash-put! :file-error "File could not be updated.")))
|
||||
(session/flash-put! :file-error "No file selected to upload."))
|
||||
(resp/redirect (str "/listfiles")))
|
||||
|
||||
(defn handle-delete-file [id]
|
||||
(if-let [deleted (files/delete-file id)]
|
||||
(session/flash-put! :file-success (str "<strong>" id "</strong> was deleted successfully."))
|
||||
|
@ -55,5 +65,6 @@
|
|||
(restricted GET "/listfiles" [] (list-files "/"))
|
||||
(restricted GET "/listfiles/*" [*] (list-files *))
|
||||
(restricted POST "/uploadfile" [path file] (handle-new-file (ensure-prefix-suffix path "/") file))
|
||||
(restricted POST "/updatefile" [id file] (handle-update-file (ensure-prefix id "/") file))
|
||||
(restricted POST "/deletefile" [id] (handle-delete-file (ensure-prefix id "/")))
|
||||
(GET "/files/*" [*] (get-file *)))
|
||||
|
|
|
@ -87,6 +87,30 @@
|
|||
</form>
|
||||
</div>
|
||||
|
||||
<div id="updateFileModal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="updateFileModalLabel" aria-hidden="true">
|
||||
<div class="modal-header">
|
||||
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
|
||||
<h3 id="updateFileModalLabel">Update File</h3>
|
||||
</div>
|
||||
<form action="{{context}}/updatefile" method="post" enctype="multipart/form-data" class="form-horizontal">
|
||||
<input type="hidden" id="updateFileId" name="id" />
|
||||
<div class="modal-body">
|
||||
<p>Select a file to upload over top of this file with:</p>
|
||||
<p><strong id="updateFileModalFilename"></strong></p>
|
||||
<div class="control-group">
|
||||
<label class="control-label" for="updateFile">Upload File</label>
|
||||
<div class="controls">
|
||||
<input type="file" id="updateFile" name="file" placeholder="File" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button class="btn" data-dismiss="modal" aria-hidden="true">Cancel</button>
|
||||
<button type="submit" class="btn btn-primary">Upload</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<div id="deleteFileModal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="deleteFileModalLabel" aria-hidden="true">
|
||||
<div class="modal-header">
|
||||
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
|
||||
|
@ -116,25 +140,22 @@ $('#tree-selector').click(function() {
|
|||
window.location.href = '{{context}}/listfiles' + path;
|
||||
});
|
||||
|
||||
$('a[data-updatefileid]').click(function() {
|
||||
var fileId = $(this).data('updatefileid');
|
||||
|
||||
$('#updateFileModal').modal({backdrop: 'static', keyboard: false});
|
||||
$('#updateFileId').val(fileId);
|
||||
$('#updateFileModalFilename').text(fileId);
|
||||
});
|
||||
|
||||
$('a[data-deletefileid]').click(function() {
|
||||
var fileId = $(this).data('deletefileid');
|
||||
|
||||
$('#deleteFileModalOkNoReset').data('forfileid', fileId);
|
||||
$('#deleteFileModalOk').data('forfileid', fileId);
|
||||
$('#deleteFileModal').modal({backdrop: 'static', keyboard: false});
|
||||
$('#deleteFileId').val(fileId);
|
||||
$('#deleteFileModalFilename').text(fileId);
|
||||
});
|
||||
|
||||
$('#deleteFileModalOkNoReset').click(function() {
|
||||
var fileId = $(this).data('forfileid');
|
||||
$('#deleteFileModal').find('button').attr('disabled', 'disabled');
|
||||
});
|
||||
|
||||
$('#publishModalOk').click(function() {
|
||||
var fileId = $(this).data('forfileid');
|
||||
$('#deleteFileModal').find('button').attr('disabled', 'disabled');
|
||||
});
|
||||
</script>
|
||||
|
||||
{% endblock %}
|
||||
|
|
Reference in a new issue