Introduction to Chains

A JavaScript chain is, like everything else in Agile Toolkit, an object. It implements a sequence of actions, such as traversing or applying modifications, and is very well known to you if you ever used jQuery.


In Agile Toolkit the same code looks like this:



In jQuery, you need to use $('selector') to specify where to start. Agile Toolkit automatically starts with the $view of your choice. Every View object has a js() function which will create a new chain, using that object's selector. To add JS code for hiding any object on your page, such as a grid, all you need to write is:



jQuery_Chain objects convert all method calls into respective jQuery code. The native PHP arguments are automatically converted into JavaScript. Native types such as integers and strings are properly quoted and converted into JavaScript.

If you specify array() then the chain will try to determine if it's an array or a hash. Hash is converted into {key:value,..} and PHP arrays are converted into ['a','b','c'] in JavaScript. If you use one chain as an argument to a method call on another chain, then that chain would be converted into JavaScript code first and then inserted appropriately.

$x 2+2;
$js $page->js(true)

// Produces: 
// $('#AgileWeb_learn_understand_chains_intro_doc_example_view')
//    .css({'width':4}).html('\x3cb\x3eO\x27Relly\x3c/b\x3e')

$field2 -> js(true)->val(  $field1->js()->val() );

// Produces: 
// $('#field2').val( $('#field1').val() );