commit 21/01/2026
This commit is contained in:
15
html/assets/js/home.js
Normal file
15
html/assets/js/home.js
Normal file
@@ -0,0 +1,15 @@
|
||||
$(document).ready(function() {
|
||||
// Your code here
|
||||
console.log("home.js is loaded and ready.");
|
||||
$('#logoutbtn').on('click', function() {
|
||||
// Clear session storage on logout
|
||||
fetch('/logout').then(() => {
|
||||
window.location.href = '/login.html';
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
$(window).on('beforeunload', function() {
|
||||
console.log("User is leaving home.html");
|
||||
// Your cleanup code here
|
||||
});
|
||||
15
html/assets/js/log.js
Normal file
15
html/assets/js/log.js
Normal file
@@ -0,0 +1,15 @@
|
||||
$(document).ready(function() {
|
||||
// Your code here
|
||||
console.log("log.js is loaded and ready.");
|
||||
$('#logoutbtn').on('click', function() {
|
||||
// Clear session storage on logout
|
||||
fetch('/logout').then(() => {
|
||||
window.location.href = '/login.html';
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
$(window).on('beforeunload', function() {
|
||||
console.log("User is leaving log.html");
|
||||
// Your cleanup code here
|
||||
});
|
||||
13
html/assets/js/login.js
Normal file
13
html/assets/js/login.js
Normal file
@@ -0,0 +1,13 @@
|
||||
$(document).ready(function() {
|
||||
// Your code here
|
||||
console.log("login.js is loaded and ready.");
|
||||
const params = new URLSearchParams(window.location.search);
|
||||
if (params.get("error")) {
|
||||
alert("Login failed. Please try again.");
|
||||
}
|
||||
});
|
||||
|
||||
$(window).on('beforeunload', function() {
|
||||
console.log("User is leaving login.html");
|
||||
// Your cleanup code here
|
||||
});
|
||||
77
html/assets/js/script.js
Normal file
77
html/assets/js/script.js
Normal file
@@ -0,0 +1,77 @@
|
||||
/**
|
||||
* Checks if a string is valid (not null and not empty)
|
||||
* @param {string} str
|
||||
* @returns true if valid, false otherwise
|
||||
*/
|
||||
function ValidString(str) {
|
||||
if (str) {
|
||||
if (str.length > 0) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs a POST request to the specified URL with the given data.
|
||||
* @param {string} url Service endpoint URL
|
||||
* @param {object} data Data to be sent in the request body
|
||||
* @param {function} onSuccess callback for successful response
|
||||
* @param {function} onError callback for error response
|
||||
*/
|
||||
function Post(url, data, onSuccess, onError) {
|
||||
fetch(url, {
|
||||
method: "POST",
|
||||
body: JSON.stringify(data)
|
||||
}).then(response => {
|
||||
if (response.ok) {
|
||||
return response.json();
|
||||
} else {
|
||||
let str = `POST request to ${url} failed. Status: ${response.statusText}`;
|
||||
throw new Error(str);
|
||||
}
|
||||
}).then(data => {
|
||||
if (onSuccess) {
|
||||
onSuccess(data);
|
||||
}
|
||||
}).catch(error => {
|
||||
if (ValidString(error.message)) {
|
||||
if (onError) {
|
||||
onError(error.message);
|
||||
} else {
|
||||
console.error(error.message);
|
||||
}
|
||||
} else console.log("An unknown error occurred during POST request.");
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs a GET request to the specified URL.
|
||||
* @param {string} url Service endpoint URL
|
||||
* @param {function} onSuccess callback for successful response
|
||||
* @param {function} onError callback for error response
|
||||
*/
|
||||
function Get(url, onSuccess, onError) {
|
||||
fetch(url).then(response => {
|
||||
if (response.ok) {
|
||||
return response.json();
|
||||
} else {
|
||||
let str = `GET request to ${url} failed. Status: ${response.statusText}`;
|
||||
throw new Error(str);
|
||||
}
|
||||
}).then(data => {
|
||||
if (onSuccess) {
|
||||
onSuccess(data);
|
||||
}
|
||||
}).catch(error => {
|
||||
if (ValidString(error.message)) {
|
||||
if (onError) {
|
||||
onError(error.message);
|
||||
} else {
|
||||
console.error(error.message);
|
||||
}
|
||||
}
|
||||
else console.log("An unknown error occurred during GET request.");
|
||||
});
|
||||
}
|
||||
168
html/assets/js/setting.js
Normal file
168
html/assets/js/setting.js
Normal file
@@ -0,0 +1,168 @@
|
||||
$(document).ready(function () {
|
||||
// Your code here
|
||||
console.log("setting.js is loaded and ready.");
|
||||
|
||||
loadSetting();
|
||||
|
||||
$('#logoutbtn').on('click', function () {
|
||||
// Clear session storage on logout
|
||||
fetch('/logout').then(() => {
|
||||
window.location.href = '/login.html';
|
||||
});
|
||||
});
|
||||
|
||||
$('#savefarm').on('click', function () {
|
||||
saveFarmParameter();
|
||||
});
|
||||
|
||||
$('#saveaas').on('click', function () {
|
||||
saveAASParameter();
|
||||
});
|
||||
});
|
||||
|
||||
$(window).on('beforeunload', function () {
|
||||
console.log("User is leaving setting.html");
|
||||
// Your cleanup code here
|
||||
});
|
||||
|
||||
function loadSetting() {
|
||||
Get("getSetting", function (data) {
|
||||
if (data) {
|
||||
if (data.farm) {
|
||||
if (data.aas1) {
|
||||
if (data.aas2) {
|
||||
if (data.aas3) {
|
||||
// all good
|
||||
$('#brokerurl').val(data.farm.url);
|
||||
$('#brokerusername').val(data.farm.username);
|
||||
$('#brokerpassword').val(data.farm.password);
|
||||
$('#brokerqueue').val(data.farm.queue);
|
||||
$('#aas1url').val(data.aas1.url);
|
||||
$('#aas1username').val(data.aas1.username);
|
||||
$('#aas1password').val(data.aas1.password);
|
||||
$('#aas2url').val(data.aas2.url);
|
||||
$('#aas2username').val(data.aas2.username);
|
||||
$('#aas2password').val(data.aas2.password);
|
||||
$('#aas3url').val(data.aas3.url);
|
||||
$('#aas3username').val(data.aas3.username);
|
||||
$('#aas3password').val(data.aas3.password);
|
||||
} else console.log("No AAS 3 data received");
|
||||
} else console.log("No AAS 2 data received");
|
||||
} else console.log("No AAS 1 data received");
|
||||
} else console.log("No FARM data received");
|
||||
} else console.log("No data received");
|
||||
|
||||
}, function (error) {
|
||||
alert(error);
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
function saveFarmParameter() {
|
||||
let url = $('#brokerurl').val();
|
||||
let username = $('#brokerusername').val();
|
||||
let password = $('#brokerpassword').val();
|
||||
let queue = $('#brokerqueue').val();
|
||||
|
||||
if (ValidString(url) == false) {
|
||||
alert("FARM Broker URL is required.");
|
||||
return;
|
||||
}
|
||||
if (ValidString(username) == false) {
|
||||
alert("FARM Broker Username is required.");
|
||||
return;
|
||||
}
|
||||
if (ValidString(password) == false) {
|
||||
alert("FARM Broker Password is required.");
|
||||
return;
|
||||
}
|
||||
if (ValidString(queue) == false) {
|
||||
alert("FARM Broker Queue is required.");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Post("saveFARM", {
|
||||
farm: {
|
||||
url: url,
|
||||
username: username,
|
||||
password: password,
|
||||
queue: queue
|
||||
}
|
||||
|
||||
}, function (data) {
|
||||
alert(data.message);
|
||||
}, function (error) {
|
||||
alert(error);
|
||||
});
|
||||
|
||||
}
|
||||
function saveAASParameter() {
|
||||
let aas1URL = $('#aas1url').val();
|
||||
let aas1username = $('#aas1username').val();
|
||||
let aas1password = $('#aas1password').val();
|
||||
let aas2URL = $('#aas2url').val();
|
||||
let aas2username = $('#aas2username').val();
|
||||
let aas2password = $('#aas2password').val();
|
||||
let aas3URL = $('#aas3url').val();
|
||||
let aas3username = $('#aas3username').val();
|
||||
let aas3password = $('#aas3password').val();
|
||||
|
||||
if (ValidString(aas1URL) == false) {
|
||||
alert("AAS1 URL is required.");
|
||||
return;
|
||||
}
|
||||
if (ValidString(aas1username) == false) {
|
||||
alert("AAS1 Username is required.");
|
||||
return;
|
||||
}
|
||||
if (ValidString(aas1password) == false) {
|
||||
alert("AAS1 Password is required.");
|
||||
return;
|
||||
}
|
||||
if (ValidString(aas2URL) == false) {
|
||||
alert("AAS2 URL is required.");
|
||||
return;
|
||||
}
|
||||
if (ValidString(aas2username) == false) {
|
||||
alert("AAS2 Username is required.");
|
||||
return;
|
||||
}
|
||||
if (ValidString(aas2password) == false) {
|
||||
alert("AAS2 Password is required.");
|
||||
return;
|
||||
}
|
||||
if (ValidString(aas3URL) == false) {
|
||||
alert("AAS3 URL is required.");
|
||||
return;
|
||||
}
|
||||
if (ValidString(aas3username) == false) {
|
||||
alert("AAS3 Username is required.");
|
||||
return;
|
||||
}
|
||||
if (ValidString(aas3password) == false) {
|
||||
alert("AAS3 Password is required.");
|
||||
return;
|
||||
}
|
||||
Post("saveAAS", {
|
||||
aas1: {
|
||||
url: aas1URL,
|
||||
username: aas1username,
|
||||
password: aas1password
|
||||
},
|
||||
aas2: {
|
||||
url: aas2URL,
|
||||
username: aas2username,
|
||||
password: aas2password
|
||||
},
|
||||
aas3: {
|
||||
url: aas3URL,
|
||||
username: aas3username,
|
||||
password: aas3password
|
||||
}
|
||||
}, function (data) {
|
||||
alert(data.message);
|
||||
}, function (error) {
|
||||
alert(error)
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user