Development

Changeset 8836

You must first sign up to be able to contribute.

Changeset 8836

Show
Ignore:
Timestamp:
05/07/08 18:51:20 (2 years ago)
Author:
FabianLange
Message:

fixed some issues with butto_to helper, query string is now appended correctly, short notation of attributes is parsed correctly, some internal refactoring and unit tests. fixes #3184

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/1.0/lib/helper/UrlHelper.php

    r7999 r8836  
    239239 * @see    url_for, link_to 
    240240 */ 
    241 function button_to($name, $internal_uri, $options = array()) 
    242 { 
    243   $html_options = _convert_options($options); 
     241function button_to($name, $internal_uri ='', $options = array()) 
     242{ 
     243  $html_options = _parse_attributes($options); 
    244244  $html_options['value'] = $name; 
    245245 
     
    256256    return form_tag($internal_uri, array('method' => 'post', 'class' => 'button_to')).content_tag('div', tag('input', $html_options)).'</form>'; 
    257257  } 
    258   else if (isset($html_options['popup'])) 
    259   { 
    260     $html_options['type'] = 'button'; 
    261     $html_options = _convert_options_to_javascript($html_options, $internal_uri); 
    262  
    263     return tag('input', $html_options); 
     258 
     259  $url = url_for($internal_uri); 
     260  if (isset($html_options['query_string'])) 
     261  { 
     262    $url = $url.'?'.$html_options['query_string']; 
     263    unset($html_options['query_string']); 
     264  } 
     265  $url = "'".$url."'"; 
     266  $html_options['type'] = 'button'; 
     267 
     268  if (isset($html_options['popup'])) 
     269  { 
     270    $html_options = _convert_options_to_javascript($html_options, $url); 
     271    unset($html_options['popup']); 
    264272  } 
    265273  else 
    266274  { 
    267     $html_options['type']    = 'button'; 
    268     $html_options['onclick'] = "document.location.href='".url_for($internal_uri)."';"; 
     275    $html_options['onclick'] = "document.location.href=".$url.";"; 
    269276    $html_options = _convert_options_to_javascript($html_options); 
    270  
    271     return tag('input', $html_options); 
    272   } 
     277  } 
     278 
     279  return tag('input', $html_options); 
    273280} 
    274281 
     
    333340} 
    334341 
    335 function _convert_options_to_javascript($html_options, $internal_uri = '') 
     342function _convert_options_to_javascript($html_options, $url = 'this.href') 
    336343{ 
    337344  // confirm 
     
    355362  else if ($confirm && $popup) 
    356363  { 
    357     $html_options['onclick'] = $onclick.'if ('._confirm_javascript_function($confirm).') { '._popup_javascript_function($popup, $internal_uri).' };return false;'; 
     364    $html_options['onclick'] = $onclick.'if ('._confirm_javascript_function($confirm).') { '._popup_javascript_function($popup, $url).' };return false;'; 
    358365  } 
    359366  else if ($confirm && $post) 
     
    378385  else if ($popup) 
    379386  { 
    380     $html_options['onclick'] = $onclick._popup_javascript_function($popup, $internal_uri).'return false;'; 
     387    $html_options['onclick'] = $onclick._popup_javascript_function($popup, $url).'return false;'; 
    381388  } 
    382389 
     
    389396} 
    390397 
    391 function _popup_javascript_function($popup, $internal_uri = '') 
    392 
    393   $url = $internal_uri == '' ? 'this.href' : "'".url_for($internal_uri)."'"; 
    394  
     398function _popup_javascript_function($popup, $url = '') 
     399
    395400  if (is_array($popup)) 
    396401  { 
  • branches/1.0/test/unit/helper/UrlHelperTest.php

    r7804 r8836  
    4343} 
    4444 
    45 $t = new lime_test(26, new lime_output_color()); 
     45$t = new lime_test(29, new lime_output_color()); 
    4646 
    4747$context = sfContext::getInstance(); 
     
    6161$t->is(link_to('test', '', array('query_string' => 'foo=bar')), '<a href="module/action?foo=bar">test</a>', 'link_to() can take an "query_string" option'); 
    6262$t->is(link_to(''), '<a href="module/action">module/action</a>', 'link_to() takes the url as the link name if the first argument is empty'); 
     63 
     64//button_to() 
     65$t->diag('button_to()'); 
     66$t->is(button_to('test'), '<input value="test" type="button" onclick="document.location.href=\'module/action\';" />', 'button_to() returns an HTML "input" tag'); 
     67$t->is(button_to('test','', array('query_string' => 'foo=bar')), '<input value="test" type="button" onclick="document.location.href=\'module/action?foo=bar\';" />', 'button_to() returns an HTML "input" tag'); 
     68$t->is(button_to('test','', array('popup' => 'true', 'query_string' => 'foo=bar')), '<input value="test" type="button" onclick="var w=window.open(\'module/action?foo=bar\');w.focus();return false;" />', 'button_to() returns an HTML "input" tag'); 
     69 
    6370class testObject 
    6471{ 

The Sensio Labs Network

Since 1998, Sensio Labs has been promoting the Open-Source software movement by providing quality web application development, training, consulting.
Sensio Labs also supports several large Open-Source projects.