Revert the auth/ldap dropdowns if saving unsaved changes is not successful

This commit is contained in:
mabashian
2018-07-18 12:35:32 -04:00
parent 0e663f3967
commit 53c9987663
2 changed files with 29 additions and 4 deletions

View File

@@ -81,7 +81,8 @@ export default [
return authVm.dropdownValue; return authVm.dropdownValue;
}; };
var activeForm = function() {
const activeForm = function(revertDropdown) {
if(!_.get($scope.$parent, [formTracker.currentFormName(), '$dirty'])) { if(!_.get($scope.$parent, [formTracker.currentFormName(), '$dirty'])) {
authVm.activeAuthForm = getActiveAuthForm(); authVm.activeAuthForm = getActiveAuthForm();
formTracker.setCurrentAuth(authVm.activeAuthForm); formTracker.setCurrentAuth(authVm.activeAuthForm);
@@ -113,6 +114,9 @@ export default [
}).catch(() => { }).catch(() => {
event.preventDefault(); event.preventDefault();
$('#FormModal-dialog').dialog('close'); $('#FormModal-dialog').dialog('close');
if (revertDropdown) {
revertDropdown();
}
}); });
}, },
"class": "btn btn-primary", "class": "btn btn-primary",
@@ -124,6 +128,26 @@ export default [
authVm.ldapSelected = (authVm.activeAuthForm.indexOf('ldap') !== -1); authVm.ldapSelected = (authVm.activeAuthForm.indexOf('ldap') !== -1);
}; };
const changeAuthDropdown = (previousVal) => {
activeForm(() => {
authVm.dropdownValue = previousVal;
CreateSelect2({
element: '#configure-dropdown-nav',
multiple: false,
});
});
};
const changeLdapDropdown = (previousVal) => {
activeForm(() => {
authVm.ldapDropdownValue = previousVal;
CreateSelect2({
element: '#configure-ldap-dropdown',
multiple: false,
});
});
};
var dropdownOptions = [ var dropdownOptions = [
{label: i18n._('Azure AD'), value: 'azure'}, {label: i18n._('Azure AD'), value: 'azure'},
{label: i18n._('GitHub'), value: 'github'}, {label: i18n._('GitHub'), value: 'github'},
@@ -412,7 +436,8 @@ export default [
angular.extend(authVm, { angular.extend(authVm, {
activeForm: activeForm, changeAuthDropdown: changeAuthDropdown,
changeLdapDropdown: changeLdapDropdown,
activeAuthForm: activeAuthForm, activeAuthForm: activeAuthForm,
authForms: authForms, authForms: authForms,
dropdownOptions: dropdownOptions, dropdownOptions: dropdownOptions,

View File

@@ -8,7 +8,7 @@
class="form-control" class="form-control"
ng-model="authVm.dropdownValue" ng-model="authVm.dropdownValue"
ng-options="opt.value as opt.label for opt in authVm.dropdownOptions" ng-options="opt.value as opt.label for opt in authVm.dropdownOptions"
ng-change="authVm.activeForm()"> ng-change="authVm.changeAuthDropdown('{{authVm.dropdownValue}}')">
</select> </select>
</div> </div>
</div> </div>
@@ -21,7 +21,7 @@
class="form-control" class="form-control"
ng-model="authVm.ldapDropdownValue" ng-model="authVm.ldapDropdownValue"
ng-options="opt.value as opt.label for opt in authVm.ldapDropdownOptions" ng-options="opt.value as opt.label for opt in authVm.ldapDropdownOptions"
ng-change="authVm.activeForm()"> ng-change="authVm.changeLdapDropdown('{{authVm.ldapDropdownValue}}')">
</select> </select>
</div> </div>
</div> </div>