codekingpro/portable-devtools
114k
1/////////////////////////////////////////////////////////////2//3// pgAdmin 4 - PostgreSQL Tools4//5// Copyright (C) 2013 - 2024, The pgAdmin Development Team6// This software is released under the PostgreSQL Licence7//8//////////////////////////////////////////////////////////////9 10const misc = require('../js/misc.js');11 12// Get the window object of view log window13let gui = require('nw.gui');14let configWindow = gui.Window.get();15 16function checkConfiguration() {17 let configData = misc.ConfigureStore.getConfigData();18 19 if (document.getElementById('fixedPortCheck').checked && configData['portNo'] !== document.getElementById('portNo').value) {20 let fixedPort = parseInt(document.getElementById('portNo').value);21 // get the available TCP port22 misc.getAvailablePort(fixedPort)23 .then(() => {24 saveConfiguration();25 })26 .catch(() => {27 alert('The port specified is already in use. Please enter a free port number.');28 });29 } else {30 saveConfiguration();31 }32}33 34function saveConfiguration() {35 misc.ConfigureStore.set('fixedPort', document.getElementById('fixedPortCheck').checked);36 misc.ConfigureStore.set('portNo', parseInt(document.getElementById('portNo').value));37 misc.ConfigureStore.set('connectionTimeout', parseInt(document.getElementById('timeOut').value));38 misc.ConfigureStore.set('openDocsInBrowser', document.getElementById('openDocsInBrowser').checked);39 40 misc.ConfigureStore.saveConfig();41 42 document.getElementById('status-text').innerHTML = 'Configuration Saved';43 44 if (confirm('pgAdmin 4 must be restarted for changes to take effect.\n\n Do you want to quit the application?') === true) {45 misc.cleanupAndQuitApp();46 }47 configWindow.close();48}49 50function onCheckChange() {51 if (this.checked) {52 document.getElementById('portNo').removeAttribute('disabled');53 } else {54 document.getElementById('portNo').setAttribute('disabled', 'disabled');55 }56 57 // Enable/Disable Save button58 enableDisableSaveButton();59}60 61function enableDisableSaveButton() {62 let configData = misc.ConfigureStore.getConfigData();63 64 if (configData['fixedPort'] !== document.getElementById('fixedPortCheck').checked ||65 configData['portNo'] != document.getElementById('portNo').value ||66 configData['connectionTimeout'] != document.getElementById('timeOut').value ||67 configData['openDocsInBrowser'] !== document.getElementById('openDocsInBrowser').checked) {68 document.getElementById('btnSave').removeAttribute('disabled');69 } else {70 document.getElementById('btnSave').setAttribute('disabled', 'disabled');71 }72}73 74configWindow.on('loaded', function() {75 document.getElementById('status-text').innerHTML = '';76 // Get the config data from the file.77 let configData = misc.ConfigureStore.getConfigData();78 79 // Set the GUI value as per configuration.80 if (configData['fixedPort']) {81 document.getElementById('fixedPortCheck').checked = true;82 document.getElementById('portNo').disabled = false;83 } else {84 document.getElementById('fixedPortCheck').checked = false;85 document.getElementById('portNo').disabled = true;86 }87 document.getElementById('portNo').value = configData['portNo'];88 document.getElementById('timeOut').value = configData['connectionTimeout'];89 90 if (configData['openDocsInBrowser']) {91 document.getElementById('openDocsInBrowser').checked = true;92 } else {93 document.getElementById('openDocsInBrowser').checked = false;94 }95 // Add event listeners96 document.getElementById('btnSave').addEventListener('click', checkConfiguration);97 document.getElementById('fixedPortCheck').addEventListener('change', onCheckChange);98 document.getElementById('portNo').addEventListener('change', enableDisableSaveButton);99 document.getElementById('timeOut').addEventListener('change', enableDisableSaveButton);100 document.getElementById('openDocsInBrowser').addEventListener('change', enableDisableSaveButton);101});102 