LP#1527342 warn patrons on history delete
authorBill Erickson <berickxx@gmail.com>
Mon, 28 Dec 2015 20:31:51 +0000 (15:31 -0500)
committerBill Erickson <berickxx@gmail.com>
Mon, 28 Dec 2015 20:31:51 +0000 (15:31 -0500)
Signed-off-by: Bill Erickson <berickxx@gmail.com>
Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Account.pm
Open-ILS/src/templates/opac/css/style.css.tt2
Open-ILS/src/templates/opac/myopac/prefs_settings.tt2

index 1b26b0b..b3c15bf 100644 (file)
@@ -616,22 +616,81 @@ sub load_myopac_prefs_settings {
         $settings{$key}= $val unless $$set_map{$key} eq $val;
     }
 
+    # Used by the settings update form when warning on history delete.
+    my $clear_circ_history = 0;
+    my $clear_hold_history = 0;
+
+    # true if we need to show the warning on next page load.
+    my $hist_warning_needed = 0;
+    my $hist_clear_confirmed = $self->cgi->param('history_delete_confirmed');
+
     my $now = DateTime->now->strftime('%F');
-    foreach my $key (qw/history.circ.retention_start history.hold.retention_start/) {
+    foreach my $key (
+            qw/history.circ.retention_start history.hold.retention_start/) {
+
         my $val = $self->cgi->param($key);
         if($val and $val eq 'on') {
             # Set the start time to 'now' unless a start time already exists for the user
             $settings{$key} = $now unless $$set_map{$key};
+
         } else {
-            # clear the start time if one previously existed for the user
-            $settings{$key} = undef if $$set_map{$key};
-            $U->simplereq(
-                'open-ils.actor',
-                'open-ils.actor.history.circ.clear',
-                $self->editor->authtoken);
+
+            next unless $$set_map{$key}; # nothing to do
+
+            $clear_circ_history = 1 if $key =~ /circ/;
+            $clear_hold_history = 1 if $key =~ /hold/;
+
+            if (!$hist_clear_confirmed) {
+                # when clearing circ history, only warn if history data exists.
+    
+                if ($clear_circ_history) {
+
+                    if ($self->fetch_user_circ_history(0, 1)->[0]) {
+                        $hist_warning_needed = 1;
+                        next; # no history updates while confirmation pending
+                    }
+
+                } else {
+
+                    my $one_hold = $e->json_query({
+                        select => {
+                            au => [{
+                                column => 'id', 
+                                transform => 'action.usr_visible_holds', 
+                                result_field => 'id'
+                            }]
+                        },
+                        from => 'au',
+                        where => {id => $e->requestor->id},
+                        limit => 1
+                    })->[0];
+
+                    if ($one_hold) {
+                        $hist_warning_needed = 1;
+                        next; # no history updates while confirmation pending
+                    }
+                }
+            }
+
+            $settings{$key} = undef;
+
+            if ($key eq 'history.circ.retention_start') {
+                # delete existing circulation history data.
+                $U->simplereq(
+                    'open-ils.actor',
+                    'open-ils.actor.history.circ.clear',
+                    $self->editor->authtoken);
+            }
         }
     }
 
+    # Warn patrons before clearing circ/hold history
+    if ($hist_warning_needed) {
+        $self->ctx->{clear_circ_history} = $clear_circ_history;
+        $self->ctx->{clear_hold_history} = $clear_hold_history;
+        $self->ctx->{confirm_history_delete} = 1;
+    }
+
     # Send the modified settings off to be saved
     $U->simplereq(
         'open-ils.actor', 
index f91b504..f5622c2 100644 (file)
@@ -2119,3 +2119,9 @@ label[for*=expert_]
     text-align: center;
     font-style: italic;
 }
+
+#clear-history-confirm {
+  font-weight: bold;
+  color: [% css_colors.text_badnews %]; 
+  padding: 10px;
+}
index 9f1288c..edefb5c 100644 (file)
@@ -72,7 +72,8 @@
                     <td>
                         <input id='[% setting %]' name='[% setting %]' 
                             type="checkbox" title="[% circ_name %]"
-                            [% IF ctx.user_setting_map.$setting; %] checked='checked' [% END %]/>
+                            [% IF ctx.user_setting_map.$setting 
+                              AND !ctx.clear_circ_history; %] checked='checked' [% END %]/>
                     </td>
                 </tr>
                 [%- setting = 'history.hold.retention_start' -%]
@@ -82,7 +83,8 @@
                     <td>
                         <input id='[% setting %]' name='[% setting %]' 
                             type="checkbox" title="[% hold_name %]"
-                            [% IF ctx.user_setting_map.$setting; %] checked='checked' [% END %]/>
+                            [% IF ctx.user_setting_map.$setting
+                              AND !ctx.clear_hold_history; %] checked='checked' [% END %]/>
                     </td>
                 </tr>
                 [%- setting = 'opac.temporary_list_no_warn' -%]
 
             </tbody>
         </table>
+        [% IF ctx.confirm_history_delete %]
+        <div id='clear-history-confirm'>
+        [% l('Disabling checkout or holds history will permanently remove all items from your history.') %]
+        <br/>
+        [% l('Are you sure you wish to continue?') %]
+        </div>
+        <a href="[% mkurl() %]">[% l('Cancel') %]</a>
+        <input type='hidden' name='history_delete_confirmed' value='1'/>
+        <input type="submit" value="[% l('Confirm') %]" class="opac-button"/>
+        [% ELSE %]
         <input type="submit" value="[% l('Save') %]" class="opac-button"/>
+        [% END %]
     </form>
     [% INCLUDE "opac/parts/myopac/prefs_hints.tt2" %]
 [% END %]