From 684c53aa8c3fee78098bb20671af4f63dcaee4af Mon Sep 17 00:00:00 2001 From: Timur Ismagilov Date: Thu, 16 Jun 2022 14:05:30 +0300 Subject: [PATCH] Isolate hypha deletion view --- hypview/hypview.go | 25 ++++- hypview/view_delete.html | 23 +++++ l18n/en/ui.json | 2 - l18n/ru/ui.json | 3 - views/modal.qtpl | 25 ----- views/modal.qtpl.go | 207 ++++++++++++--------------------------- viewutil/base.html | 2 + viewutil/viewutil.go | 2 + web/mutators.go | 9 +- 9 files changed, 114 insertions(+), 184 deletions(-) create mode 100644 hypview/view_delete.html diff --git a/hypview/hypview.go b/hypview/hypview.go index f52cf10..cfdd498 100644 --- a/hypview/hypview.go +++ b/hypview/hypview.go @@ -23,14 +23,35 @@ var ( {{define "upload a media"}}Загрузить медиа{{end}} {{define "upload a media tip"}}Загрузите изображение, видео или аудио. Распространённые форматы можно просматривать из браузера, остальные – просто скачать. Позже вы можете дописать пояснение к этому медиа.{{end}} {{define "upload a media btn"}}Загрузить{{end}} + +{{define "delete hypha?"}}Удалить {{beautifulName .}}?{{end}} +{{define "delete [[hypha]]?"}}Удалить {{beautifulName .}}?{{end}} +{{define "want to delete?"}}Вы действительно хотите удалить эту гифу?{{end}} +{{define "delete tip"}}Нельзя отменить удаление гифы, но её история останется доступной.{{end}} ` - chainNaviTitle viewutil.Chain - chainEmptyHypha viewutil.Chain + chainNaviTitle viewutil.Chain + chainEmptyHypha viewutil.Chain + chainDeleteHypha viewutil.Chain ) func Init() { chainNaviTitle = viewutil.CopyEnRuWith(fs, "view_navititle.html", "") chainEmptyHypha = viewutil.CopyEnRuWith(fs, "view_empty_hypha.html", ruTranslation) + chainDeleteHypha = viewutil.CopyEnRuWith(fs, "view_delete.html", ruTranslation) +} + +type deleteData struct { + *viewutil.BaseData + HyphaName string +} + +func DeleteHypha(meta viewutil.Meta, hyphaName string) { + viewutil.ExecutePage(meta, chainDeleteHypha, deleteData{ + BaseData: &viewutil.BaseData{ + Addr: "/delete/" + hyphaName, + }, + HyphaName: hyphaName, + }) } type emptyHyphaData struct { diff --git a/hypview/view_delete.html b/hypview/view_delete.html new file mode 100644 index 0000000..eb08429 --- /dev/null +++ b/hypview/view_delete.html @@ -0,0 +1,23 @@ +{{define "title"}}{{template "delete hypha?" .HyphaName}}{{end}} +{{define "delete hypha?"}}Delete {{beautifulName .}}?{{end}} +{{define "body"}} +
+ +
+{{end}} \ No newline at end of file diff --git a/l18n/en/ui.json b/l18n/en/ui.json index 3b9cec6..0ac55e9 100644 --- a/l18n/en/ui.json +++ b/l18n/en/ui.json @@ -50,8 +50,6 @@ "act_norights_edit": "You must be an editor to edit a hypha", "act_norights_upload_media": "You must be an editor to upload media", - "ask_delete": "Delete %s?", - "ask_delete_tip": "In this version of Mycorrhiza Wiki you cannot undelete a deleted hypha but the history can still be accessed.", "ask_remove_media": "Remove media from %s?", "ask_really": "Do you really want to {{.verb}} hypha {{.name}}?", "ask_delete_verb": "delete", diff --git a/l18n/ru/ui.json b/l18n/ru/ui.json index 7ec8274..abba6e4 100644 --- a/l18n/ru/ui.json +++ b/l18n/ru/ui.json @@ -55,11 +55,8 @@ "act_notexist_rename": "Нельзя переименовать эту гифу, потому что она не существует", "act_notexist_remove_media": "Нельзя убрать медиа, потому что нет такой гифы", - "ask_delete": "Удалить «%s»?", - "ask_delete_tip": "В этой версии Микоризы нельзя отменить удаление гифы, но её история останется доступной.", "ask_remove_media": "Убрать медиа у «%s»?", "ask_really": "Вы действительно хотите {{.verb}} гифу «{{.name}}»?", - "ask_delete_verb": "удалить", "ask_remove_media_verb": "убрать медиа", "revision_title": "{{.name}} из {{.rev}}", diff --git a/views/modal.qtpl b/views/modal.qtpl index c692862..fb9258e 100644 --- a/views/modal.qtpl +++ b/views/modal.qtpl @@ -2,31 +2,6 @@ {% import "net/http" %} {% import "github.com/bouncepaw/mycorrhiza/l18n" %} -{% func DeleteAsk(rq *http.Request, hyphaName string) %} -{% code - lc := l18n.FromRequest(rq) -%} -
- -
-{% endfunc %} - {% func RemoveMediaAsk(rq *http.Request, hyphaName string) %} {% code lc := l18n.FromRequest(rq) diff --git a/views/modal.qtpl.go b/views/modal.qtpl.go index ce5d375..5edb5ad 100644 --- a/views/modal.qtpl.go +++ b/views/modal.qtpl.go @@ -27,7 +27,7 @@ var ( ) //line views/modal.qtpl:5 -func StreamDeleteAsk(qw422016 *qt422016.Writer, rq *http.Request, hyphaName string) { +func StreamRemoveMediaAsk(qw422016 *qt422016.Writer, rq *http.Request, hyphaName string) { //line views/modal.qtpl:5 qw422016.N().S(` `) @@ -37,7 +37,7 @@ func StreamDeleteAsk(qw422016 *qt422016.Writer, rq *http.Request, hyphaName stri //line views/modal.qtpl:8 qw422016.N().S(`
-
`) -//line views/modal.qtpl:28 +//line views/modal.qtpl:27 } -//line views/modal.qtpl:28 -func WriteDeleteAsk(qq422016 qtio422016.Writer, rq *http.Request, hyphaName string) { -//line views/modal.qtpl:28 - qw422016 := qt422016.AcquireWriter(qq422016) -//line views/modal.qtpl:28 - StreamDeleteAsk(qw422016, rq, hyphaName) -//line views/modal.qtpl:28 - qt422016.ReleaseWriter(qw422016) -//line views/modal.qtpl:28 -} - -//line views/modal.qtpl:28 -func DeleteAsk(rq *http.Request, hyphaName string) string { -//line views/modal.qtpl:28 - qb422016 := qt422016.AcquireByteBuffer() -//line views/modal.qtpl:28 - WriteDeleteAsk(qb422016, rq, hyphaName) -//line views/modal.qtpl:28 - qs422016 := string(qb422016.B) -//line views/modal.qtpl:28 - qt422016.ReleaseByteBuffer(qb422016) -//line views/modal.qtpl:28 - return qs422016 -//line views/modal.qtpl:28 -} - -//line views/modal.qtpl:30 -func StreamRemoveMediaAsk(qw422016 *qt422016.Writer, rq *http.Request, hyphaName string) { -//line views/modal.qtpl:30 - qw422016.N().S(` -`) -//line views/modal.qtpl:32 - lc := l18n.FromRequest(rq) - -//line views/modal.qtpl:33 - qw422016.N().S(` -
- -
-`) -//line views/modal.qtpl:50 -} - -//line views/modal.qtpl:50 +//line views/modal.qtpl:27 func WriteRemoveMediaAsk(qq422016 qtio422016.Writer, rq *http.Request, hyphaName string) { -//line views/modal.qtpl:50 +//line views/modal.qtpl:27 qw422016 := qt422016.AcquireWriter(qq422016) -//line views/modal.qtpl:50 +//line views/modal.qtpl:27 StreamRemoveMediaAsk(qw422016, rq, hyphaName) -//line views/modal.qtpl:50 +//line views/modal.qtpl:27 qt422016.ReleaseWriter(qw422016) -//line views/modal.qtpl:50 +//line views/modal.qtpl:27 } -//line views/modal.qtpl:50 +//line views/modal.qtpl:27 func RemoveMediaAsk(rq *http.Request, hyphaName string) string { -//line views/modal.qtpl:50 +//line views/modal.qtpl:27 qb422016 := qt422016.AcquireByteBuffer() -//line views/modal.qtpl:50 +//line views/modal.qtpl:27 WriteRemoveMediaAsk(qb422016, rq, hyphaName) -//line views/modal.qtpl:50 +//line views/modal.qtpl:27 qs422016 := string(qb422016.B) -//line views/modal.qtpl:50 +//line views/modal.qtpl:27 qt422016.ReleaseByteBuffer(qb422016) -//line views/modal.qtpl:50 +//line views/modal.qtpl:27 return qs422016 -//line views/modal.qtpl:50 +//line views/modal.qtpl:27 } -//line views/modal.qtpl:52 +//line views/modal.qtpl:29 func StreamRenameAsk(qw422016 *qt422016.Writer, rq *http.Request, hyphaName string) { -//line views/modal.qtpl:52 +//line views/modal.qtpl:29 qw422016.N().S(` `) -//line views/modal.qtpl:54 +//line views/modal.qtpl:31 lc := l18n.FromRequest(rq) -//line views/modal.qtpl:55 +//line views/modal.qtpl:32 qw422016.N().S(`
`) -//line views/modal.qtpl:76 +//line views/modal.qtpl:55 } -//line views/modal.qtpl:76 +//line views/modal.qtpl:55 func WriteRenameAsk(qq422016 qtio422016.Writer, rq *http.Request, hyphaName string) { -//line views/modal.qtpl:76 +//line views/modal.qtpl:55 qw422016 := qt422016.AcquireWriter(qq422016) -//line views/modal.qtpl:76 +//line views/modal.qtpl:55 StreamRenameAsk(qw422016, rq, hyphaName) -//line views/modal.qtpl:76 +//line views/modal.qtpl:55 qt422016.ReleaseWriter(qw422016) -//line views/modal.qtpl:76 +//line views/modal.qtpl:55 } -//line views/modal.qtpl:76 +//line views/modal.qtpl:55 func RenameAsk(rq *http.Request, hyphaName string) string { -//line views/modal.qtpl:76 +//line views/modal.qtpl:55 qb422016 := qt422016.AcquireByteBuffer() -//line views/modal.qtpl:76 +//line views/modal.qtpl:55 WriteRenameAsk(qb422016, rq, hyphaName) -//line views/modal.qtpl:76 +//line views/modal.qtpl:55 qs422016 := string(qb422016.B) -//line views/modal.qtpl:76 +//line views/modal.qtpl:55 qt422016.ReleaseByteBuffer(qb422016) -//line views/modal.qtpl:76 +//line views/modal.qtpl:55 return qs422016 -//line views/modal.qtpl:76 +//line views/modal.qtpl:55 } diff --git a/viewutil/base.html b/viewutil/base.html index 0e3e0b0..9b69e64 100644 --- a/viewutil/base.html +++ b/viewutil/base.html @@ -1,3 +1,5 @@ +{{define "confirm"}}Confirm{{end}} +{{define "cancel"}}Cancel{{end}} {{define "page"}} diff --git a/viewutil/viewutil.go b/viewutil/viewutil.go index c22de16..4a3680a 100644 --- a/viewutil/viewutil.go +++ b/viewutil/viewutil.go @@ -25,6 +25,8 @@ const ruText = ` {{define "close this dialog"}}Закрыть этот диалог{{end}} {{define "login"}}Войти{{end}} {{define "register"}}Регистрация{{end}} +{{define "confirm"}}Подтвердить{{end}} +{{define "cancel"}}Отмена{{end}} ` func Init() { diff --git a/web/mutators.go b/web/mutators.go index 54adbca..a049105 100644 --- a/web/mutators.go +++ b/web/mutators.go @@ -3,6 +3,7 @@ package web import ( "fmt" "github.com/bouncepaw/mycomarkup/v5" + "github.com/bouncepaw/mycorrhiza/hypview" "github.com/bouncepaw/mycorrhiza/mycoopts" "github.com/bouncepaw/mycorrhiza/viewutil" "log" @@ -69,7 +70,6 @@ func handlerDelete(w http.ResponseWriter, rq *http.Request) { util.PrepareRq(rq) var ( u = user.FromRequest(rq) - lc = l18n.FromRequest(rq) h = hyphae.ByName(util.HyphaNameFromRq(rq, "delete")) meta = viewutil.MetaFrom(w, rq) ) @@ -89,12 +89,7 @@ func handlerDelete(w http.ResponseWriter, rq *http.Request) { } if rq.Method == "GET" { - util.HTTP200Page( - w, - views.Base( - meta, - fmt.Sprintf(lc.Get("ui.ask_delete"), util.BeautifulName(h.CanonicalName())), - views.DeleteAsk(rq, h.CanonicalName()))) + hypview.DeleteHypha(meta, h.CanonicalName()) return }