mirror of
https://github.com/gogs/gogs.git
synced 2025-09-04 19:37:58 +00:00
release: improve attachment handle
This commit is contained in:
parent
1df54ea0cd
commit
24734a33e7
10
cmd/web.go
10
cmd/web.go
@ -15,6 +15,7 @@ import (
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
"github.com/Unknwon/com"
|
||||
"github.com/go-macaron/binding"
|
||||
"github.com/go-macaron/cache"
|
||||
"github.com/go-macaron/captcha"
|
||||
@ -323,11 +324,10 @@ func runWeb(ctx *cli.Context) error {
|
||||
m.Get("/attachments/:uuid", func(ctx *context.Context) {
|
||||
attach, err := models.GetAttachmentByUUID(ctx.Params(":uuid"))
|
||||
if err != nil {
|
||||
if models.IsErrAttachmentNotExist(err) {
|
||||
ctx.Error(404)
|
||||
} else {
|
||||
ctx.Handle(500, "GetAttachmentByUUID", err)
|
||||
}
|
||||
ctx.NotFoundOrServerError("GetAttachmentByUUID", models.IsErrAttachmentNotExist, err)
|
||||
return
|
||||
} else if !com.IsFile(attach.LocalPath()) {
|
||||
ctx.NotFound()
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -48,22 +48,23 @@
|
||||
<label>{{.i18n.Tr "repo.release.content"}}</label>
|
||||
<textarea name="content">{{.content}}</textarea>
|
||||
</div>
|
||||
{{if .attachments}}
|
||||
<table class="ui table">
|
||||
<thead></thead>
|
||||
<tbody>
|
||||
{{range .attachments}}
|
||||
<tr>
|
||||
<td>
|
||||
<a target="_blank" href="{{AppSubUrl}}/attachments/{{.UUID}}" rel="nofollow">{{.Name}}</a>
|
||||
<a class="ui text red right delete-attachment-button" href="#"><i class="octicon octicon-x" data-uuid="{{.UUID}}"></i></a>
|
||||
<input name="files" type="hidden" value="{{.UUID}}">
|
||||
</td>
|
||||
</tr>
|
||||
{{end}}
|
||||
</tbody>
|
||||
</table>
|
||||
{{end}}
|
||||
<div class="field">
|
||||
{{if .attachments}}
|
||||
<table class="ui table">
|
||||
<tbody>
|
||||
{{range .attachments}}
|
||||
<tr>
|
||||
<td>
|
||||
<a target="_blank" href="{{AppSubUrl}}/attachments/{{.UUID}}" rel="nofollow">{{.Name}}</a>
|
||||
<a class="ui text red right delete-attachment-button" href="#"><i class="octicon octicon-x" data-uuid="{{.UUID}}"></i></a>
|
||||
<input name="files" type="hidden" value="{{.UUID}}">
|
||||
</td>
|
||||
</tr>
|
||||
{{end}}
|
||||
</tbody>
|
||||
</table>
|
||||
{{end}}
|
||||
</div>
|
||||
{{if .IsAttachmentEnabled}}
|
||||
<div class="files"></div>
|
||||
<div class="ui basic button dropzone" id="dropzone" data-upload-url="{{AppSubUrl}}/releases/attachments" data-accepts="{{.AttachmentAllowedTypes}}" data-max-file="{{.AttachmentMaxFiles}}" data-max-size="{{.AttachmentMaxSize}}" data-default-message="{{.i18n.Tr "dropzone.default_message"}}" data-invalid-input-type="{{.i18n.Tr "dropzone.invalid_input_type"}}" data-file-too-big="{{.i18n.Tr "dropzone.file_too_big"}}" data-remove-file="{{.i18n.Tr "dropzone.remove_file"}}"></div>
|
||||
@ -122,9 +123,18 @@
|
||||
{{end}}
|
||||
|
||||
<script>
|
||||
// Delete attachment field
|
||||
// Delete attachment row
|
||||
$('.delete-attachment-button').click(function (e) {
|
||||
$(this).parentsUntil('tbody').remove();
|
||||
var $row = $(this).parentsUntil('tbody');
|
||||
var $tbody = $row.parentsUntil('table');
|
||||
|
||||
$row.remove();
|
||||
|
||||
// Remove the entire table if this was the last row
|
||||
if ($tbody.children().length == 0) {
|
||||
$tbody.parentsUntil('.field').remove();
|
||||
}
|
||||
|
||||
e.preventDefault();
|
||||
})
|
||||
</script>
|
||||
|
Loading…
x
Reference in New Issue
Block a user