summaryrefslogtreecommitdiff
path: root/src/http/tpl/post-edit.html
blob: 1c40a3a24d770863e0ce94869889b7e3865af4f7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
{{ define "body" }}

{{ $tags := .GetTags }}

{{ $post := (or (and .Payload.IsDraft .GetThisDraftPost) .GetThisPost) }}

<p>
  {{ if .Payload.IsDraft }}
  <a href="{{ .RootURL.Drafts.MethodManage }}">
    Back to Drafts
  </a>
  {{ else }}
  <a href="{{ .RootURL.Posts.MethodManage }}">
    Back to Posts
  </a>
  {{ end }}
</p>

<form method="POST" action="{{ .RootURL.Posts }}">

  <table>

    <tr>
      <td>
        Unique ID
      </td>
      <td>
        {{ if eq $post.ID "" }}
        <input
            name="id"
            type="text"
            required
            placeholder="e.g. how-to-fly-a-kite"
            value="{{ $post.ID }}" />
        {{ else if .Payload.IsDraft }}
        {{ $post.ID }}
        <input name="id" type="hidden" value="{{ $post.ID }}" />
        {{ else }}
        <a href="{{ .RootURL.Post $post.ID }}">{{ $post.ID }}</a>
        <input name="id" type="hidden" value="{{ $post.ID }}" />
        {{ end }}
      </td>
    </tr>

    <tr>
      <td>Tags (space separated)</td>
      <td>
        <input
            name="tags"
            type="text"
            required
            value="{{- range $i, $tag := $post.Tags -}}
                     {{- if ne $i 0 }} {{ end }}{{ $tag -}}
                   {{- end -}}
                  "/>

        {{ if $tags }}
        <em>
          Existing tags:
          {{ range $i, $tag := $tags }}
            {{ if ne $i 0 }} {{ end }}{{ $tag }}
          {{ end }}
        </em>
        {{ end }}
      </td>
    </tr>

    <tr>
      <td>Series</td>
      <td>
        <input
            name="series"
            type="text"
            value="{{ $post.Series }}" />
      </td>
    </tr>

    <tr>
      <td>Title</td>
      <td>
        <input
            name="title"
            type="text"
            required
            value="{{ $post.Title }}" />
      </td>
    </tr>

    <tr>
      <td>Description</td>
      <td>
        <input
            name="description"
            type="text"
            value="{{ $post.Description }}" />
      </td>
    </tr>

    <tr>
      <td>Format</td>
      <td>
        <select name="format" required>
          <option value=""></option>

          {{ $format := $post.Format }}
          {{ range .Payload.Formats -}}
          <option
            {{- if eq . $format }}
            selected
            {{- end }}
            value="{{ . }}" >
            {{ . }}
          </option>
          {{- end }}

        </select>
      </td>
    </tr>

  </table>

  <p>
    <textarea
      name="body"
      required
      placeholder="Post body"
      style="width:100%;height: 75vh;"
      >
      {{- $post.Body -}}
    </textarea>
  </p>

  <p>

    <input
      type="submit"
      value="Preview"
      formaction="{{ (.RootURL.Post $post.ID).MethodPreview }}"
      formtarget="_blank"
      />

    {{ if .Payload.IsDraft }}
    <input type="submit" value="Save" formaction="{{ .RootURL.Drafts }}" />


    <script>
      function confirmPublish(event) {
        if (!confirm("Are you sure you're ready to publish?"))
          event.preventDefault();
      }
    </script>


    <input
      type="submit"
      value="Publish"
      formaction="{{ .RootURL.Posts }}"
      onclick="confirmPublish(event)"
      />

    {{ else }}
    <input type="submit" value="Update" formaction="{{ .RootURL.Posts }}" />
    {{ end }}

  </p>

</form>

{{ end }}

{{ template "base.html" . }}