fix #15
This commit is contained in:
parent
6453713253
commit
49baf4fcf1
File diff suppressed because one or more lines are too long
|
@ -24,6 +24,38 @@ $(document).on('ready pjax:success', function() {
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Delete a file or a field in editor
|
||||||
|
$(".delete").click(function(event) {
|
||||||
|
event.preventDefault();
|
||||||
|
button = $(this);
|
||||||
|
|
||||||
|
if (button.data("file") && confirm("Are you sure you want to delete this?")) {
|
||||||
|
$.ajax({
|
||||||
|
type: 'DELETE',
|
||||||
|
url: button.data("file")
|
||||||
|
}).done(function(data) {
|
||||||
|
button.parent().parent().fadeOut();
|
||||||
|
notification({
|
||||||
|
text: button.data("message"),
|
||||||
|
type: 'success',
|
||||||
|
timeout: 5000
|
||||||
|
});
|
||||||
|
}).fail(function(data) {
|
||||||
|
notification({
|
||||||
|
text: 'Something went wrong.',
|
||||||
|
type: 'error'
|
||||||
|
});
|
||||||
|
console.log(data);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
name = button.parent().parent().attr("for") || button.parent().parent().parent().attr("id");
|
||||||
|
console.log(name)
|
||||||
|
|
||||||
|
$('#' + name).fadeOut().remove();
|
||||||
|
$('label[for="' + name + '"]').fadeOut().remove();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// If it's editor page
|
// If it's editor page
|
||||||
if ($(".editor")[0]) {
|
if ($(".editor")[0]) {
|
||||||
editor = false;
|
editor = false;
|
||||||
|
@ -180,15 +212,6 @@ $(document).on('ready pjax:success', function() {
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
|
||||||
$(".delete").click(function(event) {
|
|
||||||
event.preventDefault();
|
|
||||||
name = $(this).parent().parent().attr("for") || $(this).parent().parent().parent().attr("id");
|
|
||||||
console.log(name)
|
|
||||||
|
|
||||||
$('#' + name).fadeOut().remove();
|
|
||||||
$('label[for="' + name + '"]').fadeOut().remove();
|
|
||||||
});
|
|
||||||
|
|
||||||
$('body').on('keypress', 'input', function(event) {
|
$('body').on('keypress', 'input', function(event) {
|
||||||
if (event.keyCode == 13) {
|
if (event.keyCode == 13) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
|
|
@ -3,6 +3,7 @@ package browse
|
||||||
import (
|
import (
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
"text/template"
|
"text/template"
|
||||||
|
|
||||||
|
@ -23,6 +24,32 @@ func ServeHTTP(w http.ResponseWriter, r *http.Request, c *config.Config) (int, e
|
||||||
r.URL.Path = "/"
|
r.URL.Path = "/"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if r.Method == "DELETE" {
|
||||||
|
// Remove both beginning and trailing slashes
|
||||||
|
r.URL.Path = strings.TrimPrefix(r.URL.Path, "/")
|
||||||
|
r.URL.Path = strings.TrimSuffix(r.URL.Path, "/")
|
||||||
|
|
||||||
|
// Check if the file or directory exists
|
||||||
|
if stat, err := os.Stat(r.URL.Path); err == nil {
|
||||||
|
var err error
|
||||||
|
// If it's dir, remove all of the content inside
|
||||||
|
if stat.IsDir() {
|
||||||
|
err = os.RemoveAll(r.URL.Path)
|
||||||
|
} else {
|
||||||
|
err = os.Remove(r.URL.Path)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check for errors
|
||||||
|
if err != nil {
|
||||||
|
return 500, err
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return 404, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
w.Header().Set("Content-Type", "application/json")
|
||||||
|
w.Write([]byte("{}"))
|
||||||
|
} else {
|
||||||
functions := template.FuncMap{
|
functions := template.FuncMap{
|
||||||
"CanBeEdited": utils.CanBeEdited,
|
"CanBeEdited": utils.CanBeEdited,
|
||||||
"Defined": utils.Defined,
|
"Defined": utils.Defined,
|
||||||
|
@ -52,3 +79,6 @@ func ServeHTTP(w http.ResponseWriter, r *http.Request, c *config.Config) (int, e
|
||||||
|
|
||||||
return b.ServeHTTP(w, r)
|
return b.ServeHTTP(w, r)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return 200, nil
|
||||||
|
}
|
||||||
|
|
|
@ -52,7 +52,7 @@
|
||||||
</td>
|
</td>
|
||||||
<td class="right hideable">{{.HumanSize}}</td>
|
<td class="right hideable">{{.HumanSize}}</td>
|
||||||
<td class="right hideable">{{.HumanModTime "01/02/2006 3:04:05 PM -0700"}}</td>
|
<td class="right hideable">{{.HumanModTime "01/02/2006 3:04:05 PM -0700"}}</td>
|
||||||
<td class="right"><button class="delete"><i class="fa fa-times"></i></button></td>
|
<td class="right"><button data-file="/admin/browse{{ $path }}{{.URL}}" data-message="File deleted." class="delete"><i class="fa fa-times"></i></button></td>
|
||||||
</tr>
|
</tr>
|
||||||
{{end}}
|
{{end}}
|
||||||
</table>
|
</table>
|
||||||
|
|
Loading…
Reference in New Issue