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