updated to work with new scriptrunner layout
authorerickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Mon, 3 Jul 2006 18:23:54 +0000 (18:23 +0000)
committererickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Mon, 3 Jul 2006 18:23:54 +0000 (18:23 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@4880 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/src/javascript/backend/circ/circ_duration.js
Open-ILS/src/javascript/backend/circ/circ_lib.js
Open-ILS/src/javascript/backend/circ/circ_max_fines.js
Open-ILS/src/javascript/backend/circ/circ_permit_hold.js
Open-ILS/src/javascript/backend/circ/circ_permit_patron.js
Open-ILS/src/javascript/backend/circ/circ_recurring_fines.js
Open-ILS/src/perlmods/OpenILS/Application/Circ/Circulate.pm
Open-ILS/src/perlmods/OpenILS/Application/Circ/ScriptBuilder.pm
Open-ILS/src/perlmods/OpenILS/Application/Penalty.pm
Open-ILS/src/perlmods/OpenILS/Utils/PermitHold.pm

index 21b638f..98ae70d 100644 (file)
@@ -3,16 +3,7 @@ function go() {
 
 /* load the lib script */
 load_lib('circ_lib.js');
-
-/* collect some useful variables */
-var copy                                       = environment.copy;
-var patron                             = environment.patron;
-var patronProfile              = patron.profile.name.toLowerCase();
-var copyStatus                 = copy.status.name.toLowerCase();
-var patronItemsOut     = environment.patronItemsOut;
-var patronFines                = environment.patronFines;
-var isRenewal                  = environment.isRenewal;
-
+log_vars('circ_duration');
 
 /* set sane defaults */
 result.durationLevel   = copy.loan_duration;
@@ -20,9 +11,4 @@ result.durationRule   = "2wk_default";
 
 
 
-
-
-return;
-
-
 } go();
index 5a02712..0afca26 100644 (file)
@@ -1,26 +1,14 @@
 
 var __scratchKey = 0;
 var __SCRATCH = {};
+
+/* useful functions for creating wrappers around system functions */
 function scratchKey()          { return '_' + __scratchKey++; };
 function scratchPad(key)       { return '__SCRATCH.'+ key; }
 function getScratch(key)       { return __SCRATCH[ key ]; }
 function scratchClear()                { for( var o in __SCRATCH ) __SCRATCH[o] = null; }
 
 
-
-/* -- Copy functions ----------------------------------------------------- */
-try {
-       if( environment.copy ) {
-               environment.copy.fetchHolds = function() {
-                       var key = scratchKey();
-                       environment.copy.__OILS_FUNC_fetch_hold(scratchPad(key));
-                       var val = getScratch(key);
-                       return (val) ? val : null;
-               }
-       } 
-} catch(e) {}
-
-
 /* note: returns false if the value is 'f' or 'F' ... */
 function isTrue(d) {
        if(     d && 
@@ -34,6 +22,12 @@ function isTrue(d) {
 
 
 /* collect the useful variables */
+var result                             = environment.result = {};
+result.event                   = 'SUCCESS';
+result.events                  = [];
+result.fatalEvents     = [];
+result.infoEvents              = [];
+
 var copy                                       = environment.copy;
 var volume                             = environment.volume;
 var title                              = environment.title;
@@ -95,9 +89,7 @@ function log_vars( prefix ) {
 
        str += ' Is Renewal: '  + ( (isTrue(isRenewal)) ? "yes" : "no" );
 
-
        log_debug(str);
 }
 
 
-
index 134b95c..ec22cf0 100644 (file)
@@ -3,19 +3,9 @@ function go() {
 
 /* load the lib script */
 load_lib('circ_lib.js');
-
-/* collect some useful variables */
-var copy                                       = environment.copy;
-var patron                             = environment.patron;
-var patronProfile              = patron.profile.name.toLowerCase();
-var copyStatus                 = copy.status.name.toLowerCase();
-var patronItemsOut     = environment.patronItemsOut;
-var patronFines                = environment.patronFines;
-var isRenewal                  = environment.isRenewal;
+log_vars('circ_max_fine');
 
 
 return result.maxFine = "books";
 
-
-
 } go();
index c46d557..f77e51d 100644 (file)
@@ -1,31 +1,12 @@
-function go() {
-
-var patron                             = environment.patron;
-var title                              = environment.title;
-var copy                                       = environment.copy;
-var volume                             = environment.volume;
-var title                              = environment.title;
-var requestor                  = environment.requestor;
-var requestLib                 = environment.requestLib;
-var titleDescriptor    = environment.titleDescriptor;
-
-log_debug('circ_permit_hold: permit circ on ' +
-       ' Copy: '                                       + copy.id + 
-       ', Patron:'                                     + patron.id +
-       ', Patron Username:'            + patron.usrname +
-       ', Patron Library: '            + patron.home_ou.name +
-       ', Copy location: '             + copy.location.name +
-       ', Item Type: '                 + titleDescriptor.item_type +
-       ', Item Form: '                 + titleDescriptor.item_form +
-       ', Item Lang: '                 + titleDescriptor.item_lang +
-       ', Item Audience: '             + titleDescriptor.audience +
-       '');
 
+function go() {
 
+load_lib('circ_lib.js');
+log_vars('circ_permit_hold');
 
 
 
-if( titleDescriptor.item_type == 'g'  /* projected medium */
+if( recDescriptor.item_type == 'g'  /* projected medium */
        && copy.circ_lib != patron.home_ou.id )
        return result.event = 'CIRC_EXCEEDS_COPY_RANGE';
 
index b98614a..1f30374 100644 (file)
@@ -5,7 +5,6 @@ load_lib('circ_lib.js');
 log_vars('circ_permit_patron');
 
 
-
 /* make sure they are not barred */
 if( isTrue(patron.barred) ) 
        result.events.push('PATRON_BARRED');
index dd3cc3f..7bcc352 100644 (file)
@@ -3,15 +3,7 @@ function go() {
 
 /* load the lib script */
 load_lib('circ_lib.js');
-
-/* collect some useful variables */
-var copy                                       = environment.copy;
-var patron                             = environment.patron;
-var patronProfile              = patron.profile.name.toLowerCase();
-var copyStatus                 = copy.status.name.toLowerCase();
-var patronItemsOut     = environment.patronItemsOut;
-var patronFines                = environment.patronFines;
-var isRenewal                  = environment.isRenewal;
+log_vars('circ_recurring_fines');
 
 /** 
 Set some sane defaults.  Valid values for result.recurringFinesLevel
index c63a277..c822827 100644 (file)
@@ -552,12 +552,11 @@ sub _run_permit_scripts {
        # ---------------------------------------------------------------------
        $logger->debug("Running circ script: " . $scripts{circ_permit_patron});
 
-       #$runner->load($scripts{circ_permit_patron});
-       $runner->run($scripts{circ_permit_patron}) or 
+       $runner->load($scripts{circ_permit_patron});
+       my $result = $runner->run or 
                throw OpenSRF::EX::ERROR ("Circ Permit Patron Script Died: $@");
 
-       my $patron_events = $runner->retrieve('result.events');
-       $patron_events = [ split(/,/, $patron_events) ]; 
+       my $patron_events = $result->{events};
        $ctx->{circ_permit_patron_events} = $patron_events;
        $logger->activity("circ_permit_patron for returned @$patron_events") if @$patron_events;
 
@@ -589,10 +588,9 @@ sub _run_permit_scripts {
        # Capture all of the copy permit events
        # ---------------------------------------------------------------------
        $runner->load($scripts{circ_permit_copy});
-       $runner->run or throw OpenSRF::EX::ERROR ("Circ Permit Copy Script Died: $@");
+       $result = $runner->run or throw OpenSRF::EX::ERROR ("Circ Permit Copy Script Died: $@");
+       my $copy_events = $result->{events};
 
-       my $copy_events = $runner->retrieve('result.events');
-       $copy_events = [ split(/,/, $copy_events) ]; 
        $ctx->{circ_permit_copy_events} = $copy_events;
        $logger->activity("circ_permit_copy for copy ".
                "$barcode returned events: @$copy_events") if @$copy_events;
@@ -868,18 +866,20 @@ sub _run_checkout_scripts {
        $runner->insert('result.maxFine');
 
        $runner->load($scripts{circ_duration});
-       $runner->run or throw OpenSRF::EX::ERROR ("Circ Duration Script Died: $@");
-       my $duration = $runner->retrieve('result.durationRule');
+       my $result = $runner->run or throw OpenSRF::EX::ERROR ("Circ Duration Script Died: $@");
+       my $duration = $result->{durationRule};
+       my $dur_level = $result->{durationLevel};
        $logger->debug("Circ duration script yielded a duration rule of: $duration");
 
        $runner->load($scripts{circ_recurring_fines});
-       $runner->run or throw OpenSRF::EX::ERROR ("Circ Recurring Fines Script Died: $@");
-       my $recurring = $runner->retrieve('result.recurringFinesRule');
+       $result = $runner->run or throw OpenSRF::EX::ERROR ("Circ Recurring Fines Script Died: $@");
+       my $recurring = $result->{recurringFinesRule};
+       my $rec_fines_level = $result->{recurringFinesLevel};
        $logger->debug("Circ recurring fines script yielded a rule of: $recurring");
 
        $runner->load($scripts{circ_max_fines});
-       $runner->run or throw OpenSRF::EX::ERROR ("Circ Max Fine Script Died: $@");
-       my $max_fine = $runner->retrieve('result.maxFine');
+       $result = $runner->run or throw OpenSRF::EX::ERROR ("Circ Max Fine Script Died: $@");
+       my $max_fine = $result->{maxFine};
        $logger->debug("Circ max_fine fines script yielded a rule of: $max_fine");
 
        ($duration, $evt) = $U->fetch_circ_duration_by_name($duration);
@@ -889,8 +889,8 @@ sub _run_checkout_scripts {
        ($max_fine, $evt) = $U->fetch_max_fine_by_name($max_fine);
        return $evt if $evt;
 
-       $ctx->{duration_level}                  = $runner->retrieve('result.durationLevel');
-       $ctx->{recurring_fines_level} = $runner->retrieve('result.recurringFinesLevel');
+       $ctx->{duration_level}                  = $dur_level;
+       $ctx->{recurring_fines_level} = $rec_fines_level;
        $ctx->{duration_rule}                   = $duration;
        $ctx->{recurring_fines_rule}    = $recurring;
        $ctx->{max_fine_rule}                   = $max_fine;
@@ -1889,10 +1889,9 @@ sub _run_renew_scripts {
        $U->logmark;
 
        $runner->load($scripts{circ_permit_renew});
-       $runner->run or throw OpenSRF::EX::ERROR ("Circ Permit Renew Script Died: $@");
+       my $result = $runner->run or throw OpenSRF::EX::ERROR ("Circ Permit Renew Script Died: $@");
+       my $events = $result->{events};
 
-       my $events = $runner->retrieve('result.events');
-       $events = [ split(/,/, $events) ]; 
        $logger->activity("circ_permit_renew for user ".
                $ctx->{patron}->id." returned events: @$events") if @$events;
 
index 26bbd9d..6a60321 100644 (file)
@@ -65,11 +65,11 @@ sub build_runner {
        $runner->insert( "$evt.patronFines", $ctx->{patronFines}, 1 );
 
        # circ script result
-       $runner->insert("result", {});
-       $runner->insert("result.event", 'SUCCESS');
-       $runner->insert("result.events", []);
-       $runner->insert('result.fatalEvents', []);
-       $runner->insert('result.infoEvents', []);
+       #$runner->insert("result", {});
+       #$runner->insert("result.event", 'SUCCESS');
+       #$runner->insert("result.events", []);
+       #$runner->insert('result.fatalEvents', []);
+       #$runner->insert('result.infoEvents', []);
 
        $runner->insert("$evt.$_", $ctx->{_direct}->{$_}) for keys %{$ctx->{_direct}};
 
index 4656341..cdaa4c7 100644 (file)
@@ -84,12 +84,11 @@ sub patron_penalty {
        # - Load up the script and run it
        $runner->add_path($path);
 
-       $runner->run($script) or 
-               throw OpenSRF::EX::ERROR ("Patron Penalty Script Died: $@");
+       $runner->load($script);
+       my $result = $runner->run or throw OpenSRF::EX::ERROR ("Patron Penalty Script Died: $@");
 
-       # array items are returned as a comma-separated list of strings
-       my @fatals = split( /,/, $runner->retrieve($fatal_key) );
-       my @infos = split( /,/, $runner->retrieve($info_key) );
+       my @fatals = @{$result->{fatalEvents}};
+       my @infos = @{$result->{infoEvents}};
        my $all = [ @fatals, @infos ];
 
        $logger->info("penalty: script returned fatal events [@fatals] and info events [@infos]");
index bc303c0..94e486e 100644 (file)
@@ -35,32 +35,15 @@ sub permit_copy_hold {
                }
        );
 
-#      my $runner      = OpenILS::Utils::ScriptRunner->new;
-#
-#      $runner->insert( "$k.patron",                           $$params{patron},                               1);
-#      $runner->insert( "$k.title",                            $$params{title},                                1);
-#      $runner->insert( "$k.copy",                             $$params{copy},                         1);
-#      $runner->insert( "$k.requestor",                        $$params{requestor},                    1);
-#      $runner->insert( "$k.requestLib",               $$params{request_lib},          1);
-#      $runner->insert( "$k.pickupLib",                        $$params{pickup_lib},           1);
-#      $runner->insert( "$k.titleDescriptor",  $$params{title_descriptor},1);
-
-#      # we get the script result from the event 
-#      $runner->insert( "result.event",        'SUCCESS' );
-#      $runner->insert( "result.events", [] );
-
        $logger->debug("Running permit_copy_hold on copy " . $$params{copy}->id);
 
        load_scripts($runner);
-       $runner->run or throw OpenSRF::EX::ERROR ("Hold Copy Permit Script Died: $@");
-       my $evtname = $runner->retrieve('result.event');
-
+       my $result = $runner->run or throw OpenSRF::EX::ERROR ("Hold Copy Permit Script Died: $@");
 
        # --------------------------------------------------------------
        # Extract and uniquify the event list
        # --------------------------------------------------------------
-       my $events = $runner->retrieve('result.events');
-       $events = [ split(/,/, $events) ]; 
+       my $events = $result->{events};
        $logger->debug("circ_permit_hold for user ".$params->{patron}->id." returned events: @$events");
 
        my @allevents;