diff --git a/ucs-school-umc-users/umc/js/schoolusers.js b/ucs-school-umc-users/umc/js/schoolusers.js index 6ebdb4e..73b6dbb 100644 --- a/ucs-school-umc-users/umc/js/schoolusers.js +++ b/ucs-school-umc-users/umc/js/schoolusers.js @@ -34,6 +34,7 @@ define([ "dojo/_base/array", "dojo/date/locale", "dojo/Deferred", + "dojo/on", "dijit/Dialog", "dojox/html/entities", "umc/dialog", @@ -51,7 +52,7 @@ define([ "umc/widgets/ProgressInfo", "umc/widgets/SearchForm", "umc/i18n!umc/modules/schoolusers" -], function(declare, lang, array, locale, Deferred, Dialog, entities, dialog, tools, Module, +], function(declare, lang, array, locale, Deferred, on, Dialog, entities, dialog, tools, Module, Grid, Page, Form, SearchBox, TextBox, ComboBox, CheckBox, Text, ContainerWidget, ProgressInfo, SearchForm, _) { return declare("umc.modules.schoolusers", [ Module ], { @@ -59,6 +60,9 @@ define([ _grid: null, _searchPage: null, _progressInfo: null, + _autosearch_on_change: false, + _classChangeHandler: null, + _classValuesLoadedHandler: null, uninitialize: function() { this.inherited(arguments); @@ -175,9 +179,12 @@ define([ this._searchPage.startup(); - tools.ucr(['ucsschool/passwordreset/autosearch', 'ucsschool/passwordreset/password-change-on-next-login', 'ucsschool/passwordreset/force-password-change-on-next-login']).then(lang.hitch(this, function(ucr) { + this._setupEventHandlers(); + + tools.ucr(['ucsschool/passwordreset/autosearch', 'ucsschool/passwordreset/autosearch_on_change', 'ucsschool/passwordreset/password-change-on-next-login', 'ucsschool/passwordreset/force-password-change-on-next-login']).then(lang.hitch(this, function(ucr) { this.changeOnNextLogin = tools.isTrue(ucr['ucsschool/passwordreset/password-change-on-next-login'] || true); this.changeOnNextLoginDisabled = tools.isTrue(ucr['ucsschool/passwordreset/force-password-change-on-next-login'] || false); + this._autosearch_on_change = tools.isTrue(ucr['ucsschool/passwordreset/autosearch_on_change'] || false); if (tools.isTrue(ucr['ucsschool/passwordreset/autosearch'] || true)) { this._searchForm.ready().then(lang.hitch(this, function() { this._grid.filter(this._searchForm.get('value')); @@ -213,6 +220,7 @@ define([ _content.addChild(new Text({ content: message })); dialog.alert(_content); } + this._searchForm.submit(); // Bug 45601 Comment #6 }); var _set_passwords = lang.hitch(this, function(password, nextLogin) { @@ -296,6 +304,47 @@ define([ 'class': 'umcPopup' } ); _dialog.show(); + }, + + // This construct results from the dependency between class data and chosen school. There was no solution found yet to solve this in a more clean way. + _setupEventHandlers() { + this._searchForm.ready().then(lang.hitch(this, function() { + this._classChangeHandler = on.pausable(this._searchForm.getWidget("class"), "change", lang.hitch(this, function(e) { + if (this._autosearch_on_change) { + this._searchForm.submit(); + } + })); + this._classChangeHandler.pause(); // Has to be paused to prevent redundant query on page load (event gets already fired). + // Unpauses the classChangeHandler after first firing of change event on class + on.once(this._searchForm.getWidget("class"), "change", lang.hitch(this, function(e) { + if (this._classChangeHandler) { + this._classChangeHandler.resume(); + } + })); + this._classValuesLoadedHandler = on.pausable(this._searchForm.getWidget("class"), "ValuesLoaded", lang.hitch(this, function(e) { + if (this._autosearch_on_change) { + this._searchForm.submit(); + this._classChangeHandler.resume(); // Has to be paused to prevent redundant query on page load (event gets already fired). + } + })) + this._classValuesLoadedHandler.pause(); + on(this._searchForm.getWidget("school"), "change", lang.hitch(this, function(e) { + if (this._searchForm.getWidget("class").get("value") !== "None") { + this._searchForm._widgets.class.setInitialValue("None"); // Workaround/Hack: Otherwise it will be the invalid value "" + } + if(this._autosearch_on_change) { + if (this._classChangeHandler) { + this._classChangeHandler.pause(); + } + } + })); + // Resumes classValuesLoaded handler after first schoolChange event + on.once(this._searchForm.getWidget("school"), "change", lang.hitch(this, function(e) { + if (this._classValuesLoadedHandler) { + this._classValuesLoadedHandler.resume(); + } + })); + })) } });