Files: 8599df15928f4db206734f0d4ed00429e6b36a86 / lib / forms.js
3938 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 '<input type="radio" class="tab-radio" id="tab1" name="tab" checked="checked"/>' + |
7 | '<input type="radio" class="tab-radio" id="tab2" name="tab"/>' + |
8 | '<div id="tab-links" class="tab-links" style="display:none">' + |
9 | '<label for="tab1" id="write-tab-link" class="tab1-link">' + |
10 | req._t('post.Write') + '</label>' + |
11 | '<label for="tab2" id="preview-tab-link" class="tab2-link">' + |
12 | req._t('post.Preview') + '</label>' + |
13 | '</div>' + |
14 | '<input type="hidden" id="repo-id" value="' + repo.id + '"/>' + |
15 | '<div id="write-tab" class="tab1">' + |
16 | '<textarea id="post-text" name="text" class="wide-input"' + |
17 | ' rows="' + (rows||4) + '" cols="77"' + |
18 | (placeholder ? ' placeholder="' + placeholder + '"' : '') + |
19 | '></textarea>' + |
20 | '</div>' + |
21 | '<div class="preview-text tab2" id="preview-tab"></div>' + |
22 | '<script>' + issueCommentScript + '</script>' |
23 | } |
24 | |
25 | forms.name = function (req, enabled, id, name, action, inputId, title, header) { |
26 | if (!inputId) inputId = action |
27 | |
28 | if (!enabled) { |
29 | return h('form', {class: 'petname', action: '', method: 'post'}, [ |
30 | header, |
31 | h('br', {clear: 'all'}) |
32 | ]) |
33 | } |
34 | |
35 | return h('form', {class: 'petname', action: '', method: 'post'}, [ |
36 | h('input', { |
37 | type: 'checkbox', class: 'name-checkbox', id: inputId, |
38 | onfocus: 'this.form.name.focus()' |
39 | }), |
40 | h('input', { |
41 | class: 'name', name: 'name', value: u.escape(name), |
42 | onkeyup: 'if (event.keyCode == 27) this.form.reset()' |
43 | }), |
44 | h('input', {type: 'hidden', name: 'action', value: action}), |
45 | h('input', {type: 'hidden', name: 'id', value: u.escape(id)}), |
46 | h('label', {class: 'name-toggle', for: inputId, title: title}, [ |
47 | h('i', '✍') |
48 | ]), |
49 | h('input', {class: 'btn name-btn', type: 'submit', value: req._t('Rename')}), |
50 | header |
51 | ]) |
52 | } |
53 | |
54 | var issueCommentScript = '(' + function () { |
55 | var $ = document.getElementById.bind(document) |
56 | $('tab-links').style.display = 'block' |
57 | $('preview-tab-link').onclick = function (e) { |
58 | with (new XMLHttpRequest()) { |
59 | open('POST', '', true) |
60 | onload = function() { |
61 | $('preview-tab').innerHTML = responseText |
62 | } |
63 | send('action=markdown' + |
64 | '&repo=' + encodeURIComponent($('repo-id').value) + |
65 | '&text=' + encodeURIComponent($('post-text').value)) |
66 | } |
67 | } |
68 | }.toString() + ')()' |
69 | |
70 | var issueCommentButtonScript = '(' + function () { |
71 | var btn = document.getElementById('comment-close-btn') |
72 | document.getElementById('post-text').onkeyup = function (e) { |
73 | btn.setAttribute('value', this.value |
74 | ? btn.getAttribute('data-value-withcomment') |
75 | : btn.getAttribute('data-value-nocomment')) |
76 | } |
77 | }.toString() + ')()' |
78 | |
79 | forms.issueComment = function (req, issue, repo, branch, type) { |
80 | return '<section><form action="" method="post">' + |
81 | '<input type="hidden" name="action" value="comment">' + |
82 | '<input type="hidden" name="id" value="' + issue.id + '">' + |
83 | '<input type="hidden" name="issue" value="' + issue.id + '">' + |
84 | '<input type="hidden" name="repo" value="' + repo.id + '">' + |
85 | '<input type="hidden" name="branch" value="' + branch + '">' + |
86 | forms.post(req, repo) + |
87 | '<input type="submit" class="btn open" value="' + |
88 | req._t('issue.Comment') + '" />' + |
89 | '<input id="comment-close-btn" type="submit" class="btn"' + |
90 | ' name="' + (issue.open ? 'close' : 'open') + '"' + |
91 | ' value="' + req._t(issue.open ? 'issue.Close' : 'issue.Reopen', |
92 | {type: type}) + '"' + |
93 | ' data-value-nocomment="' + req._t(issue.open ? |
94 | 'issue.Close' : 'issue.Reopen', |
95 | {type: type}) + '"' + |
96 | ' data-value-withcomment="' + req._t(issue.open ? |
97 | 'issue.CommentAndClose' : 'issue.CommentAndReopen', |
98 | {type: type}) + '"' + |
99 | '/>' + |
100 | '<script>' + issueCommentButtonScript + '</script>' + |
101 | '</form></section>' |
102 | } |
103 |
Built with git-ssb-web