← servoy magazine

[Challenge] Week 1/10/05: Code challenge

  • Challenge

by David Workman

This week I present to you a global function that I use throughout my solutions. Due to the JavaScript Servoy object model (SOM), I am able to use dynamic object references to abstract this bit of code to work on all forms that I call it from. In the process, the code is not quite as obvious as to its function compared to equivalent code not using object references.

Which leads to this week's quiz questions:

  • What does this function do?
  • What data structures am I passing to the function?
  • Can you give example data that is passed to the function?

I will post the answer at the end of the week. Enjoy!

var sortImages = arguments[0];
var formName = arguments[1];
var columnNum = arguments[2];

var displayImages = new Array();
var tempString = new Array();

for ( var i = 0 ; i < sortImages.length ; i++ )
{
    tempString = sortImages[i].split(':::');
    displayImages[i] = tempString[0];
}

var columnAsc = sortImages[columnNum - 1].split(':::');
var columnDesc = sortImages[columnNum].split(':::');

if (forms[formName].elements[columnAsc[0]].visible == false)
{
    forms[formName].controller.sort(columnAsc[1]);
    
    for ( var j = 0 ; j < displayImages.length ; j++ )
    {
        forms[formName].elements[displayImages[j]].visible = false
    }
    
    forms[formName].elements[columnAsc[0]].visible = true;
}
else
{
    forms[formName].controller.sort(columnDesc[1]);
    
    for ( var j = 0 ; j < displayImages.length ; j++ )
    {
        forms[formName].elements[displayImages[j]].visible = false
    }

    forms[formName].elements[columnDesc[0]].visible = true;
}

Comments (1)

Thomas Hertzler
I don't know what the code is doing (yet), but I am zapping my code with lots'a SOM and DOR as I we speak. I knew I was missing something and would like to see more of this stuff in the furture ...