git ssb

30+

cel / git-ssb-web



Tree: 4f5323ab2d208ccdc1bd0837f332f0f560bfcecf

Files: 4f5323ab2d208ccdc1bd0837f332f0f560bfcecf / lib / forms.js

5274 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.name = function (req, enabled, id, name, action, inputId, title, header) {
56 if (!inputId) inputId = action
57
58 if (!enabled) {
59 return h('form', {class: 'petname', action: '', method: 'post'}, [
60 header,
61 h('br', {clear: 'all'})
62 ])
63 }
64
65 return h('form', {class: 'petname', action: '', method: 'post'}, [
66 h('input', {
67 type: 'checkbox', class: 'name-checkbox', id: inputId,
68 onfocus: 'this.form.name.focus()'
69 }),
70 h('input', {
71 class: 'name', name: 'name', value: u.escape(name),
72 onkeyup: 'if (event.keyCode == 27) this.form.reset()'
73 }),
74 h('input', {type: 'hidden', name: 'action', value: action}),
75 h('input', {type: 'hidden', name: 'id', value: u.escape(id)}),
76 h('label', {class: 'name-toggle', for: inputId, title: title}, [
77 h('i', '✍')
78 ]),
79 h('input', {class: 'btn name-btn', type: 'submit', value: req._t('Rename')}),
80 header
81 ])
82}
83
84forms.issueComment = function (req, issue, repo, branch, type) {
85 return '<section><form action="" method="post">' +
86 '<input type="hidden" name="action" value="comment">' +
87 '<input type="hidden" name="id" value="' + issue.id + '">' +
88 '<input type="hidden" name="issue" value="' + issue.id + '">' +
89 '<input type="hidden" name="repo" value="' + repo.id + '">' +
90 '<input type="hidden" name="branch" value="' + branch + '">' +
91 forms.post(req, repo) +
92 '<input type="submit" class="btn open" value="' +
93 req._t('issue.Comment') + '" />' +
94 '<input id="comment-close-btn" type="submit" class="btn"' +
95 ' name="' + (issue.open ? 'close' : 'open') + '"' +
96 ' value="' + req._t(issue.open ? 'issue.Close' : 'issue.Reopen',
97 {type: type}) + '"' +
98 ' data-value-nocomment="' + req._t(issue.open ?
99 'issue.Close' : 'issue.Reopen',
100 {type: type}) + '"' +
101 ' data-value-withcomment="' + req._t(issue.open ?
102 'issue.CommentAndClose' : 'issue.CommentAndReopen',
103 {type: type}) + '"' +
104 '/>' +
105 '<script>' + issueCommentButtonScript + '</script>' +
106 '</form></section>'
107}
108
109forms.lineComment = function (req, repo, updateId, commitId, filePath, line) {
110 return '<section><form action="" method="post">' +
111 '<input type="hidden" name="action" value="line-comment">' +
112 '<input type="hidden" name="updateId" value="' + updateId + '">' +
113 '<input type="hidden" name="repo" value="' + repo.id + '">' +
114 '<input type="hidden" name="commitId" value="' + commitId + '">' +
115 '<input type="hidden" name="filePath" value="' + filePath + '">' +
116 '<input type="hidden" name="line" value="' + line + '">' +
117 forms.post(req, repo) +
118 '<input type="submit" class="btn open" value="' +
119 req._t('issue.LineComment') + '" />' +
120 '</form></section>'
121}
122
123forms.lineCommentReply = function (req, root, branch) {
124 return '<section><form action="" method="post">' +
125 '<input type="hidden" name="action" value="line-comment-reply">' +
126 '<input type="hidden" name="root" value="' + root + '">' +
127 '<input type="hidden" name="branch" value="' + branch + '">' +
128 forms.post(req) +
129 '<input type="submit" class="btn open" value="' +
130 req._t('Reply') + '" />' +
131 '</form></section>'
132}
133

Built with git-ssb-web