use OpenILS::Utils::CStoreEditor qw/:funcs/;
use OpenILS::Utils::Fieldmapper;
use OpenILS::Application::AppUtils;
+use OpenSRF::Utils::JSON;
my $U = 'OpenILS::Application::AppUtils';
my $self = shift;
my $e = $self->editor;
+ my $user_prefs = $self->fetch_optin_prefs;
+ $user_prefs = $self->update_optin_prefs($user_prefs)
+ if $self->cgi->request_method eq 'POST';
+
+ $self->ctx->{opt_in_settings} = $user_prefs;
+
+ return Apache2::Const::OK;
+}
+
+sub fetch_optin_prefs {
+ my $self = shift;
+ my $e = $self->editor;
+
# fetch all of the opt-in settings the user has access to
# XXX: user's should in theory have options to opt-in to notices
# for remote locations, but that opens the door for a large
[map {$_->name} @$opt_ins]
);
- $self->ctx->{opt_in_settings} = [map { {cust => $_, value => $user_set->{$_->name} } } @$opt_ins];
- return Apache2::Const::OK;
+ return [map { {cust => $_, value => $user_set->{$_->name} } } @$opt_ins];
+}
+
+sub update_optin_prefs {
+ my $self = shift;
+ my $user_prefs = shift;
+ my $e = $self->editor;
+ my @settings = $self->cgi->param('setting');
+ my %newsets;
+
+ # apply now-true settings
+ for my $applied (@settings) {
+ # see if setting is already applied to this user
+ next if grep { $_->{cust}->name eq $applied and $_->{value} } @$user_prefs;
+ $newsets{$applied} = OpenSRF::Utils::JSON->true;
+ }
+
+ # remove now-false settings
+ for my $pref (grep { $_->{value} } @$user_prefs) {
+ $newsets{$pref->{cust}->name} = undef
+ unless grep { $_ eq $pref->{cust}->name } @settings;
+ }
+
+ $U->simplereq(
+ 'open-ils.actor',
+ 'open-ils.actor.patron.settings.update',
+ $e->authtoken, $e->requestor->id, \%newsets);
+
+ # update the local prefs to match reality
+ for my $pref (@$user_prefs) {
+ $pref->{value} = $newsets{$pref->{cust}->name}
+ if exists $newsets{$pref->{cust}->name};
+ }
+
+ return $user_prefs;
}
sub load_myopac_prefs_settings {
WRAPPER "default/opac/myopac/prefs.tt2";
myopac_page = "prefs/notify" %]
-<table>
- <thead><tr>
- <th>[% l('Notifation Type') %]</th>
- <th>[% l('Enabled') %]</th>
- </tr></thead>
- <tbody class='data_grid'>
- [% IF optin.size == 0 %]
- <strong>[% l('No notification preferences are configured') %]</strong>
- [% END %]
- [% FOR optin IN ctx.opt_in_settings %]
- <tr>
- <td>[% optin.cust.label %]</td>
- <td>
- <input
- type='checkbox'
- name='[% optin.cust.name %]'
- [% IF optin.value %] checked='checked' [% END %]/>
- </td>
- </tr>
- [% END %]
- </tbody>
-</table>
+<form method='POST'>
+ <div style="float:right;width:65px;">
+ <input type='image' alt="[% l('Save') %]" src="[% ctx.media_prefix %]/images/save-btn.png" />
+ </div>
- <!-- NOTIFICATION PREFS / leaving here for reference
- <table class="hide_me"
- id="acct_notify_main">
- <tbody>
- <tr class="hide_me">
- <td><span>[% l("Default Hold Notification Method") %]</span> <a class=
- 'classic_link'
- href='#'>[% l("(Help)") %]</a></td>
-
- <td style="padding-left:15px;"><select id=
- 'prefs_hold_notify'>
- <option value='phone:email'
- selected='selected'>
- [% l("Use Phone and Email") %]
- </option>
-
- <option value='phone'>
- [% l("Use Phone Only") %]
- </option>
-
- <option value='email'>
- [% l("Use Email Only") %]
- </option>
- </select></td>
- </tr>
-
+ <table>
+ <thead><tr>
+ <th>[% l('Notifation Type') %]</th>
+ <th>[% l('Enabled') %]</th>
+ </tr></thead>
+ <tbody class='data_grid'>
+ [% IF optin.size == 0 %]
+ <strong>[% l('No notification preferences are configured') %]</strong>
+ [% END %]
+ [% FOR optin IN ctx.opt_in_settings %]
<tr>
- <td style="padding-top:10px;"><strong>Pick Up Notice for
- Holds</strong><br />
- <input type="checkbox"
- id="opac.hold_notify.email"
- name="opac.hold_notify.email" /> <label for=
- "opac.hold_notify.email">Email</label><br />
- <input type="checkbox"
- id="opac.hold_notify.phone"
- name="opac.hold_notify.phone" /> <label for=
- "opac.hold_notify.phone">Phone</label>
- <b>(Temporarily phone notification will generate a
- mailed paper notice.)</b></td>
+ <td>[% optin.cust.label %]</td>
+ <td>
+ <input type='checkbox' name='setting'
+ value='[% optin.cust.name %]'
+ [% IF optin.value %] checked='checked' [% END %]/>
+ </td>
</tr>
+ [% END %]
+ </tbody>
+ </table>
+</form>
- <tr>
- <td style="padding-top:10px;"><strong>Expire Notice for
- Holds</strong><br />
- <input type="checkbox"
- id="notification.hold.expire.email"
- name="notification.hold.expire.email" /> <label for=
- "notification.hold.expire.email">Email</label></td>
- </tr>
- <tr>
- <td style="padding-top:10px;"><strong>Cancel Notice for
- Holds</strong><br />
- <input type="checkbox"
- id="notification.hold.cancel.email"
- name="notification.hold.cancel.email" /> <label for=
- "notification.hold.cancel.email">Email</label></td>
- </tr>
+<!-- NOTIFICATION PREFS / leaving here for reference
+<table class="hide_me"
+ id="acct_notify_main">
+ <tbody>
+ <tr class="hide_me">
+ <td><span>[% l("Default Hold Notification Method") %]</span> <a class=
+ 'classic_link'
+ href='#'>[% l("(Help)") %]</a></td>
- <tr>
- <td style="padding-top:10px;"><strong>Overdue First
- Notice</strong><br />
- <input type="checkbox"
- id="notification.overdue.first.email"
- name="notification.overdue.first.email" />
- <label for=
- "notification.overdue.first.email">Email</label><br />
- <input type="checkbox"
- id="notification.overdue.first.phone"
- name="notification.overdue.first.phone" />
- <label for=
- "notification.overdue.first.phone">Phone</label>
- <b>(Temporarily phone notification will generate a
- mailed paper notice.)</b></td>
- </tr>
+ <td style="padding-left:15px;"><select id=
+ 'prefs_hold_notify'>
+ <option value='phone:email'
+ selected='selected'>
+ [% l("Use Phone and Email") %]
+ </option>
- <tr>
- <td style="padding-top:10px;"><strong>Courtesy
- Notice</strong><br />
- <input type="checkbox"
- id="notification.predue.email"
- name="notification.predue.email" /> <label for=
- "notification.predue.email">Email</label><br /></td>
- </tr>
- </tbody>
- </table>
- -->
+ <option value='phone'>
+ [% l("Use Phone Only") %]
+ </option>
+
+ <option value='email'>
+ [% l("Use Email Only") %]
+ </option>
+ </select></td>
+ </tr>
+
+ <tr>
+ <td style="padding-top:10px;"><strong>Pick Up Notice for
+ Holds</strong><br />
+ <input type="checkbox"
+ id="opac.hold_notify.email"
+ name="opac.hold_notify.email" /> <label for=
+ "opac.hold_notify.email">Email</label><br />
+ <input type="checkbox"
+ id="opac.hold_notify.phone"
+ name="opac.hold_notify.phone" /> <label for=
+ "opac.hold_notify.phone">Phone</label>
+ <b>(Temporarily phone notification will generate a
+ mailed paper notice.)</b></td>
+ </tr>
+
+ <tr>
+ <td style="padding-top:10px;"><strong>Expire Notice for
+ Holds</strong><br />
+ <input type="checkbox"
+ id="notification.hold.expire.email"
+ name="notification.hold.expire.email" /> <label for=
+ "notification.hold.expire.email">Email</label></td>
+ </tr>
+
+ <tr>
+ <td style="padding-top:10px;"><strong>Cancel Notice for
+ Holds</strong><br />
+ <input type="checkbox"
+ id="notification.hold.cancel.email"
+ name="notification.hold.cancel.email" /> <label for=
+ "notification.hold.cancel.email">Email</label></td>
+ </tr>
+
+ <tr>
+ <td style="padding-top:10px;"><strong>Overdue First
+ Notice</strong><br />
+ <input type="checkbox"
+ id="notification.overdue.first.email"
+ name="notification.overdue.first.email" />
+ <label for=
+ "notification.overdue.first.email">Email</label><br />
+ <input type="checkbox"
+ id="notification.overdue.first.phone"
+ name="notification.overdue.first.phone" />
+ <label for=
+ "notification.overdue.first.phone">Phone</label>
+ <b>(Temporarily phone notification will generate a
+ mailed paper notice.)</b></td>
+ </tr>
+
+ <tr>
+ <td style="padding-top:10px;"><strong>Courtesy
+ Notice</strong><br />
+ <input type="checkbox"
+ id="notification.predue.email"
+ name="notification.predue.email" /> <label for=
+ "notification.predue.email">Email</label><br /></td>
+ </tr>
+ </tbody>
+</table>
+-->
[% END %]