mirror of
https://github.com/pierre42100/ComunicWeb
synced 2024-11-26 05:49:22 +00:00
Send a request to update notifications settings
This commit is contained in:
parent
5373eac5df
commit
8f8fd3151c
@ -213,6 +213,24 @@ const SettingsInterface = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
await api("settings/set_data_conservation_policy", data, true)
|
await api("settings/set_data_conservation_policy", data, true)
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get notifications settings
|
||||||
|
*
|
||||||
|
* @returns {Promise<NotificationsSettings>}
|
||||||
|
*/
|
||||||
|
getNotifications: async function() {
|
||||||
|
return await api("settings/get_notifications", null, true);
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update (set) notifications settings
|
||||||
|
*
|
||||||
|
* @param {NotificationsSettings} settings
|
||||||
|
*/
|
||||||
|
setNotifications: async function(settings) {
|
||||||
|
return await api("settings/set_notifications", settings, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,17 +6,59 @@
|
|||||||
|
|
||||||
class NotificationsSettings {
|
class NotificationsSettings {
|
||||||
static async Open(args, target) {
|
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 => {
|
try {
|
||||||
$(e).iCheck({
|
// Get settings
|
||||||
checkboxClass: 'icheckbox_flat-blue',
|
const settings =await SettingsInterface.getNotifications();
|
||||||
radioClass: 'iradio_flat-blue'
|
|
||||||
|
// 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"))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
5
assets/js/typings/Settings.d.ts
vendored
5
assets/js/typings/Settings.d.ts
vendored
@ -4,6 +4,11 @@
|
|||||||
* @author Pierre Hubert
|
* @author Pierre Hubert
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
declare interface NotificationsSettings {
|
||||||
|
allow_conversations: boolean,
|
||||||
|
allow_notifications_sound: boolean,
|
||||||
|
}
|
||||||
|
|
||||||
declare interface DataConservationPolicy {
|
declare interface DataConservationPolicy {
|
||||||
inactive_account_lifetime?: number,
|
inactive_account_lifetime?: number,
|
||||||
notification_lifetime?: number,
|
notification_lifetime?: number,
|
||||||
|
@ -9,16 +9,19 @@
|
|||||||
<!-- form start -->
|
<!-- form start -->
|
||||||
|
|
||||||
<div class="box-body">
|
<div class="box-body">
|
||||||
|
|
||||||
|
<p>tr("Note: These parameters applies only for the web version of the application!")</p>
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label>
|
<label>
|
||||||
<input type="checkbox"> tr("Allow sound for notifications")
|
<input name="allow_sounds" type="checkbox" v-model="allow_sounds"> tr("Allow sound for notifications")
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<!-- /.box-body -->
|
<!-- /.box-body -->
|
||||||
|
|
||||||
<div class="box-footer">
|
<div class="box-footer">
|
||||||
<button type="submit" class="btn btn-primary">tr("Update")</button>
|
<button type="submit" class="btn btn-primary" @click="update">tr("Update")</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -36,13 +39,13 @@
|
|||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label>
|
<label>
|
||||||
<input type="checkbox"> tr("Allow conversation notifications")
|
<input name="allow_conversations" type="checkbox" v-model="allow_conversations"> tr("Allow conversation notifications")
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<!-- /.box-body -->
|
<!-- /.box-body -->
|
||||||
|
|
||||||
<div class="box-footer">
|
<div class="box-footer">
|
||||||
<button type="submit" class="btn btn-primary">tr("Update")</button>
|
<button type="submit" class="btn btn-primary" @click="update">tr("Update")</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
Loading…
Reference in New Issue
Block a user