fix up various file operations to return back to the proper path listing
This commit is contained in:
parent
f1ee2329db
commit
a00b7a1b2d
|
@ -24,7 +24,7 @@
|
|||
:success (session/flash-get :file-success)
|
||||
:notice (session/flash-get :file-notice)})))
|
||||
|
||||
(defn handle-new-file [path file]
|
||||
(defn handle-new-file [path file returnpath]
|
||||
(if (valid-upload? file)
|
||||
(let [filename (:filename file)
|
||||
tempfile (:tempfile file)
|
||||
|
@ -39,9 +39,9 @@
|
|||
(if exists? (session/flash-put! :file-notice "Existing file with the same name was updated with the uploaded file.")))
|
||||
(session/flash-put! :file-error "File could not be uploaded.")))
|
||||
(session/flash-put! :file-error "No file selected to upload."))
|
||||
(resp/redirect (str "/listfiles" path)))
|
||||
(resp/redirect (str "/listfiles" returnpath)))
|
||||
|
||||
(defn handle-update-file [id file]
|
||||
(defn handle-update-file [id file returnpath]
|
||||
(if (valid-upload? file)
|
||||
(let [tempfile (:tempfile file)
|
||||
content-type (:content-type file)]
|
||||
|
@ -49,19 +49,19 @@
|
|||
(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")))
|
||||
(resp/redirect (str "/listfiles" returnpath)))
|
||||
|
||||
(defn handle-delete-file [id]
|
||||
(defn handle-delete-file [id returnpath]
|
||||
(if-let [deleted (files/delete-file id)]
|
||||
(session/flash-put! :file-success (str "<strong>" id "</strong> was deleted successfully."))
|
||||
(session/flash-put! :file-error "File could not be deleted."))
|
||||
(resp/redirect "/listfiles"))
|
||||
(resp/redirect (str "/listfiles" returnpath)))
|
||||
|
||||
(defn handle-publish-file [id publish?]
|
||||
(defn handle-publish-file [id publish? returnpath]
|
||||
(if-let [published (files/publish-file id publish?)]
|
||||
(session/flash-put! :file-success (str "<strong>" id "</strong> was " (if (:published published) "published" "unpublished") " successfully."))
|
||||
(session/flash-put! :file-error "Could not update file's published state."))
|
||||
(resp/redirect "/listfiles"))
|
||||
(resp/redirect (str "/listfiles" returnpath)))
|
||||
|
||||
(defn get-file [path]
|
||||
(if-let [file (files/get-file path (auth/logged-in?))]
|
||||
|
@ -71,9 +71,9 @@
|
|||
(defroutes files-routes
|
||||
(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 "/")))
|
||||
(restricted GET "/publishfile/*" [*] (handle-publish-file * true))
|
||||
(restricted GET "/unpublishfile/*" [*] (handle-publish-file * false))
|
||||
(restricted POST "/uploadfile" [path file returnpath] (handle-new-file (ensure-prefix-suffix path "/") file returnpath))
|
||||
(restricted POST "/updatefile" [id file returnpath] (handle-update-file (ensure-prefix id "/") file returnpath))
|
||||
(restricted POST "/deletefile" [id returnpath] (handle-delete-file (ensure-prefix id "/") returnpath))
|
||||
(restricted GET "/publishfile/*" [* returnpath] (handle-publish-file * true returnpath))
|
||||
(restricted GET "/unpublishfile/*" [* returnpath] (handle-publish-file * false returnpath))
|
||||
(GET "/files/*" [*] (get-file *)))
|
||||
|
|
|
@ -54,10 +54,10 @@
|
|||
<td style="text-align: right;">
|
||||
<a class="btn btn-warning" title="Update File" data-updatefileid="{{file.id}}" href="#"><i class="icon-pencil icon-white"></i></a>
|
||||
{% if file.published %}
|
||||
<a class="btn btn-warning" title="Unpublish File" href="{{context}}/unpublishfile{{file.id}}"><i class="icon-minus-sign icon-white"></i></a>
|
||||
<a class="btn btn-warning" title="Unpublish File" href="{{context}}/unpublishfile{{file.id}}?returnpath={{path}}"><i class="icon-minus-sign icon-white"></i></a>
|
||||
{% endif %}
|
||||
{% if not file.published %}
|
||||
<a class="btn btn-success" title="Publish File" href="{{context}}/publishfile{{file.id}}"><i class="icon-ok-sign icon-white"></i></a>
|
||||
<a class="btn btn-success" title="Publish File" href="{{context}}/publishfile{{file.id}}?returnpath={{path}}"><i class="icon-ok-sign icon-white"></i></a>
|
||||
{% endif %}
|
||||
<a class="btn btn-danger" title="Delete File" data-deletefileid="{{file.id}}" href="#"><i class="icon-remove icon-white"></i></a>
|
||||
</td>
|
||||
|
@ -75,7 +75,7 @@
|
|||
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
|
||||
<h3 id="newFileModalLabel">Upload File</h3>
|
||||
</div>
|
||||
<form action="{{context}}/uploadfile" method="post" enctype="multipart/form-data" class="form-horizontal">
|
||||
<form action="{{context}}/uploadfile?returnpath={{path}}" method="post" enctype="multipart/form-data" class="form-horizontal">
|
||||
<input type="hidden" id="newPath" name="path" value="{{path}}" />
|
||||
<div class="modal-body">
|
||||
<div class="control-group">
|
||||
|
@ -98,7 +98,7 @@
|
|||
<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">
|
||||
<form action="{{context}}/updatefile?returnpath={{path}}" 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>
|
||||
|
@ -122,7 +122,7 @@
|
|||
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
|
||||
<h3 id="deleteFileModalLabel">Delete File</h3>
|
||||
</div>
|
||||
<form action="{{context}}/deletefile" method="post" class="form-horizontal">
|
||||
<form action="{{context}}/deletefile?returnpath={{path}}" method="post" class="form-horizontal">
|
||||
<input type="hidden" id="deleteFileId" name="id" />
|
||||
<div class="modal-body">
|
||||
<p>Confirm that you would like to delete the following file:</p>
|
||||
|
|
Reference in a new issue