ComunicWeb/assets/js/pages/settings/sections/notifications.js

67 lines
2.3 KiB
JavaScript
Raw Permalink Normal View History

2021-04-10 17:42:03 +00:00
/**
* Notifications settings
*
* @author Pierre Hubert
*/
class NotificationsSettings {
static async Open(args, target) {
try {
// Get settings
const settings =await SettingsInterface.getNotifications();
// Load template
const tpl = await Page.loadHTMLTemplate("pages/settings/notifications/NotificationsSection.html");
const el = document.createElement("div")
el.innerHTML = tpl;
target.appendChild(el);
// Create new application
const VueApp = {
data() {
return {
allow_sounds: settings.allow_notifications_sound,
allow_conversations: settings.allow_conversations
};
},
methods: {
async update() {
try {
let newSettings = {
allow_notifications_sound: el.querySelector("input[name='allow_sounds']").checked,
allow_conversations: el.querySelector("input[name='allow_conversations']").checked
}
await SettingsInterface.setNotifications(newSettings);
2021-04-11 12:02:17 +00:00
// Apply new settings immediatly
NotificationsSong.enableSong = newSettings.allow_notifications_sound;
notify(tr("Successfully updated settings!"), "success")
} catch(e) {
console.error(e)
notify(tr("Failed to update settings!"), "danger")
}
}
}
}
Vue.createApp(VueApp).mount(el);
el.querySelectorAll("input[type='checkbox']").forEach(e => {
$(e).iCheck({
checkboxClass: 'icheckbox_flat-blue',
radioClass: 'iradio_flat-blue'
});
2021-04-10 17:42:03 +00:00
});
}
catch(e) {
console.error(e);
target.appendChild(ComunicWeb.common.messages.createCalloutElem(tr("Error"), tr("Failed to load notifications settings!"), "danger"))
}
2021-04-10 17:42:03 +00:00
}
}