fix #15
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;
|
||||
});
|
||||
|
||||
// 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 ($(".editor")[0]) {
|
||||
editor = false;
|
||||
|
@ -180,15 +212,6 @@ $(document).on('ready pjax:success', function() {
|
|||
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) {
|
||||
if (event.keyCode == 13) {
|
||||
event.preventDefault();
|
||||
|
|
|
@ -3,6 +3,7 @@ package browse
|
|||
import (
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
"text/template"
|
||||
|
||||
|
@ -23,32 +24,61 @@ func ServeHTTP(w http.ResponseWriter, r *http.Request, c *config.Config) (int, e
|
|||
r.URL.Path = "/"
|
||||
}
|
||||
|
||||
functions := template.FuncMap{
|
||||
"CanBeEdited": utils.CanBeEdited,
|
||||
"Defined": utils.Defined,
|
||||
}
|
||||
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, "/")
|
||||
|
||||
tpl, err := utils.GetTemplate(r, functions, "browse")
|
||||
// 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)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
return 500, err
|
||||
}
|
||||
|
||||
b := browse.Browse{
|
||||
Next: middleware.HandlerFunc(func(w http.ResponseWriter, r *http.Request) (int, error) {
|
||||
// Check for errors
|
||||
if err != nil {
|
||||
return 500, err
|
||||
}
|
||||
} else {
|
||||
return 404, nil
|
||||
}),
|
||||
Root: "./",
|
||||
Configs: []browse.Config{
|
||||
browse.Config{
|
||||
PathScope: "/",
|
||||
Variables: c,
|
||||
Template: tpl,
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.Write([]byte("{}"))
|
||||
} else {
|
||||
functions := template.FuncMap{
|
||||
"CanBeEdited": utils.CanBeEdited,
|
||||
"Defined": utils.Defined,
|
||||
}
|
||||
|
||||
tpl, err := utils.GetTemplate(r, functions, "browse")
|
||||
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
return 500, err
|
||||
}
|
||||
|
||||
b := browse.Browse{
|
||||
Next: middleware.HandlerFunc(func(w http.ResponseWriter, r *http.Request) (int, error) {
|
||||
return 404, nil
|
||||
}),
|
||||
Root: "./",
|
||||
Configs: []browse.Config{
|
||||
browse.Config{
|
||||
PathScope: "/",
|
||||
Variables: c,
|
||||
Template: tpl,
|
||||
},
|
||||
},
|
||||
},
|
||||
IgnoreIndexes: true,
|
||||
IgnoreIndexes: true,
|
||||
}
|
||||
|
||||
return b.ServeHTTP(w, r)
|
||||
}
|
||||
|
||||
return b.ServeHTTP(w, r)
|
||||
return 200, nil
|
||||
}
|
||||
|
|
|
@ -52,7 +52,7 @@
|
|||
</td>
|
||||
<td class="right hideable">{{.HumanSize}}</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>
|
||||
{{end}}
|
||||
</table>
|
||||
|
|
Loading…
Reference in New Issue