HATS Tricks

2 Posts tagged with the custom tag
0

The following code sample can be used to change the appearance of the active HATS input field.


  • This block of code can be added to the header of an individual transformation to apply this feature to a single page or to the template of the project to apply to all transformations.


<script type="text/javascript">
function highlight(e) {
   //get event from browser
   if (!e) var e = window.event;
      var element =  e.srcElement || e.target;
      if(element != null){
         //focus event occurs when input gains focus
         if(e.type == 'focus'){
            //store previous background color if it exists
            element.style.oldColor = element.style.backgroundColor;
            //set new background color to specified value
            element.style.backgroundColor="#ffff90";
         }
         //blur event occurs when input loses focus
         else if(e.type == 'blur'){
            //if input had a specific background color restore it
            if(element.style.oldColor) {
               element.style.backgroundColor = element.style.oldColor;
            }
            //else set background color back to white
            else {
               element.style.backgroundColor = "#FFFFFF";
            }
         }
      }
}

function initInputs() {
   //get array with all input elements on HATS Form
   var inputs = document.HATSForm.getElementsByTagName("input");

   for (i=0; i<inputs.length; i++) {
      var attr = inputs[i].getAttribute("type");
      //assign events to inputs that are visible, text and password
      if ((attr == "text"|| attr == "password") && (attr != "hidden")) {
         //this syntax appends events instead of overwriting the current event list
         //Mozilla uses addEventListener to append events
         if(window.addEventListener) {
            inputs[i].addEventListener("focus",highlight,false);
            inputs[i].addEventListener("blur", highlight,false);
         } 
         //IE uses attachEvent to append events
         else if (window.attachEvent) {
            inputs[i].attachEvent('onfocus', highlight);
            inputs[i].attachEvent('onblur', highlight);
         }
      }
   }
}

//use window.onload event to run function once page is loaded
if(document.createElement) window.onload = function(){
   initInputs();
};
</script>

Using this code the resulting screen would look like this:
http://www-949.ibm.com/software/rational/cafe/servlet/JiveServlet/downloadImage/1574/highlight.gif

  • An alternate highlighting option could be to highlight the border of the input instead of the background. This can be accomplished by changing the highlight function in the code above to the following:


function highlight(e) {
   //get event from browser
   if (!e) var e = window.event;
   var element =  e.srcElement || e.target;
   if(element != null){
      //focus event occurs when input gains focus
      if(e.type == 'focus'){
         //store previous border color
         element.style.oldBorderColor = element.style.borderColor;
         //set new border color to specified value
         element.style.borderColor = "black";
      }
      //blur event occurs when input loses focus
      else if(e.type == 'blur'){
         //set the border color back to the original value
         element.style.borderColor = element.style.oldBorderColor;
      }
   }
}


Using this code the resulting screen would look like this:
http://www-949.ibm.com/software/rational/cafe/servlet/JiveServlet/downloadImage/1575/border.gif

The two options could also be combined to highlight the background and border together:
http://www-949.ibm.com/software/rational/cafe/servlet/JiveServlet/downloadImage/1576/highlight_border.gif

0 Comments Permalink
1

How to use Global Variables to populate Macro Variables in a HATS Transformation Macro

If you want to populate a macro variable with a global variable value, there is an easy way to do so.
The first step is to make sure that there is a global variable to prompt from.

Create a Global Variable

  1. In your screen customization, go to the Actions tab.
  2. Choose Add and select Set Global Variable.
  3. Name the global variable and give it an initial value so that we can use it in the macro later.
  4. Click Finish and make sure that the actions are in the proper order (the Set Global Variable should be before the Play Macro).
http://www-949.ibm.com/software/rational/cafe/servlet/JiveServlet/downloadImage/38-1197-1553/setGlobalVariable.JPG
Now we need to make sure that your macro is set up to work with macro variables, and that the macro has a macro variable available to work with.

Create a Macro Variable

  1. Open up the macro with the Visual Macro Editor.
  2. Right click on the screen and choose properties.
  3. In the properties panel choose Variables and Types.
  4. Make sure the choice for Enable support for variables and arithmetic expressions is enabled.
  5. If you have a macro variable, make sure it is available, otherwise create a macro variable on this page.
  6. To create a macro variable, click Add and give the variable a name (you do NOT need $ symbols around the name for this wizard) and a value (string values require single quotes) and press Finish.
http://www-949.ibm.com/software/rational/cafe/servlet/JiveServlet/downloadImage/38-1197-1554/addMacroVar.jpg
This macro variable will show in the source view as
<vars>
<create name="$testMV1$" type="string" value="'hello world!'"/>

</vars>
Now that we have a valid macro variable, we can use it in the prompt action.

Create a Prompt Action

  1. In the macro, create a new prompt action using the Visual Macro Editor. In the macro main view, right click on the screen that you wish to modify and choose properties.
  2. Choose Actions. In the actions table, choose Add. When given the choice of what action to add, choose Prompt.
  3. In the Prompt panel, name the prompt, select save value to variable and choose the correct macro variable. Make sure to enable Do not insert value into field unless it was specifically your intention to do otherwise. For the handler, choose Set prompt to global variable and choose the correct global variable. Press Finish and make sure that the new prompt action is in the correct place in the list.
http://www-949.ibm.com/software/rational/cafe/servlet/JiveServlet/downloadImage/38-1197-1555/add+macro+prompt+steps.jpg
In the source view you can see that the following action was added to the screen.
<prompt assigntovar="$testMV1$" clearfield="false" col="0" default="" description="" encrypted="false" len="80" movecursor="false" name="'gv_to_mv'" required="false" row="0" title="" varupdateonly="true" xlatehostkeys="false"/>
Note that the assigntovar parameter has the macro variable name with the $ symbol surrounding the macro variable name. Also notice that the varupdateonly parameter in the prompt action was set to true, so that we will not accidentally change the host screen.
We are finished, and now can get our global variable value to our macro variable!

Next time I will cover how to copy data in the other direction, from a macro variable to a global variable.

1 Comments Permalink
Bottom Banner