From c81fc2bfc765a37380e3f1a5b0569321f88389a0 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Mon, 28 Mar 2016 15:22:52 -0400 Subject: [PATCH] LP#1564685 Alert and stop on invalid fields Display an alert message and prevent save or save+clone when invalid values exist in the patron edit form. Signed-off-by: Bill Erickson Signed-off-by: Kathy Lussier Signed-off-by: Galen Charlton --- Open-ILS/src/templates/staff/circ/patron/index.tt2 | 2 ++ .../src/templates/staff/circ/patron/register.tt2 | 2 ++ .../web/js/ui/default/staff/circ/patron/regctl.js | 31 ++++++++++++++-------- 3 files changed, 24 insertions(+), 11 deletions(-) diff --git a/Open-ILS/src/templates/staff/circ/patron/index.tt2 b/Open-ILS/src/templates/staff/circ/patron/index.tt2 index df0cea5335..85b8866cf2 100644 --- a/Open-ILS/src/templates/staff/circ/patron/index.tt2 +++ b/Open-ILS/src/templates/staff/circ/patron/index.tt2 @@ -44,6 +44,8 @@ angular.module('egCoreMod').run(['egStrings', function(s) { s.RENEW_ITEMS = "[% l('Renew Items?') %]"; s.RENEW_ALL_ITEMS = "[% l('Renew All Items?') %]"; s.CHECK_IN_CONFIRM = "[% l('Check In Items?') %]"; + s.REG_INVALID_FIELDS = + "[% l('Please enter valid values for all required fields.') %]" }]); diff --git a/Open-ILS/src/templates/staff/circ/patron/register.tt2 b/Open-ILS/src/templates/staff/circ/patron/register.tt2 index 81b42790cf..3eac3ef7fe 100644 --- a/Open-ILS/src/templates/staff/circ/patron/register.tt2 +++ b/Open-ILS/src/templates/staff/circ/patron/register.tt2 @@ -12,6 +12,8 @@ diff --git a/Open-ILS/web/js/ui/default/staff/circ/patron/regctl.js b/Open-ILS/web/js/ui/default/staff/circ/patron/regctl.js index da7cfeda19..534bda5f2d 100644 --- a/Open-ILS/web/js/ui/default/staff/circ/patron/regctl.js +++ b/Open-ILS/web/js/ui/default/staff/circ/patron/regctl.js @@ -1047,8 +1047,8 @@ angular.module('egCoreMod') }]); -function PatronRegCtrl($scope, $routeParams, - $q, $modal, $window, egCore, patronSvc, patronRegSvc, egUnloadPrompt) { +function PatronRegCtrl($scope, $routeParams, $q, $modal, $window, egCore, + patronSvc, patronRegSvc, egUnloadPrompt, egAlertDialog) { $scope.page_data_loaded = false; $scope.clone_id = patronRegSvc.clone_id = $routeParams.clone_id; @@ -1669,27 +1669,36 @@ function PatronRegCtrl($scope, $routeParams, ); } + // Returns true if the Save and Save & Clone buttons should be disabled. + $scope.edit_passthru.hide_save_actions = function() { + return $scope.patron.isnew ? + !$scope.perms.CREATE_USER : + !$scope.perms.UPDATE_USER; + } + // Returns true if any input elements are tagged as invalid - $scope.edit_passthru.has_invalid_fields = function() { + // via Angular patterns or required attributes. + function form_has_invalid_fields() { return $('#patron-reg-container .ng-invalid').length > 0; } - // Returns true if the Save and Save & Clone buttons should be disabled. - $scope.edit_passthru.hide_save_actions = function() { - var can_save = $scope.patron.isnew ? - $scope.perms.CREATE_USER : $scope.perms.UPDATE_USER; - + function form_is_incomplete() { return ( - !can_save || $scope.dupe_username || $scope.dupe_barcode || - $scope.edit_passthru.has_invalid_fields() + form_has_invalid_fields() ); + } $scope.edit_passthru.save = function(save_args) { if (!save_args) save_args = {}; + if (form_is_incomplete()) { + // User has not provided valid values for all required fields. + return egAlertDialog.open(egCore.strings.REG_INVALID_FIELDS); + } + // remove page unload warning prompt egUnloadPrompt.clear(); @@ -1758,5 +1767,5 @@ function PatronRegCtrl($scope, $routeParams, // This controller may be loaded from different modules (patron edit vs. // register new patron), so we have to inject the controller params manually. PatronRegCtrl.$inject = ['$scope', '$routeParams', '$q', '$modal', - '$window', 'egCore', 'patronSvc', 'patronRegSvc', 'egUnloadPrompt']; + '$window', 'egCore', 'patronSvc', 'patronRegSvc', 'egUnloadPrompt', 'egAlertDialog']; -- 2.11.0