1var providers = {}; 2var idstcApiToken = null; 3 4var app = angular.module('app', ['kendo.directives', 'ui.router', 'ngSanitize'], function ($controllerProvider, $compileProvider, $provide) { 5 providers = { 6 $controllerProvider: $controllerProvider, 7 $compileProvider: $compileProvider, 8 $provide: $provide 9 }; 10}); 11 12//Expose our idstc object into angular for injection 13app.constant('idstc', window.idstc); 14 15//Add transform from idstc() library 16app.config(function ($httpProvider, idstc) { 17 18 $httpProvider.defaults.withCredentials = true; 19 $httpProvider.defaults.transformResponse.push(function (data, headersGetter) { 20 21 //Handling types such as: application/json; charset=utf-8 22 if (/application\/json;/.test(headersGetter('Content-Type'))) { 23 24 return ProcessIdstcResponseObject(data); 25 } else { 26 return data; 27 } 28 }); 29 30 $httpProvider.interceptors.push(function ($q) { 31 return { 32 // optional method 33 'request': function (config) { 34 35 if (idstcApiToken != null) { 36 let apiUrlLowercase = idstc_setting_apiurl.toLowerCase(); 37 38 if (config.url.toLowerCase().indexOf(apiUrlLowercase) >= 0) { 39 config.headers.Authorization = 'bearer ' + idstcApiToken; 40 } 41 } 42 43 // do something on success 44 return config; 45 }, 46 'response': function (response) { 47 return response; 48 }, 49 'requestError': function (rejectReason) { 50 }, 51 'responseError': function (response) { 52 if (response.status === 403) { 53 var personType = localStorage.getItem('pesonType'); 54 if (personType === 2 && location.href !== '/log-in-customer') { 55 location.href = '/log-in-customer'; 56 } 57 if (personType === 1 && location.href !== '/log-in-consultant') { 58 location.href = '/log-in-consultant'; 59 } 60 } 61 throw response; 62 } 63 }; 64 }); 65 66 //Hoisting makes this available to the above transform function 67 function isIdstcResponseObject(o) { 68 if (angular.isObject(o)) { 69 return o.hasOwnProperty('ResultCode') && o.hasOwnProperty('Notifications') && o.hasOwnProperty('ValidationResults'); 70 } 71 72 return false; 73 } 74 75 function ProcessIdstcResponseObject(o) { 76 77 if (isIdstcResponseObject(o)) { 78 79 //If we get this far, must have been a success. If not, I modified the standard responseMessage fn to default to 'error' 80 var actualNewObject = {}; 81 82 //SD: Not sure the idstc object is doing the right thing here so i'm explicitly setting 'this' to a brand new object 83 return new idstc().responseMessage.call(actualNewObject, o.Notifications, o.Value, o.ResultCode, 'success', o.ValidationResults, o); 84 } 85 86 return o; 87 } 88}); 89 90//Decorator pattern to capture errors and put into our notifications. (easier troubleshooting) 91app.config(function ($provide) { 92 $provide.decorator('$exceptionHandler', function ($delegate, $injector) { 93 return function (exception, cause) { 94 95 $delegate(exception, cause); 96 97 var idstc = $injector.get('idstc'); 98 99 JL('Angular').fatalException(cause, exception); 100 101 idstc().notify({ message: exception.message, title: 'Error Notification', success: 'error' }); 102 }; 103 }); 104}); 105 106// Handle routing for the client support app 107app.config(['$locationProvider', function ($locationProvider) { 108 $locationProvider.html5Mode({ 109 enabled: true, 110 requireBase: false, 111 rewriteLinks: false 112 }); 113}]); 114 115app.run(['$rootScope', '$location', '$state', '$stateParams', function ($rootScope, $location, $state, $stateParams) { 116 //Client-side security. Server-side framework MUST add it's 117 //own security as well since client-based security is easily hacked 118 $rootScope.$on('$stateChangeStart', 119 function (event, toState, toParams, fromState, fromParams) { 120 $(document).progressStart(); 121 } 122 ); 123 124 $rootScope.$on('$stateChangeSuccess', 125 function (event, toState, toParams, fromState, fromParams) { 126 $(document).progressFinish(); 127 } 128 ); 129
130 // It's very handy to add references to $state and $stateParams to the $rootScope 131 // so that you can access them from any scope within your applications.For example, 132 // <li ng-class='{ active: $state.includes('contacts.list') }'> will set the <li> 133 // to active whenever 'contacts.list' or one of its decendents is active. 134 $rootScope.$state = $state; 135 $rootScope.$stateParams = $stateParams; 136}]); 137 138function getParameterByName(name, ignoreCase = false) { 139 name = name.replace(/[\[]/, '\\[').replace(/[\]]/, '\\]'); 140 const flags = ignoreCase ? 'i' : ''; 141 const regex = new RegExp('[\\?&]' + name + '=([^&#]*)', flags); 142 const results = regex.exec(location.search); 143 return results === null ? '' : decodeURIComponent(results[1].replace(/\+/g, ' ')); 144} 145 146$(document).ready(function ($) { 147 148 var consultant = $.parseJSON(sessionStorage.getItem('consultant')); 149 150 // Store our _invokeQueue length before loading our controllers/directives/services 151 // This is just so we don't re-register anything 152 var queueLen = angular.module('app')._invokeQueue.length; 153 154 // Load javascript file with controllers/directives/services 155 angular.module('app') 156 .controller('siteController', function ($scope, $rootScope, $http, $q, appService, shoppingCartModel) { 157 var vm = this; 158 159 appService.scope = $scope; 160 vm.appService = appService; 161 vm.shoppingCartModel = shoppingCartModel; 162 163 vm.init = function () { 164 var promises = [appService.makeReady()]; 165 166 $q.all(promises).then(function (result) { 167 168 }); 169 } 170 171 vm.init(); 172 }) 173 .factory('appService', function ($http, $q, $sce, $compile, $location, $filter) { 174 var service = this; 175 176 service.consultant = null; 177 service.apiToken = null; 178 service.getAPITokenPromise = null; 179 service.currencyTypePromise = null; 180 service.dateFormatPromise = null; 181 service.timeFormatPromise = null; 182 service.utcOffsetPromise = null; 183 service.businessUnitIDPromise = null; 184 service.getConsultantPromise = null; 185 service.makeReadyPromise = null; 186 187 service.loggedIn = idstc().getExpirableLocalStorageVar('loggedIn', 60); 188 service.personTypeId = idstc().getExpirableLocalStorageVar('personType', 60); 189 service.translatedPageNames = JSON.parse(translatedPageNames); 190 191 // The configData is a JSON representation of the data required to build the URL. 192 service.createShortUrl = function (configData) { 193 if (service.consultant != null) { 194 configData.replicatedSiteUrl = service.consultant.Url; 195 } 196 197 if (service.referringCustomerDisplayId != null) { 198 configData.referringCustomerDisplayId = service.referringCustomerDisplayId; 199 } 200 201 if (php_vars && php_vars.languageCode) { 202 configData.languageCode = php_vars.languageCode; 203 } 204 205 let url = templateUrl + 'api/addShortUrl.php'; 206 207 let postVar = { 208 configData: JSON.stringify(configData) 209 } 210 211 return $http.post(url, postVar).then( 212 function (response) { 213 let shareUrl = location.protocol + '//' + location.hostname; 214 215 shareUrl += response.data; 216 217 service.shareUrl = shareUrl; 218 }, 219 function (errorResult) { 220 idstc().processError({ error: errorResult, showNotifications: true }); 221 } 222 ); 223 }; 224 225 service.getLanguagePrefix = function (languageCode, countryCode) { 226 let url = '/wp-admin/admin-ajax.php?action=idstc_get_languages'; 227 228 return $http.get(url).then( 229 function (successResult) { 230 let siteLanguages = successResult.data; 231 let prefix = '/'; 232 233 if (languageCode != null) { 234 let langCode = languageCode; 235 236 if (countryCode != null) { 237 langCode += '-' + countryCode; 238 } 239 240 if (siteLanguages.default != '' && siteLanguages.default != langCode) { 241 if ($filter('filter')(siteLanguages.languages, langCode, true) != null && $filter('filter')(siteLanguages.languages, langCode, true).length > 0) { 242 prefix += langCode; 243 } 244 else { 245 langOnly = $filter('filter')(siteLanguages.languages, languageCode, false); 246 if (langOnly != null && langOnly.length > 0) {
247 prefix += langOnly[0]; 248 } 249 } 250 251 prefix += '/'; 252 } 253 } 254 255 return prefix; 256 }, 257 function (errorResult) { 258 idstc().processError({ error: errorResult, showNotifications: true }); 259 return '/'; 260 } 261 ); 262 }; 263 264 service.logout = function (gotoHome) { 265 localStorage.removeItem('Authorization'); 266 localStorage.removeItem('idstc-cart'); 267 localStorage.removeItem('loggedIn'); 268 localStorage.removeItem('personType'); 269 localStorage.removeItem('CartID'); 270 localStorage.removeItem('CustomerCartID'); 271 localStorage.removeItem('CartItemQuantity'); 272 localStorage.removeItem('displayCategoryId'); 273 localStorage.removeItem('subSkuForWeb'); 274 localStorage.removeItem('referringCustomerDisplayId'); 275 sessionStorage.removeItem('displayCategories'); 276 sessionStorage.removeItem('translations'); 277 localStorage.removeItem('accountTypeID'); 278 localStorage.removeItem('flightCustomFields'); 279 280 if (gotoHome == null || gotoHome == true) { 281 service.getLanguagePrefix(localStorage.getItem('languageCode'), localStorage.getItem('countryCode')).then(function (result) { 282 let languagePrefix = result; 283 window.location = languagePrefix; 284 }); 285 } 286 }; 287 288 if ($location.search().logout == '1') { 289 service.logout(); 290 } 291 292 service.collectCustomFieldsFromUrl = function () { 293 service.setCustomField('utm_campaign'); 294 service.setCustomField('utm_content'); 295 service.setCustomField('utm_medium'); 296 service.setCustomField('utm_source'); 297 service.setCustomField('utm_term'); 298 } 299 300 service.setCustomField = function (field) { 301 let value = getParameterByName(field) || ''; 302 303 if (value != '') { 304 let storedItem = localStorage.getItem('flightCustomFields'); 305 306 if (storedItem == null) { 307 storedItem = {}; 308 } 309 else { 310 storedItem = JSON.parse(storedItem); 311 } 312 313 storedItem[field] = value; 314 315 localStorage.setItem('flightCustomFields', JSON.stringify(storedItem)); 316 } 317 } 318 319 service.makeReady = function () { 320 if (service.makeReadyPromise) { 321 return service.makeReadyPromise; 322 } 323 324 var promises = []; 325 service.newAuthToken = localStorage.getItem('newAuthToken'); 326 327 service.makeReadyPromise = $q.all(promises).then(function (result) { 328 service.collectCustomFieldsFromUrl(); 329 330 if (service.newAuthToken != null || service.tokenValid) { 331 if (service.newAuthToken != null) { 332 service.newAuthToken = service.newAuthToken.replace('bearer ', ''); 333 334 idstc().setExpirableLocalStorageVar('Authorization', service.newAuthToken); 335 idstc().setExpirableLocalStorageVar('loggedIn', true); 336 337 localStorage.removeItem('newAuthToken'); 338 339 service.apiToken = service.newAuthToken; 340 idstcApiToken = service.newAuthToken; 341 service.loggedIn = true; 342 service.tokenValid = true; 343 } 344 } 345 346 // Try to get replicated site url 347 let repUrl = getParameterByName('u'); 348 349 if (repUrl == null || repUrl == '') { 350 if (typeof (pluginReplSite) != 'undefined' && pluginReplSite != null && pluginReplSite != '') { 351 repUrl = pluginReplSite; 352 } 353 } 354 355 // Check to see if you were on a replicated site and now it is changing 356 // if so, clear cart info to avoid person shopping with bad parameters. 357 if (repUrl != null && repUrl != '') { 358 var localRepUrl = localStorage.getItem('replicatedSiteUrl'); 359 if (localRepUrl != null && localRepUrl != '' && repUrl != localRepUrl) {
360 localStorage.removeItem('CartID'); 361 localStorage.removeItem('CustomerCartID'); 362 localStorage.removeItem('CartItemQuantity'); 363 localStorage.removeItem('displayCategoryId'); 364 localStorage.removeItem('referringCustomerDisplayId'); 365 sessionStorage.removeItem('displayCategories'); 366 localStorage.removeItem('accountTypeID'); 367 sessionStorage.removeItem('validatedEventID'); 368 localStorage.removeItem('idstc-cart'); 369 } 370 } 371 372 if (repUrl == null || repUrl == '') { 373 repUrl = localStorage.getItem('replicatedSiteUrl'); 374 } 375 376 // Try to get referring customer display id 377 // First from URL 378 // Second from local storage 379 service.referringCustomerDisplayId = getParameterByName('r'); 380 381 if (service.referringCustomerDisplayId == null || service.referringCustomerDisplayId == '') { 382 service.referringCustomerDisplayId = localStorage.getItem('referringCustomerDisplayId'); 383 } 384 else { 385 localStorage.setItem('referringCustomerDisplayId', service.referringCustomerDisplayId); 386 } 387 388 if ((repUrl != null && repUrl != '') && (consultant == null || consultant.Url == null || consultant.Url.toLowerCase() != repUrl.toLowerCase())) { 389 promises.push(service.getConsultant(repUrl)); 390 } 391 else if (consultant != null) { 392 service.consultant = consultant; 393 flightConsultant = consultant; 394 } 395 else if (idstc_setting_businessunitsenabled) { 396 promises.push(service.getDefaultBusinessUnitID()); 397 } 398 399 return $q.all(promises).then(function (result) { 400 if (service.newAuthToken == null || !service.tokenValid) { 401 promises.push(service.getAPIToken()); 402 } 403 404 return $q.all(promises).then(function (result) { 405 promises = [service.getCurrencyTypes(), service.getUTCOffset(), service.getDateFormat(), service.getTimeFormat(), service.getCountries()]; 406 407 if (service.newAuthToken != null) { 408 var cartId = idstc().getExpirableLocalStorageVar('CartID', idstc_setting_acutacartexpirationseconds); 409 410 // Now try to get the replicated site owner for this customer 411 if (repUrl == null || repUrl == '') { 412 promises.push(service.getReplicatedSiteOwner()); 413 } 414 else { 415 var keepSiteOwner = localStorage.getItem('keepSiteOwner'); 416 417 if (keepSiteOwner != null) { 418 service.keepSiteOwner = true; 419 localStorage.removeItem('keepSiteOwner'); 420 } 421 else if (!service.keepSiteOwner) { 422 promises.push(service.getReplicatedSiteOwner()); 423 } 424 } 425 426 promises.push(service.setCurrentPerson(cartId)); 427 } 428 429 return $q.all(promises).then(function (result) { 430 if (service.consultant != null && service.consultant.Url != null) { 431 // Append the replicated site url as u 432 let repUrlParam = getParameterByName('u') || ''; 433 434 if (repUrlParam == '') { 435 let path = window.location.pathname || ''; 436 let queryString = window.location.search || ''; 437 let newPath = path + queryString; 438 let appendText = 'u=' + service.consultant.Url; 439 440 if (queryString == '') { 441 appendText = '?' + appendText; 442 } 443 else { 444 appendText = '&' + appendText; 445 } 446 447 if (newPath.toLowerCase().indexOf('/' + service.consultant.Url.toLowerCase()) == -1) { 448 window.history.replaceState(null, null, newPath + appendText); 449 } 450 } 451 $('body').addClass(service.consultant.Url.toLowerCase()); 452 $('body').addClass('rank-' + service.consultant.RankTypeID);
453 //Also - set the body class to let site know we are replicated in case styling should be different 454 $('body').removeClass('non-replicated'); 455 $('body').addClass('replicated'); 456 } 457 458 if (service.referringCustomerDisplayId != null && service.referringCustomerDisplayId != '') { 459 // Append the referring customer display id as r 460 let referringCustomerDisplayIdParam = getParameterByName('r') || ''; 461 462 if (referringCustomerDisplayIdParam == '') { 463 let path = window.location.pathname || ''; 464 let queryString = window.location.search || ''; 465 let newPath = path + queryString; 466 let appendText = 'r=' + service.referringCustomerDisplayId; 467 468 if (queryString == '') { 469 appendText = '?' + appendText; 470 } 471 else { 472 appendText = '&' + appendText; 473 } 474 475 if (newPath.toLowerCase().indexOf('/' + service.referringCustomerDisplayId.toLowerCase()) == -1) { 476 window.history.replaceState(null, null, newPath + appendText); 477 } 478 } 479 } 480 }); 481 }); 482 }); 483 }); 484 485 return service.makeReadyPromise; 486 } 487 488 service.setCurrentPerson = function (cartId) { 489 if (cartId != null) { 490 return $http.post(apiRoot + 'api/Shopping/SetCurrentPerson?cartId=' + cartId).then( 491 function (results) { 492 // success 493 }); 494 } 495 } 496 497 service.getReplicatedSiteOwner = function () {
498 return $http.get(apiRoot + 'api/Shopping/GetReplicatedSiteOwnerUrl').then( 499 function (result) { 500 // The "idstc_setting_corporateconsultanturl" variable is written to page via the php_vars.js (wordpress method of getting server variables to client script). 501 // We will default to the corporate site owner when the newly-logged-in customer's replicated site owner can't be found or is not active (BlockWebsite flag is true). 502 var url = idstc_setting_corporateconsultanturl; 503 504 if (result.data != null && result.data != '') { 505 url = result.data; 506 } 507 508 return service.getConsultant(url); 509 }); 510 } 511 512 service.getAndStoreUserAvailableUIElements = function () { 513 return $http.get(apiRoot + 'api/Website/GetUserAvailableUIElements').then( 514 function (result) { 515 storage.set('AvailableUIElements', result.data); 516 }); 517 } 518 519 service.getAPIToken = function () { 520 service.apiToken = idstc().getExpirableLocalStorageVar('Authorization', 1440); 521 idstcApiToken = service.apiToken; 522 existingLanguageCode = localStorage.getItem('languageCode'); 523 524 // language code comes from polylang and is stored in php_vars variable 525 // the first 2 digits should match the language code in idstc 526 if (php_vars && php_vars.languageCode && php_vars.languageCode.length > 0) { 527 languageCode = php_vars.languageCode.substring(0, 2); 528 } 529 530 var languageChanged = false; 531 if (languageCode != null && languageCode != existingLanguageCode) { 532 if (!service.loggedIn) { 533 service.apiToken = null; 534 idstcApiToken = null; 535 } 536 sessionStorage.removeItem('translations'); 537 sessionStorage.removeItem('displayCategories'); 538 service.setLanguageCode(languageCode, 'app.js - getAPIToken - languageCode'); 539 languageChanged = true; 540 } 541 542 var existingCountryCode = localStorage.getItem('countryCode'); 543 544 // country code comes from polylang and is stored in php_vars variable 545 // the last 2 digits should match the country code abbreviation in idstc 546 // We will not set the countryCode from polylang if setting is enabled 547 if (php_vars && php_vars.languageCode && php_vars.languageCode.length > 0 && idstc_setting_acutacustomcountrycodeenabled != 'on') { 548 countryCode = php_vars.languageCode.substring(3, 5); 549 } 550 551 let countryCodeToLower = null; 552 let existingCountryCodeToLower = null; 553 554 if (countryCode != null) { 555 countryCodeToLower = countryCode.toLowerCase(); 556 } 557 if (existingCountryCode != null) { 558 existingCountryCodeToLower = existingCountryCode.toLowerCase(); 559 } 560 561 var countryChanged = false; 562 if (existingCountryCodeToLower != countryCodeToLower) { 563 if (existingCountryCodeToLower == null && localStorage.getItem('RecommendedCartID') != null) { 564 565 } 566 else { 567 localStorage.removeItem('CartID'); 568 localStorage.removeItem('idstc-cart'); 569 localStorage.removeItem('CustomerCartID'); 570 } 571 572 sessionStorage.removeItem('translations'); 573 574 service.setCountryCode(countryCode); 575 localStorage.removeItem('JoinCartID'); 576 localStorage.removeItem('CartItemQuantity'); 577 localStorage.removeItem('provinceID'); 578 countryChanged = true; 579 } 580 581 if (service.getAPITokenPromise) { 582 return service.getAPITokenPromise; 583 } 584 else if (service.apiToken && !languageChanged && !countryChanged) { 585 return; 586 } 587 588 service.getAPITokenPromise = service.getAPITokenFromServer(); 589 590 return service.getAPITokenPromise; 591 } 592 593 service.getAPITokenFromServer = function () { 594 var url = apiRoot + 'api/WebsiteSession/GetBaseSiteDataWithCountry?languageCode=' + languageCode; 595 if (typeof countryCode != 'undefined' && countryCode != null && countryCode != '') { 596 url = url + '&countryCode=' + countryCode; 597 } 598 if (idstc_setting_businessunitsenabled) { 599 var businessUnitID = sessionStorage.getItem('businessUnitID'); 600 if (typeof businessUnitID != 'undefined' && businessUnitID != null && businessUnitID != '') { 601 url = url + '&businessUnitID=' + businessUnitID; 602 } 603 } 604 605 return $http.get(url).then( 606 function (successResult) { 607 var dto = successResult.data; 608 609 var apiJSONObject = $.parseJSON(dto.APIToken); // needs to be parsed to remove "Access_Token" stuff; 610 if (apiJSONObject.access_token && apiJSONObject.access_token != '') { 611 service.apiToken = apiJSONObject.access_token; 612 idstcApiToken = service.apiToken; 613 } 614 615 idstc().setExpirableLocalStorageVar('Authorization', service.apiToken); 616 617 localStorage.setItem('AvailableUIElements', JSON.stringify(dto.AvailableUIElements)); 618 localStorage.setItem('shippingAddressResidentialDefault', dto.ShippingAddressResidentialDefault); 619 service.setLanguageCode(languageCode, 'app.js - getAPITokenFromServer - languageCode'); 620 621 service.storeCountries(dto.Countries); 622 service.storeCurrencyTypes(dto.CurrencyTypes); 623 service.storeDateFormat(dto.DateFormat); 624 service.storeTimeFormat(dto.TimeFormat); 625 service.storeUTCOffset(dto.UTCOffset); 626 627 var existingCountryCode = localStorage.getItem('countryCode'); 628 // country code comes from polylang and is stored in php_vars variable 629 // the last 2 digits should match the country code abbreviation in idstc 630 // We will not set the countryCode from polylang if setting is enabled 631 if (php_vars && php_vars.languageCode && php_vars.languageCode.length > 0 && idstc_setting_acutacustomcountrycodeenabled != 'on') { 632 countryCode = php_vars.languageCode.substring(3, 5); 633 } 634 635 let countryCodeToLower = null; 636 let existingCountryCodeToLower = null; 637 638 if (countryCode != null) { 639 countryCodeToLower = countryCode.toLowerCase(); 640 } 641 if (existingCountryCode != null) { 642 existingCountryCodeToLower = existingCountryCode.toLowerCase(); 643 } 644 645 // if has not changed then just set new person (possibly anonymous) on order 646 // otherwise, clear cart info which will allow new cart to be created 647 if (existingCountryCodeToLower == countryCodeToLower) { 648 var cartId = idstc().getExpirableLocalStorageVar('CartID', idstc_setting_acutacartexpirationseconds); 649 if (typeof cartId != 'undefined' && cartId != null && cartId != '') { 650 return service.setCurrentPerson(cartId); 651 } 652 } 653 else { 654 service.setCountryCode(countryCode); 655 localStorage.removeItem('provinceID'); 656 } 657 658 return 'done'; 659 }); 660 } 661 662 service.getConsultant = function (replSite) { 663 if (replSite != null && replSite != '' && replSite != 'null') { 664 if (service.getConsultantPromise) { 665 return service.getConsultantPromise; 666 } 667 668 service.getConsultantPromise = service.getConsultantFromServer(replSite); 669 670 return service.getConsultantPromise; 671 } 672 } 673 674 service.getConsultantFromServer = function (replSite) {
675 var returnIfBlocked = 'false'; 676 if (idstc_setting_proceedtocorpwhenbadreplsite == 'on') { 677 returnIfBlocked = 'true'; 678 } 679 return $http.post(apiRoot + 'api/Website/GetConsultantReplicationSiteInfo?url=' + replSite + '&returnIfBlocked=' + returnIfBlocked).then( 680 function (successResult) { 681 if (successResult.data != null && typeof successResult.data.DisplayID != 'undefined' && successResult.data.DisplayID != null && successResult.data.BlockWebsite == false) { 682 service.setConsultant(successResult.data); 683 service.getConsultantPromise = null; 684 return; 685 } 686 else { 687 if (idstc_setting_proceedtocorpwhenbadreplsite == 'on' && successResult.data != null && typeof successResult.data.BlockWebsite != 'undefined' && successResult.data.BlockWebsite == true) { 688 return $http.post(apiRoot + 'api/Website/GetConsultantReplicationSiteInfo?url=' + idstc_setting_corporateconsultanturl + '&returnIfBlocked=false').then( 689 function (successResult) { 690 service.setConsultant(successResult.data); 691 service.getConsultantPromise = null; 692 return; 693 }); 694 } 695 else { 696 service.getConsultantPromise = null; 697 return; 698 } 699 } 700 }); 701 } 702 703 service.getDefaultBusinessUnitID = function () { 704 var businessUnitID = sessionStorage.getItem('businessUnitID'); 705 706 if (service.businessUnitIDPromise) { 707 return service.businessUnitIDPromise; 708 } 709 710 if (typeof businessUnitID == 'undefined' || businessUnitID == null || businessUnitID != '') { 711 service.businessUnitIDPromise = service.getAndStoreBusinessUnitID(); 712 } 713 714 return service.businessUnitIDPromise; 715 } 716 717 service.getAndStoreBusinessUnitID = function () {
718 return $http.get(apiRoot + 'api/Website/GetDefaultBusinessUnitID').then( 719 function (successResult) { 720 sessionStorage.setItem('businessUnitID', successResult.data); 721 }); 722 } 723 724 service.convertJsonToUrlEncoded = function (obj) { 725 var str = []; 726 for (var key in obj) { 727 if (obj.hasOwnProperty(key)) { 728 str.push(encodeURIComponent(key) + '=' + encodeURIComponent(obj[key])) 729 } 730 } 731 return str.join('&'); 732 } 733 734 service.loginPortal = function () { 735 var url = apiRoot + 'api/CustomerPortal/LoginPortal'; 736 737 // Generate a new external login provider key for the currently logged in customer via the API 738 $http.post(url, null).then( 739 function (resp) { 740 var loginRootPath = customerPortalRootPath; 741 var loginForm = document.getElementById('loginPortalForm'); 742 743 if (loginForm != null) { 744 // Update form inputs and then programmatically post the hidden form to push user to portal 745 document.getElementById('IDSTCPortalProviderKey').value = resp.data.ProviderKey; 746 document.getElementById('IDSTCPortalUserId').value = resp.data.UserId; 747 748 loginForm.action = loginRootPath + 'Account/ExternalLoginRedirectFromForm'; 749 loginForm.submit(); 750 } 751 752 $(document).progressFinish(); 753 }, 754 function (err) { 755 idstc().notifyServerResponse(err.data); 756 $(document).progressFinish(); 757 }); 758 } 759 760 service.setConsultant = function (consultant) { 761 localStorage.setItem('replicatedSiteUrl', consultant.Url); 762 sessionStorage.setItem('consultant', JSON.stringify(consultant)); 763 sessionStorage.setItem('businessUnitID', consultant.BusinessUnitID); 764 sessionStorage.removeItem('displayCategories'); 765 service.consultant = consultant; 766 flightConsultant = consultant; 767 } 768 769 service.getCurrencyTypes = function (force) { 770 var currencyTypes = JSON.parse(localStorage.getItem('CurrencyTypes')); 771 772 if (service.currencyTypePromise) { 773 return service.currencyTypePromise; 774 } 775 776 if (currencyTypes != null) { 777 var diffTime = new Date().getTime() - currencyTypes.dateTime; 778 var diffInMinutes = Math.floor(diffTime / 1000 / 60); //get minutes from time 779 780 if (diffInMinutes >= 30 && !force) { //cache for 30 minutes 781 service.currencyTypePromise = service.getCurrencyTypes(true); 782 }; 783 784 if (localStorage.getItem('CurrencyTypes') == null || !currencyTypes.dateTime || force) { //reset currency types 785 service.currencyTypePromise = service.getAndStoreCurrencyTypes(); 786 } 787 } 788 else { 789 service.currencyTypePromise = service.getAndStoreCurrencyTypes(); 790 } 791 792 return service.currencyTypePromise; 793 } 794 795 service.getAndStoreCurrencyTypes = function () {
796 return $http.get(apiRoot + 'api/CurrencyTypes/GetCurrencyTypes').then( 797 function (successResult) { 798 service.storeCurrencyTypes(successResult.data); 799 }); 800 } 801 802 service.storeCurrencyTypes = function (currencyTypes) { 803 if (currencyTypes == null) { 804 console.log('Warning - Attempt to store CurrencyTypes in LocalStorage as null'); 805 return; 806 } 807 808 var valueToSave = { 809 currencyTypes: currencyTypes, 810 dateTime: new Date().getTime() //set timestamp for cache 811 }; 812 813 localStorage.setItem('CurrencyTypes', JSON.stringify(valueToSave)); 814 } 815 816 service.getCountries = function (force) { 817 var countries = JSON.parse(localStorage.getItem('Countries')); 818 819 if (service.countryPromise) { 820 return service.countryPromise; 821 } 822 823 if (countries != null) { 824 var diffTime = new Date().getTime() - countries.dateTime; 825 var diffInMinutes = Math.floor(diffTime / 1000 / 60); //get minutes from time 826 827 if (diffInMinutes >= 30 && !force) { //cache for 30 minutes 828 service.countryPromise = service.getCountries(true); 829 }; 830 831 if (localStorage.getItem('Countries') == null || !countries.dateTime || force) { //reset currency types 832 service.countryPromise = service.getAndStoreCountries(); 833 } 834 } 835 else { 836 service.countryPromise = service.getAndStoreCountries(); 837 } 838 839 return service.countryPromise; 840 } 841 842 service.getAndStoreCountries = function () {
843 return $http.get(apiRoot + 'api/CountryProvinces/GetCountriesForDropdown?websiteId=' + idstc_setting_websiteid).then( 844 function (successResult) { 845 service.storeCountries(successResult.data); 846 }); 847 } 848 849 service.storeCountries = function (countries) { 850 if (countries == null) { 851 console.log('Warning - Attempt to store Countries in LocalStorage as null'); 852 return; 853 } 854 855 var valueToSave = { 856 countries: countries, 857 dateTime: new Date().getTime() //set timestamp for cache 858 }; 859 860 localStorage.setItem('Countries', JSON.stringify(valueToSave)); 861 } 862 863 service.getDateFormat = function (force) { 864 var format = JSON.parse(localStorage.getItem('DateFormatString')); 865 866 if (service.dateFormatPromise) { 867 return service.dateFormatPromise; 868 } 869 870 if (format != null) { 871 var diffTime = new Date().getTime() - format.dateTime; 872 var diffInMinutes = Math.floor(diffTime / 1000 / 60); //get minutes from time 873 874 if (diffInMinutes >= 30 && !force) { //cache for 30 minutes 875 service.dateFormatPromise = service.getDateFormat(true); 876 }; 877 878 if (localStorage.getItem('DateFormatString') === undefined || !format.dateTime || force) { //reset UTC offset 879 service.dateFormatPromise = service.getAndStoreDateFormat(); 880 } 881 } 882 else { 883 service.dateFormatPromise = service.getAndStoreDateFormat(); 884 } 885 886 return service.dateFormatPromise; 887 } 888 889 service.getAndStoreDateFormat = function () {
890 return $http.get(apiRoot + 'api/DateTime/GetDateFormatString').then( 891 function (successResult) { 892 service.storeDateFormat(successResult.data); 893 }); 894 } 895 896 service.storeDateFormat = function (dateFormat) { 897 if (dateFormat == null) { 898 console.log('Warning - Attempt to store DateFormatString in LocalStorage as null'); 899 return; 900 } 901 902 var valueToSave = { 903 dateFormat: dateFormat, 904 dateTime: new Date().getTime() //set timestamp for cache 905 }; 906 907 localStorage.setItem('DateFormatString', JSON.stringify(valueToSave)); 908 } 909 910 service.getUTCOffset = function (force) { 911 var offset = JSON.parse(localStorage.getItem('UTCOffset')); 912 913 if (service.utcOffsetPromise) { 914 return service.utcOffsetPromise; 915 } 916 917 if (offset != null) { //offset is in localstorage 918 var diffTime = new Date().getTime() - offset.dateTime; 919 var diffInMinutes = Math.floor(diffTime / 1000 / 60); //get minutes from time 920 921 if (diffInMinutes >= 30 && !force) { //cache offset value for this user for 30 minutes 922 service.utcOffsetPromise = service.getUTCOffset(true); 923 }; 924 925 if (localStorage.getItem('UTCOffset') == null || !offset.dateTime || force) { //reset UTC offset 926 service.utcOffsetPromise = service.getAndStoreUTCOffset(); 927 } 928 } else { //offset is not in localStorage 929 service.utcOffsetPromise = service.getAndStoreUTCOffset(); 930 } 931 932 return service.utcOffsetPromise; 933 } 934 935 service.getAndStoreUTCOffset = function () {
936 return $http.get(apiRoot + 'api/DateTime/GetUTCOffset').then( 937 function (successResult) { 938 service.storeUTCOffset(successResult.data); 939 }); 940 } 941 942 service.storeUTCOffset = function (utcOffset) { 943 if (utcOffset == null) { 944 console.log('Warning - Attempt to store UTCOffset in LocalStorage as null'); 945 return; 946 } 947 948 var valueToSave = { 949 offset: utcOffset, 950 dateTime: new Date().getTime() //set timestamp for cache 951 }; 952 953 localStorage.setItem('UTCOffset', JSON.stringify(valueToSave)); 954 } 955 956 service.getTimeFormat = function (force) { 957 var TimeFormat = JSON.parse(localStorage.getItem('TimeFormat')); 958 959 if (service.timeFormatPromise) { 960 return service.timeFormatPromise; 961 } 962 963 if (TimeFormat != null) { //permissions are in localStorage 964 var diffTime = new Date().getTime() - TimeFormat.dateTime; 965 var diffInMinutes = Math.floor(diffTime / 1000 / 60); //get minutes from time 966 967 if (diffInMinutes >= 30 && !force) { //cache permissions for this user for 30 minutes 968 service.timeFormatPromise = service.getTimeFormat(true); 969 }; 970 971 if (localStorage.getItem('TimeFormat') == null || !TimeFormat.dateTime || force) { //reset UTC offset 972 service.timeFormatPromise = service.getAndStoreTimeFormat(); 973 } 974 } 975 else { //currency types are not in localStorage 976 service.timeFormatPromise = service.getAndStoreTimeFormat(); 977 } 978 979 return service.timeFormatPromise; 980 } 981 982 service.getAndStoreTimeFormat = function () {
983 return $http.get(apiRoot + 'api/DateTime/GetTimeFormat').then( 984 function (successResult) { 985 service.storeTimeFormat(successResult.data); 986 }); 987 } 988 989 service.storeTimeFormat = function (timeFormat) { 990 if (timeFormat == null) { 991 console.log('Warning - Attempt to store TimeFormat in LocalStorage as null'); 992 return; 993 } 994 995 var valueToSave = { 996 timeFormat: timeFormat, 997 dateTime: new Date().getTime() //set timestamp for cache 998 }; 999 1000 localStorage.setItem('TimeFormat', JSON.stringify(valueToSave)); 1001 } 1002 1003 service.renderHTML = function (html_code) { 1004 return $sce.trustAsHtml(html_code); 1005 }; 1006 1007 service.setCountryCode = function (countryCode, source) { 1008 console.log('setCountryCode', countryCode, source); 1009 1010 if (countryCode == null || countryCode == '') { 1011 console.log('Warning - app.js - Attempt to set countryCode to null or empty', countryCode, source); 1012 return; 1013 } 1014 1015 localStorage.setItem('countryCode', countryCode); 1016 document.cookie = 'countryCode=' + countryCode + '; path=/'; 1017 } 1018 1019 service.setLanguageCode = function (languageCode, source) { 1020 if (languageCode == null || languageCode == '') { 1021 console.log('Warning - app.js - Attempt to set languageCode to null or empty', countryCode, source); 1022 } 1023 1024 localStorage.setItem('languageCode', languageCode); 1025 document.cookie = 'languageCode=' + languageCode + '; path=/'; 1026 } 1027 1028 return service; 1029 }) 1030 .directive('testDirective', function () { 1031 return function (scope, elem) { 1032 $(elem).text('Directives also work'); 1033 } 1034 }); 1035 1036 // Load html file with content which uses above content 1037 $('body').attr('ng-controller', 'siteController as siteCtrl'); 1038 $('body').addClass('non-replicated'); 1039 1040 $('<div class="body slide" id="SlideBody"><div class="sidebar-wrapper" id="sidebar-wrapper"><span id="notification-wrapper"></span></div></div><div id="screen-overlay"></div><div class="loader"><div class="cp-spinner cp-round"></div><span class="sr-only">Loading...</span></div>').prependTo('body'); 1041 1042 // Bootstrap app 1043 angular.bootstrap($('body'), ['app']); 1044 1045 // Register the controls/directives/services we just loaded 1046 var queue = angular.module('app')._invokeQueue; 1047 for (var i = queueLen; i < queue.length; i++) { 1048 var call = queue[i]; 1049 // call is in the form [providerName, providerFunc, providerArguments] 1050 var provider = providers[call[0]]; 1051 if (provider) { 1052 // e.g. $controllerProvider.register("Ctrl", function() { ... }) 1053 provider[call[1]].apply(provider, call[2]); 1054 } 1055 } 1056 1057 // compile the new element 1058 $('body').injector().invoke(function ($compile, $rootScope) { 1059 // CMH: I thought this would be needed to force the dynamic site-wide angular "app" to compile...but this does not appear to be the case (it is actually causing) 1060 //$compile($('body'))($rootScope); 1061 //$rootScope.$apply(); 1062 }); 1063}); 1064 1065// Polyfill for "startsWith" for Internet Explorer 1066if (!String.prototype.startsWith) { 1067 String.prototype.startsWith = function (searchString, position) { 1068 position = position || 0; 1069 return this.indexOf(searchString, position) === position; 1070 }; 1071}
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.