Bug 3534 - Patron quick add form
authorNick Clemens <nick@bywatersolutions.com>
Fri, 4 Mar 2016 21:34:07 +0000 (21:34 +0000)
committerKyle M Hall <kyle@bywatersolutions.com>
Thu, 7 Jul 2016 18:35:01 +0000 (18:35 +0000)
This patch adds a new system preference:
    PatronQuickAddFields

When either this pref or BorrowerMandatoryField is populated this will add a new dropdown to the bew patron toolbar.
When a category is chosen from this dropdown the fields in PatronQuickAddFields and BorrowerMandatoryField will be displayed.
There will be a button allowing a user to switch from the quickadd to the full form and fields will be copied between the forms when toggling.

The Quick add will only be displayed on add of a new patron, future edits should display the full form.

Test plan:
 1 - Apply patch
 2 - run updatedatabase.pl
 3 - Add a new patron and ensure nothing has changed
 4 - Populate either PatronQuickAddFields or BorrowerMandatory fields
 and note the new button for adding a patron
 5 - Click the Quick add and choose a type
 6 - Only required or quick add fields should be displayed
 7 - Verify toggling forms copies information
 8 - Ensure you cannot save patron without filling required fields
 (quick add fields should be optional)
 9 - Ensure you can save patron with fields filled out
10 - Ensure that a duplicate patron brings up the duplicate/add new
buttons with full form displayed
11 - Verify that subsequent edits use only full form
12 - Verify that data on form submitted is the data saved to patron
13 - Test with various values in both MandatoryBorrowerFields and PatronQuickAddFields

Sponsored by: VOKAL (Vermont Organization of Koha Automated Libraries)

Followed test plan, works as expected.
Re-tested together with followup, works as expected (2016-06-02)
Signed-off-by: Marc VĂ©ron <veron@veron.ch>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
installer/data/mysql/atomicupdate/bug_3534_add_PatronQuickAdd_sysprefs.sql [new file with mode: 0644]
installer/data/mysql/sysprefs.sql
koha-tmpl/intranet-tmpl/prog/en/includes/patron-toolbar.inc
koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/patrons.pref
koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt
members/memberentry.pl

diff --git a/installer/data/mysql/atomicupdate/bug_3534_add_PatronQuickAdd_sysprefs.sql b/installer/data/mysql/atomicupdate/bug_3534_add_PatronQuickAdd_sysprefs.sql
new file mode 100644 (file)
index 0000000..b210b0d
--- /dev/null
@@ -0,0 +1 @@
+INSERT IGNORE INTO systempreferences (variable,value,explanation,options,type) VALUES ('PatronQuickAddFields', '', 'A list of fields separated by "|" to be displayed along with mandatory fields in the patron quick add form if chosen at patron entry', NULL, 'Free');
index eb4209b..a2a5d63 100644 (file)
@@ -383,6 +383,7 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, `
 ('PatronSelfRegistrationVerifyByEmail','0',NULL,'If enabled, any patron attempting to register themselves via the OPAC will be required to verify themselves via email to activate his or her account.','YesNo'),
 ('PatronsPerPage','20','20','Number of Patrons Per Page displayed by default','Integer'),
 ('EnablePayPalOpacPayments',  '0', NULL ,  'Enables the ability to pay fees and fines from  the OPAC via PayPal',  'YesNo' ),
+('PatronQuickAddFields',  '', NULL ,  'A list of fields separated by "|" to be displayed along with mandatory fields in the patron quick add form if chosen at patron entry',  'Free' ),
 ('PayPalChargeDescription',  'Koha fee payment', NULL ,  'This preference defines what the user will see the charge listed as in PayPal',  'Free'),
 ('PayPalPwd',  '', NULL ,  'Your PayPal API password',  'Free'),
 ('PayPalSandboxMode',  '1', NULL ,  'If enabled, the system will use PayPal''s sandbox server for testing, rather than the production server.',  'YesNo'),
index 88c477f..0ad0308 100644 (file)
@@ -1,4 +1,5 @@
 [% USE Categories %]
+[% USE Koha %]
 [% SET categories = Categories.all %]
 
 [% UNLESS ( no_add ) %]
@@ -9,8 +10,17 @@
                 [% FOREACH category IN categories %]<li><a href="/cgi-bin/koha/members/memberentry.pl?op=add&amp;categorycode=[% category.categorycode %]">[% category.description %]</a></li>[% END %]
             </ul>
     </div>
+    [% IF Koha.Preference('PatronQuickAddFields') || Koha.Preference('BorrowerMandatoryField') %]
+    <div class="btn-group">
+        <button class="btn btn-small dropdown-toggle" data-toggle="dropdown"><i class="fa fa-plus"></i> Quick add new patron <span class="caret"></span></button>
+            <ul class="dropdown-menu">
+                [% FOREACH category IN categories %]<li><a href="/cgi-bin/koha/members/memberentry.pl?op=add&amp;categorycode=[% category.categorycode %]&amp;quickadd=true">[% category.description %]</a></li>[% END %]
+            </ul>
+    </div>
+    [% END %]
     [% IF CAN_user_tools_manage_patron_lists %]
         <a class="btn btn-small" href="/cgi-bin/koha/patron_lists/lists.pl"><i class="fa fa-edit"></i>Patron lists</a>
     [% END %]
+
 </div>
 [% END %]
index 4dc43db..61c1bd6 100644 (file)
@@ -99,6 +99,11 @@ Patrons:
          - pref: PatronsPerPage
            class: integer
          - results per page in the staff client.
+     -
+         - pref: PatronQuickAddFields
+           class: multi
+         - (separate columns with |)
+         - "add these fields to the patron quick add form when entering a new patron. Displays only mandatory fields and fields specified here"
      -
          - "Use the SMS::Send::"
          - pref: SMSSendDriver
index 17eeb5b..7eef3da 100644 (file)
@@ -33,6 +33,44 @@ $(document).ready(function() {
        [% END %]
 });
 
+$(document).ready(function() {
+
+    var toggle_quick_add = $(".toggle_quick_add");
+    $(toggle_quick_add).click(function(e){
+        toggle_quick_add.toggle();
+        e.preventDefault();
+        var toggle_to = '';
+        var toggle_from = '';
+        if( $("#entryform:visible").length ) {
+            toggle_to = "#quick_add_form label";
+            toggle_from = "#entryform label";
+        } else {
+            toggle_to="#entryform label";
+            toggle_from = "#quick_add_form label";
+        }
+        $(toggle_from).each(function() {
+            var input_label = $(this).attr('for');
+            if ( input_label == 'sex-male' || input_label == 'sex-none' || input_label == 'sex-female' ) {
+            $(toggle_to+"[for='"+input_label+"']").next().prop('checked', $(this).next().prop('checked') );
+            return;
+            }
+            if( $(this).next().val() != '' ) { $(toggle_to+"[for='"+input_label+"']").next().val(  $(this).next().val() );}
+        });
+
+        $(".toggler").toggle();
+    });
+
+    $(".save_quick_add").click(function(){
+        $("#quick_add_form").validate();
+        if( $("#quick_add_form").valid()){
+            $('.toggle_quick_add').click();
+            $('#entryform button[name="save"]').click();
+        }
+        else {return false;}
+    });
+
+});
+
         var MSG_SEPARATOR = _("Separator must be / in field %s");
         var MSG_INCORRECT_DAY = _("Invalid day entered in field %s");
         var MSG_INCORRECT_MONTH = _("Invalid month entered in field %s");
@@ -59,12 +97,12 @@ $(document).ready(function() {
 [% INCLUDE 'header.inc' %]
 [% INCLUDE 'patron-search.inc' %]
 
-<div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; <a href="/cgi-bin/koha/members/members-home.pl">Patrons</a>  &rsaquo; 
+<div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; <a href="/cgi-bin/koha/members/members-home.pl">Patrons</a>  &rsaquo;
 [% IF (firstname || surname ) %] <a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% borrowernumber %]">[% IF (firstname) %][% firstname %] [% END %][% IF (surname) %][% surname %] [% END %]</a>  &rsaquo;[% END %]
 <strong>[% IF ( opadd ) %]Add[% ELSIF ( opduplicate ) %]Duplicate[% ELSE %] Modify[% END %] patron ([%IF ( categoryname ) %][% categoryname %][% ELSE %][% IF ( I ) %]Organization[% END %][% IF ( A ) %]Adult[% END %][% IF ( C ) %]Child[% END %][% IF ( P ) %]Professional[% END %][% IF ( S ) %]Staff[% END %][% END %])</strong>
 </div>
 [% IF ( opadd ) %]<div id="doc" class="yui-t7">[% ELSE %]<div id="doc3" class="yui-t2">[% END %]
-   
+
    <div id="bd">
        <div id="yui-main">
        <div class="yui-b">
@@ -85,7 +123,12 @@ $(document).ready(function() {
 
        [% UNLESS ( no_add ) %]
     <h1>[% IF ( opadd ) %]Add[% ELSIF ( opduplicate ) %]Duplicate[% ELSE %] Modify[% END %] patron [% IF (firstname) %][% firstname %] [% END %][% IF (surname) %][% surname %] [% END %]([%IF ( categoryname ) %][% categoryname %][% ELSE %][% IF ( I ) %]Organization[% END %][% IF ( A ) %]Adult[% END %][% IF ( C ) %]Child[% END %][% IF ( P ) %]Professional[% END %][% IF ( S ) %]Staff[% END %][% END %])</h1>
-  
+
+    [% IF quickadd && opadd && !check_member %]
+        <a href="#" class="toggle_quick_add"><i class="fa fa-plus-square"></i> Show full form</a>
+        <a href="#" class="toggle_quick_add" style="display:none"><i class="fa fa-minus-square"></i> Show brief form</a>
+    [% END %]
+
        [% IF ( check_member ) %]
                        <div class="dialog alert">
                                <h3>Duplicate patron record?</h3>
@@ -118,12 +161,12 @@ $(document).ready(function() {
                 <li id="ERROR_cardnumber">Cardnumber length is incorrect.</li>
             [% END %]
                        [% IF ( ERROR_age_limitations ) %]
-                               <li id="ERROR_age_limitations">Patron's age is incorrect for their category.  
+            <li id="ERROR_age_limitations">Patron's age is incorrect for their category.
                     Ages allowed are [% age_low %]-[% age_high %].</li>
                        [% END %]
                        [% IF ( ERROR_branch ) %]
                                <li id="ERROR_branch">Library is invalid.</li>
-                       [% END %]   
+            [% END %]
                        [% IF ( ERROR_dateofbirth ) %]
                                <li id="ERROR_dateofbirth">Date of birth is invalid.</li>
                        [% END %]
@@ -156,7 +199,7 @@ $(document).ready(function() {
        [% END %]
 
 
-[% UNLESS ( check_member ) %]<form name="form" id="entryform"  action="/cgi-bin/koha/members/memberentry.pl" method="post" autocomplete="off">
+[% UNLESS ( check_member ) %]<form name="form" id="entryform"  action="/cgi-bin/koha/members/memberentry.pl" method="post" autocomplete="off" class="toggler" >
 <input type="hidden" name="nodouble"  value="[% nodouble %]" /> [% END %]
 <!--    field always hidden in different form (1,2,3) -->
 <input type="hidden" name="BorrowerMandatoryField" value="[% BorrowerMandatoryField %]" />
@@ -430,7 +473,7 @@ $(document).ready(function() {
     <legend id="contact_lgd">Contact</legend><ol>
         [% UNLESS nophone %]
       <li>
-      [% IF ( mandatoryphone ) %] 
+      [% IF ( mandatoryphone ) %]
       <label for="phone" class="required">
       [% ELSE %]
       <label for="phone">
@@ -480,7 +523,7 @@ $(document).ready(function() {
         [% END %]
         [% UNLESS noemailpro %]
     <li>
-      [% IF ( mandatoryemailpro ) %] 
+      [% IF ( mandatoryemailpro ) %]
       <label for="emailpro" class="required">
       [% ELSE %]
       <label for="emailpro">
@@ -693,7 +736,7 @@ $(document).ready(function() {
                                <label for="opacnote" class="required">
                        [% ELSE %]
                                <label for="opacnote">
-                       [% END %]       
+            [% END %]
                        OPAC note: </label>
             <textarea id="opacnote" name="opacnote" cols="55" rows="5">[% UNLESS opduplicate %][% opacnote %][% END %]</textarea>
                        <div class="hint">This message appears on this patron's user page in the OPAC</div>
@@ -702,7 +745,7 @@ $(document).ready(function() {
         [% END %]
         [% UNLESS noborrowernotes %]
                <li>
-                       [% IF ( mandatoryborrowernotes ) %]     
+            [% IF ( mandatoryborrowernotes ) %]
                                <label for="borrowernotes" class="required">
                        [% ELSE %]
                                <label for="borrowernotes">
@@ -1044,7 +1087,38 @@ $(document).ready(function() {
 [% END %] [% END %]
 
 </form>
-  
+
+[% IF quickadd && opadd  && !check_member %]
+    <form id="quick_add_form" class="toggler">
+        <fieldset class="rows quick_add"><legend>Quick add</legend>
+            <ol id="quick_add_list">
+            </ol>
+        </fieldset>
+
+        <fieldset class="action">
+            <input type="button" class="save_quick_add"  value="Save" />
+           <a class="cancel" href="/cgi-bin/koha/members/member.pl">Cancel</a>
+        </fieldset>
+
+    </form>
+    <script>
+        $(document).ready(function () {
+            $("#entryform").hide();
+            [% q_add_f = Koha.Preference('PatronQuickAddFields').split('\|') %]
+            var qaddfields = "[% FOREACH field IN q_add_f.unique %][% field %] [% END %]";
+            $("#entryform label").each(function () {
+                var input_label = $(this).attr('for');
+                if ( input_label == 'sex-female' ) { input_label='sex'; }
+                else if ( input_label == 'btitle' ) { input_label='title'; }
+                if( qaddfields.indexOf( input_label ) != -1 || $(this).attr('class') == 'required' ){
+                $(this).parent().clone().appendTo("#quick_add_list");
+                if( input_label == 'password') $("#entryform label[for='password2']").parent().clone().appendTo("#quick_add_list");
+                }
+             });
+            $("#quick_add_form").show();
+        });
+    </script>
+[% END %]
 </div>
 </div>
 
index 597c68d..aea21c3 100755 (executable)
@@ -86,6 +86,7 @@ my $cardnumber     = $input->param('cardnumber');
 my $check_member   = $input->param('check_member');
 my $nodouble       = $input->param('nodouble');
 my $duplicate      = $input->param('duplicate');
+my $quickadd       = $input->param('quickadd');
 $nodouble = 1 if ($op eq 'modify' or $op eq 'duplicate');    # FIXME hack to represent fact that if we're
                                      # modifying an existing patron, it ipso facto
                                      # isn't a duplicate.  Marking FIXME because this
@@ -144,6 +145,7 @@ foreach (@field_check) {
        $template->param( "no$_" => 1);
 }
 $template->param( "add" => 1 ) if ( $op eq 'add' );
+$template->param( "quickadd" => 1 ) if ( $quickadd );
 $template->param( "duplicate" => 1 ) if ( $op eq 'duplicate' );
 $template->param( "checked" => 1 ) if ( defined($nodouble) && $nodouble eq 1 );
 ( $borrower_data = GetMember( 'borrowernumber' => $borrowernumber ) ) if ( $op eq 'modify' or $op eq 'save' or $op eq 'duplicate' );