Show/Hide Toolbars

Managing an FVTerm Child iFrame in Javascript

Navigation: » No topics above this level «

Single File Sample

Scroll Prev Top Next More

Here is a sample, minimal page demonstrating how to implement a complete integration with the FVTerm application at the scripting level, including a sample logon script.

 

This is an older example built prior to the implementation of the FVTermParent.js file and is not recommended to copy but can be useful in understanding the FVTerm javascript integration.

 

<!DOCTYPE html">

<html xmlns="http://www.w3.org/1999/xhtml" >

<head>

  <title>Inventu Viewer+ Emulator Host Page Demonstration</title>

<script type="text/javascript">

var FVCtlMarker=true,

 fnRestartEmulator=null,

 fnStopEmulator=null,

 fvTermSession = null;

 

function FVTermSession(fvWin)

{

 this.fvWin=fvWin;

 this.emSess=null;

 this.screenCount=0;

 fvWin.emEvents.RegisterClient(this);

}

var FVT = FVTermSession.prototype;

 

// Called on each screen being sent to host

// Return false to prevent screen from being sent

FVT.OnSend = function (emSess, key)

{

 // emSess=emulation object

 // key=user AID key

 return true;

}

 

// Called when user clicks the Connect...

// return value ignored

FVT.OnRestart = function ()

{

 this.emSess=null;

}

 

// Called for each screen being displayed.  If the FVTerm web.config

// file has an application and definition file defined, will include

// the recognized screen's name or default if not recognized.

// return value is ignored

FVT.OnLoad = function (emSess, screenName)

{

 if (this.emSess == null)

 {

         // First time loaded...can do additional setup here

         this.logonState = "logon";

         this.emSess = emSess;

 }

 if (this.logonState)

 {

         var me = this;

         switch (this.logonState)

         {

                 case "logon":

                         if (this.GetScnText(1, 18, 7) == "Welcome")

                         {

                                 me.SendKeys('userID[tab]passWord[enter]');

                                 this.logonState = "guestMenu";

                         }

                         break;

                 case "guestMenu":

                         if (this.GetScnText(1, 30, 10) == "GUEST menu")

                         {

                                 me.SendKeys('demo[enter]');

                                 this.logonState = "mainMenu";

                         }

                         break;

                 case "mainMenu":

                         if (this.GetScnText(3, 34, 9) == "Main Menu")

                         {

                                 me.SendKeys('2[enter]');

                                 this.logonState = null;

                         }

                         break;

         }

 }

}

 

FVT.SetCursor = function (row, column, readyFunc, timeOut)

{

 if (!this.emSess)

         return false;

 var em = this.emSess,

          targCsrO = (row - 1) * em.cols + column - 1,

          atRow, atCol, keys, key, downCount, rightCount,

          me = this, readyId;

 

 if (targCsrO != em.csrO)

 {

         if (em.formMode)

         {

                 em.csrO = targCsrO;

                 this.fvWin.SetCursor(this.emSess);

         }

         else

         {

                 atRow = Math.floor(em.csrO / em.cols);

                 atCol = Math.floor(em.csrO % em.cols);

                 keys = '';

                 downCount = row - atRow;

                 rightCount = column - atCol;

                 if (downCount >= 0)

                         key = '[down]';

                 else

                 {

                         key = '[up]';

                         downCount *= -1;

                 }

                 while (downCount--)

                 {

                         keys += key;

                 }

                 if (rightCount >= 0)

                         key = '[right]';

                 else

                 {

                         key = '[left]';

                         rightCount *= -1;

                 }

                 while (rightCount--)

                 {

                         keys += key;

                 }

                 this.fvWin.SendKeys(keys, this.emSess.hostWriteCount, false);

         }

 }

 if (readyFunc)

 {

         if (!timeOut)

                 timeOut = 10; // seconds

         timeOut *= 10;   // # 100 millisecond intervals

         readyId = window.setInterval(function ()

         {

                 if (em.csrO == targCsrO)

                 {

                         window.clearInterval(readyId);

                         readyFunc(true);

                 }

                 else

                 {

                         timeOut--;

                         if (timeOut <= 0)

                         {

                                 window.clearInterval(readyId);

                                 readyFunc(false);

                         }

                 }

         }, 100);

 }

 return true;

}

 

FVT.SendKeys = function (keys)

{

 if (!this.emSess)

         return;

 this.fvWin.SendKeys(keys, this.emSess.hostWriteCount, false);

}

 

FVT.GetField = function(row, column)

{

 if (!this.emSess)

         return null;

 return this.fvWin.SCGetField(this.emSess, row, column);

}

 

FVT.SetField = function(row, column, text)

{

 if (!this.emSess)

         return;

 this.fvWin.SCSetField(this.emSess, row, column, text);

}

 

FVT.GetScnText = function(row, column, length)

{

 if (!this.emSess)

         return null;

 return this.fvWin.SCScreenVal(this.emSess, row, column, length);

}

 

FVT.GetScnRows = function(startRow, endRow)

{

 if (!this.emSess)

         return null;

 return this.emSess.GetScnRows(startRow, endRow);

}

 

// Called each time focus moves off a field

// emSess = active session object

// field = active field object

// aidKey = if present means this has been called at the start of

//                a screen send.  

// Can return false to cancel the send

FVT.OnChange = function (emSess, field, aidKey)

{

 return true;

}

 

// The screen contents (user entries) have been saved to the session.

// This is a callback which will result from calling the emSess.fnSaveChanges(emSess)

FVT.OnSave = function ()

{

}

 

// Called when the session is closed

FVT.OnClose = function ()

{

 this.emSess=null;

}

 

var retries=0;

function ConnectFVTerm()

{

 var fvTerm=document.getElementById("FVTerm"),

          fvWin = fvTerm.contentWindow;

 if (fvWin && fvWin.emEvents && fvWin.main)

         fvTermSession=new FVTermSession(fvWin);

 else

 {

         retries++;

         if (retries>10)

                 alert("Could not connect to FVTerm!");

         else

                 window.setTimeout('ConnectFVTerm()',500);

 }

}

</script>

</head>

<body onload="ConnectFVTerm()">

<iframe id="FVTerm" style="position:absolute;left:0px;top:0px;width:100%;height:100%" frameborder="0" src="SCTermDev.html?Application="></iframe>

</body>

</html>