testing Leddy and Law for valid patron groups
authorpzed <pzed@6d9bc8c9-1ec2-4278-b937-99fde70a366f>
Wed, 19 Aug 2009 15:19:03 +0000 (15:19 +0000)
committerpzed <pzed@6d9bc8c9-1ec2-4278-b937-99fde70a366f>
Wed, 19 Aug 2009 15:19:03 +0000 (15:19 +0000)
git-svn-id: svn://svn.open-ils.org/ILS-Contrib/conifer/trunk@625 6d9bc8c9-1ec2-4278-b937-99fde70a366f

circ/circ_permit_copy.js

index b7d05b6..cbc3e17 100644 (file)
@@ -52,24 +52,31 @@ if( ! isTrue(copy.circulate) ||
 if (copy.circ_lib.shortname == 'OWA') {\r
 \r
        // permit circulations for the following circ modifiers to all patrons\r
+       var valid_patrons = ['Faculty', 'Graduate', 'Undergraduate', 'Staff members', 'Readers'];\r
        var circ_allow_list = ['CIRC', 'CRC MEDIA', 'CRC SPEC', 'CRC TEXT', 'DOC', 'DVD VIDEO', 'MAP (CIRCULATING)', 'MEDIA', 'MFORM', 'REF', 'THESIS'];\r
 \r
-       // add permissions for patron groups who are not external borrowers\r
-       if (patronProfile == 'Faculty' || patronProfile == 'Graduate' || patronProfile == 'Undergraduate' || patronProfile == 'Staff members') {\r
-               circ_allow_list = circ_allow_list.concat('CIRC SHORT', 'RSV1', 'RSV2', 'RSV3', 'RSV7');\r
-       }\r
+       if (isValidPatron(patronProfile, valid_patrons)) {\r
+  \r
+               // add permissions for patron groups who are not external borrowers\r
+               if (patronProfile == 'Faculty' || patronProfile == 'Graduate' || patronProfile == 'Undergraduate' || patronProfile == 'Staff members') {\r
+                       circ_allow_list = circ_allow_list.concat('CIRC SHORT', 'RSV1', 'RSV2', 'RSV3', 'RSV7');\r
+               }\r
 \r
-       // faculty, grads, and staff can borrow serials\r
-       if (patronProfile == 'Faculty' || patronProfile == 'Graduate'|| patronProfile == 'Staff members') {\r
-               circ_allow_list = circ_allow_list.concat('SER');\r
-       }\r
+               // faculty, grads, and staff can borrow serials\r
+               if (patronProfile == 'Faculty' || patronProfile == 'Graduate'|| patronProfile == 'Staff members') {\r
+                       circ_allow_list = circ_allow_list.concat('SER');\r
+               }\r
 \r
-       // faculty and staff can also borrow music CDs\r
-       if (patronProfile == 'Faculty' || patronProfile == 'Staff members') {\r
-               circ_allow_list = circ_allow_list.concat('CD MUSIC');\r
-       }\r
+               // faculty and staff can also borrow music CDs\r
+               if (patronProfile == 'Faculty' || patronProfile == 'Staff members') {\r
+                       circ_allow_list = circ_allow_list.concat('CD MUSIC');\r
+               }\r
 \r
-       if ( ! testCircAllow(circ_allow_list) ) {\r
+               if ( ! testCircAllow(circ_allow_list) ) {\r
+                       result.events.push('COPY_CIRC_NOT_ALLOWED');\r
+               }\r
+\r
+       } else {\r
                result.events.push('COPY_CIRC_NOT_ALLOWED');\r
        }\r
 } // end permissions for Windsor Leddy\r
@@ -77,25 +84,33 @@ if (copy.circ_lib.shortname == 'OWA') {
 // set permissions for Windsor Law\r
 if (copy.circ_lib.shortname == 'OWAL') {\r
 \r
-       // only Law external borrowers can borrow Law items\r
-       if (patronProfile == 'Readers' && patron.home_ou.shortname <> 'OWAL'){\r
-               result.events.push('COPY_CIRC_NOT_ALLOWED');\r
-       }\r
+       var valid_patrons = ['Faculty', 'Graduate', 'Undergraduate', 'Staff members', 'Readers'];\r
 \r
-       // permit circulations for the following circ modifiers to all patrons not excluded above\r
-       var circ_allow_list = ['LAW MONO'];\r
+       if (isValidPatron(patronProfile, valid_patrons)) {\r
 \r
-       // add permissions for patron groups who are not external borrowers\r
-       if (patronProfile == 'Faculty' || patronProfile == 'Graduate' || patronProfile == 'Undergraduate' || patronProfile == 'Staff members') {\r
-               circ_allow_list = circ_allow_list.concat('LAW RES1D', 'LAW RES3D', 'LAW RES3H', 'LAW RES5H');\r
-       }\r
+               // only Law external borrowers can borrow Law items\r
+               if (patronProfile == 'Readers' && patron.home_ou.shortname != 'OWAL') {\r
+                       result.events.push('COPY_CIRC_NOT_ALLOWED');\r
+               }\r
 \r
-       // faculty can borrow non-circulating items and serials\r
-       if (patronProfile == 'Faculty') {\r
-               circ_allow_list = circ_allow_list.concat('LAW NOCIRC', 'LAW SERIAL');\r
-       }\r
+               // permit circulations for the following circ modifiers to all patrons not excluded above\r
+               var circ_allow_list = ['LAW MONO'];\r
+\r
+               // add permissions for patron groups who are not external borrowers\r
+               if (patronProfile == 'Faculty' || patronProfile == 'Graduate' || patronProfile == 'Undergraduate' || patronProfile == 'Staff members') {\r
+                       circ_allow_list = circ_allow_list.concat('LAW RES1D', 'LAW RES3D', 'LAW RES3H', 'LAW RES5H');\r
+               }\r
+\r
+               // faculty can borrow non-circulating items and serials\r
+               if (patronProfile == 'Faculty') {\r
+                       circ_allow_list = circ_allow_list.concat('LAW NOCIRC', 'LAW SERIAL');\r
+               }\r
 \r
-       if ( ! testCircAllow(circ_allow_list) ) {\r
+               if ( ! testCircAllow(circ_allow_list) ) {\r
+                       result.events.push('COPY_CIRC_NOT_ALLOWED');\r
+               }\r
+\r
+       } else {\r
                result.events.push('COPY_CIRC_NOT_ALLOWED');\r
        }\r
 } // end permissions for Windsor Law\r
@@ -118,6 +133,15 @@ function isAMember(shortname, group) {
        return false;\r
 }\r
 \r
+function isValidPatron(patronProfile, valid_patrons) {\r
+    for (var i = 0; i < valid_patrons.length; i++) {\r
+        if (valid_patrons[i] == patronProfile) {\r
+            return true;\r
+        }\r
+    }\r
+    return false;\r
+}\r
+\r
 function testCircAllow(circ_allow_list) {\r
        for (var i = 0; i < circ_allow_list.length; i++) {\r
                if (circ_allow_list[i] == copy.circ_modifier) {\r