|
|
@@ -1,32 +1,37 @@
|
|
|
-function doAPIRequestWithCallback (mod, func, handler, errorHandler, args) {
|
|
|
+function doAPIRequestWithCallback (meth, mod, func, handler, errorHandler, args) {
|
|
|
'use strict';
|
|
|
let oReq = new XMLHttpRequest();
|
|
|
oReq.onreadystatechange = function() {
|
|
|
if (this.readyState === XMLHttpRequest.DONE) {
|
|
|
if( this.status === 200 ) {
|
|
|
- handler(this);
|
|
|
+ handler(this.responseText);
|
|
|
} else {
|
|
|
- errorHandler(mod, func, this.status, this.responseText);
|
|
|
+ errorHandler(meth, mod, func, this.status, this.responseText);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- oReq.addEventListener("load", handler);
|
|
|
- let argarr = [];
|
|
|
+ let argarr = [ `module=${mod}`, `function=${func}` ];
|
|
|
if( typeof args === 'Object' ) {
|
|
|
Object.keys(args).forEach( function(argument) {
|
|
|
argarr.push(`${argument}=${args[argument]}`);
|
|
|
});
|
|
|
}
|
|
|
+ let argstr = argarr.join("&");
|
|
|
|
|
|
- oReq.open( "POST", "api.cgi", true );
|
|
|
- oReq.setRequestHeader( "Content-type", "application/x-www-form-urlencoded" );
|
|
|
- oReq.send(argarr.join("&"));
|
|
|
+ if( meth === 'GET' ) {
|
|
|
+ oReq.open( meth, `api.cgi?${argstr}`, true );
|
|
|
+ oReq.send();
|
|
|
+ } else if ( meth === 'POST' ) {
|
|
|
+ oReq.open( meth, "api.cgi", true );
|
|
|
+ oReq.setRequestHeader( "Content-type", "application/x-www-form-urlencoded" );
|
|
|
+ oReq.send();
|
|
|
+ }
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
-function generalErrorHandler(mod, func, code, txt) {
|
|
|
+function generalErrorHandler(meth, mod, func, code, txt) {
|
|
|
console.log(txt);
|
|
|
- alert(`API call to ${mod}::${func} failed with error code ${code}! Please see the JS console for details.`);
|
|
|
+ alert(`${meth} call to Troglodyne::API::${mod}::${func} failed with error code ${code}! Please see the JS console for details.`);
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
@@ -41,11 +46,10 @@ function safeParseJSON(txt) {
|
|
|
return obj;
|
|
|
}
|
|
|
|
|
|
-function versionHandler (xhr) {
|
|
|
+function versionHandler (resp) {
|
|
|
'use strict';
|
|
|
- let obj = safeParseJSON(xhr.responseText);
|
|
|
+ let obj = safeParseJSON(resp);
|
|
|
if(obj.result === 1) {
|
|
|
- console.log(obj);
|
|
|
|
|
|
// Construct version warning/display
|
|
|
let pgVersion = obj.data.installed_version.major + '.' + obj.data.installed_version.minor;
|
|
|
@@ -56,8 +60,6 @@ function versionHandler (xhr) {
|
|
|
html += ' -- You are using a version of PostgreSQL Server that is no longer supported by ';
|
|
|
html += '<a href="https://www.postgresql.org/support/versioning/" title="PostgreSQL Supported versions page">postgresql.org</a>!<br>';
|
|
|
if( obj.data.eol_versions.hasOwnProperty(pgVersion) ) {
|
|
|
- console.log(obj.data.eol_versions[pgVersion]);
|
|
|
- console.log(obj.data.eol_versions[pgVersion].EOL);
|
|
|
html += "<strong>EOL</strong> -- " + new Date(obj.data.eol_versions[pgVersion].EOL * 1000).toLocaleString( undefined, { year: 'numeric', month: 'long', day: 'numeric' } ) + "<br>";
|
|
|
}
|
|
|
html += "<strong>Immediate upgrade is recommended.</strong>";
|
|
|
@@ -93,9 +95,9 @@ function versionHandler (xhr) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-function doInstallScroller (xhr) {
|
|
|
+function doInstallScroller (resp) {
|
|
|
'use strict';
|
|
|
- let obj = JSON.parse(xhr.responseText);
|
|
|
+ let obj = JSON.parse(resp);
|
|
|
let upgradeWell = document.getElementById('upgradeWell');
|
|
|
let submitBtn = document.getElementById('submit');
|
|
|
if(obj.result === 1) {
|
|
|
@@ -112,7 +114,7 @@ function doInstallScroller (xhr) {
|
|
|
}
|
|
|
// Ok, now kick off actual install TODO use WebSocket?
|
|
|
upgradeWell.textContent += "\nNow proceeding with install of PostgreSQL " + window.selectedVersion + "...\n";
|
|
|
- doAPIRequestWithCallback( 'Postgres', 'start_postgres_install', handlePGInstall, generalErrorHandler, { "version": window.selectedVersion } );
|
|
|
+ doAPIRequestWithCallback( 'POST', 'Postgres', 'start_postgres_install', handlePGInstall, generalErrorHandler, { "version": window.selectedVersion } );
|
|
|
} else {
|
|
|
upgradeWell.textContent += "Installlation of community repositories failed:" + obj.reason;
|
|
|
submitBtn.textContent = 'Re-Try';
|
|
|
@@ -121,9 +123,9 @@ function doInstallScroller (xhr) {
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
-function handlePGInstall (xhr) {
|
|
|
+function handlePGInstall (resp) {
|
|
|
'use strict';
|
|
|
- let obj = safeParseJSON(xhr.responseText);
|
|
|
+ let obj = safeParseJSON(resp);
|
|
|
if(obj.result === 1) {
|
|
|
console.log(obj);
|
|
|
console.log("OK. Now doing our install.");
|
|
|
@@ -143,11 +145,11 @@ window.doUpgrade = function () {
|
|
|
submitBtn.disabled = true;
|
|
|
submitBtn.innerHTML = '<span class="fa fa-spin fa-spinner"></span>';
|
|
|
document.getElementById('upgradeDiv').innerHTML = '<pre id="upgradeWell" class="well">Ensuring that the PostgreSQL Community repository is installed...\n</pre>';
|
|
|
- doAPIRequestWithCallback('Postgres', 'enable_community_repositories', doInstallScroller, generalErrorHandler );
|
|
|
+ doAPIRequestWithCallback( 'GET', 'Postgres', 'enable_community_repositories', doInstallScroller, generalErrorHandler );
|
|
|
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
// Now kickoff the page load post bits
|
|
|
document.getElementById('submit').disabled = true;
|
|
|
-doAPIRequestWithCallback( 'Postgres', 'get_postgresql_versions', versionHandler, generalErrorHandler );
|
|
|
+doAPIRequestWithCallback( 'GET', 'Postgres', 'get_postgresql_versions', versionHandler, generalErrorHandler );
|