src/scripts/clientsidescripts.js
// which will always have a 'log' and will have 'error' only when loading of dependensies was unsuccessful
which will always have a 'log' and will have 'error' only when loading of dependensies was unsuccessful
which will always have a ' log ' and will have ' error ' only when loading of dependensies was unsuccessful
function loadUI5Dependencies (mScriptParams, fnCallback) {
    var sDebugLog = 'Loading UI5 dependencies';
    var waitedTime = 0;
    (function wait () {
      if (window.sap && window.sap.ui) {
        window.sap.ui.getCore().attachInit(function() {
          window.uiveri5 = window.uiveri5 || {};
          loadControlFinder()
            .then(function () {
              if (mScriptParams.useClassicalWaitForUI5) {
                sDebugLog += '\nLoading classical waitForUI5 implementation.';
                return loadClassicalWaitForUI5();
              } else {
                sDebugLog += '\nLoading OPA5 waitForUI5 implementation.';
                return loadOPAWaitForUI5().catch(function (sError) {
                  sDebugLog += '\nFailed to load OPA5 waitForUI5, Fallback to loading classical waitForUI5 implementation. Details: ' + sError;
                  return loadClassicalWaitForUI5();
                });
              }
            }).then(function (sLog) {
              fnCallback({log: sDebugLog + (sLog || '')});
            }).catch(function (sError, sLog) {
              fnCallback({error: sError, log: sDebugLog + (sLog || '')});
            });
        });
      } else if (waitedTime < mScriptParams.autoWait.timeout) {
        waitedTime += mScriptParams.autoWait.interval;
        setTimeout(wait, mScriptParams.autoWait.interval);
      } else {
        fnCallback({log: sDebugLog, error: 'No UI5 on this page'});
      }
    })();
    function loadClassicalWaitForUI5() {
      return new Promise(function (resolve) {
        if (window.uiveri5.ClassicalWaitForUI5) {
          resolve();
        } else {
          var ClassicalWaitForUI5 = new Function('return (' + mScriptParams.ClassicalWaitForUI5 + ').apply(this, arguments)');
          window.sap.ui.getCore().registerPlugin({
            startPlugin: function (oCore) {
              window.uiveri5.ClassicalWaitForUI5 = new ClassicalWaitForUI5(mScriptParams.autoWait.timeout, {
                getUIDirty: oCore.getUIDirty.bind(oCore),
                attachUIUpdated: oCore.attachUIUpdated.bind(oCore)
              });
              resolve();
            }
          });
        }
      });
    }
    function loadOPAWaitForUI5() {
      return new Promise(function (resolve, reject) {
        if (window.uiveri5.autoWaiterAsync) {
          resolve();
        } else {
          var onError = function (oError) {
            reject('Cannot define uiveri5.autoWaiterAsync. Details: ' + oError);
          };
          try {
            window.sap.ui.require([
              'sap/ui/test/autowaiter/_autoWaiterAsync'
            ], function(_autoWaiterAsync) {
              _autoWaiterAsync.extendConfig(mScriptParams.autoWait);
              window.uiveri5.autoWaiterAsync = _autoWaiterAsync;
              resolve();
            }, onError);
          } catch (oError) {
            onError(oError);
          }
        }
      });
    }
    function loadControlFinder() {
      return new Promise(function (resolve) {
        if (window.uiveri5._ControlFinder) {
          resolve();
        } else {
          sDebugLog += '\nLoading OPA5 control locator utilities.';
          var onError = function (oError) {
            resolve('Control locators will not be enabled.' +
            ' Minimum UI5 versions supporting control locators: 1.52.12; 1.54.4; 1.55 and up. Details: ' + oError);
          };
          try {
            window.sap.ui.require([
              'sap/ui/test/_ControlFinder'
            ], function (_ControlFinder) {
              window.uiveri5._ControlFinder = _ControlFinder;
              resolve();
            }, onError);
          } catch (oError) {
            onError(oError);
          }
        }
      });
    }
  }
function loadUI5Dependencies ( mScriptParams , fnCallback ) { var sDebugLog = 'Loading UI5 dependencies' ; var waitedTime = 0 ; ( function wait ( ) { if ( window . sap && window . sap . ui ) { window . sap . ui . getCore ( ) . attachInit ( function ( ) { window . uiveri5 = window . uiveri5 || { } ; loadControlFinder ( ) . then ( function ( ) { if ( mScriptParams . useClassicalWaitForUI5 ) { sDebugLog += '\nLoading classical waitForUI5 implementation.' ; return loadClassicalWaitForUI5 ( ) ; } else { sDebugLog += '\nLoading OPA5 waitForUI5 implementation.' ; return loadOPAWaitForUI5 ( ) . catch ( function ( sError ) { sDebugLog += '\nFailed to load OPA5 waitForUI5, Fallback to loading classical waitForUI5 implementation. Details: ' + sError ; return loadClassicalWaitForUI5 ( ) ; } ) ; } } ) . then ( function ( sLog ) { fnCallback ( { log : sDebugLog + ( sLog || '' ) } ) ; } ) . catch ( function ( sError , sLog ) { fnCallback ( { error : sError , log : sDebugLog + ( sLog || '' ) } ) ; } ) ; } ) ; } else if ( waitedTime < mScriptParams . autoWait . timeout ) { waitedTime += mScriptParams . autoWait . interval ; setTimeout ( wait , mScriptParams . autoWait . interval ) ; } else { fnCallback ( { log : sDebugLog , error : 'No UI5 on this page' } ) ; } } ) ( ) ; function loadClassicalWaitForUI5 ( ) { return new Promise ( function ( resolve ) { if ( window . uiveri5 . ClassicalWaitForUI5 ) { resolve ( ) ; } else { var ClassicalWaitForUI5 = new Function ( 'return (' + mScriptParams . ClassicalWaitForUI5 + ').apply(this, arguments)' ) ; window . sap . ui . getCore ( ) . registerPlugin ( { startPlugin : function ( oCore ) { window . uiveri5 . ClassicalWaitForUI5 = new ClassicalWaitForUI5 ( mScriptParams . autoWait . timeout , { getUIDirty : oCore . getUIDirty . bind ( oCore ) , attachUIUpdated : oCore . attachUIUpdated . bind ( oCore ) } ) ; resolve ( ) ; } } ) ; } } ) ; } function loadOPAWaitForUI5 ( ) { return new Promise ( function ( resolve , reject ) { if ( window . uiveri5 . autoWaiterAsync ) { resolve ( ) ; } else { var onError = function ( oError ) { reject ( 'Cannot define uiveri5.autoWaiterAsync. Details: ' + oError ) ; } ; try { window . sap . ui . require ( [ 'sap/ui/test/autowaiter/_autoWaiterAsync' ] , function ( _autoWaiterAsync ) { _autoWaiterAsync . extendConfig ( mScriptParams . autoWait ) ; window . uiveri5 . autoWaiterAsync = _autoWaiterAsync ; resolve ( ) ; } , onError ) ; } catch ( oError ) { onError ( oError ) ; } } } ) ; } function loadControlFinder ( ) { return new Promise ( function ( resolve ) { if ( window . uiveri5 . _ControlFinder ) { resolve ( ) ; } else { sDebugLog += '\nLoading OPA5 control locator utilities.' ; var onError = function ( oError ) { resolve ( 'Control locators will not be enabled.' + ' Minimum UI5 versions supporting control locators: 1.52.12; 1.54.4; 1.55 and up. Details: ' + oError ) ; } ; try { window . sap . ui . require ( [ 'sap/ui/test/_ControlFinder' ] , function ( _ControlFinder ) { window . uiveri5 . _ControlFinder = _ControlFinder ; resolve ( ) ; } , onError ) ; } catch ( oError ) { onError ( oError ) ; } } } ) ; } }
which will always have a 'log' and will have 'error' only when loading of dependensies was unsuccessful
which will always have a ' log ' and will have ' error ' only when loading of dependensies was unsuccessful
// retry checking for UI5 // wait for UI5 core to complete initialisation /* global uiveri5 */ // --- helper function declarations below --- // only throw error if dependency is missing when a control locator is actually used