From 47bfda2570939d9560e1c3aac330feb1e2e735d5 Mon Sep 17 00:00:00 2001 From: Thomas Berezansky Date: Tue, 31 Jan 2012 16:50:21 -0500 Subject: [PATCH] Add registration/edit time barcode restrictions In the quest to not let staff put bad data into the system (losing battle, but hey, gotta keep trying, right?), add a barcode regex specifically for patron registration. This intentionally does *not* check the opac "is this a barcode?" value. Use cases for not checking that value include, but are not limited to: Special "barcodes" for staff accounts. Specific OUs may have a barcode regex of ".*" to ensure they can use anything for these accounts. Different prefixes per library - To prevent libraries from using another library's prefix, but still detect all of them as barcodes. Special case "this is a barcode" checks for the opac, like legacy barcodes that should no longer be assigned to new patrons, or on edits. Signed-off-by: Thomas Berezansky Signed-off-by: Pasi Kallinen Signed-off-by: Ben Shum --- Open-ILS/src/sql/Pg/950.data.seed-values.sql | 9 +++++++++ .../Pg/upgrade/XXXX.check_barcode_regex.sql | 10 ++++++++++ .../web/js/ui/default/actor/user/register.js | 19 +++++++++++++++++++ 3 files changed, 38 insertions(+) create mode 100644 Open-ILS/src/sql/Pg/upgrade/XXXX.check_barcode_regex.sql diff --git a/Open-ILS/src/sql/Pg/950.data.seed-values.sql b/Open-ILS/src/sql/Pg/950.data.seed-values.sql index d181ff4f1c..fec8adbc08 100644 --- a/Open-ILS/src/sql/Pg/950.data.seed-values.sql +++ b/Open-ILS/src/sql/Pg/950.data.seed-values.sql @@ -4196,6 +4196,15 @@ INSERT into config.org_unit_setting_type 'coust', 'description'), 'bool', null) +,( 'ui.patron.edit.ac.barcode.regex', 'gui', + oils_i18n_gettext('ui.patron.edit.ac.barcode.regex', + 'Regex for barcodes on patron registration', + 'coust', 'label'), + oils_i18n_gettext('ui.patron.edit.ac.barcode.regex', + 'The Regular Expression for validation on barcodes in patron registration.', + 'coust', 'description'), + 'string', null) + ,( 'ui.patron.edit.au.day_phone.example', 'gui', oils_i18n_gettext('ui.patron.edit.au.day_phone.example', 'Example for day_phone field on patron registration', diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.check_barcode_regex.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.check_barcode_regex.sql new file mode 100644 index 0000000000..0d2bcef43c --- /dev/null +++ b/Open-ILS/src/sql/Pg/upgrade/XXXX.check_barcode_regex.sql @@ -0,0 +1,10 @@ +INSERT into config.org_unit_setting_type +( name, grp, label, description, datatype, fm_class ) VALUES +( 'ui.patron.edit.ac.barcode.regex', 'gui', + oils_i18n_gettext('ui.patron.edit.ac.barcode.regex', + 'Regex for barcodes on patron registration', + 'coust', 'label'), + oils_i18n_gettext('ui.patron.edit.ac.barcode.regex', + 'The Regular Expression for validation on barcodes in patron registration.', + 'coust', 'description'), + 'string', null); diff --git a/Open-ILS/web/js/ui/default/actor/user/register.js b/Open-ILS/web/js/ui/default/actor/user/register.js index 810ab3a82e..b62c3b6992 100644 --- a/Open-ILS/web/js/ui/default/actor/user/register.js +++ b/Open-ILS/web/js/ui/default/actor/user/register.js @@ -132,6 +132,7 @@ function load() { 'ui.patron.edit.au.prefix.require', 'ui.patron.edit.au.prefix.show', 'ui.patron.edit.au.prefix.suggest', + 'ui.patron.edit.ac.barcode.regex', 'ui.patron.edit.au.second_given_name.show', 'ui.patron.edit.au.second_given_name.suggest', 'ui.patron.edit.au.suffix.show', @@ -1239,6 +1240,24 @@ function attachWidgetEvents(fmcls, fmfield, widget) { if(fmcls == 'ac') { if(fmfield == 'barcode') { + widget.widget.isValid = function() { + if(this.attr('disabled') || this.attr('readOnly')) { + return true; + } + if(orgSettings['ui.patron.edit.ac.barcode.regex']) { // This serves as a master "on" for these checks + // No spaces + if(this.attr("value").match(/\s/)) { + return false; + } + var test_regexp = new RegExp(orgSettings['ui.patron.edit.ac.barcode.regex']); + if(test_regexp.test(this.attr("value"))) { + return true; + } + return false; + } + + return true; + } dojo.connect(widget.widget, 'onChange', function() { var barcode = this.attr('value'); -- 2.43.2