}
}
+ // Loads field regex's into the scope for field validation.
+ function inject_field_patterns() {
+ $scope.patterns = {au : {}, aua : {}, ac : {}};
+
+ if ($scope.org_settings['opac.username_regex']) {
+ $scope.patterns.au.usrname =
+ new RegExp($scope.org_settings['opac.username_regex']);
+ }
+
+ if ($scope.org_settings['opac.barcode_regex']) {
+ $scope.patterns.ac.barcode =
+ new RegExp($scope.org_settings['opac.barcode_regex']);
+ }
+
+ if ($scope.org_settings['global.password_regex']) {
+ $scope.patterns.au.passwd =
+ new RegExp($scope.org_settings['global.password_regex']);
+ }
+
+ console.log($scope.patterns.au.passwd);
+
+ if ($scope.org_settings['ui.patron.edit.phone.regex']) {
+ // apply generic phone regex first, replace below as needed.
+
+ $scope.patterns.au.day_phone =
+ new RegExp($scope.org_settings['ui.patron.edit.phone.regex']);
+ $scope.patterns.au.evening_phone =
+ new RegExp($scope.org_settings['ui.patron.edit.phone.regex']);
+ $scope.patterns.au.other_phone =
+ new RegExp($scope.org_settings['ui.patron.edit.phone.regex']);
+ }
+
+ // the remaining patterns fit a well-known key name pattern
+
+ angular.forEach($scope.org_settings, function(val, key) {
+ if (!val) return;
+ var parts = key.match(/ui.patron.edit\.(\w+)\.(\w+)\.regex/);
+ if (!parts) return;
+ var cls = parts[1];
+ var name = parts[2];
+ $scope.patterns[cls][name] = new RegExp(val);
+ });
+ }
+
$q.all([
$scope.initTab ? // initTab comes from patron app
set_new_patron_defaults(prs);
$scope.page_data_loaded = true;
+
+ inject_field_patterns();
});
// update the currently displayed field documentation
// The alternative is ng-change, but it's called with each character
// typed, which would be overkill for many of the actions called here.
$scope.handle_field_changed = function(obj, field_name) {
-
var cls = obj.classname; // set by egIdl
var value = obj[field_name];
console.log('changing field ' + field_name + ' to ' + value);
- console.log($scope.reg_form.usrname.$error);
-
- if (field_name == 'usrname') {
- console.log('invalid : ' + $scope.field_is_invalid('usrname'));
- }
-
switch (field_name) {
case 'day_phone' :
if ($scope.patron.day_phone &&
$scope.field_modified();
}
+ // Returns true if a required field has no value or a field's
+ // value does not match its configured regex pattern.
// Tests angular's form field validation toggles.
$scope.field_is_invalid = function(field_name) {
- console.log('err: ' + field_name + ' : '
- + $scope.reg_form[field_name].$error.required);
- return
- $scope.reg_form[field_name].$error.required ||
- !$scope.reg_form[field_name].$error.valid;
+ return (
+ $scope.reg_form[field_name].$error.required === true
+ ||
+ // valid will be undefined if no pattern is set.
+ $scope.reg_form[field_name].$error.valid === false
+ );
}