KMAIN-11: Default Dropdown for patron messages
authorBill Erickson <berickxx@gmail.com>
Wed, 29 Oct 2014 21:06:47 +0000 (17:06 -0400)
committerBill Erickson <berickxx@gmail.com>
Thu, 21 Mar 2019 19:46:23 +0000 (15:46 -0400)
    Cross-port: 84acdf5

Conflicts:
Open-ILS/src/perlmods/lib/OpenILS/Application/Actor.pm

Conflicts:
Open-ILS/xul/staff_client/chrome/content/main/constants.js

Open-ILS/src/perlmods/lib/OpenILS/Application/Actor.pm
Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/Publisher/action.pm
Open-ILS/xul/staff_client/chrome/content/main/constants.js
Open-ILS/xul/staff_client/server/patron/new_standing_penalty.js
Open-ILS/xul/staff_client/server/patron/new_standing_penalty.xul

index 5787224..33a830f 100644 (file)
@@ -4700,6 +4700,7 @@ __PACKAGE__->register_method(
 sub get_barcodes {
     my( $self, $client, $auth, $org_id, $context, $barcode ) = @_;
     my $e = new_editor(authtoken => $auth);
+
     return $e->event unless $e->checkauth;
     return $e->event unless $e->allowed('STAFF_LOGIN', $org_id);
 
@@ -5035,4 +5036,34 @@ sub filter_group_entry_crud {
     }
 }
 
+# Handles stored messages for patrons
+
+__PACKAGE__->register_method(
+    method    => "patron_message_list",
+    api_name  => "open-ils.actor.patron_message_list",
+    signature => q/
+               Grabs a list of all pre-defined messages that can be sent to a patron.
+               /
+);
+
+# Gets the list of default messages
+sub patron_message_list {
+
+       my $message_ref = $U->storagereq('open-ils.storage.direct.action.patron_message_list');
+       my @message = @$message_ref;
+       my $stringtoSend;
+
+       foreach (@message) {
+
+               my @sub_message = @$_;
+
+               foreach (@sub_message) {
+
+                       $stringtoSend .= $_ . "&SPLIT&";
+               }
+       }
+
+       return $stringtoSend;
+}
+
 1;
index 97df335..3b300be 100644 (file)
@@ -2434,5 +2434,33 @@ __PACKAGE__->register_method(
 );
 
 
+sub patron_message_list {
+
+       # Grab self, client
+       my $self = shift;
+       my $client = shift;
+
+       $logger->debug("PATRONPROBLEM");
+
+       # Build SQL statement
+       my $select = <<"        SQL";
+               SELECT message, weight FROM config.patron_message;
+       SQL
+
+       # Load and execute statement
+       my $sth = action::survey->db_Main->prepare_cached($select);
+
+       $sth->execute();
+
+       return $sth->fetchall_arrayref;
+}
+
+__PACKAGE__->register_method(
+       api_name        => 'open-ils.storage.direct.action.patron_message_list',
+       method          => 'patron_message_list',
+       api_level       => 1,
+       stream          => 1,
+);
+
 1;
 
index 85b7b5f..5b465a4 100644 (file)
@@ -374,7 +374,8 @@ var api = {
     'USER_ORG_UNIT_OPT_IN_CHECK' : { 'app' : 'open-ils.actor', 'method' : 'open-ils.actor.user.org_unit_opt_in.check' },
     'USER_ORG_UNIT_OPT_IN_CREATE' : { 'app' : 'open-ils.actor', 'method' : 'open-ils.actor.user.org_unit_opt_in.create' },
     'GET_BARCODES' : { 'app' : 'open-ils.actor', 'method' : 'open-ils.actor.get_barcodes' },
-    'ADJUST_BILLS_TO_ZERO' : { 'app' : 'open-ils.circ', 'method' : 'open-ils.circ.money.billable_xact.adjust_to_zero' }
+    'ADJUST_BILLS_TO_ZERO' : { 'app' : 'open-ils.circ', 'method' : 'open-ils.circ.money.billable_xact.adjust_to_zero' },
+    'PATRON_MESSAGE_LIST' : { 'app' : 'open-ils.actor', 'method' : 'open-ils.actor.patron_message_list' }
 }
 
 var urls = {
index 2c0139c..5125a6a 100644 (file)
@@ -67,6 +67,7 @@ function new_penalty_init() {
         window.new_standing_penalty_event_listeners.add(document.getElementById('cancel_btn'), 
             'command', function() { window.close(); }, false
         );
+
         window.new_standing_penalty_event_listeners.add(document.getElementById('apply_btn'), 
             'command', 
             function() {
@@ -95,6 +96,7 @@ function new_penalty_init() {
         if (error) error.standard_unexpected_error_alert(err_prefix,E); else alert(err_prefix + E);
     }
 
+       build_message_menu();
 }
 
 function new_penalty_cleanup() {
@@ -128,3 +130,68 @@ function build_penalty_menu() {
     }
 }
 
+function loadMessage(text){
+
+       var messageBox = document.getElementById("note_tb");
+       messageBox.value = text;
+}
+
+function build_message_menu(){
+
+   // Load the dropdown
+       var messageString = fieldmapper.standardRequest(
+               [ api.PATRON_MESSAGE_LIST.app, api.PATRON_MESSAGE_LIST.method ],
+               {   async: false,
+                       timeout: 10
+               }
+       );
+
+       
+
+       var messageList = messageString.split(/&SPLIT&/);
+
+       // Array of arrays
+       var weightArray = [];
+
+       // Message, weight pairs
+       for (var i = 0; i < messageList.length; i+=2){
+
+               if (i < messageList.length -1){
+
+                       var message = messageList[i];
+                       var weight = messageList[i + 1];
+
+                       // In case I didn't end up with a real weight for some reason
+                       if (!isInteger(weight)){
+
+                               weight = 1000;
+                       }
+
+                       // Ensure weight array is long enough, and there is already an array at index messageList[i + 2]
+                       if ( !(weightArray[weight] instanceof Array) ){
+
+                               weightArray[weight] = [];
+                       }
+
+                       weightArray[ weight ].push( message );
+               }
+       }
+
+       // Order by weight, then alphabetically
+       for(var i in weightArray){
+
+               weightArray[i].sort();
+
+               for (var n in weightArray[i]){
+
+                       var message = weightArray[i][n];
+
+                       var dropdown = document.getElementById("csp_messagelist");
+                       dropdown.appendItem( message, message, "" );
+               }
+       }
+}
+
+function isInteger(possibleInteger) {
+    return !isNaN(parseFloat(n)) && isFinite(n);
+}
index cef7264..0200749 100644 (file)
                 label="&staff.patron_display.apply_penalty_dialog.radio_btn.block.label;" accesskey="&staff.patron_display.apply_penalty_dialog.radio_btn.block.accesskey;" />
             <toolbarspring/>
             <toolbaritem>
-                <menulist id="csp_menulist" label="">
+                <menulist id="csp_menulist" label="Labels" style="width:90px;">
                     <menupopup id="csp_menupopup" value="21"/> <!-- default SILENT_NOTE -->
                 </menulist>
             </toolbaritem>
+                       <toolbaritem>
+                               <menulist id="csp_messagelist" label="Messages" oncommand="loadMessage(event.target.value)" style="width:180px;">
+
+                               </menulist>
+                       </toolbaritem>
         </toolbar>
     </toolbox>
     <textbox id="note_tb" multiline="true" />