git ssb

30+

cel / git-ssb-web



Tree: 07b3119b1103ad1b3e666beed774e28f425a53c8

Files: 07b3119b1103ad1b3e666beed774e28f425a53c8 / lib / forms.js

5598 bytesRaw
1var h = require('pull-hyperscript')
2var u = require('./util')
3var forms = exports
4
5var issueCommentScript = `;(function () {
6 var container = [].slice.call(document.querySelectorAll('.post-form')).pop() || document.body
7 var $ = container.querySelector.bind(container)
8 $('.tab-links').style.display = 'block'
9 $('.tab2-link').onclick = function (e) {
10 with (new XMLHttpRequest()) {
11 open('POST', '', true)
12 onload = function() {
13 $('.preview-text').innerHTML = responseText
14 }
15 var repoInput = $('.repo-id')
16 send('action=markdown' +
17 (repoInput ? '&repo=' + encodeURIComponent(repoInput.value) : '') +
18 '&text=' + encodeURIComponent($('.post-text').value))
19 }
20 }
21}())`
22
23var issueCommentButtonScript = `;(function () {
24 var btn = document.getElementById('comment-close-btn')
25 document.getElementById('post-text').onkeyup = function (e) {
26 btn.setAttribute('value', this.value
27 ? btn.getAttribute('data-value-withcomment')
28 : btn.getAttribute('data-value-nocomment'))
29 }
30}())`
31
32forms.post = function (req, repo, placeholder, rows) {
33 return '<div class="post-form">' +
34 '<input type="radio" class="tab-radio" id="tab1" name="tab" checked="checked"/>' +
35 '<input type="radio" class="tab-radio" id="tab2" name="tab"/>' +
36 '<div id="tab-links" class="tab-links" style="display:none">' +
37 '<label for="tab1" id="write-tab-link" class="tab1-link">' +
38 req._t('post.Write') + '</label>' +
39 '<label for="tab2" id="preview-tab-link" class="tab2-link">' +
40 req._t('post.Preview') + '</label>' +
41 '</div>' +
42 (repo ?
43 '<input type="hidden" id="repo-id" class="repo-id" value="' + repo.id + '"/>'
44 : '') +
45 '<div id="write-tab" class="tab1">' +
46 '<textarea id="post-text" class="post-text" name="text" class="wide-input"' +
47 ' rows="' + (rows||4) + '" cols="77"' +
48 (placeholder ? ' placeholder="' + placeholder + '"' : '') +
49 '></textarea>' +
50 '</div>' +
51 '<div class="preview-text tab2" id="preview-tab"></div></div>' +
52 '<script>' + issueCommentScript + '</script>'
53}
54
55forms.labels = function (req, repo, placeholder, rows) {
56 return '<div class="post-form">' +
57 '<input type="hidden" name="repo" id="repo-id" class="repo-id" value="' +
58 repo.id +
59 '"/>' +
60 '<input id="post-text" class="post-text label-input" name="text"></input>' +
61 '<script>' + issueCommentScript + '</script>'
62}
63
64forms.name = function (req, enabled, id, name, action, inputId, title, header) {
65 if (!inputId) inputId = action
66
67 if (!enabled) {
68 return h('form', {class: 'petname', action: '', method: 'post'}, [
69 header,
70 h('br', {clear: 'all'})
71 ])
72 }
73
74 return h('form', {class: 'petname', action: '', method: 'post'}, [
75 h('input', {
76 type: 'checkbox', class: 'name-checkbox', id: inputId,
77 onfocus: 'this.form.name.focus()'
78 }),
79 h('input', {
80 class: 'name', name: 'name', value: u.escape(name),
81 onkeyup: 'if (event.keyCode == 27) this.form.reset()'
82 }),
83 h('input', {type: 'hidden', name: 'action', value: action}),
84 h('input', {type: 'hidden', name: 'id', value: u.escape(id)}),
85 h('label', {class: 'name-toggle', for: inputId, title: title}, [
86 h('i', '✍')
87 ]),
88 h('input', {class: 'btn name-btn', type: 'submit', value: req._t('Rename')}),
89 header
90 ])
91}
92
93forms.issueComment = function (req, issue, repo, branch, type) {
94 return '<section><form action="" method="post">' +
95 '<input type="hidden" name="action" value="comment">' +
96 '<input type="hidden" name="id" value="' + issue.id + '">' +
97 '<input type="hidden" name="issue" value="' + issue.id + '">' +
98 '<input type="hidden" name="repo" value="' + repo.id + '">' +
99 '<input type="hidden" name="branch" value="' + branch + '">' +
100 forms.post(req, repo) +
101 '<input type="submit" class="btn open" value="' +
102 req._t('issue.Comment') + '" />' +
103 '<input id="comment-close-btn" type="submit" class="btn"' +
104 ' name="' + (issue.open ? 'close' : 'open') + '"' +
105 ' value="' + req._t(issue.open ? 'issue.Close' : 'issue.Reopen',
106 {type: type}) + '"' +
107 ' data-value-nocomment="' + req._t(issue.open ?
108 'issue.Close' : 'issue.Reopen',
109 {type: type}) + '"' +
110 ' data-value-withcomment="' + req._t(issue.open ?
111 'issue.CommentAndClose' : 'issue.CommentAndReopen',
112 {type: type}) + '"' +
113 '/>' +
114 '<script>' + issueCommentButtonScript + '</script>' +
115 '</form></section>'
116}
117
118forms.lineComment = function (req, repo, updateId, commitId, filePath, line) {
119 return '<section><form action="" method="post">' +
120 '<input type="hidden" name="action" value="line-comment">' +
121 '<input type="hidden" name="updateId" value="' + updateId + '">' +
122 '<input type="hidden" name="repo" value="' + repo.id + '">' +
123 '<input type="hidden" name="commitId" value="' + commitId + '">' +
124 '<input type="hidden" name="filePath" value="' + filePath + '">' +
125 '<input type="hidden" name="line" value="' + line + '">' +
126 forms.post(req, repo) +
127 '<input type="submit" class="btn open" value="' +
128 req._t('issue.LineComment') + '" />' +
129 '</form></section>'
130}
131
132forms.lineCommentReply = function (req, root, branch) {
133 return '<section><form action="" method="post">' +
134 '<input type="hidden" name="action" value="line-comment-reply">' +
135 '<input type="hidden" name="root" value="' + root + '">' +
136 '<input type="hidden" name="branch" value="' + branch + '">' +
137 forms.post(req) +
138 '<input type="submit" class="btn open" value="' +
139 req._t('Reply') + '" />' +
140 '</form></section>'
141}
142

Built with git-ssb-web