1/* 2 * SecureStart functionality 3 * 4 * This script needs to be loaded after plugins.js and before additional jQueries. 5 */ 6(function ($) { 7 8 // dialog 'subclass' 9 var oldAWSModal = $.fn.awsModal; 10 11 /** 12 * Zipcode Formatting 13 */ 14 $(function() { 15 $("input.format-zipcode").mask("99999?-9999"); 16 }); 17 18 /** 19 * Login modal 20 */ 21 $(function () { 22 23 if ($(".ss-login").length === 0) { 24 /* avoid initializing except for pages that don't have the SS dialog. */ 25 return; 26 } 27 28 /* hide the error message when the dialog opens. */ 29 $(document).on("awsdialogopen", function (ev, inst) { 30 $(inst).find(".mod-errors").hide(); 31 }); 32 33 $.fn.awsModal = function (a, source) { 34 var inst = oldAWSModal.call(this, a, source); 35 36 /* retain the href of the invoking element. */ 37 inst.data("href", $(source).attr("href")); 38 39 $(document).trigger("awsdialogopen", [inst]); 40 41 return inst; 42 }; 43 }); 44 45 /* Forgot password handling */ 46 $(function () { 47 $("#loginResetPassword").on("click", function (ev) { 48 ev.preventDefault(); 49 50 $.ajax({
51 url: "/services/SecureStartForgotPasswordHandler.ashx", 52 type: "post", 53 dataType: "json", 54 data: { 55 loginEmail: $("#loginEmail").val() 56 }, 57 success: function (resp) { 58 if (resp.success) { 59 $("#forgot-password-body #forgot-password-success").show(); 60 $("#forgot-password-body #forgot-password-error").hide(); 61 } else { 62 $("#forgot-password-body #forgot-password-error").show(); 63 $("#forgot-password-body #forgot-password-success").hide(); 64 } 65 }, 66 error: function (err) { 67 $("#forgot-password-body #forgot-password-error").show(); 68 $("#forgot-password-body #forgot-password-success").hide(); 69 } 70 }); 71 }); 72 }); 73 74 /* Login handling */ 75 $(function () { 76 77 $(document).on("loginsuccess", function (ev, href) { 78 $("#login-dialog-body .mod-errors").hide(); 79 80 // Remove anchor tags 81 window.location.href = href.replace(/#.*$/g, ""); 82 }); 83 84 $(document).on("loginerror", function (ev, href, err) { 85 // show error message 86 $("#login-dialog-body .mod-errors").show(); 87 88 // unlock dialog controls. 89 $("#login-dialog-body input, #login-dialog-body button").removeAttr("disabled"); 90 }); 91 92 $("#loginSubmit").on("click", function (ev) { 93 ev.preventDefault(); 94 95 var href = $("#login").data("href"); 96 97 // hide the error message 98 $("#login-dialog-body .mod-errors").hide(); 99 100 // lock dialog controls 101 $("#login-dialog-body input, #login-dialog-body button").attr({ 102 "disabled": 1 103 }); 104 105 $.ajax({
106 url: "/services/SecureStartLoginHandler.ashx", 107 type: "post", 108 dataType: "json", 109 data: { 110 loginUsername: $("#loginUsername").val(), 111 loginPassword: $("#loginPassword").val() 112 }, 113 success: function (resp) { 114 if (resp.href) { 115 /* redirect somewhere where the problem may be solved */ 116 window.location.href = resp.href; 117 return; 118 } 119 if (resp.success) { 120 $(document).trigger("loginsuccess", [href]); 121 } else { 122 $(document).trigger("loginerror", [href,resp]); 123 } 124 }, 125 error: function (err) { 126 (window.console && window.console.error && console.error(err)); 127 128 $(document).trigger("loginerror", [href, err]); 129 } 130 }); 131 }); 132 }); 133 134 /* logout handler */ 135 $(document).on("securestartlogout", function (ev, opts) { 136 137 // allow a modal dialog to "cancel" the actual logout by 138 // sending an additional 'beforesecurestartlogout' event. 139 // pass {nocancel:true} to avoid the 'before' event. 140 var allow_cancel = true; 141 if (opts !== undefined && opts.nocancel === true) { 142 allow_cancel = false; 143 } 144 145 if (allow_cancel) { 146 var beforesecurestartlogout = $.Event("beforesecurestartlogout", {}); 147 148 $(document).trigger(beforesecurestartlogout); 149 150 if (beforesecurestartlogout.isDefaultPrevented()) { 151 return; 152 } 153 } 154 155 $.ajax({
156 url: "/services/SecureStartLoginHandler.ashx?logout=1", 157 type: "post", 158 dataType: "json", 159 success: function (resp) { 160 $("#ss-user_bar").hide("fast"); 161 162 if (resp && resp.href) { 163 // use logout redirect 164 window.location.href = resp.href; 165 } 166 else { 167 // will also redirect (or at least remove the user bar) 168 window.location.reload(); 169 } 170 }, 171 error: function (resp) { 172 console.error(resp); 173 } 174 }); 175 }); 176 177 /* watch for logout on sample order pages and warn if unsaved data. */ 178 $(function() { 179 if ($("*[data-ss-confirmlogout]").length !== 0) { 180 $(document).on("beforesecurestartlogout", function (ev) { 181 ev.preventDefault(); 182 $('#confirm_logout').awsModal(); 183 }); 184 } 185 }); 186 187 /* user bar logout handler */ 188 $(function() { 189 $("#ss-user_bar").on("click", "a.btn.btn-ss-logout", function(ev) { 190 ev.preventDefault(); 191 $(document).trigger("securestartlogout"); 192 }); 193 }); 194 195 /* see if there are any messages for us on the server. */ 196 $(function () { 197 if ($("#ss-user_bar").length === 0) { 198 /* only run on securestart pages */ 199 return; 200 } 201 $.getJSON("/services/SecureStartMessageHandler.ashx", function (data) { 202 if (!data || !data.message) 203 return; 204 $("#ss-user_bar").find(".mod-errors") 205 .removeClass("hidden") 206 .find("p[data-key='EmailChangedMessage']") 207 .removeClass("hidden") 208 .text(data.message); 209 }); 210 }); 211 212 /* userbar login handler */ 213 $(function() { 214 /* store reference to the userbar main container */ 215 var userbar = $( "#ss-user_bar" ); 216 217 /* alternately visible containers for login and forgot password */ 218 var userbar_login = userbar.find( "#userbar_login" ); 219 var userbar_forgot = userbar.find("#userbar_forgot"); 220 221 /* different messages depending on response errors */ 222 var userbar_YourInformationIsNotRecognized = userbar_login.find("p[data-key='YourInformationIsNotRecognized']"); 223 var userbar_AccountResetRequired = userbar_login.find("p[data-key='AccountResetRequired']"); 224 var userbar_FailedRequest = userbar_login.find("p[data-key='FailedRequest']"); 225 226 /* username field handle for setting initial value */ 227 var userbar_username = userbar_login.find("input.userbar-login-username"); 228 var ssCookie_username = "SecureStart_Username"; 229 230 /* lookup a cookie */ 231 var getCookie = function (query) { 232 var cookieName = query + "="; 233 var allCookies = document.cookie.split(";"); 234 for (var i = 0; i < allCookies.length; i++) { 235 var cookie = allCookies[i]; 236 while (cookie.charAt(0) === " ") { 237 cookie = cookie.substring(1); 238 } 239 if (cookie.indexOf(cookieName) === 0) { 240 return cookie.substring(cookieName.length, cookie.length); 241 } 242 } 243 return ""; 244 }; 245 246 /* set initial username field value */ 247 if (getCookie(ssCookie_username) !== "") { 248 userbar_username.val(getCookie(ssCookie_username)); 249 } 250 251 var loginHandler = function(ev) { 252 ev.preventDefault(); 253 254 userbar_login.find("button.login").addClass("disabled"); 255 256 // hide errors 257 userbar_login.find(".mod-errors, .mod-errors > p").addClass("hidden"); 258 259 $.ajax({
260 url: "/services/SecureStartLoginHandler.ashx", 261 type: "post", 262 dataType: "json", 263 data: { 264 loginUsername: userbar_login.find( "input.userbar-login-username" ).val(), 265 loginPassword: userbar_login.find( "input.userbar-login-password" ).val() 266 }, 267 success: function (resp) { 268 var href = window.location.href; 269 if (resp.success) { 270 /* Remember me functionality */ 271 if (userbar_login.find("#RememberMe").val() === "true") { 272 /* set cookie */ 273 if (getCookie(ssCookie_username) === "" && getCookie("AllowCookies") !== "") { 274 var d = new Date(); 275 d.setTime(d.getTime() + (30 * 24 * 60 * 60 * 1000)); 276 document.cookie = ssCookie_username + "=" + userbar_username.val() + ";expires=" + d.toUTCString() + ";path=/"; 277 } 278 } else { 279 /* delete cookie if remember me is unchecked */ 280 if (getCookie(ssCookie_username) !== "") { 281 document.cookie = ssCookie_username + "=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/"; 282 } 283 } 284 /* process successful login */ 285 $(document).trigger("loginsuccess", [href]); 286 } 287 else { 288 if (resp.href) { 289 /* redirect somewhere where the problem may be solved */ 290 window.location.href = resp.href; 291 return; 292 } 293 /* re-add the click handler now that we've completed server side processing. */ 294 userbar_login.find( "button.login" ).one( "click", loginHandler ).removeClass("disabled"); 295 296 /* show the error container */ 297 userbar_login.find(".mod-errors").removeClass("hidden"); 298 if (resp.resetRequired) { 299 /* show the reset message */ 300 userbar_AccountResetRequired.removeClass("hidden"); 301 } else { 302 /* show the generic message */ 303 userbar_YourInformationIsNotRecognized.removeClass("hidden"); 304 } 305 $(document).trigger("loginerror", [href,resp]); 306 } 307 }, 308 error: function (err) { 309 (window.console && console.warn && console.warn(err)); 310 userbar_FailedRequest.append("<span id='failedRequestStatusMsg'></span>"); 311 $("#failedRequestStatusMsg").text(err.status + " - " + err.statusText); 312 userbar_FailedRequest.removeClass("hidden"); 313 userbar_login.find(".mod-errors").removeClass("hidden"); 314 userbar_login.find( "button.login" ).one( "click", loginHandler ).removeClass("disabled"); 315 $(document).trigger("loginerror");//, [href, resp]); 316 } 317 }); 318 }; 319 320 /* begin login attempt */ 321 userbar_login.find( "button.login" ).one( "click", loginHandler ); 322 323 userbar_forgot.find("button.resetpassword").on("click", function(ev) { 324 ev.preventDefault(); 325 326 /* hide errors */ 327 userbar_forgot.children(".module").addClass("hidden"); 328 329 $.ajax({
330 url: "/services/SecureStartForgotPasswordHandler.ashx", 331 type: "post", 332 dataType: "json", 333 data: { 334 loginEmail: userbar_forgot.find( "input.userbar-login-email" ).val() 335 }, 336 success: function (resp) { 337 if (resp.success) { 338 /* show success message */ 339 userbar_forgot.find(".mod-success").removeClass("hidden"); 340 } else { 341 /* show error message */ 342 userbar_forgot.find(".mod-errors:first").removeClass("hidden"); 343 } 344 }, 345 error: function (err) { 346 console.error(err); 347 /* show error message */ 348 userbar_forgot.find(".mod-errors:first").removeClass("hidden"); 349 } 350 }); 351 }); 352 }); 353 354 /* handle 'cookies required' message */ 355 $(function() { 356 var element = $("#userbar_login p[data-key='CookiesRequired']"); 357 if (element.length === 0) { 358 return; 359 } 360 if (navigator.cookieEnabled === false) { 361 element.add(element.parent()).removeClass("hidden").show(); 362 } 363 }); 364 365 /* authenticated page state handler */ 366 $(function() { 367 if ($("*[data-ssauthenticated]").length !== 0) { 368 // fixme: remove the cart icon for secure start pages 369 $("#utility_navigation .cart").remove(); 370 371 /* remove locked links */ 372 $(".ss-locked").removeClass("ss-locked"); 373 374 /* avoid showing the login dialog for locked pages */ 375 $("#content .section .launch-modal[data-target='#login']").each(function () { 376 $(this).removeClass("launch-modal"); 377 }); 378 } 379 }); 380 381 /* prevent double submissions on patient forms */ 382 $(function () { 383 $(".patient_submit").on("click", function (ev) { 384 if ($(this).hasClass("disabled")) { 385 ev.preventDefault(); 386 return; 387 } 388 $(".patient_submit").addClass("disabled").attr("disabled", "1"); 389 }); 390 }); 391 392})(jQuery);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.