SymphonyElectron/js/notify/settings/configure-notification-position-preload.js
Vishwas Shashidhar a26a1d609c
ELECTRON-519: support Japanese localization for menus, dialogs and windows (#401)
- add basic localisation implementation for menu items
- add more strings to support localisation on menus
- add more strings to support localisation on menus
- add all menu items for localisation
- refactor i18n code
- Add localization for screen picker, basic auth and notification settings child windows
- Add localization bridge
- add i18n support to more strings
- update translations
- add events to change language and redo menu template
- move config update logic to windowMgr
- fix linting issues and refactor
- add snipping tool messages
2018-06-19 20:26:04 +05:30

100 lines
2.9 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');
});
});
}
/**
* Updates the configuration and closes the 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);
});
}
});
ipc.on('i18n-notification-settings', (event, content) => {
if (content && typeof content === 'object') {
const i18nNodes = document.querySelectorAll('[data-i18n-text]');
for (let node of i18nNodes) {
if (node.attributes['data-i18n-text'] && node.attributes['data-i18n-text'].value) {
node.innerText = content[node.attributes['data-i18n-text'].value] || node.attributes['data-i18n-text'].value;
}
}
}
});