1////#region Global Methods 2 3var $ = jQuery.noConflict(); 4var flightConsultant = null; 5 6//#endregion 7 8//#region Global Functions / Properties that should probably either be moved into IDSTC object or to another location 9 10var HideIDSTCNotifyTimeout; 11 12//WebsiteChange -- website global 13var apiRoot = idstc_setting_apiurl; 14var acutaSiteRoot = idstc_setting_baseurl; 15var consultantPortalRootPath = idstc_setting_consultantportalurl; // this will usually be an external URL 16var customerPortalRootPath = idstc_setting_customerportalurl; // this will usually be an external URL 17var siteRoot = idstc_setting_baseurl; // this will usually be an external URL 18var websiteGlobal = { 19 // appName: "mysite" 20 appName: idstc_setting_appname 21}; 22var entityMap = { 23 "&": "&", 24 "<": "<", 25 ">": ">", 26 '"': '"', 27 "'": ''', 28 "/": '/' 29}; 30 31//end website global 32 33/** 34 * Acuta cart/bootstrap uses 2-letter ISO country codes (e.g. be). 35 * Locale strings such as fr-BE are normalized to the country portion. 36 */ 37function idstcNormalizeAcutaCountryCode(value) { 38 if (value == null || value === '') { 39 return value; 40 } 41 var s = String(value).trim(); 42 var dash = s.indexOf('-'); 43 if (dash >= 0) { 44 s = s.substring(dash + 1); 45 } 46 return s.length >= 2 ? s.substring(0, 2).toLowerCase() : s.toLowerCase(); 47} 48window.idstcNormalizeAcutaCountryCode = idstcNormalizeAcutaCountryCode; 49 50function getCookie(cname) { 51 var name = cname + "="; 52 var ca = document.cookie.split(';'); 53 for (var i = 0; i < ca.length; i++) { 54 var c = ca[i]; 55 while (c.charAt(0) === ' ') c = c.substring(1); 56 if (c.indexOf(name) === 0) return c.substring(name.length, c.length); 57 } 58 return ""; 59} 60 61function deleteCookie(name) { 62 document.cookie = name + '=; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT;'; 63} 64 65function getNotificationsArray() { 66 var strNotifications = getCookie("notifications"); 67 68 if (strNotifications.length > 0) { 69 return JSON.parse(strNotifications); 70 } 71 else { 72 return []; 73 } 74} 75 76function hideNotification(e, hideOnlyIfOld) { 77 clearTimeout(HideIDSTCNotifyTimeout); 78 79 var timestamp = $(e).data("timestamp"); 80 81 if (hideOnlyIfOld) { 82 var diff = Math.abs(Date.now() - timestamp); 83 if (diff < 5000) { 84 return; 85 } 86 } 87 88 $(e).closest(".k-notification").remove(); 89 90 var notifications = getNotificationsArray(); 91 var index = notifications.indexOf(notifications.filter(function (item) { 92 return item.timestamp === timestamp; 93 })[0]); 94 95 if (index != null && index >= 0) { 96 notifications.splice(index, 1); 97 document.cookie = "notifications=" + JSON.stringify(notifications) + "; path=/"; 98 99 if (notifications.length === 0) { 100 $("#sidebar-wrapper", window.parent.document).removeClass("active"); 101 $("#notification").removeClass("flash"); 102 } 103 } 104} 105 106function getNotificationDetails(e) { 107 var notification = $(e).closest(".k-notification"); 108 alert(notification.find('p').text()); 109} 110 111//#endregion 112 113//#region Global on load stuff ( Load notifications from cookie (if any), attach events, etc. 114jQuery(document).ready(function ($) { 115 $(function () { 116 var notifications = getNotificationsArray(); 117 118 var anyToShowNow = false; 119 120 $.each(notifications, function () { 121 if ($("div[data-timestamp='" + this.timestamp + "']").length === 0) { 122 if (this.showNext) { 123 anyToShowNow = true; 124 this.showNext = false; 125 } 126 127 idstc().notify( 128 { message: this.message, success: this.type, fromCookie: true, timestamp: this.timestamp }, 129 null 130 ); 131 } 132 }); 133 134 if (anyToShowNow) { 135 var wp = window.parent.document; 136 137 $("#sidebar-wrapper", wp).addClass("active"); 138
139 document.cookie = "notifications=" + JSON.stringify(notifications) + "; path=/"; 140 } 141 }); 142}); 143//#endregion 144 145//#region Instantiate the idstc object -- requires dependency to jquery 146 147var idstc = function (container) { 148 // if a container is specified return that object or window if none specified. 149 if (container) { 150 if (window === this) { 151 return new idstc(container); 152 } 153 154 this.el = jQuery(container); 155 return this; 156 } 157 else { 158 // return window object if no identifier specified. 159 160 return new idstc(window); 161 } 162}; 163//#endregion 164 165//#region Notification Templates 166idstc.templates = function (type, o) { 167 var template = ""; 168 if (type === "successerrorwarn") { 169 //#region Success/Error/Warn Template 170 template = "<div class='row notify-row notify-wrapper-#= type #'>" + 171 "<div class='col-md-2 col-xs-2 notify text-center notify-#= type #' onclick='getNotificationDetails(this);'>" + 172 "<i class='fa fa-warning mega'></i>" + 173 "</div>" +
174 "<div class='col-md-10 col-xs-10 dark'>" + 175 "<div class='col-md-11 col-xs-11 half-pad-top no-pad-right no-pad-left'>" + 176 "<p>#= message #</p>" + 177 "</div>" + 178 "<div class='col-md-1 col-xs-1 no-pad-right half-pad-top no-pad-left'>" + 179 "<div data-timestamp='#= timestamp #' onclick='hideNotification(this);' class='pull-right mega mega-x'>" + 180 "<i class='glyphicon glyphicon-remove'></i>" + 181 "</div>" + 182 "</div>" + 183 "<div class='clearfix'></div>" + 184 "<div class='row'>" + 185 "<p class='text-right half-pad-right time'>#= age # minutes</p>" + 186 "</div>" + 187 "</div>" + 188 "</div>"; 189 //#endregion 190 } 191 else if (type === "confirm") { 192 template = "<div id='confirm-dialog'>" + 193 "<p class='confirm-message'>" + o.message + "</p>" + 194 "<div class='padding'></div>" + 195 "<div class='confirm-actions'>" + 196 "<button class='pull-left btn btn-" + (o.cancelBtnClass ? o.cancelBtnClass : "warning") + " btncancel'>" + (o.cancelText ? o.cancelText : "Cancel") + "</button>" + 197 "<button class='pull-right btn btn-" + (o.continueBtnClass ? o.continueBtnClass : "primary") + " btnconfirm'>" + (o.continueText ? o.continueText : "Continue") + "</button>" + 198 "</div>" + 199 "</div>"; 200 } 201 else if (type === "confirmandresponse") { 202 template = "<div id='confirm-dialog'>" + 203 "<p class='confirm-message'>" + o.message + "</p>" + 204 "<textarea class='form-control confirmandresponse-textarea'></textarea>" + 205 "<div class='padding'></div>" + 206 "<div class='confirm-actions'>" + 207 "<button class='pull-left btn btn-" + (o.cancelBtnClass ? o.cancelBtnClass : "warning") + " btncancel'>" + (o.cancelText ? o.cancelText : "Cancel") + "</button>" + 208 "<button class='pull-right btn btn-" + (o.continueBtnClass ? o.continueBtnClass : "primary") + " btnconfirm'>" + (o.continueText ? o.continueText : "Continue") + "</button>" + 209 "</div>" + 210 "</div>"; 211 } 212 else if (type === "alert") { 213 template = "<div id='confirm-dialog'><p class='confirm-message'>" + o.message + "</p>" + 214 "<div class='padding'></div>" + 215 "<div class='confirm-actions center'>" + 216 "<button class='center btn btn-primary btncancel'>" + idstc().translate('general', 'Continue', 'Continue') + "</button>" + 217 "</div>" + 218 "</div > "; 219 } 220 221 return template; 222}; 223//#endregion 224 225idstc.prototype = function () { 226 var consultant = {}; 227 var pageNames = JSON.parse(translatedPageNames); 228 var validation = {}; 229 var translations = {}; 230 231 // Public property so that directives/controllers can use this data globally 232 233 var makeReady = function () { 234 return; 235 } 236 237 var getTranslations = function (container) { 238 var containerTranslations; 239 var translations = idstc().getExpirableSessionStorageVar('translations', 60); 240 241 var languageCode = localStorage.getItem('languageCode'); 242 var countryCode = localStorage.getItem('countryCode'); 243 244 if (translations == null) { 245 translations = {}; 246 } 247 else { 248 translations = JSON.parse(translations); 249 containerTranslations = translations[container]; 250 } 251 252 if (containerTranslations == null) { 253 if (this[container + 'promise']) { 254 return this[container + 'promise']; 255 } 256 257 var translationUrl = apiRoot + 'api/translation/getTranslationsByCountryLanguage?container=' + container; 258 259 if (languageCode != null && languageCode != '') { 260 translationUrl += '&languageCode=' + languageCode; 261 } 262 263 if (countryCode != null && countryCode != '') { 264 translationUrl += '&countryCode=' + countryCode; 265 } 266 267 this[container + 'promise'] = 268 $.ajax({
269 url: translationUrl, 270 type: 'GET', 271 contentType: 'application/json', 272 success: function (result) { 273 // Get from storage again in case another call caused an update while waiting for this response from server 274 var translations = idstc().getExpirableSessionStorageVar('translations', 60); 275 if (translations == null) { 276 translations = {}; 277 } 278 else { 279 translations = JSON.parse(translations); 280 } 281 282 translations[container] = result.data; // Set to local variable and use that for session storage (doesn't seem to like stringify'ing the angular scope variable) 283 284 idstc().setExpirableSessionStorageVar('translations', JSON.stringify(translations)); 285 }, 286 error: function (errorResult) { 287 idstc().processError({ error: errorResult, showNotifications: true }); 288 } 289 }); 290 291 292 return this[container + 'promise']; 293 } 294 else { 295 this.translations[container] = containerTranslations; 296 } 297 } 298 299 var removeAllNotifications = function () { 300 jQuery.each($(".k-notification"), function (i, val) { 301 hideNotification(val); 302 }); 303 304 document.cookie = "notifications=; path=/"; 305 } 306 307 var getURLParam = function (name) { 308 var url = window.location.href; 309 var results = new RegExp('[\\?&]' + name + '=([^&#]*)', 'i').exec(url); 310 311 if (!results) { 312 return null; 313 } 314 return results[1] || undefined; 315 } 316 317 var translate = function (container, prop, defaultText) { 318 try { 319 var stored = idstc().getExpirableSessionStorageVar('translations', 60); 320 if (stored != null) { 321 var containerTranslations = JSON.parse(stored)[container]; 322 if (containerTranslations != null) { 323 if (containerTranslations[prop] != null) { 324 return containerTranslations[prop]; 325 } 326 if (containerTranslations[prop.toLowerCase()] != null) { 327 return containerTranslations[prop.toLowerCase()]; 328 } 329 } 330 } 331 } catch (e) { 332 // Fall through to the default text if storage is unreadable. 333 } 334 335 return defaultText; 336 } 337 338 var getKendoCulture = function () { 339 if (php_vars && php_vars.languageCode) { 340 if (php_vars.languageCode.length == 5) { 341 var langArr = php_vars.languageCode.split('-'); 342 if (langArr.length == 2) { 343 return langArr[0].toLowerCase() + '-' + langArr[1].toUpperCase(); 344 } 345 else { 346 return 'en-US'; 347 } 348 } 349 else { 350 return 'en-US'; 351 } 352 } 353 else { 354 return 'en-US'; 355 } 356 } 357 358 var getAfterpayLocaleInfo = function (countryCode, cultureCode) { 359 var culture = cultureCode; 360 if (!culture) { 361 try { 362 culture = localStorage.getItem('languageCode'); 363 if (culture != null && culture.length == 2) { 364 var ccFromStorage = localStorage.getItem('countryCode'); 365 if (ccFromStorage != null && ccFromStorage != '') { 366 culture = culture + '-' + ccFromStorage; 367 } 368 } 369 } catch (e) { } 370 } 371 if (!culture) { 372 try { 373 if (php_vars && php_vars.languageCode) { 374 culture = php_vars.languageCode; 375 } 376 } catch (e) { } 377 } 378 if (!culture) { 379 culture = 'en-US'; 380 } 381 culture = culture.replace(/_/g, '-'); 382 383 var languageCode = null; 384 if (culture) { 385 languageCode = (culture.length > 2 ? culture.substring(0, 2) : culture).toLowerCase(); 386 } 387 388 var cc = countryCode; 389 if (!cc && culture) { 390 var parts = culture.split('-'); 391 if (parts.length > 1 && parts[1]) { 392 cc = parts[1]; 393 } 394 } 395 if (!cc) { 396 try { 397 cc = localStorage.getItem('countryCode'); 398 } catch (e) { } 399 } 400 cc = cc ? cc.toUpperCase() : null; 401 402 var consumerLocale = null; 403 var placementLocale = null; 404 405 if (cc === 'CA') { 406 consumerLocale = (languageCode === 'fr') ? 'fr-CA' : 'en-CA'; 407 placementLocale = (languageCode === 'fr') ? 'fr_CA' : 'en_CA'; 408 } 409 else if (cc === 'US') { 410 consumerLocale = 'en-US'; 411 placementLocale = 'en_US'; 412 } 413 else if (cc === 'GB' || cc === 'UK') { 414 consumerLocale = 'en-GB'; 415 placementLocale = 'en_GB'; 416 } 417 else if (cc === 'NZ') { 418 consumerLocale = 'en-NZ'; 419 placementLocale = 'en_NZ'; 420 } 421 else if (cc === 'AU') { 422 consumerLocale = 'en-AU'; 423 placementLocale = 'en_AU'; 424 } 425 else if (cc && languageCode) { 426 consumerLocale = languageCode + '-' + cc; 427 placementLocale = languageCode + '_' + cc; 428 } 429 430 return { 431 culture: culture, 432 languageCode: languageCode, 433 countryCode: cc, 434 consumerLocale: consumerLocale, 435 placementLocale: placementLocale 436 }; 437 } 438 439 var formatDateTime = function (date, format, culture, isStatic) { 440 if (typeof date === 'string') { 441 //microsoft's json serializer comes back with this weird date format sometimes. 442 //http://stackoverflow.com/questions/206384/how-do-i-format-a-microsoft-json-date 443 var regex = /\/Date\(\d+\)\//; 444 if (regex.test(date)) { 445 date = new Date(parseInt(date.substr(6))); 446 } 447 else { 448 date = new Date(moment(date)); 449 } 450 } 451 452 if (isStatic) { 453 date = new Date(date.valueOf() + date.getTimezoneOffset() * 60 * 1000); 454 } 455 456 format = format || 'd'; //set default to 'd' if no format passed in 457 culture = culture || 'en-US'; //set to culture for user if no culture passed in 458 459 if (typeof date == 'undefined') { 460 date = new Date(); 461 } 462 463 //get the culture script since we might have passed a culture we don't have a script for yet 464 return kendo.toString(date, format, culture); 465 } 466 467 var formatPhoneNumber = function (number) { 468 if (!number) { return ''; } 469 470 number = String(number); 471 472 var strippedNumber = number.replace(/\D/g, ''); 473 474 if (number == strippedNumber) { 475
476 // Will return formattedNumber. 477 // If phonenumber isn't longer than an area code, just show number 478 var formattedNumber = number; 479 480 // if the first character is '1', strip it out and add it back 481 var c = (number[0] === '1') ? '1 ' : ''; 482 number = number[0] === '1' ? number.slice(1) : number; 483 484 // # (###) ###-#### as c (area) front-end 485 var area = number.substring(0, 3); 486 var front = number.substring(3, 6); 487 var end = number.substring(6, 10); 488 489 if (front) { 490 formattedNumber = (c + '(' + area + ') ' + front); 491 } 492 if (end) { 493 formattedNumber += ('-' + end); 494 } 495 496 return formattedNumber; 497 } 498 499 return number; 500 } 501 502 var getProvinceForDisplay = function (address) { 503 if (!address) { 504 return ''; 505 } 506 507 if (address.Region) { 508 if (address.hasOwnProperty('DisplayRegion')) { 509 if (address.DisplayRegion) { 510 return address.Region; 511 } 512 } 513 } 514 515 if (address.ProvinceName) { 516 return address.ProvinceName; 517 } 518 519 if (address.Province) { 520 return address.Province.Name; 521 } 522 523 if (address.ProvinceAbbreviation) { 524 return address.ProvinceAbbreviation; 525 } 526 527 return ''; 528 } 529 530 var getCountryForDisplay = function (address) { 531 532 if (!address) { 533 return ''; 534 } 535 536 if (address.CountryName) { 537 return address.CountryName; 538 } 539 540 if (address.Province) { 541 return address.Province.CountryName; 542 } 543 544 if (address.CountryTwoLetterISO) { 545 return address.CountryTwoLetterISO; 546 } 547 548 return ''; 549 } 550 551 var formatNumberToCurrency = function (number, currencyTypeID) { 552 if (typeof number == 'undefined' || number == null) { 553 number = 0; 554 } 555 556 var formattedNumber = String(number); 557 558 // The following currency type id logic is a catchall intended to match that 559 // which was added for the portal. This code will ensure any currencytypeid 560 // value passed in is a valid number (regardless of type) and set to 561 // the default of '1' if it is not. 562 if (!isNaN(currencyTypeID) && typeof (currencyTypeID) !== 'number') { 563 //we have a valid numeric value but its not of type numeric so convert it 564 currencyTypeID = Number(currencyTypeID); 565 } 566 567 if (!currencyTypeID || isNaN(currencyTypeID)) { 568 //fallback to usd if the currency type isn't is null or a bad parameter 569 currencyTypeID = 1; 570 } 571 572 if (storage.get('CurrencyTypes') && currencyTypeID) { 573 574 var currencyTypes = storage.get('CurrencyTypes').currencyTypes; 575 576 // get the currency type info that will be used to format the number 577 var index = currencyTypes.indexOf(currencyTypes.filter(function (CurrencyType) { 578 return CurrencyType.CurrencyTypeID == currencyTypeID; 579 })[0]); 580 581 if (index >= 0) { 582 // get the individual parts of the number passed in 583 var numberArray = formattedNumber.split("."); 584 585 var decimalValue = ""; 586 var numberValue = ""; 587 588 if (numberArray.length > 0) { 589 numberValue = numberArray[0].toString().replace(/\B(?=(\d{3})+(?!\d))/g, currencyTypes[index].SeparatorSymbol.Symbol); 590 591 if (numberArray.length > 1) { 592 decimalValue = (numberArray[1] + Array(currencyTypes[index].DecimalDigits.DecimalDigits).join('0')).substring(0, currencyTypes[index].DecimalDigits.DecimalDigits); 593 } 594 else { 595 // decimalValue = Array(currencyTypes[index].DecimalDigits.DecimalDigits).join('0'); 596 decimalValue = (new Array(currencyTypes[index].DecimalDigits.DecimalDigits + 1)).join('0'); 597 } 598 } 599 else { 600 numberValue = numberArray.toString().replace(/\B(?=(\d{3})+(?!\d))/g, currencyTypes[index].SeparatorSymbol.Symbol); 601 602 decimalValue = Array(currencyTypes[index].DecimalDigits.DecimalDigits).join('0'); 603 } 604 605 formattedNumber = numberValue + currencyTypes[index].DecimalSymbol.Symbol + decimalValue; 606 607 if (currencyTypes[index].SymbolDisplayLocation.SymbolDisplayLocationID == 1) { 608 formattedNumber = currencyTypes[index].Symbol + formattedNumber; 609 } 610 else { 611 formattedNumber = formattedNumber + currencyTypes[index].Symbol; 612 } 613 } 614 } 615 616 return formattedNumber; 617 } 618 619 var formatDateFromUTC = function (date, dateTypeID) { 620 /*** 621 dataTypeID: 1 - Get date only, no time nor seconds 622 dataTypeID: 2 - Get date and time (no seconds) with utc offset
623 Anything else: Get date and time (with seconds) 624 */ 625 var formattedDate = String(date); 626 var browserOffset = (new Date().getTimezoneOffset()) / 60; 627 var format = storage.get('DateFormatString').dateFormat; 628 629 format = format.replace("dd", "DD"); 630 format = format.replace("yyyy", "YYYY"); 631 632 if (storage.get('UTCOffset') != null) { 633 var offset = storage.get('UTCOffset').offset; 634 var timeFormat = ' LT'; 635 636 if (storage.get('TimeFormat') != null) { 637 if (storage.get('TimeFormat').timeFormat == '24') { 638 timeFormat = ' HH:mm'; 639 } 640 } 641 else { 642 var valueToSave = { 643 timeFormat: '12', 644 dateTime: new Date().getTime() //set timestamp for cache 645 }; 646 storage.set('TimeFormat', valueToSave); 647 } 648 649 if (dateTypeID == 1) { // date only 650 var dateTime = new Date(moment(formattedDate)); 651 formattedDate = moment(dateTime).format(format); 652 } 653 else if (dateTypeID == 2) { // datetime with offset 654 format = format + timeFormat; 655 var dateTime = new Date(moment.utc(formattedDate)); 656 dateTime.setHours(dateTime.getHours() + offset); 657 formattedDate = moment.utc(dateTime).format(format); 658 } 659 else if (dateTypeID == 3) { // datetime with no offset (including seconds) 660 if (timeFormat == 'HH:mm') { 661 format = format + timeFormat + ':ss'; 662 } 663 else { 664 format = format + timeFormat + 'S'; 665 } 666 667 var dateTime = new Date(moment(formattedDate)); 668 formattedDate = moment(dateTime).format(format); 669 } 670 else if (dateTypeID == 4) { // utc date only 671 672 var dateTime = new Date(moment.utc(formattedDate)); 673 formattedDate = moment.utc(dateTime).format(format); 674 } 675 } 676 677 return (formattedDate == "Invalid date") ? "" : formattedDate; 678 } 679 680 var formatDateToUTC = function (date, dateTypeID) { 681 var formattedDate = String(date); 682 683 if (storage.get('UTCOffset') != null) { 684 var offset = storage.get('UTCOffset').offset; 685 formattedDate = moment(formattedDate).utc().utcOffset(offset).format("YYYY-MM-DD HH:mm:ss") 686 } 687 688 return formattedDate; 689 } 690 691 var processResponse = function (oArgs) { 692 if (oArgs && oArgs.showNotifications) { 693 if (oArgs.response.statusCode != 0) { 694 if (oArgs.response.Notifications == null || oArgs.response.Notifications.length == 0) { 695 if (oArgs.response.valResults != null && oArgs.response.valResults.length > 0) { 696 oArgs.response.Notifications = []; 697 698 for (var i = 0; i < oArgs.response.valResults.length; i++) { 699 oArgs.response.messages.push({ 700 Message: oArgs.response.valResults[i].ErrorMessage, 701 NotificationType: 1 702 }); 703 } 704 } 705 } 706 707 idstc().notifyServerResponse(oArgs.response); 708 709 return false; 710 } 711 else { 712 idstc().notifyServerResponse(oArgs.response); 713 } 714 } 715 716 return true; 717 } 718 719 var processError = function (oArgs) { 720 // check for standard exception 721 if (oArgs.error && oArgs.error.data && oArgs.error.data.ExceptionMessage && oArgs.showNotifications) { 722 oArgs.response = {}; 723 oArgs.response.Notifications = []; 724 oArgs.response.messages = []; 725 726 oArgs.response.messages.push({ 727 Message: oArgs.error.data.ExceptionMessage, 728 NotificationType: 1, 729 ShowNext: oArgs.showNext 730 }); 731 732 idstc().notifyServerResponse(oArgs.response); 733 } 734 else if (oArgs.error && oArgs.error.data && oArgs.error.data.messages && oArgs.error.data.messages.length > 0 && oArgs.showNotifications) { 735 oArgs.response = {}; 736 oArgs.response.Notifications = []; 737 oArgs.response.messages = oArgs.error.data.messages; 738 739 idstc().notifyServerResponse(oArgs.response); 740 } 741 else { 742 // check for http exception 743 if (oArgs.error && oArgs.error.status && oArgs.error.statusText && oArgs.showNotifications) { 744 oArgs.response = {}; 745 oArgs.response.Notifications = []; 746 oArgs.response.messages = []; 747 748 oArgs.response.messages.push({ 749 Message: oArgs.error.statusText, 750 NotificationType: 1, 751 ShowNext: oArgs.showNext 752 }); 753 754 idstc().notifyServerResponse(oArgs.response); 755 } 756 else { 757 if (oArgs.error && oArgs.error.messages) { 758 oArgs.response = {}; 759 oArgs.response.Notifications = []; 760 oArgs.response.messages = []; 761 762 oArgs.response.messages = oArgs.error.messages; 763 764 idstc().notifyServerResponse(oArgs.response); 765 } 766 } 767 } 768 } 769 770 // get an expirable local storage variable. these variables are set to expire in 24 hours. 771 var getExpirableLocalStorageVar = function (varName, expireMinutes) { 772 var lsVariable = localStorage.getItem(varName); 773 774 if (lsVariable != null && lsVariable != '') { 775 lsVariable = JSON.parse(lsVariable); 776 777 if (lsVariable != null) { 778 if (lsVariable.dateTime !== undefined && lsVariable.dateTime != null) { 779 var diffTime = new Date().getTime() - lsVariable.dateTime; 780 var diffInMinutes = Math.floor(diffTime / 1000 / 60); //get minutes from time 781 782 if (diffInMinutes >= expireMinutes) { //cache for the amount of minutes passed in; if expired then remove from local storage 783 localStorage.removeItem(varName); 784 return null; 785 } 786 787 return lsVariable.value; 788 } 789 else { 790 localStorage.removeItem(varName); 791 return null; 792 } 793 } 794 else { 795 return null; 796 } 797 } 798 else { 799 return null; 800 } 801 }; 802 803 var setExpirableLocalStorageVar = function (varName, value) { 804 if (value == null) { 805 console.log('Warning - idstc.js - setExpirableLocalStorageVar - value is null for ', varName); 806 } 807 808 var valueToSave = { 809 value: value, 810 dateTime: new Date().getTime() //set timestamp for cache 811 }; 812 var jsonValue = JSON.stringify(valueToSave); 813 localStorage.setItem(varName, jsonValue); 814 }; 815 816 // get an expirable session storage variable. these variables are set to expire in 1 hours. 817 var getExpirableSessionStorageVar = function (varName, expireMinutes) { 818 var lsVariable = sessionStorage.getItem(varName); 819 lsVariable = JSON.parse(lsVariable); 820 821 if (lsVariable != null) { 822 if (lsVariable.dateTime !== undefined && lsVariable.dateTime != null) { 823 var diffTime = new Date().getTime() - lsVariable.dateTime; 824 var diffInMinutes = Math.floor(diffTime / 1000 / 60); //get minutes from time 825 826 if (diffInMinutes >= expireMinutes) { //cache for the amount of minutes passed in; if expired then remove from session storage 827 sessionStorage.removeItem(varName); 828 return null; 829 } 830 831 return lsVariable.value; 832 } 833 else { 834 sessionStorage.removeItem(varName); 835 return null; 836 } 837 } 838 else { 839 return null; 840 } 841 }; 842 843 var setExpirableSessionStorageVar = function (varName, value) { 844 if (value == null) { 845 console.log('Warning - idstc.js - setExpirableSessionStorageVar - value is null for ', varName); 846 } 847 848 var valueToSave = { 849 value: value, 850 dateTime: new Date().getTime() //set timestamp for cache 851 }; 852 var jsonValue = JSON.stringify(valueToSave); 853 sessionStorage.setItem(varName, jsonValue); 854 }; 855 856 // framework functions 857 // ******************* 858 var responseMessage = function (messages, data, statusCode, success, valResults, origObj) { 859 this.messages = messages; 860 this.statusCode = statusCode; 861 this.success = success || "error"; 862 this.data = data; 863 this.valResults = valResults; 864 this.originalObject = origObj; 865 866 return this; 867 } 868 869 //#region Notification Panel 870 var toggleNotificationPanel = function (close, log, forceShow, o) { 871 var wp = window.parent.document; 872 873 if (log) { 874 console.log(log); 875 } 876 877 if (forceShow) { 878 $("#sidebar-wrapper", wp).addClass("active"); 879 880 return true; 881 } 882 883 if (close) { 884 clearTimeout(HideIDSTCNotifyTimeout); 885 886 $("#sidebar-wrapper", wp).removeClass("active"); 887 888 return true; 889 } 890 else { 891 clearTimeout(HideIDSTCNotifyTimeout); 892 893 if (!o.fromCookie) { 894 $("#sidebar-wrapper", wp).addClass("active"); 895 896 if (o && o.success.toLowerCase() === "success") { 897 HideIDSTCNotifyTimeout = setTimeout(function () { 898 idstc().toggleNotificationPanel(true, null); 899 $("#notification").removeClass("flash"); 900 }, 1750); 901 } 902 } 903 } 904 } 905 //#endregion 906 907 //#region Common Dialog Helpers 908 var notifyServerResponse = function (response, callback) { 909 910 if (response && response.data && response.data.messages) { 911 response = response.data; 912 } 913 914 if (response && response.data && response.data.ExceptionMessage) { 915 response = response.data; 916 } 917 918 if (response && response.data && response.data.Notifications) { 919 response = response.data; 920 } 921 922 if (response && response.Notifications && response.messages == null) { 923 //In case the return response hasn't been converted from server format; do it now 924 var r = response; 925 response = new idstc().responseMessage(r.Notifications, r.Value, r.ResultCode, "success", r.ValidationResults); 926 } 927 928 if (response && response.messages) { 929 $.each(response.messages, function () { 930 var errortype; 931 932 if (this.NotificationType === 0) { 933 errortype = "success"; 934 } 935 else if (this.NotificationType === 1) { 936 errortype = "error"; 937 } 938 else if (this.NotificationType === 2 || this.NotificationType === 3) { 939 errortype = "warn"; 940 } 941 942 // if (this.NotificationType != 3) { 943 idstc().notify( 944 { message: this.Message, success: errortype, showNext: this.ShowNext }, 945 callback 946 ); 947 // } 948 }); 949 } 950 } 951 952 var notifyServerResponseHelp = function () { 953 var help = { 954 inputs: "idstc ServerResponse object, callback()", 955 requiredProperties: "idstc serverreponse object", 956 description: "Call this method after using $http get and post methods. Get and Post return a client side " + 957 "server response object that may contain notifications. For each notification in the server response this method will display " + 958 "a notification as the corresponding type returned from the server. Success = 0, Warn =2, Error = 1" 959 } 960 961 console.log(help); 962 } 963 //#endregion 964 965 //#region Common Dialog 966 var notify = function (o, callback) { 967 o.type = "notification"; 968 dialog(o, callback); 969 } 970 971 var notifyHelp = function () { 972 console.log("this method overloads dialog with a type of 'notification'. Run dialogHelp for detailed information."); 973 } 974 975 var dialog = function (o, callback) { 976 var wp = window.parent.document; 977 978 if (!o.type) { 979 o.type = "confirm"; 980 } 981 982 if (o.type.toLowerCase() === "notification") { 983 // #region Notification 984 var n; 985 986 if (!o.message) { 987 throw "Supply a message property for notification"; 988 } 989 990 if (!o.success) { 991 throw "Supply a success property for notification"; 992 } 993 994 if (o.success.toLowerCase() === "success" || o.success.toLowerCase() === "warn" || o.success.toLowerCase() === "error" || o.success.toLowerCase() === "alert") { 995 996 } else throw "Unacceptable success value from response. success, warn, error are supported."; 997 998 if (o.template) { 999 n = $("#notification-wrapper", wp).kendoNotification({ 1000 appendTo: $("#sidebar-wrapper", wp), 1001 autoHideAfter: o.template.autoHideAfter, 1002 stacking: o.template.stacking, 1003 templates: o.template.templates, 1004 button: true, 1005 hideOnClick: false 1006 }); 1007 } 1008 else { 1009 jQuery.each($('[data-timestamp]'), function (i, val) { 1010 hideNotification(val, true); 1011 }); 1012 1013 var timestamp = o.timestamp || Date.now(); 1014 1015 n = $("#notification-wrapper", wp).kendoNotification({ 1016 appendTo: $("#sidebar-wrapper", wp), 1017 autoHideAfter: 0, 1018 stacking: "up", 1019 allowHideAfter: 1000, 1020 button: true, 1021 hideOnClick: false, 1022 templates: [ 1023 { 1024 type: "successerrorwarn", 1025 template: idstc.templates("successerrorwarn") 1026 } 1027 ] 1028 }).data("kendoNotification"); 1029 1030 if (!o.fromCookie) { 1031 // Only add notification to cookie if it needs to be displayed on next page load 1032 if (o.showNext) { 1033 var notification = { message: o.message, type: o.success, timestamp: timestamp, showNext: o.showNext }; 1034 var notifications = getNotificationsArray(); 1035 1036 notifications.push(notification); 1037
1038 document.cookie = "notifications=" + JSON.stringify(notifications) + "; path=/"; 1039 } 1040 } 1041 1042 if ($("div[data-timestamp='" + timestamp + "']").length === 0) { 1043 var diff = Math.abs(Date.now() - timestamp); 1044 1045 o.age = Math.floor((diff / 1000) / 60); 1046 1047 if (n) { 1048 n.show( 1049 { 1050 type: o.success || "", 1051 message: o.message || "", 1052 age: o.age || "0", 1053 timestamp: timestamp 1054 }, 1055 "successerrorwarn" 1056 ); 1057 1058 idstc().toggleNotificationPanel(false, null, null, o); 1059 1060 if (!o.fromCookie) { 1061 $("#notification").addClass("flash"); 1062 } 1063 } 1064 } 1065 1066 // run callback 1067 if (callback && typeof (callback) === "function") { 1068 callback(); 1069 } 1070 } 1071 // #endregion 1072 } 1073 else if (o.type.toLowerCase().indexOf("confirm") > -1) { 1074 // #region Confirm 1075 1076 var winEl = $("#confirmDialog"); 1077 1078 var kendoWindow = winEl.kendoWindow({ 1079 title: o.title, 1080 resizable: false, 1081 modal: true 1082 }); 1083 1084 if (o.type.toLowerCase() === "confirm") { 1085 var kWindow = kendoWindow.data("kendoWindow"); 1086 kWindow.wrapper.addClass("confirmWindow"); 1087 kWindow.content( 1088 idstc.templates("confirm", o) 1089 ).center().open(); 1090 } else { 1091 if (o.type.toLowerCase() === 'confirmandresponse') { 1092 var kWindow = kendoWindow.data("kendoWindow"); 1093 kWindow.wrapper.addClass("confirmResponseWindow"); 1094 kWindow.content( 1095 idstc.templates('confirmandresponse', o) 1096 ).center().open(); 1097 } 1098 else { 1099 var kWindow = kendoWindow.data("kendoWindow"); 1100 kWindow.wrapper.addClass("confirmResponseInputWindow"); 1101 kWindow.content( 1102 idstc.templates('confirmandresponseinput', o) 1103 ).center().open(); 1104 } 1105 } 1106 1107 if (o.cancelButtonText != null) { 1108 $('.confirm-actions > .btncancel').text(o.cancelButtonText); 1109 } 1110 1111 if (o.confirmButtonText != null) { 1112 $('.confirm-actions > .btnconfirm').text(o.confirmButtonText); 1113 } 1114 1115 $(".confirm-actions").on("click", ".btnconfirm", function () { 1116 // run whatever method was passed in on confirm 1117 if ($(this).hasClass("btnconfirm")) { 1118 // run callback 1119 if (callback && typeof (callback) === "function") { 1120 callback(true, $(this)); 1121 } 1122 1123 } 1124 1125 winEl.data("kendoWindow").close(); 1126 1127 return this; 1128 }); 1129 1130 $(".confirm-actions").on("click", ".btncancel", function () { 1131 1132 winEl.data("kendoWindow").close(); 1133 1134 if (callback && typeof (callback) === "function") { 1135 callback(false, $(this)); 1136 } 1137 1138 return this; 1139 1140 }); 1141 // #endregion 1142 } 1143 else if (o.type.toLowerCase() === "alert") { 1144 // #region Alert 1145 var winEl = $("#confirmDialog"); 1146 1147 var kendoWindow = winEl.kendoWindow({ 1148 title: o.title, 1149 resizable: false, 1150 modal: true, 1151 actions: ["Close"], 1152 close: function () { 1153 if (callback && typeof (callback) === "function") { 1154 callback(false, $(this)); 1155 } 1156 }, 1157 }); 1158 1159 var kWindow = kendoWindow.data("kendoWindow"); 1160 kWindow.wrapper.addClass("alertWindow"); 1161 kWindow.content( 1162 idstc.templates("alert", o) 1163 ).center().open(); 1164 1165 $(".confirm-actions").on("click", ".btncancel", function () { 1166 1167 winEl.data("kendoWindow").close(); 1168 1169 if (callback && typeof (callback) === "function") { 1170 callback(false, $(this)); 1171 } 1172 1173 return this; 1174 1175 }); 1176 // #endregion 1177 } 1178 else { 1179 if (o.type) { 1180 throw "incorrect dialog type specified. expecting confirm, or notification"; 1181 } 1182 else { 1183 throw "no dialog type specified."; 1184 } 1185 } 1186 1187 return this; 1188 } 1189 1190 var dialogHelp = function () { 1191 var help = { 1192 inputs: "object{ type, success, message, title, kendoNotificationTemplate{}
1192, continueText, cancelText, continueBtnClass, cancelBtnClass }", 1193 requiredProperties: "success, message", 1194 defaults: "type = confirm, title = '', continueText = 'Continue', cancelText = 'Cancel', continueBtnClass = 'primary', cancelBtnClass = 'warn'", 1195 kendoTemplateDefault: { 1196 appendTo: "#notificationpanel", 1197 autoHideAfter: 4800, 1198 stacking: "up", 1199 templates: [ 1200 { 1201 type: "successerrorwarn", 1202 template: idstc.templates("successerrorwarn") 1203 } 1204 ] 1205 }, 1206 overrides: "use notify which overrides dialog to a notification type.", 1207 notes: "pass an anonymous fn() to run code after dialog" 1208 }; 1209 1210 console.log(help); 1211 } 1212 //#endregion 1213 1214 1215 1216 var spinner = function () { 1217 1218 } 1219 1220 //#region Method Returns 1221 return { 1222 pageNames: pageNames, 1223 validation: validation, 1224 translations: translations, 1225 removeAllNotifications: removeAllNotifications, 1226 getURLParam: getURLParam, 1227 notify: notify, 1228 notifyHelp: notifyHelp, 1229 dialog: dialog, 1230 dialogHelp: dialogHelp, 1231 processResponse: processResponse, 1232 processError: processError, 1233 responseMessage: responseMessage, 1234 toggleNotificationPanel: toggleNotificationPanel, 1235 notifyServerResponse: notifyServerResponse, 1236 notifyServerResponseHelp: notifyServerResponseHelp, 1237 formatDateTime: formatDateTime, 1238 formatPhoneNumber: formatPhoneNumber, 1239 formatNumberToCurrency: formatNumberToCurrency, 1240 formatDateFromUTC: formatDateFromUTC, 1241 formatDateToUTC: formatDateToUTC, 1242 getExpirableLocalStorageVar: getExpirableLocalStorageVar, 1243 setExpirableLocalStorageVar: setExpirableLocalStorageVar, 1244 getExpirableSessionStorageVar: getExpirableSessionStorageVar, 1245 setExpirableSessionStorageVar: setExpirableSessionStorageVar, 1246 getTranslations: getTranslations, 1247 getProvinceForDisplay: getProvinceForDisplay, 1248 getCountryForDisplay: getCountryForDisplay, 1249 makeReady: makeReady, 1250 translate: translate, 1251 getKendoCulture: getKendoCulture, 1252 getAfterpayLocaleInfo: getAfterpayLocaleInfo 1253 }; 1254 //#endregion 1255 1256}(); 1257 1258//#region Validation object to append to idstc object 1259idstc.prototype.validation = { 1260 1261 getCreditCardType: function (number, allowedCardTypes) { 1262 var card, card_type, card_types, get_card_type; 1263 1264 //#region Card_Types array 1265 card_types = []; 1266 1267 if (allowedCardTypes == null) allowedCardTypes = [1, 2, 3, 4]; 1268 1269 if (allowedCardTypes.indexOf(1) > -1) { 1270 card_types.push({ 1271 id: '1', 1272 name: 'Visa', 1273 pattern: /^4/, 1274 valid_length: [16] 1275 }); 1276 } 1277 if (allowedCardTypes.indexOf(2) > -1) { 1278 card_types.push({ 1279 id: '2', 1280 name: 'MasterCard', 1281 pattern: /^5[1-5]/, 1282 valid_length: [16] 1283 }); 1284 } 1285 if (allowedCardTypes.indexOf(3) > -1) { 1286 card_types.push({ 1287 id: '3', 1288 name: 'AmericanExpress', 1289 pattern: /^3[47]/, 1290 valid_length: [15] 1291 }); 1292 } 1293 if (allowedCardTypes.indexOf(4) > -1) { 1294 card_types.push({ 1295 id: '4', 1296 name: 'Discover', 1297 pattern: /^(6011|622(12[6-9]|1[3-9][0-9]|[2-8][0-9]{2}|9[0-1][0-9]|92[0-5]|64[4-9])|65)/, 1298 valid_length: [16] 1299 }); 1300 } 1301 1302 //#endregion 1303 1304 var options = {}; 1305 1306 get_card_type = function (number) { 1307 var _j, _len1, _ref2; 1308 _ref2 = (function () { 1309 var _k, _len1, _ref2, _results; 1310 _results = []; 1311 for (_k = 0, _len1 = card_types.length; _k < _len1; _k++) { 1312 card = card_types[_k]; 1313 if (_ref2 = card.name) { 1314 _results.push(card); 1315 } 1316 } 1317 return _results; 1318 })(); 1319 for (_j = 0, _len1 = _ref2.length; _j < _len1; _j++) { 1320 card_type = _ref2[_j];
1321 if (number.match(card_type.pattern)) { 1322 return card_type; 1323 } 1324 } 1325 return null; 1326 }; 1327 1328 return get_card_type(number); 1329 } 1330}; 1331//#endregion
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.