Bug 19630: Added Status column to Patron Holds table
[koha.git] / koha-tmpl / intranet-tmpl / prog / js / messaging-preference-form.js
1 $(document).ready(function(){
2     $(".none").click(function(){
3         if($(this).prop("checked")){
4             var rowid = $(this).attr("id");
5             var newid = Number(rowid.replace("none",""));
6             $("#sms"+newid).prop("checked", false);
7             $("#email"+newid).prop("checked", false);
8             $("#phone"+newid).prop("checked", false);
9             $("#digest"+newid).prop("checked", false);
10             $("#rss"+newid).prop("checked", false);
11         }
12     });
13     $(".active_notify").on("change",function(){
14         var attr_id = $(this).data("attr-id");
15         if( $(this).prop("checked") ){
16             $("#none" + attr_id ).prop("checked", false);
17         }
18     });
19     $("#info_digests").tooltip();
20
21     var message_prefs_dirty = false;
22     $('#memberentry_messaging_prefs > *').change(function() {
23         message_prefs_dirty = true;
24     });
25
26     if( $("#messaging_prefs_loading").length ){ // This element only appears in the template if op=add
27         $('#categorycode_entry').change(function() {
28             var messaging_prefs_loading = $("#messaging_prefs_loading");
29             // Upon selecting a new patron category, show "Loading" message for messaging defaults
30             messaging_prefs_loading.show();
31             var categorycode = $(this).val();
32             if (message_prefs_dirty) {
33                 if (!confirm( MSG_MESSAGING_DFEAULTS )) {
34                     // Not loading messaging defaults. Hide loading indicator
35                     messaging_prefs_loading.hide();
36                     return;
37                 }
38             }
39             $(".none").prop("checked", false); // When loading default prefs the "Do not notify" boxes should be cleared
40             var jqxhr = $.getJSON('/cgi-bin/koha/members/default_messageprefs.pl?categorycode=' + categorycode, function(data) {
41                 $.each(data.messaging_preferences, function(i, item) {
42                     var attrid = item.message_attribute_id;
43                     var transports = ['email', 'rss', 'sms'];
44                     $.each(transports, function(j, transport) {
45                         if (item['transports_' + transport] == 1) {
46                             $('#' + transport + attrid).prop('checked', true);
47                         } else {
48                             $('#' + transport + attrid).prop('checked', false);
49                         }
50                     });
51                     if (item.digest && item.digest != ' ') {
52                         $('#digest' + attrid).prop('checked', true);
53                     } else {
54                         $('#digest' + attrid).prop('checked', false);
55                     }
56                     if (item.takes_days == '1') {
57                         $('[name=' + attrid + '-DAYS]').val('' + item.days_in_advance);
58                     }
59                 });
60                 message_prefs_dirty = false;
61             })
62                 .always(function() {
63                     // Loaded messaging defaults. Hide loading indicator
64                     messaging_prefs_loading.hide();
65                 });
66         });
67     }
68 });