SymphonyElectron/js/notify/settings/configure-notification-position-preload.js
Kiran Niranjan 2b6ec2aeb8 Electron-43 (Configure Notification Position) (#142)
* ELECTRON-43 - Implemented Alert settings functionality

* ELECTRON-43
1. Added multiple monitor support for notifications in windows
2. Implemented a settings window to change notification position
3. Completed implementing configure alert position window

* ELECTRON-43 - Refactored code and changed config data

* ELECTRON-43
1. Refactored the code
2. Added modal property to browser window

* ELECTRON-43
1. Resolved conflicts
2. Made config default display value to null
3. Renamed api method from 'showAlertSettings' to 'showNotificationSettings' for consistency
4. Fixed some bugs
2017-06-16 15:29:56 -07:00

83 lines
2.4 KiB
JavaScript

'use strict';
const electron = require('electron');
const ipc = electron.ipcRenderer;
let availableScreens;
let selectedPosition;
let selectedDisplay;
renderSettings();
// Method that renders the data from user config
function renderSettings() {
document.addEventListener('DOMContentLoaded', function () {
let okButton = document.getElementById('ok-button');
let cancel = document.getElementById('cancel');
okButton.addEventListener('click', function () {
selectedPosition = document.querySelector('input[name="position"]:checked').value;
let selector = document.getElementById('screen-selector');
selectedDisplay = selector.options[selector.selectedIndex].value;
// update the user selected data and close the window
updateAndClose();
});
cancel.addEventListener('click', function () {
ipc.send('close-alert');
});
});
}
function updateAndClose() {
ipc.send('update-config', {position: selectedPosition, display: selectedDisplay});
ipc.send('close-alert');
}
ipc.on('notificationSettings', (event, args) => {
// update position from user config
if (args && args.position) {
document.getElementById(args.position).checked = true;
}
// update selected display from user config
if (args && args.display) {
if (availableScreens) {
let index = availableScreens.findIndex((item) => {
let id = item.id.toString();
return id === args.display;
});
if (index !== -1){
let option = document.getElementById(availableScreens[index].id);
if (option){
option.selected = true;
}
}
}
}
});
ipc.on('screens', (event, screens) => {
availableScreens = screens;
let screenSelector = document.getElementById('screen-selector');
if (screenSelector && screens){
// clearing the previously added content to
// make sure the content is not repeated
screenSelector.innerHTML = '';
screens.forEach((scr, index) => {
let option = document.createElement('option');
option.value = scr.id;
option.id = scr.id;
option.innerHTML = index + 1;
screenSelector.appendChild(option);
});
}
});