Using undocumented JavaScript CAF methods

Hi,

I needed to add a confirmation dialog to a DeleteRowButton (as I describe in http://tech.forums.softwareag.com/viewtopic.php?t=24646 ) so I created the following code in a Script Block to execute the row deletion to be called on the OnClick client-side event of a Async Command Icon:


// Send the actual ID of the DOM object as in
// deleteRoleButConfirmBefore(this,'#&#123;caf:cid("<control>")}');
//
// the confirmation is using the value in the innerHTML of the columnIndexOfDataForConfirmation td 
// element of the row
function deleteRoleButConfirmBefore(Role,columnIndexOfDataForConfirmation,ElementToBeRefreshed) &#123;

    if ( Role == null || Role.id == null || columnIndexOfDataForConfirmation == null ) return(false);
    
    // This will only work if the this object is at the bottom of the path table>tbody>tr>td (table is the 4th ancestor)
    // var theTable=CAF.model(Role.parentNode.parentNode.parentNode.parentNode.id);
    // var theRow=CAF.model(theTable.findParentItem(Role.id));  
    
    // This might break as CAF.Table.getTableIdFromRowId seems to a private method (does not appear on the documentation)
    var theRow      = CAF.model(CAF.Table.getTableIdFromRowId(Role.id));   
    if ( theRow == null ) return(false);
    
    var theTable    = CAF.model(CAF.Table.getTableIdFromRowId(theRow.id));
    if ( theTable == null ) return(false);
    
    // innerText for IE, textContent for standards compliance 
    // http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/core.html#Node3-textContent
    var theRoleName = theRow.element.cells[columnIndexOfDataForConfirmation].textContent ||
                      theRow.element.cells[columnIndexOfDataForConfirmation].innerText;
    if ( theRoleName == null ) return(false);
 
    if ( confirm("Are you sure want to delete the role \"" + theRoleName +"\"?") ) &#123;
        theTable.remove(theRow);
        if ( ElementToBeRefreshed != null ) &#123; CAF.model(ElementToBeRefreshed).refresh(); };
        return(true);
    } else &#123;
        return(false);
    }; 
};

My problem is that I am using the undocumented JavaScript CAF methods CAF.Table.getTableIdFromRowId and remove for which I cannot find any documentation but both have been mentioned in this forum by SAG staff.

Is it ok to use these functions? Where can I find their definitions?
Or do I risk the possibility of the code being broken in the next fixes or versions?

Why not just add another parameter into your function?

You have this comment:
deleteRoleButConfirmBefore(this,‘#{caf:cid(“”)}’);

can you extend the function to be:

deleteRoleButConfirmBefore(this,'#&#123;caf:cid("<control>")}','#&#123;caf:cid("<table>")}'); 

Regards,
–mark

That only removes one of the calls, I still have to use getTableIdFromRowId to get the row’s ID so I can use its ‘remove’ method.

There is an easier way to get the Row Model. Have a look at the Designer On-line help section called: ‘CAF.Table.Row.Model’

Regards,
–mark

Would you mind supplying an example?

I tried CAF.Table.Row.Model.prototype.getControlId(this.id) on onClick Client-Side action of the button but it returns again the button ID and not the Row ID.

Thank you.

Oh boy, i owe you an apology. Your approach was correct and i’ve filed an internal defect to ensure that the APIs: getTableIdFromRowId and remove will be documented and supported.

Please accept my apologies.
Regards,
–mark

That’s ok :wink:

At least I am on the right track. :slight_smile: