« [News] New released IT2Be plugins | Main | [Tip] Function "getAsPlainText" explained »

January 10, 2005

[Challenge] Week 1/10/05: Code 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;
}

| Posted by David Workman on January 10, 2005 at 11:57 AM in Challenge | Permalink

TrackBack

TrackBack URL for this entry:
http://www.typepad.com/services/trackback/6a00d8341c8d8153ef00d83475372e69e2

Listed below are links to weblogs that reference [Challenge] Week 1/10/05: Code challenge:

Comments

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 ...

Posted by: Thomas Hertzler | Jan 11, 2005 4:52:44 PM

Post a comment