const NotificationConfig = { is_notify_each_image: false, is_notify_all_done: true, obj_modal: null, init: () => { NotificationConfig._create_badge(); NotificationConfig._create_modal(); NotificationConfig._bind_events(); NotificationConfig._load_config(); }, _create_badge: () => { let obj_nav_right = document.querySelector("nav .d-flex.gap-2"); let obj_badge = document.createElement("button"); obj_badge.id = "btn_notification_config"; obj_badge.className = "btn btn-sm btn-outline-secondary"; obj_badge.title = "Notifications"; obj_badge.innerHTML = ''; let obj_blender_btn = document.getElementById("btn_blender_status"); if (obj_blender_btn) { obj_nav_right.insertBefore(obj_badge, obj_blender_btn.nextSibling); } else { obj_nav_right.insertBefore(obj_badge, obj_nav_right.firstChild); } obj_badge.addEventListener("click", () => { NotificationConfig._open_modal(); }); }, _create_modal: () => { let obj_modal_el = document.createElement("div"); obj_modal_el.id = "modal_notification_config"; obj_modal_el.className = "modal fade"; obj_modal_el.tabIndex = -1; obj_modal_el.innerHTML = ''; document.body.appendChild(obj_modal_el); NotificationConfig.obj_modal = new bootstrap.Modal(obj_modal_el); }, _bind_events: () => { let obj_btn_save = document.getElementById("btn_save_notification"); obj_btn_save.addEventListener("click", () => { NotificationConfig._save_config(); }); }, _open_modal: () => { document.getElementById("check_notify_each_image").checked = NotificationConfig.is_notify_each_image; document.getElementById("check_notify_all_done").checked = NotificationConfig.is_notify_all_done; NotificationConfig.obj_modal.show(); }, _load_config: () => { window.api.get_notification_config() .then((obj_config) => { if (obj_config) { NotificationConfig.is_notify_each_image = obj_config.is_notify_each_image || false; NotificationConfig.is_notify_all_done = obj_config.is_notify_all_done !== undefined ? obj_config.is_notify_all_done : true; NotificationConfig._update_badge(); } }) .catch(() => { // Config non trouvee, valeurs par defaut }); }, _save_config: () => { NotificationConfig.is_notify_each_image = document.getElementById("check_notify_each_image").checked; NotificationConfig.is_notify_all_done = document.getElementById("check_notify_all_done").checked; let obj_config = { is_notify_each_image: NotificationConfig.is_notify_each_image, is_notify_all_done: NotificationConfig.is_notify_all_done, }; window.api.set_notification_config(obj_config) .then(() => { NotificationConfig._update_badge(); NotificationConfig.obj_modal.hide(); ConsoleLog.add("Configuration notifications sauvegardee."); }) .catch((obj_err) => { ConsoleLog.add("Erreur sauvegarde notifications : " + obj_err.message); }); }, _update_badge: () => { let obj_badge = document.getElementById("btn_notification_config"); let is_any_active = NotificationConfig.is_notify_each_image || NotificationConfig.is_notify_all_done; if (is_any_active) { obj_badge.className = "btn btn-sm btn-outline-success"; obj_badge.title = "Notifications activees"; } else { obj_badge.className = "btn btn-sm btn-outline-secondary"; obj_badge.title = "Notifications desactivees"; } }, };