Nimirou

Unlock in Component.js

Feb 23rd, 2021
452
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. onWindowBeforeUnload() {
  2.       const appProperties = this.getModel('appProperties');
  3.       if (appProperties.getProperty('/skipUnlockOnRedirect')) {
  4.         appProperties.setProperty('/skipUnlockOnRedirect', false);
  5.         return;
  6.       }
  7.       this.sendInfrcUnlockAsync(appProperties, this.getModel());
  8.     }
  9.     sendInfrcUnlockAsync(appProperties, oModel) {
  10.       const _guid = appProperties.getProperty('/guid');
  11.       if (!_guid) {
  12.         return;
  13.       }
  14.       const xhr = new XMLHttpRequest(), sCookie = document.cookie;
  15.       let sapClient = '';
  16.       sCookie.split(';').forEach((i) => {
  17.         const aParam = i.split('=');
  18.         // we can have more '=' in cookie parameter string e.g sap-usercontext=sap-client=n
  19.         if (aParam[0].trim() === 'sap-usercontext') {
  20.           sapClient = i.substring(i.indexOf(aParam[1]));
  21.         }
  22.       });
  23.       const sGuid = jQuery.sap.encodeURL(`'${_guid}'`);
  24.       xhr.open('POST', `${oModel.sServiceUrl}/InfrcUnlock?${sapClient}&Guid=${sGuid}`, true);
  25.       xhr.setRequestHeader('x-csrf-token', oModel.getSecurityToken());
  26.       xhr.send();
  27.     }
RAW Paste Data