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();