Skip to content

Commit

Permalink
bug 3222: moved messaging preference editing
Browse files Browse the repository at this point in the history
The display and editing of messaging preferences
for a patron have been moved as follows:

* the prefs for a patron are now displayed on the
  patron details tab, not the messaging tab.
* the prefs are now modified by editing the patron
  record, not on the messaging tab.

The messaging tab now contains only the list of
messages that have been or will be sent to the patron.

When creating a new patron record, changing the patron
category via the category dropdown now also changes
the default messaging preferences for that patron.  If
you start editing a new patron, change one of the messaging
preferences, then change the patron category, the form will
ask you if you want to keep the preferences or get
the defaults belonging to the new patron category.

Note that when you edit an existing patron record, changing
the patron category will *not* cause the messaging preferences
to be automatically changed.

Programmer's note: this commit introduces a new web service,
members/default_messagingprefs.pl, that uses Jesse Weaver's
C4::Service module.

Signed-off-by: Daniel Sweeney <daniel.sweeney@liblime.com>
Signed-off-by: Galen Charlton <galen.charlton@liblime.com>
  • Loading branch information
Galen Charlton committed May 22, 2009
1 parent 8e5eea5 commit b6e6248
Show file tree
Hide file tree
Showing 9 changed files with 217 additions and 54 deletions.
1 change: 1 addition & 0 deletions C4/Form/MessagingPreferences.pm
Expand Up @@ -126,6 +126,7 @@ sub set_form_values {
# make a hashref of the days, selecting one.
if ( $option->{'takes_days'} ) {
my $days_in_advance = $pref->{'days_in_advance'} ? $pref->{'days_in_advance'} : 0;
$option->{days_in_advance} = $days_in_advance;
@{$option->{'select_days'}} = map {; {
day => $_,
selected => $_ == $days_in_advance ? 'selected="selected"' :'' }
Expand Down
Expand Up @@ -18,12 +18,23 @@
<input type="hidden" name="modify" value="yes" />
<input type="hidden" name="borrowernumber" value="<!-- TMPL_VAR NAME="borrowernumber" -->" />
<table>
<tr><th></th><th>Days in advance</th><!-- TMPL_IF NAME="SMSSendDriver" --><th>SMS</th><!-- /TMPL_IF --><th>Email</th><th>Digests only?</th><!-- <th>RSS</th> --><th>Do not notify</th></tr>
<tr><th></th>
<th>Days in advance</th>
<!-- TMPL_IF NAME="SMSSendDriver" --><th>SMS</th><!-- /TMPL_IF -->
<th>Email</th><th>Digests only?</th>
<!-- <th>RSS</th> -->
<!-- TMPL_UNLESS NAME="messaging_form_inactive" --><th>Do not notify</th><!-- /TMPL_UNLESS -->
</tr>
<!-- TMPL_LOOP name="messaging_preferences" -->
<tr>
<td><!-- TMPL_VAR NAME="message_name" --></td>
<!-- TMPL_IF NAME="takes_days" -->
<td><select name="<!-- TMPL_VAR NAME="message_attribute_id" -->-DAYS">
<td>
<!-- TMPL_IF NAME="messaging_form_inactive" -->
<select name="<!-- TMPL_VAR NAME="message_attribute_id" -->-DAYS" disabled="disabled">
<!-- TMPL_ELSE -->
<select name="<!-- TMPL_VAR NAME="message_attribute_id" -->-DAYS">
<!-- /TMPL_IF -->
<!-- TMPL_LOOP name="select_days" -->
<!-- TMPL_IF NAME="selected" --><option value="<!-- TMPL_VAR NAME="day" -->" selected="selected"><!-- TMPL_VAR NAME="day" --></option><!-- TMPL_ELSE -->
<option value="<!-- TMPL_VAR NAME="day" -->"><!-- TMPL_VAR NAME="day" --></option>
Expand All @@ -35,46 +46,80 @@
<td>-</td>
<!-- /TMPL_IF -->
<!-- TMPL_IF NAME="transport-sms" -->
<!-- TMPL_IF NAME="SMSSendDriver" --><td><input type="checkbox"
<!-- TMPL_IF NAME="SMSSendDriver" --><td>
<!-- TMPL_IF NAME="messaging_form_inactive" -->
<input type="checkbox"
id="sms<!-- TMPL_VAR NAME="message_attribute_id" -->"
name="<!-- TMPL_VAR NAME="message_attribute_id" -->"
value="sms" <!-- TMPL_VAR NAME="transport-sms" --> disabled="disabled" />
<!-- TMPL_ELSE -->
<input type="checkbox"
id="sms<!-- TMPL_VAR NAME="message_attribute_id" -->"
name="<!-- TMPL_VAR NAME="message_attribute_id" -->"
value="sms" <!-- TMPL_VAR NAME="transport-sms" --> onclick = "$('#none'+'<!-- TMPL_VAR NAME="message_attribute_id" -->').attr('checked','');" />
<!-- /TMPL_IF -->
</td><!-- /TMPL_IF -->
<!-- TMPL_ELSE -->
<td>-</td>
<!-- /TMPL_IF -->

<!-- TMPL_IF NAME="transport-email" -->
<td><input type="checkbox"
<td>
<!-- TMPL_IF NAME="messaging_form_inactive" -->
<input type="checkbox"
id="email<!-- TMPL_VAR NAME="message_attribute_id" -->"
name="<!-- TMPL_VAR NAME="message_attribute_id" -->"
value="email" <!-- TMPL_VAR NAME="transport-email" --> disabled="disabled" />
<!-- TMPL_ELSE -->
<input type="checkbox"
id="email<!-- TMPL_VAR NAME="message_attribute_id" -->"
name="<!-- TMPL_VAR NAME="message_attribute_id" -->"
value="email" <!-- TMPL_VAR NAME="transport-email" --> onclick = "$('#none'+'<!-- TMPL_VAR NAME="message_attribute_id" -->').attr('checked','');" />
<!-- /TMPL_IF -->
</td>
<!-- TMPL_ELSE -->
<td>-</td>
<!-- /TMPL_IF -->

<!-- TMPL_IF NAME="has_digest" -->
<td><input type="checkbox"
<td>
<!-- TMPL_IF NAME="messaging_form_inactive" -->
<input type="checkbox"
id="digest<!-- TMPL_VAR NAME="message_attribute_id" -->"
value="<!-- TMPL_VAR NAME="message_attribute_id" -->"
name="digest" <!-- TMPL_VAR NAME="digest" --> disabled="disabled" />
<!-- TMPL_ELSE -->
<input type="checkbox"
id="digest<!-- TMPL_VAR NAME="message_attribute_id" -->"
value="<!-- TMPL_VAR NAME="message_attribute_id" -->"
name="digest" <!-- TMPL_VAR NAME="digest" --> onclick = "$('#none'+'<!-- TMPL_VAR NAME="message_attribute_id" -->').attr('checked','');" />
<!-- /TMPL_IF -->
</td>
<!-- TMPL_ELSE -->
<td>-</td>
<!-- /TMPL_IF -->

<!-- <!-- TMPL_IF NAME="transport-rss" -->
<td><input type="checkbox"
<td>
<!-- TMPL_IF NAME="messaging_form_inactive" -->
<input type="checkbox"
id="rss<!-- TMPL_VAR NAME="message_attribute_id" -->"
name="<!-- TMPL_VAR NAME="message_attribute_id" -->"
value="rss" <!-- TMPL_VAR NAME="transport-rss" --> disabled="disabled" />
<!-- TMPL_ELSE -->
<input type="checkbox"
id="rss<!-- TMPL_VAR NAME="message_attribute_id" -->"
name="<!-- TMPL_VAR NAME="message_attribute_id" -->"
value="rss" <!-- TMPL_VAR NAME="transport-rss" --> onclick = "$('#none'+'<!-- TMPL_VAR NAME="message_attribute_id" -->').attr('checked','');" />
<!-- /TMPL_IF -->
</td>
<!-- TMPL_ELSE -->
<td>-</td>
<!-- /TMPL_IF --> -->

<!-- TMPL_UNLESS NAME="messaging_form_inactive" -->
<td><input type="checkbox" class="none" id="none<!-- TMPL_VAR NAME="message_attribute_id" -->" /></td>
<!-- /TMPL_UNLESS -->
</tr>
<!-- /TMPL_LOOP -->
</table>
Expand Up @@ -929,6 +929,65 @@
</fieldset>
<!-- /TMPL_IF--><!-- /TMPL_IF --><!-- /TMPL_UNLESS -->

<!-- TMPL_IF NAME="step_5" --><!-- TMPL_IF NAME="EnhancedMessagingPreferences" -->
<fieldset class="rows" id="memberentry_messaging_prefs">
<!-- TMPL_IF NAME="opadd" -->
<!-- handle changing prefs if creating new patron and changing
the patron category
-->
<script language="javascript" type="text/javascript">//<![CDATA[
$(document).ready(function(){
var message_prefs_dirty = false;
$('#memberentry_messaging_prefs > *').change(function() {
message_prefs_dirty = true;
});
$('#categorycode').change(function() {
var categorycode = $(this).val();
if (message_prefs_dirty) {
if (!confirm('Change messaging preferences to default for this category?')) {
return;
}
}
$.getJSON('/cgi-bin/koha/members/default_messageprefs.pl?categorycode=' + categorycode,
function(data) {
$.each(data.messaging_preferences, function(i, item) {
var attrid = item.message_attribute_id;
var transports = ['email', 'rss', 'sms'];
$.each(transports, function(j, transport) {
if (item['transport-' + transport] != ' ') {
$('#' + transport + attrid).attr('checked', item['transport-' + transport]);
} else {
$('#' + transport + attrid).removeAttr('checked');
}
});
if (item.digest && item.digest != ' ') {
$('#digest' + attrid).attr('checked', item.digest);
} else {
$('#digest' + attrid).removeAttr('checked');
}
if (item.takes_days == '1') {
$('[name=' + attrid + '-DAYS]').val('' + item.days_in_advance);
}
});
message_prefs_dirty = false;
}
);
});
});
//]]>
</script>
<!-- /TMPL_IF -->
<input type="hidden" name="setting_messaging_prefs" value="1" />
<legend>Patron messaging preferences</legend>
<!-- TMPL_INCLUDE NAME="messaging-preference-form.inc" -->
<!-- TMPL_IF NAME="SMSSendDriver" -->
<p><label for="SMSnumber">SMS number:</label>
<input type="text" id="SMSnumber" name="SMSnumber" value="<!-- TMPL_VAR NAME="SMSnumber" -->" />
</p>
<!-- /TMPL_IF -->
</fieldset>
<!-- /TMPL_IF --> <!-- /TMPL_IF -->

<fieldset class="action">
<input type="submit" name="save" onclick="return check_form_borrowers();" value="Save" />
<!-- TMPL_IF NAME="opadd" -->
Expand Down
17 changes: 0 additions & 17 deletions koha-tmpl/intranet-tmpl/prog/en/modules/members/messaging.tmpl
Expand Up @@ -42,23 +42,6 @@
</div>
<!-- TMPL_ELSE -->

<form method="get" name="messaging" action="/cgi-bin/koha/members/messaging.pl">
<!-- TMPL_IF NAME= "settings_updated" -->
<div class="dialog message"><h4>Settings Updated</h4>
The patron settings have been updated</div>
<!-- /TMPL_IF -->

<h3>Manage patron messaging settings</h3>

<!-- TMPL_INCLUDE NAME="messaging-preference-form.inc" -->

<!-- TMPL_IF NAME="transport-sms" --><p><label for="SMSnumber">SMS number:</label> <input type="text" id="SMSnumber" name="SMSnumber" value="<!-- TMPL_VAR NAME="SMSnumber" -->" /></p><!-- /TMPL_IF -->
<fieldset class="action">
<input type="submit" value="Submit Changes" /> <a class="cancel" href="/cgi-bin/koha/opac-user.pl">Cancel</a>
</fieldset>

</form>

<!-- TMPL_IF NAME="message_queue" -->
<table>
<caption>Message Queue</caption>
Expand Down
16 changes: 15 additions & 1 deletion koha-tmpl/intranet-tmpl/prog/en/modules/members/moremember.tmpl
Expand Up @@ -279,6 +279,19 @@ if (nodename =="barcodes[]"){
<div class="action"><a href="memberentry.pl?op=modify&amp;borrowernumber=<!-- TMPL_VAR NAME="borrowernumber" -->&amp;step=4">Edit</a></div>
<!-- /TMPL_UNLESS -->
<!-- /TMPL_IF -->

<!-- TMPL_IF NAME="EnhancedMessagingPreferences" -->
<div id="patron-messaging-prefs" style="padding-top: 1em;">
<h3>Patron messaging preferences</h3>
<!-- TMPL_INCLUDE NAME="messaging-preference-form.inc" -->
<!-- TMPL_IF NAME="SMSSendDriver" -->
<div class="rows"> <ol><li><span class="label">SMS number:</span><!-- TMPL_VAR NAME="SMSnumber" -->
</li></ol></div>
<!-- /TMPL_IF -->
</div>
<div class="action"><a href="memberentry.pl?op=modify&amp;borrowernumber=<!-- TMPL_VAR NAME="borrowernumber" -->&amp;step=5">Edit</a></div>
<!-- /TMPL_IF -->

</div>
<div class="yui-u">
<div id="patron-library-details">
Expand Down Expand Up @@ -443,7 +456,7 @@ if (nodename =="barcodes[]"){
</td>
<!-- /TMPL_IF -->
</tr>
<!-- /tmpl_loop --></tbody>
<!-- /tmpl_loop -->
<tr>
<td colspan="4" style="text-align: right; font-weight:bold;">Totals:</td>
<td><!-- TMPL_VAR NAME="totaldue" --></td>
Expand All @@ -467,6 +480,7 @@ if (nodename =="barcodes[]"){
</p>
</td>
</tr>
</tbody>
</table>
<fieldset class="action">
<!-- TMPL_IF NAME="CAN_user_circulate_override_renewals" -->
Expand Down
35 changes: 35 additions & 0 deletions members/default_messageprefs.pl
@@ -0,0 +1,35 @@
#!/usr/bin/perl

# Copyright 2009 LibLime
#
# This file is part of Koha.
#
# Koha is free software; you can redistribute it and/or modify it under the
# terms of the GNU General Public License as published by the Free Software
# Foundation; either version 2 of the License, or (at your option) any later
# version.
#
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with
# Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
# Suite 330, Boston, MA 02111-1307 USA
#

use strict;
use warnings;
use C4::Service;
use C4::Form::MessagingPreferences;

# Simple JSON service to get the default messaging preferences
# for a patron category - used by the patron editing form to
# update the prefs if operator is creating a new patron and has
# changed the patron category from its original value.

my ($query, $response) = C4::Service->init(borrowers => 1);
my ($categorycode) = C4::Service->require_params('categorycode');
C4::Form::MessagingPreferences::set_form_values({ categorycode => $categorycode }, $response);
C4::Service->return_success( $response );

0 comments on commit b6e6248

Please sign in to comment.