Changeset 8837
- Timestamp:
- 05/07/08 18:51:41 (1 year ago)
- Files:
-
- branches/1.1/lib/helper/UrlHelper.php (modified) (6 diffs)
- branches/1.1/test/unit/helper/UrlHelperTest.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/1.1/lib/helper/UrlHelper.php
r8465 r8837 232 232 * @see url_for, link_to 233 233 */ 234 function button_to($name, $internal_uri , $options = array())235 { 236 $html_options = _ convert_options($options);234 function button_to($name, $internal_uri ='', $options = array()) 235 { 236 $html_options = _parse_attributes($options); 237 237 $html_options['value'] = $name; 238 238 … … 249 249 return form_tag($internal_uri, array('method' => 'post', 'class' => 'button_to')).content_tag('div', tag('input', $html_options)).'</form>'; 250 250 } 251 else if (isset($html_options['popup'])) 252 { 253 $html_options['type'] = 'button'; 254 $html_options = _convert_options_to_javascript($html_options, $internal_uri); 255 256 return tag('input', $html_options); 251 252 $url = url_for($internal_uri); 253 if (isset($html_options['query_string'])) 254 { 255 $url = $url.'?'.$html_options['query_string']; 256 unset($html_options['query_string']); 257 } 258 $url = "'".$url."'"; 259 $html_options['type'] = 'button'; 260 261 if (isset($html_options['popup'])) 262 { 263 $html_options = _convert_options_to_javascript($html_options, $url); 264 unset($html_options['popup']); 257 265 } 258 266 else 259 267 { 260 $html_options['type'] = 'button'; 261 $html_options['onclick'] = "document.location.href='".url_for($internal_uri)."';"; 268 $html_options['onclick'] = "document.location.href=".$url.";"; 262 269 $html_options = _convert_options_to_javascript($html_options); 263 264 return tag('input', $html_options); 265 }270 } 271 272 return tag('input', $html_options); 266 273 } 267 274 … … 326 333 } 327 334 328 function _convert_options_to_javascript($html_options, $ internal_uri = '')335 function _convert_options_to_javascript($html_options, $url = 'this.href') 329 336 { 330 337 // confirm … … 348 355 else if ($confirm && $popup) 349 356 { 350 $html_options['onclick'] = $onclick.'if ('._confirm_javascript_function($confirm).') { '._popup_javascript_function($popup, $ internal_uri).' };return false;';357 $html_options['onclick'] = $onclick.'if ('._confirm_javascript_function($confirm).') { '._popup_javascript_function($popup, $url).' };return false;'; 351 358 } 352 359 else if ($confirm && $post) … … 371 378 else if ($popup) 372 379 { 373 $html_options['onclick'] = $onclick._popup_javascript_function($popup, $ internal_uri).'return false;';380 $html_options['onclick'] = $onclick._popup_javascript_function($popup, $url).'return false;'; 374 381 } 375 382 … … 382 389 } 383 390 384 function _popup_javascript_function($popup, $internal_uri = '') 385 { 386 $url = $internal_uri == '' ? 'this.href' : "'".url_for($internal_uri)."'"; 387 391 function _popup_javascript_function($popup, $url = '') 392 { 388 393 if (is_array($popup)) 389 394 { branches/1.1/test/unit/helper/UrlHelperTest.php
r7805 r8837 20 20 } 21 21 22 $t = new lime_test(2 6, new lime_output_color());22 $t = new lime_test(29, new lime_output_color()); 23 23 24 24 $context = sfContext::getInstance(array('controller' => 'myController')); … … 41 41 $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'); 42 42 $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'); 43 44 //button_to() 45 $t->diag('button_to()'); 46 $t->is(button_to('test'), '<input value="test" type="button" onclick="document.location.href=\'module/action\';" />', 'button_to() returns an HTML "input" tag'); 47 $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'); 48 $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'); 49 43 50 class testObject 44 51 {

