Nimirou

Unlock in init

Feb 23rd, 2021
471
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. attachLeaveApplication() {
  2.     $(window).unbind('beforeunload', this.leaveApplicationHandler);
  3.     $(window).bind('beforeunload', {context: this}, this.leaveApplicationHandler);
  4.   }
  5.   leaveApplicationHandler(event) {
  6.     if (event.data.context.getAppProperty('skipUnlockOnRedirect')) {
  7.       event.data.context.setAppProperty('skipUnlockOnRedirect', false);
  8.       return;
  9.     }
  10.     event.data.context.sendInfrcUnlockSynch(event);
  11.   };
  12.  
  13.   /**
  14.    *
  15.    * @param oEvent
  16.    */
  17.   sendInfrcUnlockSynch(oEvent) {
  18.     const xhr = new XMLHttpRequest(), sCookie = document.cookie;
  19.     let sapClient = '';
  20.     sCookie.split(';').forEach((i) => {
  21.       const aParam = i.split('=');
  22.       // we can have more '=' in cookie parameter string e.g sap-usercontext=sap-client=n
  23.       if (aParam[0].trim() === 'sap-usercontext') {
  24.         sapClient = i.substring(i.indexOf(aParam[1]));
  25.       }
  26.     });
  27.     const sGuid = jQuery.sap.encodeURL(`'${this._guid}'`);
  28.     xhr.open('POST', `${this._oModel.sServiceUrl}/InfrcUnlock?${sapClient}&Guid=${sGuid}`, true);
  29.     xhr.setRequestHeader('x-csrf-token', this._oModel.getSecurityToken());
  30.     xhr.send();
  31.   }
RAW Paste Data