|
2 | 2 | <html> |
3 | 3 | <head> |
4 | 4 | <meta charset=utf-8> |
| 5 | + <meta http-equiv="Content-Security-Policy" content="script-src 'self' 'unsafe-inline'"> |
5 | 6 | <title>Task</title> |
6 | 7 | <link rel=stylesheet href='style/ride-base.css'> |
7 | 8 | <link rel=stylesheet class=theme id=theme_dark href='style/dark-theme.css'> |
|
12 | 13 | <div id=gd class="dlg floating"><!--generic dialog for processing OptionsDialog,StringDialog,TaskDialog--> |
13 | 14 | <div class=dlg_content id=gd_content></div> |
14 | 15 | <div class=dlg_btns id=gd_btns ></div> |
| 16 | + <div id="gd_footer"> |
| 17 | + <div id="gd_footer_btns"></div> |
| 18 | + <input id=gd_footer_qn type="checkbox" name="question"> |
| 19 | + <label id=gd_footer_qn_lbl for=gd_footer_qn></label> |
| 20 | + </div> |
15 | 21 | </div> |
16 | 22 |
|
17 | 23 | <script> |
18 | 24 | const ESC = { '<': '<', '>': '>', '&': '&', "'": ''', '"': '"' }; |
19 | 25 | const esc = s => s.replace(/[<>&'"]/g, x => ESC[x]); |
20 | 26 |
|
21 | 27 | const ipc = require('node-ipc'); |
| 28 | + const el = require('electron').remote; |
| 29 | + const bw = el.getCurrentWindow(); |
| 30 | + const [width] = bw.getSize(); |
22 | 31 | const qp = require('querystring').parse(window.location.search.slice(1)); |
| 32 | + const iswin = /^win/i.test(process.platform); |
| 33 | + |
23 | 34 | ipc.config.id = 'dialog'; |
24 | 35 | ipc.config.appspace = qp.appid; |
25 | 36 | ipc.config.retry = 1500; |
|
30 | 41 | rm.on('connect', () => { |
31 | 42 | window.onbeforeunload = (e) => { |
32 | 43 | e.returnValue = false; |
33 | | - rm.emit('dialogClose', [token, task ? -1 : value]); |
| 44 | + rm.emit('dialogClose', [token, { index: task ? -1 : value }]); |
34 | 45 | }; |
35 | 46 | rm.emit('dialogCreated'); |
36 | 47 | }); |
|
48 | 59 |
|
49 | 60 | const gd_content = document.getElementById('gd_content'); |
50 | 61 | const gd_btns = document.getElementById('gd_btns'); |
| 62 | + const gd_footer = document.getElementById('gd_footer'); |
| 63 | + const gd_footer_btns = document.getElementById('gd_footer_btns'); |
| 64 | + const gd_footer_qn = document.getElementById('gd_footer_qn'); |
| 65 | + const gd_footer_qn_lbl = document.getElementById('gd_footer_qn_lbl'); |
| 66 | + |
51 | 67 | let value; |
52 | 68 | let task; |
53 | 69 | let token; |
|
57 | 73 | document.title = x.title || 'Dyalog'; |
58 | 74 | task = !!x.buttonText; |
59 | 75 | value = x.defaultValue || null; |
| 76 | + gd_footer.hidden = !task; |
60 | 77 | if (task) { |
61 | 78 | gd_content.innerHTML = esc(x.text || '') + (x.subtext ? `<div class=task_subtext>${esc(x.subtext)}</div>` : ''); |
62 | 79 | let btns = (x.buttonText || []).map((y) => { |
63 | 80 | const [caption, ...details] = esc(y).split('\n'); |
64 | 81 | return '<button class=task><div class="btn_icon"><span class="fas fa-chevron-circle-right"></span></div>' + |
65 | 82 | `${caption}<br><div class="task_detail">${details.join('<br>')}</div></button>`; |
66 | 83 | }).join(''); |
67 | | - btns += (x.footer ? `<div class=task_footer>${esc(x.footer)}</div>` : ''); |
68 | 84 | gd_btns.innerHTML = btns; |
69 | | - const ret = (r) => { |
70 | | - gd_btns.onclick = null; |
71 | | - rm.emit('dialogClose', [token, r]); |
| 85 | + gd_footer_btns.innerHTML = x.options.map((y) => `<button>${y}</button>`).join(''); |
| 86 | + gd_footer_qn_lbl.innerHTML = x.questionlabel; |
| 87 | + gd_footer_qn.checked = false; |
| 88 | + const ret = (index, questionkey) => { |
| 89 | + [...gd_btns.getElementsByTagName('button')].forEach(x => x.onclick = null); |
| 90 | + gd_footer_btns.onclick = null; |
| 91 | + rm.emit('dialogClose', [token, { index, questionkey }]); |
72 | 92 | }; |
73 | 93 | const clickCb = (e) => { |
74 | | - let t = e.currentTarget; |
75 | | - let i = 99; |
| 94 | + let t = e.currentTarget == gd_footer_btns ? e.target : e.currentTarget; |
| 95 | + let i = e.currentTarget == gd_footer_btns ? -1 : 99; |
76 | 96 | while (t) { t = t.previousSibling; i += 1; } |
77 | | - ret(i); |
| 97 | + ret(i, gd_footer_qn.checked && x.questionkey); |
78 | 98 | }; |
79 | 99 | [...gd_btns.getElementsByTagName('button')].forEach(x => x.onclick = clickCb); |
| 100 | + gd_footer_btns.onclick = clickCb; |
| 101 | + |
80 | 102 | gd_btns.querySelector('button').focus(); |
81 | 103 | } else { |
82 | 104 | gd_content.innerText = x.text || ''; |
83 | 105 | gd_content.insertAdjacentHTML('beforeend', `<br><input ${x.pass ? 'type=password' : ''}>`); |
84 | 106 | const inp = gd_content.querySelector('input'); |
85 | 107 | inp.value = x.initialValue || ''; |
86 | 108 | gd_btns.innerHTML = '<button>OK</button><button>Cancel</button>'; |
87 | | - const ret = (r) => { |
| 109 | + const ret = (index) => { |
88 | 110 | gd_btns.onclick = null; |
89 | | - rm.emit('dialogClose', [token, r]); |
| 111 | + rm.emit('dialogClose', [token, { index }]); |
90 | 112 | }; |
91 | 113 | gd_btns.onclick = (e) => { |
92 | 114 | if (e.target.nodeName === 'BUTTON') { |
|
104 | 126 | }; |
105 | 127 | setTimeout(() => { inp.focus(); }, 1); |
106 | 128 | } |
| 129 | + bw.resizable = true; |
| 130 | + setTimeout(() => { |
| 131 | + bw.setSize(width, document.body.clientHeight + (iswin ? 39 : 0)); |
| 132 | + bw.resizable = false; |
| 133 | + }, 1); |
107 | 134 | } |
108 | 135 | </script> |
109 | 136 | </body> |
|
0 commit comments