mirror of
				https://github.com/pierre42100/ComunicWeb
				synced 2025-11-04 04:04:20 +00:00 
			
		
		
		
	Send a request to update notifications settings
This commit is contained in:
		@@ -6,17 +6,59 @@
 | 
			
		||||
 | 
			
		||||
class NotificationsSettings {
 | 
			
		||||
    static async Open(args, target) {
 | 
			
		||||
        // Load template
 | 
			
		||||
		const tpl = await Page.loadHTMLTemplate("pages/settings/notifications/NotificationsSection.html");
 | 
			
		||||
		const el = document.createElement("div")
 | 
			
		||||
		el.innerHTML = tpl;
 | 
			
		||||
		target.appendChild(el);
 | 
			
		||||
 | 
			
		||||
        el.querySelectorAll("input[type='checkbox']").forEach(e => {
 | 
			
		||||
            $(e).iCheck({
 | 
			
		||||
                checkboxClass: 'icheckbox_flat-blue',
 | 
			
		||||
                  radioClass: 'iradio_flat-blue'
 | 
			
		||||
        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);
 | 
			
		||||
 | 
			
		||||
                            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"))
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user