mirror of
https://github.com/pierre42100/ComunicWeb
synced 2024-11-24 13:09:20 +00:00
67 lines
2.3 KiB
JavaScript
67 lines
2.3 KiB
JavaScript
/**
|
|
* 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);
|
|
|
|
// 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'
|
|
});
|
|
});
|
|
|
|
}
|
|
catch(e) {
|
|
console.error(e);
|
|
target.appendChild(ComunicWeb.common.messages.createCalloutElem(tr("Error"), tr("Failed to load notifications settings!"), "danger"))
|
|
}
|
|
}
|
|
} |