()
| 271 | |
| 272 | // Initialize handlers for saving/loading configurations. |
| 273 | function initConfigManager() { |
| 274 | 'use strict'; |
| 275 | |
| 276 | // Initialize various elements. |
| 277 | function elem(id) { |
| 278 | const result = document.getElementById(id); |
| 279 | if (!result) console.warn('element ' + id + ' not found'); |
| 280 | return result; |
| 281 | } |
| 282 | const overlay = elem('dialog-overlay'); |
| 283 | const saveDialog = elem('save-dialog'); |
| 284 | const saveInput = elem('save-name'); |
| 285 | const saveError = elem('save-error'); |
| 286 | const delDialog = elem('delete-dialog'); |
| 287 | const delPrompt = elem('delete-prompt'); |
| 288 | const delError = elem('delete-error'); |
| 289 | |
| 290 | let currentDialog = null; |
| 291 | let currentDeleteTarget = null; |
| 292 | |
| 293 | function showDialog(dialog) { |
| 294 | if (currentDialog != null) { |
| 295 | overlay.style.display = 'none'; |
| 296 | currentDialog.style.display = 'none'; |
| 297 | } |
| 298 | currentDialog = dialog; |
| 299 | if (dialog != null) { |
| 300 | overlay.style.display = 'block'; |
| 301 | dialog.style.display = 'block'; |
| 302 | } |
| 303 | } |
| 304 | |
| 305 | function cancelDialog(e) { |
| 306 | showDialog(null); |
| 307 | } |
| 308 | |
| 309 | // Show dialog for saving the current config. |
| 310 | function showSaveDialog(e) { |
| 311 | saveError.innerText = ''; |
| 312 | showDialog(saveDialog); |
| 313 | saveInput.focus(); |
| 314 | } |
| 315 | |
| 316 | // Commit save config. |
| 317 | function commitSave(e) { |
| 318 | const name = saveInput.value; |
| 319 | const url = new URL(document.URL); |
| 320 | // Set path relative to existing path. |
| 321 | url.pathname = new URL('./saveconfig', document.URL).pathname; |
| 322 | url.searchParams.set('config', name); |
| 323 | saveError.innerText = ''; |
| 324 | sendURL('POST', url, (ok) => { |
| 325 | if (!ok) { |
| 326 | saveError.innerText = 'Save failed'; |
| 327 | } else { |
| 328 | showDialog(null); |
| 329 | location.reload(); // Reload to show updated config menu |
| 330 | } |
no test coverage detected
searching dependent graphs…