$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',
<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' -%]
<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 %]