git ssb

30+

cel / git-ssb-web



Tree: fbf36ab9f3e81a1c5b6e0b4c6eed51005e6e07ab

Files: fbf36ab9f3e81a1c5b6e0b4c6eed51005e6e07ab / lib / forms.js

3216 bytesRaw
1var u = require('./util')
2var forms = exports
3
4forms.post = function (req, repo, placeholder, rows) {
5 return '<input type="radio" class="tab-radio" id="tab1" name="tab" checked="checked"/>' +
6 '<input type="radio" class="tab-radio" id="tab2" name="tab"/>' +
7 '<div id="tab-links" class="tab-links" style="display:none">' +
8 '<label for="tab1" id="write-tab-link" class="tab1-link">' +
9 req._t('post.Write') + '</label>' +
10 '<label for="tab2" id="preview-tab-link" class="tab2-link">' +
11 req._t('post.Preview') + '</label>' +
12 '</div>' +
13 '<input type="hidden" id="repo-id" value="' + repo.id + '"/>' +
14 '<div id="write-tab" class="tab1">' +
15 '<textarea id="post-text" name="text" class="wide-input"' +
16 ' rows="' + (rows||4) + '" cols="77"' +
17 (placeholder ? ' placeholder="' + placeholder + '"' : '') +
18 '></textarea>' +
19 '</div>' +
20 '<div class="preview-text tab2" id="preview-tab"></div>' +
21 '<script>' + issueCommentScript + '</script>'
22}
23
24forms.name = function (req, enabled, id, name, action, inputId,
25 title, header) {
26 if (!inputId) inputId = action
27 return '<form class="petname" action="" method="post">' +
28 (enabled ?
29 '<input type="checkbox" class="name-checkbox" id="' + inputId + '" ' +
30 'onfocus="this.form.name.focus()" />' +
31 '<input name="name" class="name" value="' + u.escape(name) + '" ' +
32 'onkeyup="if (event.keyCode == 27) this.form.reset()" />' +
33 '<input type="hidden" name="action" value="' + action + '">' +
34 '<input type="hidden" name="id" value="' +
35 u.escape(id) + '">' +
36 '<label class="name-toggle" for="' + inputId + '" ' +
37 'title="' + title + '"><i>✍</i></label> ' +
38 '<input class="btn name-btn" type="submit" value="' +
39 req._t('Rename') + '">' +
40 header :
41 header + '<br clear="all"/>'
42 ) +
43 '</form>'
44}
45
46var issueCommentScript = '(' + function () {
47 var $ = document.getElementById.bind(document)
48 $('tab-links').style.display = 'block'
49 $('preview-tab-link').onclick = function (e) {
50 with (new XMLHttpRequest()) {
51 open('POST', '', true)
52 onload = function() {
53 $('preview-tab').innerHTML = responseText
54 }
55 send('action=markdown' +
56 '&repo=' + encodeURIComponent($('repo-id').value) +
57 '&text=' + encodeURIComponent($('post-text').value))
58 }
59 }
60}.toString() + ')()'
61
62forms.issueComment = function (req, issue, repo, branch, isAuthor, type) {
63 return '<section><form action="" method="post">' +
64 '<input type="hidden" name="action" value="comment">' +
65 '<input type="hidden" name="id" value="' + issue.id + '">' +
66 '<input type="hidden" name="issue" value="' + issue.id + '">' +
67 '<input type="hidden" name="repo" value="' + repo.id + '">' +
68 '<input type="hidden" name="branch" value="' + branch + '">' +
69 forms.post(req, repo) +
70 '<input type="submit" class="btn open" value="' +
71 req._t('issue.Comment') + '" />' +
72 (isAuthor ?
73 '<input type="submit" class="btn"' +
74 ' name="' + (issue.open ? 'close' : 'open') + '"' +
75 ' value="' + req._t(
76 issue.open ? 'issue.Close' : 'issue.Reopen', {type: type}
77 ) + '"/>' : '') +
78 '</form></section>'
79}
80

Built with git-ssb-web