1 $(document).ready(function(){
2 $("#info_digests").tooltip();
4 var message_prefs_dirty = false;
5 $('#memberentry_messaging_prefs > *').change(function() {
6 message_prefs_dirty = true;
9 if( $("#messaging_prefs_loading").length ){ // This element only appears in the template if op=add
10 $('#categorycode_entry').change(function() {
11 var messaging_prefs_loading = $("#messaging_prefs_loading");
12 // Upon selecting a new patron category, show "Loading" message for messaging defaults
13 messaging_prefs_loading.show();
14 var categorycode = $(this).val();
15 if (message_prefs_dirty) {
16 if (!confirm( MSG_MESSAGING_DFEAULTS )) {
17 // Not loading messaging defaults. Hide loading indicator
18 messaging_prefs_loading.hide();
22 var jqxhr = $.getJSON('/cgi-bin/koha/members/default_messageprefs.pl?categorycode=' + categorycode, function(data) {
23 $.each(data.messaging_preferences, function(i, item) {
24 var attrid = item.message_attribute_id;
25 var transports = ['email', 'rss', 'sms'];
26 $.each(transports, function(j, transport) {
27 if (item['transports_' + transport] == 1) {
28 $('#' + transport + attrid).prop('checked', true);
30 $('#' + transport + attrid).prop('checked', false);
33 if (item.digest && item.digest != ' ') {
34 $('#digest' + attrid).prop('checked', true);
36 $('#digest' + attrid).prop('checked', false);
38 if (item.takes_days == '1') {
39 $('[name=' + attrid + '-DAYS]').val('' + item.days_in_advance);
42 message_prefs_dirty = false;
45 // Loaded messaging defaults. Hide loading indicator
46 messaging_prefs_loading.hide();
51 // At load time, we want digest disabled if no digest using transport is enabled
52 $(".pmp_email").each(function(){
53 var rowid = $(this).attr("id");
54 id = Number(rowid.replace("email",""));
55 if ( $("#email"+id).prop("checked") || $("#sms"+id).prop("checked") ) {
56 $("#digest"+id).attr("disabled", false).tooltip('disable');
58 $("#digest"+id).attr("disabled", true).prop("checked",false).tooltip('enable');
62 // If user clears all digest using transports for a notice, disable digest checkbox
63 $(".pmp_email").click(function(){
64 var rowid = $(this).attr("id");
65 id = Number(rowid.replace("email",""));
66 if ( $("#email"+id).prop("checked") || $("#sms"+id).prop("checked") ) {
67 $("#digest"+id).attr("disabled", false).tooltip('disable');
69 $("#digest"+id).attr("disabled", true).prop("checked",false).tooltip('enable');
72 $(".pmp_sms").click(function(){
73 var rowid = $(this).attr("id");
74 id = Number(rowid.replace("sms",""));
75 if ( $("#email"+id).prop("checked") || $("#sms"+id).prop("checked") ) {
76 $("#digest"+id).attr("disabled", false).tooltip('disable');
78 $("#digest"+id).attr("disabled", true).prop("checked",false).tooltip('enable');
82 // $('#memberentry_messaging_prefs [data-toggle="tooltip"][disabled]').tooltip();