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 function toggle_digest(id){
52 if ( $("#email"+id).prop("checked") || $("#sms"+id).prop("checked") ) {
53 $("#digest"+id).attr("disabled", false).tooltip('disable');
55 $("#digest"+id).attr("disabled", true).prop("checked",false).tooltip('enable');
59 // At load time, we want digest disabled if no digest using transport is enabled
60 $(".pmp_email").each(function(){
61 toggle_digest(Number($(this).attr("id").replace("email", "")));
64 // If user clears all digest using transports for a notice, disable digest checkbox
65 $(".pmp_email").click(function(){
66 toggle_digest(Number($(this).attr("id").replace("email", "")));
68 $(".pmp_sms").click(function(){
69 toggle_digest(Number($(this).attr("id").replace("sms", "")));
72 // $('#memberentry_messaging_prefs [data-toggle="tooltip"][disabled]').tooltip();