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