diff --git a/client/js/controllers/user_controller.js b/client/js/controllers/user_controller.js index 20f8c99..7c34eb8 100644 --- a/client/js/controllers/user_controller.js +++ b/client/js/controllers/user_controller.js @@ -2,6 +2,7 @@ const router = require('../router.js'); const api = require('../api.js'); +const misc = require('../util/misc.js'); const config = require('../config.js'); const views = require('../util/views.js'); const User = require('../models/user.js'); @@ -51,6 +52,7 @@ class UserController { canDelete: api.hasPrivilege(`users:delete:${infix}`), ranks: ranks, }); + this._view.addEventListener('change', e => this._evtChange(e)); this._view.addEventListener('submit', e => this._evtUpdate(e)); this._view.addEventListener('delete', e => this._evtDelete(e)); }, errorMessage => { @@ -59,7 +61,12 @@ class UserController { }); } + _evtChange(e) { + misc.enableExitConfirmation(); + } + _evtSaved(e) { + misc.disableExitConfirmation(); if (this._name !== e.detail.user.name) { router.replace( '/user/' + e.detail.user.name + '/edit', null, false); diff --git a/client/js/views/user_edit_view.js b/client/js/views/user_edit_view.js index 0e07df3..078a292 100644 --- a/client/js/views/user_edit_view.js +++ b/client/js/views/user_edit_view.js @@ -30,6 +30,13 @@ class UserEditView extends events.EventTarget { }); } + for (let node of this._formNode.querySelectorAll('input, select')) { + node.addEventListener( + 'change', e => { + this.dispatchEvent(new CustomEvent('change')); + }); + } + this._formNode.addEventListener('submit', e => this._evtSubmit(e)); } diff --git a/client/js/views/user_view.js b/client/js/views/user_view.js index 5ef03dc..fbef9a7 100644 --- a/client/js/views/user_view.js +++ b/client/js/views/user_view.js @@ -48,6 +48,7 @@ class UserView extends events.EventTarget { this._view = new UserSummaryView(ctx); } + events.proxyEvent(this._view, this, 'change'); views.syncScrollPosition(); }