diff --git a/http_mutators.go b/http_mutators.go index 6927e7f..ff81346 100644 --- a/http_mutators.go +++ b/http_mutators.go @@ -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) diff --git a/templates/asset.qtpl.go b/templates/asset.qtpl.go index e8ff5cb..300aa46 100644 --- a/templates/asset.qtpl.go +++ b/templates/asset.qtpl.go @@ -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;} diff --git a/templates/default.css b/templates/default.css index 89247dc..41c3208 100644 --- a/templates/default.css +++ b/templates/default.css @@ -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;} diff --git a/templates/http_mutators.qtpl b/templates/http_mutators.qtpl index 049f8ae..72466bd 100644 --- a/templates/http_mutators.qtpl +++ b/templates/http_mutators.qtpl @@ -1,7 +1,7 @@ {% import "net/http" %} {% func EditHTML(rq *http.Request, hyphaName, textAreaFill, warning string) %} -
+
{%s= navHTML(rq, hyphaName, "edit") %}

Edit {%s hyphaName %}

{%s= warning %} @@ -9,8 +9,27 @@ action="/upload-text/{%s hyphaName %}">
- - Cancel + + + Cancel
{% endfunc %} + +{% func PreviewHTML(rq *http.Request, hyphaName, textAreaFill, warning string, renderedPage string) %} +
+{%s= navHTML(rq, hyphaName, "edit") %} +

Edit {%s hyphaName %} (preview)

+ {%s= warning %} +
+ +
+ + + Cancel +
+

Note that the hypha is not saved yet. You can preview the changes ↓

+
{%s= renderedPage %}
+
+{% endfunc %} diff --git a/templates/http_mutators.qtpl.go b/templates/http_mutators.qtpl.go index 62a24a1..7c1c342 100644 --- a/templates/http_mutators.qtpl.go +++ b/templates/http_mutators.qtpl.go @@ -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(` -
+
`) //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(`
- + + Cancel +//line templates/http_mutators.qtpl:14 + qw422016.N().S(`" class="edit-form__cancel">Cancel
`) -//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(` +
+`) +//line templates/http_mutators.qtpl:21 + qw422016.N().S(navHTML(rq, hyphaName, "edit")) +//line templates/http_mutators.qtpl:21 + qw422016.N().S(` +

Edit `) +//line templates/http_mutators.qtpl:22 + qw422016.E().S(hyphaName) +//line templates/http_mutators.qtpl:22 + qw422016.N().S(` (preview)

+ `) +//line templates/http_mutators.qtpl:23 + qw422016.N().S(warning) +//line templates/http_mutators.qtpl:23 + qw422016.N().S(` +
+ +
+ + + Cancel +
+

Note that the hypha is not saved yet. You can preview the changes ↓

+
`) +//line templates/http_mutators.qtpl:33 + qw422016.N().S(renderedPage) +//line templates/http_mutators.qtpl:33 + qw422016.N().S(`
+
+`) +//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 }