Changeset 199

Show
Ignore:
Timestamp:
04/12/07 19:34:13 (2 years ago)
Author:
bermiferrer
Message:

Applying Jeromes patch and test #45. Now prototype helper works for real :D

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/MAINTAINERS.txt

    r119 r199  
    11Bermi Ferrer Martinez <bermi-a.t-akelos-d.ot-co.m> Lead developer 
     2 
     3Jerome Loyet,  <jerome-a-t-nospam-loyet net> Core Contributor 
    24 
    35Jose Salavert <salavert-a-t-akelos-d.ot-co.m> Core Contributor 
  • trunk/THANKS.txt

    r178 r199  
    2626  - AkActiveRecord refactoring and improvement. 2007-03-03 
    2727 
     28Jerome Loyet 
     29 
     30 - Multiple patches and contributions. 2007-04-01 till present :D 
     31 
    2832 
    2933Contributions submitted as patches 
     
    3842 
    3943 - AkXhtmlValidator.php patch. 2007-02-23 
    40  
    41 Jerome Loyet 
    42  
    43  - Multiple patches and contributions. 2007-04-01 till present :D 
    4444  
    4545Matias Quaglia 
  • trunk/lib/AkActionView/helpers/prototype_helper.php

    r195 r199  
    194194    * Example: 
    195195    *   $prototype->form_remote_tag('html' => array('action' => $this->_controller->url_helper->url_for(array('controller' => 'some', 'action' => 'place'))); 
     196    *   $prototype->form_remote_tag('url' => array('controller' => 'foo', 'action' => 'bar'), 'update' => 'div_to_update', html => array('id' => 'form_id')); 
    196197    * 
    197198    * The Hash passed to the 'html' key is equivalent to the options (2nd)  
     
    203204    function form_remote_tag($options = array()) 
    204205    { 
     206         
     207        $options['url'] = empty($options['url']) ? array() : $options['url']; 
     208         
    205209        $options['form'] = true; 
    206  
    207         if (empty($options['html'])) { 
    208             $options['html'] = array(); 
    209         }else{ 
    210             $options['html']['onsubmit'] = $this->remote_function($options).'; return false;'; 
    211             $options['html']['action'] = !empty($options['html']['action']) ? $options['html']['action'] : $this->_controller->url_helper->url_for($options['url']); 
    212             $options['html']['method'] = !empty($options['html']['method']) ? $options['html']['method'] : 'post'; 
    213         } 
     210        $options['html'] = empty($options['html']) ? array() : $options['html']; 
     211        $options['html']['onsubmit'] = $this->remote_function($options).'; return false;'; 
     212        $options['html']['action'] = !empty($options['html']['action']) ? $options['html']['action'] : (is_array($options['url']) ? $this->_controller->url_helper->url_for($options['url']) : $options['url']); 
     213        $options['html']['method'] = !empty($options['html']['method']) ? $options['html']['method'] : 'post'; 
    214214 
    215215        return $this->_controller->tag_helper->tag('form', $options['html'], true); 
     
    437437    function observe_form($form_id, $options = array()) 
    438438    { 
    439         if (!empty($options['frequency']))
     439        if (!empty($options['frequency']) && $options['frequency']>0)
    440440            return $this->_buildObserver('Form.Observer', $form_id, $options); 
    441441        }else{ 
    442             return $this->buildObserver('Form.EventObserver', $form_id, $options); 
     442            return $this->_buildObserver('Form.EventObserver', $form_id, $options); 
    443443        } 
    444444    } 
  • trunk/test/unit/lib/AkActionView/helpers/prototype_helper.php

    r190 r199  
    1212    function test_setup() 
    1313    { 
    14         $Controller = &new AkActionController(); 
    15         $Controller->Request =& new MockAkRequest($this); 
    16         $Controller->controller_name = 'test'; 
    17         $Controller->instantiateHelpers(); 
     14        $this->controller = &new AkActionController(); 
     15        $this->controller->Request =& new MockAkRequest($this); 
     16        $this->controller->controller_name = 'test'; 
     17        $this->controller->instantiateHelpers(); 
    1818         
    19         $this->PrototypeHelper =& $Controller->prototype_helper; 
     19        $this->PrototypeHelper =& $this->controller->prototype_helper; 
    2020    } 
    2121     
    22     /** 
    23      * @todo Add all the tests for prototype helper 
     22    /* 
     23     * TODO: Complete test_remote_form_for() and test_form_remote_for() 
    2424     */ 
    25      
     25 
     26    function test_link_to_remote() 
     27    { 
     28        $this->assertEqual( 
     29            $this->PrototypeHelper->link_to_remote('test', array('url' => 'http://www.akelos.org', 'update' => 'listing')), 
     30            '<a href="#" onclick="new Ajax.Updater(\'listing\', \'http://www.akelos.org\', {}); return false;">test</a>' 
     31        ); 
     32        $this->assertEqual( 
     33            $this->PrototypeHelper->link_to_remote('test', array('url' => array('controller' => 'foo', 'action' => 'bar'), 'update' => 'listing')), 
     34            '<a href="#" onclick="new Ajax.Updater(\'listing\', \'/foo/bar/\', {}); return false;">test</a>' 
     35        ); 
     36 
     37        $this->assertEqual( 
     38            $this->PrototypeHelper->link_to_remote('test', array('url' => array('controller' => 'foo', 'action' => 'bar', 'm' => 'ore', 'b' => 'eer'), 'update' => 'listing')), 
     39            '<a href="#" onclick="new Ajax.Updater(\'listing\', \'/foo/bar/?m=ore&amp;b=eer\', {}); return false;">test</a>' 
     40        ); 
     41 
     42    } 
     43 
     44    function test_periodically_call_remote() 
     45    { 
     46        $this->assertEqual( 
     47            $this->PrototypeHelper->periodically_call_remote(array('url' => 'http://localhost', 'update' => 'listing', 'frequency' => 1)), 
     48            "<script type=\"text/javascript\">\n//<![CDATA[\nnew PeriodicalExecuter(function() {new Ajax.Updater('listing', 'http://localhost', {})}, 1)\n//]]>\n</script>" 
     49        ); 
     50 
     51        $this->assertEqual( 
     52            $this->PrototypeHelper->periodically_call_remote(array('url' => array('controller' => 'foo', 'action' => 'bar'), 'update' => 'listing', 'frequency' => 1)), 
     53            "<script type=\"text/javascript\">\n//<![CDATA[\nnew PeriodicalExecuter(function() {new Ajax.Updater('listing', '/foo/bar/', {})}, 1)\n//]]>\n</script>" 
     54        ); 
     55    } 
     56 
     57    function test_form_remote_tag() 
     58    { 
     59        $this->assertEqual( 
     60            $this->PrototypeHelper->form_remote_tag(array('url' => array('controller' => 'foo', 'action' => 'bar'), 'update' => 'div_to_update', 'html' => array('id' => 'form_id'))), 
     61            '<form action="/foo/bar/" id="form_id" method="post" onsubmit="new Ajax.Updater(\'div_to_update\', \'/foo/bar/\', {parameters:Form.serialize(this)}); return false;">' 
     62        ); 
     63        $this->assertEqual( 
     64            $this->PrototypeHelper->form_remote_tag(array('url' => 'http://www.akelos.org', 'update' => 'div_to_update', 'html' => array('id' => 'form_id'))), 
     65            '<form action="http://www.akelos.org" id="form_id" method="post" onsubmit="new Ajax.Updater(\'div_to_update\', \'http://www.akelos.org\', {parameters:Form.serialize(this)}); return false;">' 
     66        ); 
     67        $this->assertEqual( 
     68            $this->PrototypeHelper->form_remote_tag(array('url' => array('controller' => 'foo', 'action' => 'bar'), 'update' => 'div_to_update', 'html' => array('id' => 'form_id', 'action' => $this->controller->url_helper->url_for(array('controller' => 'some', 'action' => 'place'))))), 
     69            '<form action="/some/place/" id="form_id" method="post" onsubmit="new Ajax.Updater(\'div_to_update\', \'/foo/bar/\', {parameters:Form.serialize(this)}); return false;">' 
     70        ); 
     71    } 
     72 
     73    function test_remote_form_for() 
     74    { 
     75    } 
     76 
     77    function test_form_remote_for() 
     78    { 
     79    } 
     80 
    2681    function test_submit_to_remote() 
    2782    { 
    28         $this->assertEqual("<input name=\"More beer!\" onclick=\"new Ajax.Updater('empty_bottle', 'http://www.example.com/', {parameters:Form.serialize(this.form)}); return false;\" type=\"button\" value=\"1000000\" />", 
     83        $this->assertEqual( 
     84            $this->PrototypeHelper->submit_to_remote("More beer!", "1000000", array('update' => 'empty_bottle','url'=>'http://www.example.com/')), 
     85            '<input name="More beer!" onclick="new Ajax.Updater(\'empty_bottle\', \'http://www.example.com/\', {parameters:Form.serialize(this.form)}); return false;" type="button" value="1000000" />' 
     86        ); 
    2987 
    30         $this->PrototypeHelper->submit_to_remote("More beer!", "1000000", array('update' => 'empty_bottle','url'=>'http://www.example.com/'))); 
     88        $this->assertEqual( 
     89            $this->PrototypeHelper->submit_to_remote("More beer!", "1000000", array('update' => 'empty_bottle', 'url' => array('controller' => 'foo', 'action' => 'bar'))), 
     90            '<input name="More beer!" onclick="new Ajax.Updater(\'empty_bottle\', \'/foo/bar/\', {parameters:Form.serialize(this.form)}); return false;" type="button" value="1000000" />' 
     91        ); 
     92    } 
     93 
     94    function test_update_element_function() 
     95    { 
     96        $this->assertEqual( 
     97            $this->PrototypeHelper->update_element_function('products', array('position' => 'bottom'), array('content' => '<p>New product!</p>')), 
     98            "new Insertion.Bottom('products','Array');\n" 
     99        ); 
     100    } 
     101 
     102    function test_evaluate_remote_response() 
     103    { 
     104        $this->assertEqual($this->PrototypeHelper->evaluate_remote_response(), 'eval(request.responseText)'); 
     105    } 
     106 
     107    function test_remote_function() 
     108    { 
     109        $this->assertEqual( 
     110            $this->PrototypeHelper->remote_function(array('url' => 'http://akelos.org', 'update' => 'div_update')), 
     111            'new Ajax.Updater(\'div_update\', \'http://akelos.org\', {})' 
     112        ); 
     113    } 
     114 
     115    function test_observe_field() 
     116    { 
     117        $this->assertEqual( 
     118            $this->PrototypeHelper->observe_field('form_id', array('url' => 'http://akelos.org', 'frequency' => 2, 'update' => 'div_update')), 
     119            "<script type=\"text/javascript\">\n//<![CDATA[\nnew Form.Element.Observer('form_id', 2, function(element, value) {new Ajax.Updater('div_update', 'http://akelos.org', {parameters:value})})\n//]]>\n</script>" 
     120        ); 
     121        $this->assertEqual( 
     122            $this->PrototypeHelper->observe_field('form_id', array('url' => 'http://akelos.org', 'update' => 'div_update')), 
     123            "<script type=\"text/javascript\">\n//<![CDATA[\nnew Form.Element.EventObserver('form_id', function(element, value) {new Ajax.Updater('div_update', 'http://akelos.org', {parameters:value})})\n//]]>\n</script>" 
     124        ); 
     125    } 
     126 
     127    function test_observe_form() 
     128    { 
     129        $this->assertEqual( 
     130            $this->PrototypeHelper->observe_form('form_id', array('url' => 'http://akelos.org', 'frequency' => 2, 'update' => 'div_update')), 
     131            "<script type=\"text/javascript\">\n//<![CDATA[\nnew Form.Observer('form_id', 2, function(element, value) {new Ajax.Updater('div_update', 'http://akelos.org', {parameters:value})})\n//]]>\n</script>" 
     132        ); 
     133        $this->assertEqual( 
     134            $this->PrototypeHelper->observe_form('form_id', array('url' => 'http://akelos.org', 'update' => 'div_update')), 
     135            "<script type=\"text/javascript\">\n//<![CDATA[\nnew Form.EventObserver('form_id', function(element, value) {new Ajax.Updater('div_update', 'http://akelos.org', {parameters:value})})\n//]]>\n</script>" 
     136        ); 
    31137    } 
    32138}