v3.1
This commit is contained in:
@@ -2,16 +2,29 @@ document.addEventListener('DOMContentLoaded', async function () {
|
|||||||
await insertUsername();
|
await insertUsername();
|
||||||
setInterval(loadReceivedFiles, 3000); // Call loadReceivedFiles every 5000 ms (5 seconds)
|
setInterval(loadReceivedFiles, 3000); // Call loadReceivedFiles every 5000 ms (5 seconds)
|
||||||
|
|
||||||
const backupButton = document.getElementById('backup');
|
const backupButton = document.getElementById('backup_dir');
|
||||||
const shareButton = document.getElementById('share_dir');
|
const shareButton = document.getElementById('share_dir');
|
||||||
|
const departmentButton = document.getElementById('department_dir');
|
||||||
|
|
||||||
const manageDepartmentButton = document.getElementById('manage_department');
|
const changeDepartmentButton = document.getElementById('change_department');
|
||||||
const manageUsersButton = document.getElementById('manage_users');
|
|
||||||
const changeInfoButton = document.getElementById('change_info');
|
const changeInfoButton = document.getElementById('change_info');
|
||||||
const shareFileButton = document.getElementById('share_file');
|
const shareFileButton = document.getElementById('share_file');
|
||||||
const decryptButton = document.getElementById('decrypt');
|
const decryptButton = document.getElementById('decrypt');
|
||||||
const logoutButton = document.getElementById('logout');
|
const logoutButton = document.getElementById('logout');
|
||||||
|
|
||||||
|
const overlay = document.getElementById('overlay');
|
||||||
|
const ceoBackButton = document.getElementById('back_button');
|
||||||
|
const ceoSubmitButton = document.getElementById('submit_button');
|
||||||
|
|
||||||
|
let ip = '';
|
||||||
|
await window.electronAPI.readFile('ipConfig.json')
|
||||||
|
.then(result => {
|
||||||
|
const jsonData = JSON.parse(result.content);
|
||||||
|
ip = jsonData.ip;
|
||||||
|
})
|
||||||
|
|
||||||
|
let triggerSource = '';
|
||||||
|
|
||||||
async function loadReceivedFiles() {
|
async function loadReceivedFiles() {
|
||||||
const checkFileReceived = await window.electronAPI.checkFileExists('filesReceived.json');
|
const checkFileReceived = await window.electronAPI.checkFileExists('filesReceived.json');
|
||||||
if (!checkFileReceived) {
|
if (!checkFileReceived) {
|
||||||
@@ -59,6 +72,45 @@ document.addEventListener('DOMContentLoaded', async function () {
|
|||||||
.catch(error => console.error('Error removing path:', error));
|
.catch(error => console.error('Error removing path:', error));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function handleOverlayOpen(buttonId) {
|
||||||
|
overlay.style.display = 'block';
|
||||||
|
triggerSource = buttonId; // Remember the button that triggered the overlay
|
||||||
|
console.log(`${buttonId} button clicked!`);
|
||||||
|
}
|
||||||
|
|
||||||
|
ceoBackButton.addEventListener('click', function () {
|
||||||
|
overlay.style.display = 'none';
|
||||||
|
});
|
||||||
|
|
||||||
|
ceoSubmitButton.addEventListener('click', async function (event) {
|
||||||
|
event.preventDefault();
|
||||||
|
const password = document.getElementById('ceo_password').value;
|
||||||
|
|
||||||
|
await fetch(`http://${ip}/users/validate_ceo_password`, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
'x-api-key': 'uc_api',
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
|
password: password
|
||||||
|
})
|
||||||
|
}).then(async result => {
|
||||||
|
const data = await result.json();
|
||||||
|
if (!result.ok) {
|
||||||
|
throw new Error(data.message);
|
||||||
|
}
|
||||||
|
if (triggerSource === 'change_department') {
|
||||||
|
fadeOut('change_department.html');
|
||||||
|
} else if (triggerSource === 'decrypt') {
|
||||||
|
console.log('astept decryptarea')
|
||||||
|
fadeOut('decrypting_backup.html');
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
overlay.style.display = 'none';
|
||||||
|
triggerSource = '';
|
||||||
|
});
|
||||||
|
|
||||||
checkDirBackupFileExists()
|
checkDirBackupFileExists()
|
||||||
.then(() => console.log('verificare backupDir facuta'));
|
.then(() => console.log('verificare backupDir facuta'));
|
||||||
@@ -66,6 +118,9 @@ document.addEventListener('DOMContentLoaded', async function () {
|
|||||||
checkShareDirFileExists()
|
checkShareDirFileExists()
|
||||||
.then(() => console.log('verificare ShareDir facuta'));
|
.then(() => console.log('verificare ShareDir facuta'));
|
||||||
|
|
||||||
|
checkDepartmentDirFileExists()
|
||||||
|
.then(() => {console.log('verificare departmentDir facuta')})
|
||||||
|
|
||||||
backupButton.addEventListener('click', function () {
|
backupButton.addEventListener('click', function () {
|
||||||
console.log('Set backup directory button clicked!');
|
console.log('Set backup directory button clicked!');
|
||||||
|
|
||||||
@@ -80,14 +135,20 @@ document.addEventListener('DOMContentLoaded', async function () {
|
|||||||
console.log('Set backup directory button clicked!');
|
console.log('Set backup directory button clicked!');
|
||||||
|
|
||||||
window.electronAPI.openJsonDirConfigDialog('dirShare.json')
|
window.electronAPI.openJsonDirConfigDialog('dirShare.json')
|
||||||
.then(() => console.log('Back-up directory set'))
|
.then(() => console.log('Share directory set'))
|
||||||
.catch(async error => await window.electronAPI.showAlert(error.message)
|
.catch(async error => await window.electronAPI.showAlert(error.message)
|
||||||
.then(() => console.log('Alert window opened'))
|
.then(() => console.log('Alert window opened'))
|
||||||
.catch(error => console.error('Error showing alert:', error)));
|
.catch(error => console.error('Error showing alert:', error)));
|
||||||
});
|
});
|
||||||
|
|
||||||
manageUsersButton.addEventListener('click', async function(){
|
departmentButton.addEventListener('click', function () {
|
||||||
fadeOut('manage_users.html');
|
console.log('Set backup directory button clicked!');
|
||||||
|
|
||||||
|
window.electronAPI.openJsonDirConfigDialog('dirDepartment.json')
|
||||||
|
.then(() => console.log('Department directory set'))
|
||||||
|
.catch(async error => await window.electronAPI.showAlert(error.message)
|
||||||
|
.then(() => console.log('Alert window opened'))
|
||||||
|
.catch(error => console.error('Error showing alert:', error)));
|
||||||
});
|
});
|
||||||
|
|
||||||
changeInfoButton.addEventListener('click', function () {
|
changeInfoButton.addEventListener('click', function () {
|
||||||
@@ -95,13 +156,12 @@ document.addEventListener('DOMContentLoaded', async function () {
|
|||||||
fadeOut('profile.html');
|
fadeOut('profile.html');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
changeDepartmentButton.addEventListener('click', function () {
|
||||||
|
handleOverlayOpen('change_department');
|
||||||
|
});
|
||||||
|
|
||||||
decryptButton.addEventListener('click', function () {
|
decryptButton.addEventListener('click', function () {
|
||||||
fadeOut('decrypting_backup.html');
|
handleOverlayOpen('decrypt');
|
||||||
});
|
|
||||||
|
|
||||||
changeInfoButton.addEventListener('click', function () {
|
|
||||||
console.log('Change your info button clicked!');
|
|
||||||
fadeOut('profile.html');
|
|
||||||
});
|
});
|
||||||
|
|
||||||
shareFileButton.addEventListener('click', function () {
|
shareFileButton.addEventListener('click', function () {
|
||||||
@@ -109,10 +169,6 @@ document.addEventListener('DOMContentLoaded', async function () {
|
|||||||
fadeOut('share_file.html');
|
fadeOut('share_file.html');
|
||||||
});
|
});
|
||||||
|
|
||||||
manageDepartmentButton.addEventListener('click', function() {
|
|
||||||
fadeOut('manage_departments.html');
|
|
||||||
})
|
|
||||||
|
|
||||||
logoutButton.addEventListener('click', async function () {
|
logoutButton.addEventListener('click', async function () {
|
||||||
console.log('Logout button clicked!');
|
console.log('Logout button clicked!');
|
||||||
await window.electronAPI.killBeforeLogout();
|
await window.electronAPI.killBeforeLogout();
|
||||||
@@ -120,9 +176,6 @@ document.addEventListener('DOMContentLoaded', async function () {
|
|||||||
fadeOut('login.html');
|
fadeOut('login.html');
|
||||||
});
|
});
|
||||||
|
|
||||||
decryptButton.addEventListener('click', async function (){
|
|
||||||
|
|
||||||
});
|
|
||||||
async function checkDirBackupFileExists() {
|
async function checkDirBackupFileExists() {
|
||||||
try {
|
try {
|
||||||
// Make an IPC call to check file existence
|
// Make an IPC call to check file existence
|
||||||
@@ -149,7 +202,7 @@ document.addEventListener('DOMContentLoaded', async function () {
|
|||||||
if (!fileExists) {
|
if (!fileExists) {
|
||||||
const notificationsDiv = document.getElementById('notifications');
|
const notificationsDiv = document.getElementById('notifications');
|
||||||
const button = document.createElement('button');
|
const button = document.createElement('button');
|
||||||
button.id = 'share_file_alert';
|
button.id = 'share_dir_alert';
|
||||||
button.name = 'alert';
|
button.name = 'alert';
|
||||||
button.textContent = 'Set your share directory!';
|
button.textContent = 'Set your share directory!';
|
||||||
button.addEventListener('click', handleShareButtonPressed);
|
button.addEventListener('click', handleShareButtonPressed);
|
||||||
@@ -160,6 +213,24 @@ document.addEventListener('DOMContentLoaded', async function () {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function checkDepartmentDirFileExists() {
|
||||||
|
try {
|
||||||
|
const fileExists = await window.electronAPI.checkFileExists('dirDepartment.json');
|
||||||
|
|
||||||
|
if (!fileExists) {
|
||||||
|
const notificationsDiv = document.getElementById('notifications');
|
||||||
|
const button = document.createElement('button');
|
||||||
|
button.id = 'department_dir_alert';
|
||||||
|
button.name = 'alert';
|
||||||
|
button.textContent = 'Set your department directory!';
|
||||||
|
button.addEventListener('click', handleDepartmentButtonPressed);
|
||||||
|
notificationsDiv.appendChild(button);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error checking file existence:', error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function handleBackupButtonPressed() {
|
async function handleBackupButtonPressed() {
|
||||||
console.log('Button clicked!');
|
console.log('Button clicked!');
|
||||||
|
|
||||||
@@ -182,7 +253,20 @@ document.addEventListener('DOMContentLoaded', async function () {
|
|||||||
.then(() => console.log('Alert window opened'))
|
.then(() => console.log('Alert window opened'))
|
||||||
.catch(error => console.error('Error showing alert:', error)));
|
.catch(error => console.error('Error showing alert:', error)));
|
||||||
|
|
||||||
const button = document.getElementById('share_alert');
|
const button = document.getElementById('share_dir_alert');
|
||||||
|
button.remove();
|
||||||
|
}
|
||||||
|
|
||||||
|
async function handleDepartmentButtonPressed() {
|
||||||
|
console.log('Button clicked!');
|
||||||
|
|
||||||
|
await window.electronAPI.openJsonDirConfigDialog('dirDepartment.json')
|
||||||
|
.then(() => console.log('Department directory set'))
|
||||||
|
.catch(async error => await window.electronAPI.showAlert(error.message)
|
||||||
|
.then(() => console.log('Alert window opened'))
|
||||||
|
.catch(error => console.error('Error showing alert:', error)));
|
||||||
|
|
||||||
|
const button = document.getElementById('department_dir_alert');
|
||||||
button.remove();
|
button.remove();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -202,4 +286,4 @@ document.addEventListener('DOMContentLoaded', async function () {
|
|||||||
usernameField.textContent = 'User!';
|
usernameField.textContent = 'User!';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
Reference in New Issue
Block a user