Creating a screen rule with a handler

Top  Previous  Next

A rule set must be created in order to bind together the terminal screens, the data set (that HostSurfer creates from each screen) and the actions that will be applied to both navigating the applications as well as interacting with the underlying screen.

Rules are declared as Javascript objects in files under "/myapp/rules" folder, exposing specific properties that determine the linkage between the entities mentioned above. Also, the file hsangular.js must be edited accordingly so that each rule file is loaded in runtime and AngularJS Route provider can properly manage the application flow.

Please refer to HostSurfer Rules for more details.

 

We will proceed creating one HostSurfer rule by following these steps:

 

Identifying the host screen
Declaring fields
Setting the rule web page
Setting the rule actions

 

Having passed through the preceding steps and completed each of the rule properties, this is how the rule definition, in signin.js file, looks like:

 

(function () {

  var _signin = {

       id : 'signin',

       match : [{text: "USERNAME", row:19, col: 55}],

       apply : {

            fields : [

               { name : 'username', row : 19, col : 67, len : 6},

               { name : 'password',  row : 20, col : 67, len : 6},

               { name : 'newPassword', row : 21, col : 67, len : 6}

           ],

           render: {

             route: '#!signin'

           },

           actions : {

               main: function (hs) {

                   alert("action 'main' has been called");

                   hs.send.enter();

               },

               exit : function(hs) {

                   hs.send.pf1();

               }

           }

       }};

   zScope.hostSurfer.register(_signin);

})();

 

 

 

As mentioned in the first paragraph, every rule created must be added to the hsangular.js code, which contents are shown in the following code snippet:

 

 

var hs = new zScope.HostSurfer({

   view: {

       id: "hsview"

   },

   term: {

       url: "http://zanywhere.cybelesoft.com/hsdemo/",

       float: {

           top: 0, right: 0

       }

   },

   rules: {

       baseUrl: "rules/",

       paths: ["signin"]

   }

});

 

var app = angular.module('hs', ['ngRoute']);

app.controller('hscontroller', function ($scope) {

   $scope.hs = hs.data;

   hs.on('fldupdate', function () {

       $scope.$apply(function () {

           $scope.hs = hs.data;

       });

   });

});

 

hs.on('ready', function () {

   angular.bootstrap(document, ['hs']);

});

 

app.config(function ($routeProvider) {

   $routeProvider

       .when("/signin", { templateUrl: 'signin.html', controller: 'hscontroller' })

  .otherwise({ redirectTo: '/' });

})

 

 

Please note that a reference to signin.html must be set both, in the rule file as well as in hsangular.js.