Files: ac38f3bf0c59103522861df8b3a1f1f545247977 / lib / forms.js
4030 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 | // NB this needs an empty 3rd arg to render for some reason? |
51 | header |
52 | ]) |
53 | } |
54 | |
55 | var issueCommentScript = '(' + function () { |
56 | var $ = document.getElementById.bind(document) |
57 | $('tab-links').style.display = 'block' |
58 | $('preview-tab-link').onclick = function (e) { |
59 | with (new XMLHttpRequest()) { |
60 | open('POST', '', true) |
61 | onload = function() { |
62 | $('preview-tab').innerHTML = responseText |
63 | } |
64 | send('action=markdown' + |
65 | '&repo=' + encodeURIComponent($('repo-id').value) + |
66 | '&text=' + encodeURIComponent($('post-text').value)) |
67 | } |
68 | } |
69 | }.toString() + ')()' |
70 | |
71 | var issueCommentButtonScript = '(' + function () { |
72 | var btn = document.getElementById('comment-close-btn') |
73 | document.getElementById('post-text').onkeyup = function (e) { |
74 | btn.setAttribute('value', this.value |
75 | ? btn.getAttribute('data-value-withcomment') |
76 | : btn.getAttribute('data-value-nocomment')) |
77 | } |
78 | }.toString() + ')()' |
79 | |
80 | forms.issueComment = function (req, issue, repo, branch, type) { |
81 | return '<section><form action="" method="post">' + |
82 | '<input type="hidden" name="action" value="comment">' + |
83 | '<input type="hidden" name="id" value="' + issue.id + '">' + |
84 | '<input type="hidden" name="issue" value="' + issue.id + '">' + |
85 | '<input type="hidden" name="repo" value="' + repo.id + '">' + |
86 | '<input type="hidden" name="branch" value="' + branch + '">' + |
87 | forms.post(req, repo) + |
88 | '<input type="submit" class="btn open" value="' + |
89 | req._t('issue.Comment') + '" />' + |
90 | '<input id="comment-close-btn" type="submit" class="btn"' + |
91 | ' name="' + (issue.open ? 'close' : 'open') + '"' + |
92 | ' value="' + req._t(issue.open ? 'issue.Close' : 'issue.Reopen', |
93 | {type: type}) + '"' + |
94 | ' data-value-nocomment="' + req._t(issue.open ? |
95 | 'issue.Close' : 'issue.Reopen', |
96 | {type: type}) + '"' + |
97 | ' data-value-withcomment="' + req._t(issue.open ? |
98 | 'issue.CommentAndClose' : 'issue.CommentAndReopen', |
99 | {type: type}) + '"' + |
100 | '/>' + |
101 | '<script>' + issueCommentButtonScript + '</script>' + |
102 | '</form></section>' |
103 | } |
104 |
Built with git-ssb-web