Lines 54-72
$(document).ready(function(){
Link Here
|
54 |
}); |
54 |
}); |
55 |
} |
55 |
} |
56 |
|
56 |
|
57 |
function toggle_digest(id){ |
|
|
58 |
let phone_checked = TalkingTechItivaPhoneNotification ? false : PhoneNotification ? $("#phone"+id).prop("checked") : false; |
59 |
if ( $("#email"+id).prop("checked") || $("#sms"+id).prop("checked") || phone_checked ) { |
60 |
if ($("#forcedigest"+id).length === 0) { |
61 |
$("#digest"+id).attr("disabled", false).tooltip('disable'); |
62 |
} |
63 |
} else { |
64 |
if ($("#forcedigest"+id).length === 0) { |
65 |
$("#digest"+id).attr("disabled", true).prop("checked",false).tooltip('enable'); |
66 |
} |
67 |
} |
68 |
|
69 |
} |
70 |
// At load time, we want digest disabled if no digest using transport is enabled |
57 |
// At load time, we want digest disabled if no digest using transport is enabled |
71 |
$(".pmp_email").each(function(){ |
58 |
$(".pmp_email").each(function(){ |
72 |
toggle_digest(Number($(this).attr("id").replace("email", ""))); |
59 |
toggle_digest(Number($(this).attr("id").replace("email", ""))); |
Lines 85-87
$(document).ready(function(){
Link Here
|
85 |
|
72 |
|
86 |
// $('#memberentry_messaging_prefs [data-toggle="tooltip"][disabled]').tooltip(); |
73 |
// $('#memberentry_messaging_prefs [data-toggle="tooltip"][disabled]').tooltip(); |
87 |
}); |
74 |
}); |
|
|
75 |
|
76 |
function toggle_digest(id){ |
77 |
let phone_checked = TalkingTechItivaPhoneNotification ? false : PhoneNotification ? $("#phone"+id).prop("checked") : false; |
78 |
if ( $("#email"+id).prop("checked") || $("#sms"+id).prop("checked") || phone_checked ) { |
79 |
if ($("#forcedigest"+id).length === 0) { |
80 |
$("#digest"+id).attr("disabled", false).tooltip('disable'); |
81 |
|
82 |
} |
83 |
} else { |
84 |
if ($("#forcedigest"+id).length === 0) { |
85 |
$("#digest"+id).attr("disabled", true).prop("checked",false).tooltip('enable'); |
86 |
} |
87 |
} |
88 |
|
89 |
} |
90 |
|
91 |
var patron_messaging_checkbox_preferences = { |
92 |
email: { |
93 |
checked_checkboxes: null, |
94 |
is_enabled: true, |
95 |
disabled_checkboxes: null |
96 |
}, |
97 |
sms: { |
98 |
checked_checkboxes: null, |
99 |
is_enabled: true, |
100 |
disabled_checkboxes: null |
101 |
}, |
102 |
phone: { |
103 |
checked_checkboxes: null, |
104 |
is_enabled: true, |
105 |
disabled_checkboxes: null |
106 |
}, |
107 |
}; |
108 |
|
109 |
function disableCheckboxesWithInvalidPreferences(elem, id_attr) { |
110 |
|
111 |
if (!$(elem).length && typeof window["patron_" + id_attr] !== "undefined") { |
112 |
return; |
113 |
} |
114 |
|
115 |
// Get checkbox preferences for the element |
116 |
var checkbox_prefs = patron_messaging_checkbox_preferences[id_attr]; |
117 |
|
118 |
// Check if element is empty or not valid |
119 |
if (!$(elem).length || $(elem).val().length == 0 || !$(elem).valid()) { |
120 |
|
121 |
if (checkbox_prefs.is_enabled) { |
122 |
|
123 |
if ($("input[type='checkbox'][id^=" + id_attr + "]").length === 0) { |
124 |
return; |
125 |
} |
126 |
|
127 |
// Save the state of checked checkboxes |
128 |
checkbox_prefs.checked_checkboxes = $("input[type='checkbox'][id^=" + id_attr + "][value=" + id_attr + "]:checked,input[type='checkbox'][id^=digest]:checked"); |
129 |
|
130 |
// Clear patron messaging preferences checkboxes |
131 |
$("input[type='checkbox'][id^=" + id_attr + "][value=" + id_attr + "]").removeAttr("checked"); |
132 |
|
133 |
// Then disable checkboxes from patron messaging perferences |
134 |
$("input[type='checkbox'][id^=" + id_attr + "][value=" + id_attr + "]").prop("disabled", "disabled"); |
135 |
|
136 |
// Color table cell's background emphasize the disabled state of the checkbox |
137 |
$("input[type='checkbox'][id^=" + id_attr + "][value=" + id_attr + "]").parent().css("background-color", "#E8F0F8"); |
138 |
|
139 |
disable_digest = true; |
140 |
$.each(patron_messaging_checkbox_preferences, function(key, obj) { |
141 |
if (key === id_attr) { |
142 |
return; |
143 |
} |
144 |
if ($("input[type='checkbox'][id^=" + key + "]:not(:disabled)").length) { |
145 |
disable_digest = false; |
146 |
} |
147 |
}); |
148 |
|
149 |
if (disable_digest) { |
150 |
$("input[type='checkbox'][id^=digest]").removeAttr("checked"); |
151 |
$("input[type='checkbox'][id^=digest]").prop("disabled", "disabled"); |
152 |
$("input[type='checkbox'][id^=digest]").parent().css("background-color", "#E8F0F8"); |
153 |
} |
154 |
|
155 |
// Remove notification of missing contact |
156 |
$("div.missing-message-pref-contact").css("display", "block"); |
157 |
|
158 |
checkbox_prefs.is_enabled = false; |
159 |
} |
160 |
|
161 |
return false; |
162 |
|
163 |
} else { |
164 |
|
165 |
if (!checkbox_prefs.is_enabled) { |
166 |
// Enable patron messaging preferences checkboxes |
167 |
$("input[type='checkbox'][id^=" + id_attr + "][value=" + id_attr + "]").prop("disabled", false); |
168 |
|
169 |
$("input[type='checkbox'][id^=digest]").parent().css("background-color", ""); |
170 |
|
171 |
// Restore the state of checkboxes |
172 |
checkbox_prefs.checked_checkboxes.each(function() { |
173 |
$(this).prop("checked", "checked"); |
174 |
if (!$("input[type='checkbox'][id='digest"+$(this).attr("data-attr-id")+"']:checked").length === 0) { |
175 |
toggle_digest($(this).attr("data-attr-id")); |
176 |
} |
177 |
}); |
178 |
|
179 |
// Remove the background color from table cell |
180 |
$("input[type='checkbox'][id^=" + id_attr + "][value=" + id_attr + "]").parent().css("background-color", ""); |
181 |
|
182 |
// Remove notification of missing contact |
183 |
$("div.missing-message-pref-contact").css("display", "none"); |
184 |
|
185 |
checkbox_prefs.is_enabled = true; |
186 |
} |
187 |
|
188 |
return true; |
189 |
|
190 |
} |
191 |
} |