-
Notifications
You must be signed in to change notification settings - Fork 7
/
uiOutput.js
218 lines (122 loc) · 4.61 KB
/
uiOutput.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
/****************************************************************************
* uiOutput.js
* openacousticdevices.info
* June 2022
*****************************************************************************/
'use strict';
/* global document */
const {dialog} = require('@electron/remote');
const outputCheckbox = document.getElementById('output-checkbox');
const outputButton = document.getElementById('output-button');
const outputLabel = document.getElementById('output-label');
const subdirectoriesLabel = document.getElementById('subdirectories-label');
const subdirectoriesCheckbox = document.getElementById('subdirectories-checkbox');
let outputDir = '';
const prefixInput = document.getElementById('prefix-input');
const prefixCheckbox = document.getElementById('prefix-checkbox');
const prefixLabel = document.getElementById('prefix-label');
const selectionRadios = document.getElementsByName('selection-radio');
function getSelectedRadioValue (radioName) {
return parseInt(document.querySelector('input[name="' + radioName + '"]:checked').value);
}
/* Update label to notify user if a custom output directtory is being used */
function updateOutputLabel () {
if (outputDir === '' || !outputCheckbox.checked) {
outputLabel.textContent = 'Writing WAV files to source folder.';
} else {
outputLabel.textContent = 'Writing WAV files to destination folder.';
}
};
function updateSubdirectoriesCheckbox () {
const selectionType = getSelectedRadioValue('selection-radio');
if (outputCheckbox.checked && outputDir !== '' && selectionType === 1) {
subdirectoriesCheckbox.disabled = false;
subdirectoriesLabel.classList.remove('grey');
} else {
subdirectoriesCheckbox.disabled = true;
subdirectoriesLabel.classList.add('grey');
}
}
/* Add listener which handles enabling/disabling custom output directory UI */
outputCheckbox.addEventListener('change', () => {
updateOutputLabel();
updateSubdirectoriesCheckbox();
outputButton.disabled = !outputCheckbox.checked;
});
/* Select a custom output directory. If Cancel is pressed, assume no custom direcotry is wantted */
outputButton.addEventListener('click', () => {
const destinationName = dialog.showOpenDialogSync({
title: 'Select Destination',
nameFieldLabel: 'Destination',
multiSelections: false,
properties: ['openDirectory'],
defaultPath: outputDir
});
if (destinationName !== undefined) {
outputDir = destinationName[0];
}
updateOutputLabel();
updateSubdirectoriesCheckbox();
});
/* Remove all characters which aren't A-Z, a-z, 0-9, and _ */
prefixInput.addEventListener('keydown', (e) => {
if (prefixInput.disabled) {
e.preventDefault();
return;
}
const reg = /[^A-Za-z-_0-9]{1}/g;
if (reg.test(e.key)) {
e.preventDefault();
}
});
prefixInput.addEventListener('paste', (e) => {
e.stopPropagation();
e.preventDefault();
if (prefixInput.disabled) {
return;
}
/* Read text from clipboard */
const clipboardData = e.clipboardData || window.clipboardData;
const pastedData = clipboardData.getData('Text');
/* Perform paste, but remove all unsupported characters */
prefixInput.value += pastedData.replace(/[^A-Za-z_0-9]{1}/g, '');
/* Limit max number of characters */
prefixInput.value = prefixInput.value.substring(0, prefixInput.maxLength);
});
/* Add listener to handle enabling/disabling prefix UI */
prefixCheckbox.addEventListener('change', () => {
if (prefixCheckbox.checked) {
prefixLabel.classList.remove('grey');
prefixInput.classList.remove('grey');
prefixInput.disabled = false;
} else {
prefixLabel.classList.add('grey');
prefixInput.classList.add('grey');
prefixInput.disabled = true;
}
});
exports.disableOutputCheckbox = () => {
outputCheckbox.disabled = true;
};
exports.disableOutputButton = () => {
outputButton.disabled = true;
};
exports.enableOutputCheckbox = () => {
outputCheckbox.disabled = false;
};
exports.enableOutputButton = () => {
if (outputCheckbox.checked) {
outputButton.disabled = false;
}
};
exports.isCustomDestinationEnabled = () => {
return outputCheckbox.checked;
};
exports.getOutputDir = () => {
return outputDir;
};
exports.isCreateSubdirectoriesEnabled = () => {
return subdirectoriesCheckbox.checked;
};
selectionRadios[0].addEventListener('change', updateSubdirectoriesCheckbox);
selectionRadios[1].addEventListener('change', updateSubdirectoriesCheckbox);