mirror of
https://github.com/osmarks/mycorrhiza.git
synced 2024-12-12 05:20:26 +00:00
Add edit previews
This commit is contained in:
parent
306f536aa6
commit
731a9946c5
@ -5,6 +5,7 @@ import (
|
||||
"log"
|
||||
"net/http"
|
||||
|
||||
"github.com/bouncepaw/mycorrhiza/markup"
|
||||
"github.com/bouncepaw/mycorrhiza/templates"
|
||||
"github.com/bouncepaw/mycorrhiza/user"
|
||||
"github.com/bouncepaw/mycorrhiza/util"
|
||||
@ -151,6 +152,7 @@ func handlerUploadText(w http.ResponseWriter, rq *http.Request) {
|
||||
var (
|
||||
hyphaName = HyphaNameFromRq(rq, "upload-text")
|
||||
textData = rq.PostFormValue("text")
|
||||
action = rq.PostFormValue("action")
|
||||
u = user.FromRequest(rq)
|
||||
)
|
||||
if ok := user.CanProceed(rq, "upload-text"); !ok {
|
||||
@ -162,7 +164,9 @@ func handlerUploadText(w http.ResponseWriter, rq *http.Request) {
|
||||
HttpErr(w, http.StatusBadRequest, hyphaName, "Error", "No text data passed")
|
||||
return
|
||||
}
|
||||
if hop := UploadText(hyphaName, textData, u); len(hop.Errs) != 0 {
|
||||
if action == "Preview" {
|
||||
util.HTTP200Page(w, base("Preview "+hyphaName, templates.PreviewHTML(rq, hyphaName, textData, "", markup.Doc(hyphaName, textData).AsHTML())))
|
||||
} else if hop := UploadText(hyphaName, textData, u); len(hop.Errs) != 0 {
|
||||
HttpErr(w, http.StatusInternalServerError, hyphaName, "Error", hop.Errs[0].Error())
|
||||
} else {
|
||||
http.Redirect(w, rq, "/page/"+hyphaName, http.StatusSeeOther)
|
||||
|
@ -37,9 +37,12 @@ body {height:100%; margin:0; font-size:16px; font-family: 'PT Sans', 'Liberation
|
||||
main {border-radius: 0 0 .25rem .25rem; }
|
||||
main > form {margin-bottom:1rem;}
|
||||
textarea {font-size:16px; font-family: 'PT Sans', 'Liberation Sans', sans-serif;}
|
||||
.edit {height:100%;}
|
||||
.edit_no-preview {height:100%;}
|
||||
.edit_with-preview .edit-form textarea { min-height: 500px; }
|
||||
.edit__preview { border: 2px dashed #ddd; }
|
||||
.edit-form {height:90%;}
|
||||
.edit-form textarea {width:100%;height:90%;}
|
||||
.edit-form__save { font-weight: bold; }
|
||||
.icon {margin-right: .25rem; vertical-align: bottom; }
|
||||
|
||||
main h1:not(.navi-title) {font-size:1.7rem;}
|
||||
|
@ -12,9 +12,12 @@ body {height:100%; margin:0; font-size:16px; font-family: 'PT Sans', 'Liberation
|
||||
main {border-radius: 0 0 .25rem .25rem; }
|
||||
main > form {margin-bottom:1rem;}
|
||||
textarea {font-size:16px; font-family: 'PT Sans', 'Liberation Sans', sans-serif;}
|
||||
.edit {height:100%;}
|
||||
.edit_no-preview {height:100%;}
|
||||
.edit_with-preview .edit-form textarea { min-height: 500px; }
|
||||
.edit__preview { border: 2px dashed #ddd; }
|
||||
.edit-form {height:90%;}
|
||||
.edit-form textarea {width:100%;height:90%;}
|
||||
.edit-form__save { font-weight: bold; }
|
||||
.icon {margin-right: .25rem; vertical-align: bottom; }
|
||||
|
||||
main h1:not(.navi-title) {font-size:1.7rem;}
|
||||
|
@ -1,7 +1,7 @@
|
||||
{% import "net/http" %}
|
||||
|
||||
{% func EditHTML(rq *http.Request, hyphaName, textAreaFill, warning string) %}
|
||||
<main class="edit">
|
||||
<main class="edit edit_no-preview">
|
||||
{%s= navHTML(rq, hyphaName, "edit") %}
|
||||
<h1>Edit {%s hyphaName %}</h1>
|
||||
{%s= warning %}
|
||||
@ -9,8 +9,27 @@
|
||||
action="/upload-text/{%s hyphaName %}">
|
||||
<textarea name="text">{%s textAreaFill %}</textarea>
|
||||
<br/>
|
||||
<input type="submit"/>
|
||||
<a href="/page/{%s hyphaName %}">Cancel</a>
|
||||
<input type="submit" name="action" value="Save" class="edit-form__save"/>
|
||||
<input type="submit" name="action" value="Preview" class="edit-form__preview">
|
||||
<a href="/page/{%s hyphaName %}" class="edit-form__cancel">Cancel</a>
|
||||
</form>
|
||||
</main>
|
||||
{% endfunc %}
|
||||
|
||||
{% func PreviewHTML(rq *http.Request, hyphaName, textAreaFill, warning string, renderedPage string) %}
|
||||
<main class="edit edit_with-preview">
|
||||
{%s= navHTML(rq, hyphaName, "edit") %}
|
||||
<h1>Edit {%s hyphaName %} (preview)</h1>
|
||||
{%s= warning %}
|
||||
<form method="post" class="edit-form"
|
||||
action="/upload-text/{%s hyphaName %}">
|
||||
<textarea name="text">{%s textAreaFill %}</textarea>
|
||||
<br/>
|
||||
<input type="submit" name="action" value="Save" class="edit-form__save"/>
|
||||
<input type="submit" name="action" value="Preview" class="edit-form__preview">
|
||||
<a href="/page/{%s hyphaName %}" class="edit-form__cancel">Cancel</a>
|
||||
</form>
|
||||
<p class="warning">Note that the hypha is not saved yet. You can preview the changes ↓</p>
|
||||
<section class="edit__preview">{%s= renderedPage %}</section>
|
||||
</main>
|
||||
{% endfunc %}
|
||||
|
@ -24,7 +24,7 @@ var (
|
||||
func StreamEditHTML(qw422016 *qt422016.Writer, rq *http.Request, hyphaName, textAreaFill, warning string) {
|
||||
//line templates/http_mutators.qtpl:3
|
||||
qw422016.N().S(`
|
||||
<main class="edit">
|
||||
<main class="edit edit_no-preview">
|
||||
`)
|
||||
//line templates/http_mutators.qtpl:5
|
||||
qw422016.N().S(navHTML(rq, hyphaName, "edit"))
|
||||
@ -52,40 +52,118 @@ func StreamEditHTML(qw422016 *qt422016.Writer, rq *http.Request, hyphaName, text
|
||||
//line templates/http_mutators.qtpl:10
|
||||
qw422016.N().S(`</textarea>
|
||||
<br/>
|
||||
<input type="submit"/>
|
||||
<input type="submit" name="action" value="Save" class="edit-form__save"/>
|
||||
<input type="submit" name="action" value="Preview" class="edit-form__preview">
|
||||
<a href="/page/`)
|
||||
//line templates/http_mutators.qtpl:13
|
||||
//line templates/http_mutators.qtpl:14
|
||||
qw422016.E().S(hyphaName)
|
||||
//line templates/http_mutators.qtpl:13
|
||||
qw422016.N().S(`">Cancel</a>
|
||||
//line templates/http_mutators.qtpl:14
|
||||
qw422016.N().S(`" class="edit-form__cancel">Cancel</a>
|
||||
</form>
|
||||
</main>
|
||||
`)
|
||||
//line templates/http_mutators.qtpl:16
|
||||
//line templates/http_mutators.qtpl:17
|
||||
}
|
||||
|
||||
//line templates/http_mutators.qtpl:16
|
||||
//line templates/http_mutators.qtpl:17
|
||||
func WriteEditHTML(qq422016 qtio422016.Writer, rq *http.Request, hyphaName, textAreaFill, warning string) {
|
||||
//line templates/http_mutators.qtpl:16
|
||||
//line templates/http_mutators.qtpl:17
|
||||
qw422016 := qt422016.AcquireWriter(qq422016)
|
||||
//line templates/http_mutators.qtpl:16
|
||||
//line templates/http_mutators.qtpl:17
|
||||
StreamEditHTML(qw422016, rq, hyphaName, textAreaFill, warning)
|
||||
//line templates/http_mutators.qtpl:16
|
||||
//line templates/http_mutators.qtpl:17
|
||||
qt422016.ReleaseWriter(qw422016)
|
||||
//line templates/http_mutators.qtpl:16
|
||||
//line templates/http_mutators.qtpl:17
|
||||
}
|
||||
|
||||
//line templates/http_mutators.qtpl:16
|
||||
//line templates/http_mutators.qtpl:17
|
||||
func EditHTML(rq *http.Request, hyphaName, textAreaFill, warning string) string {
|
||||
//line templates/http_mutators.qtpl:16
|
||||
//line templates/http_mutators.qtpl:17
|
||||
qb422016 := qt422016.AcquireByteBuffer()
|
||||
//line templates/http_mutators.qtpl:16
|
||||
//line templates/http_mutators.qtpl:17
|
||||
WriteEditHTML(qb422016, rq, hyphaName, textAreaFill, warning)
|
||||
//line templates/http_mutators.qtpl:16
|
||||
//line templates/http_mutators.qtpl:17
|
||||
qs422016 := string(qb422016.B)
|
||||
//line templates/http_mutators.qtpl:16
|
||||
//line templates/http_mutators.qtpl:17
|
||||
qt422016.ReleaseByteBuffer(qb422016)
|
||||
//line templates/http_mutators.qtpl:16
|
||||
//line templates/http_mutators.qtpl:17
|
||||
return qs422016
|
||||
//line templates/http_mutators.qtpl:16
|
||||
//line templates/http_mutators.qtpl:17
|
||||
}
|
||||
|
||||
//line templates/http_mutators.qtpl:19
|
||||
func StreamPreviewHTML(qw422016 *qt422016.Writer, rq *http.Request, hyphaName, textAreaFill, warning string, renderedPage string) {
|
||||
//line templates/http_mutators.qtpl:19
|
||||
qw422016.N().S(`
|
||||
<main class="edit edit_with-preview">
|
||||
`)
|
||||
//line templates/http_mutators.qtpl:21
|
||||
qw422016.N().S(navHTML(rq, hyphaName, "edit"))
|
||||
//line templates/http_mutators.qtpl:21
|
||||
qw422016.N().S(`
|
||||
<h1>Edit `)
|
||||
//line templates/http_mutators.qtpl:22
|
||||
qw422016.E().S(hyphaName)
|
||||
//line templates/http_mutators.qtpl:22
|
||||
qw422016.N().S(` (preview)</h1>
|
||||
`)
|
||||
//line templates/http_mutators.qtpl:23
|
||||
qw422016.N().S(warning)
|
||||
//line templates/http_mutators.qtpl:23
|
||||
qw422016.N().S(`
|
||||
<form method="post" class="edit-form"
|
||||
action="/upload-text/`)
|
||||
//line templates/http_mutators.qtpl:25
|
||||
qw422016.E().S(hyphaName)
|
||||
//line templates/http_mutators.qtpl:25
|
||||
qw422016.N().S(`">
|
||||
<textarea name="text">`)
|
||||
//line templates/http_mutators.qtpl:26
|
||||
qw422016.E().S(textAreaFill)
|
||||
//line templates/http_mutators.qtpl:26
|
||||
qw422016.N().S(`</textarea>
|
||||
<br/>
|
||||
<input type="submit" name="action" value="Save" class="edit-form__save"/>
|
||||
<input type="submit" name="action" value="Preview" class="edit-form__preview">
|
||||
<a href="/page/`)
|
||||
//line templates/http_mutators.qtpl:30
|
||||
qw422016.E().S(hyphaName)
|
||||
//line templates/http_mutators.qtpl:30
|
||||
qw422016.N().S(`" class="edit-form__cancel">Cancel</a>
|
||||
</form>
|
||||
<p class="warning">Note that the hypha is not saved yet. You can preview the changes ↓</p>
|
||||
<section class="edit__preview">`)
|
||||
//line templates/http_mutators.qtpl:33
|
||||
qw422016.N().S(renderedPage)
|
||||
//line templates/http_mutators.qtpl:33
|
||||
qw422016.N().S(`</section>
|
||||
</main>
|
||||
`)
|
||||
//line templates/http_mutators.qtpl:35
|
||||
}
|
||||
|
||||
//line templates/http_mutators.qtpl:35
|
||||
func WritePreviewHTML(qq422016 qtio422016.Writer, rq *http.Request, hyphaName, textAreaFill, warning string, renderedPage string) {
|
||||
//line templates/http_mutators.qtpl:35
|
||||
qw422016 := qt422016.AcquireWriter(qq422016)
|
||||
//line templates/http_mutators.qtpl:35
|
||||
StreamPreviewHTML(qw422016, rq, hyphaName, textAreaFill, warning, renderedPage)
|
||||
//line templates/http_mutators.qtpl:35
|
||||
qt422016.ReleaseWriter(qw422016)
|
||||
//line templates/http_mutators.qtpl:35
|
||||
}
|
||||
|
||||
//line templates/http_mutators.qtpl:35
|
||||
func PreviewHTML(rq *http.Request, hyphaName, textAreaFill, warning string, renderedPage string) string {
|
||||
//line templates/http_mutators.qtpl:35
|
||||
qb422016 := qt422016.AcquireByteBuffer()
|
||||
//line templates/http_mutators.qtpl:35
|
||||
WritePreviewHTML(qb422016, rq, hyphaName, textAreaFill, warning, renderedPage)
|
||||
//line templates/http_mutators.qtpl:35
|
||||
qs422016 := string(qb422016.B)
|
||||
//line templates/http_mutators.qtpl:35
|
||||
qt422016.ReleaseByteBuffer(qb422016)
|
||||
//line templates/http_mutators.qtpl:35
|
||||
return qs422016
|
||||
//line templates/http_mutators.qtpl:35
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user