Changeset 8836
- Timestamp:
- 05/07/08 18:51:20 (2 years ago)
- Files:
-
- branches/1.0/lib/helper/UrlHelper.php (modified) (6 diffs)
- branches/1.0/test/unit/helper/UrlHelperTest.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/1.0/lib/helper/UrlHelper.php
r7999 r8836 239 239 * @see url_for, link_to 240 240 */ 241 function button_to($name, $internal_uri , $options = array())242 { 243 $html_options = _ convert_options($options);241 function button_to($name, $internal_uri ='', $options = array()) 242 { 243 $html_options = _parse_attributes($options); 244 244 $html_options['value'] = $name; 245 245 … … 256 256 return form_tag($internal_uri, array('method' => 'post', 'class' => 'button_to')).content_tag('div', tag('input', $html_options)).'</form>'; 257 257 } 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']); 264 272 } 265 273 else 266 274 { 267 $html_options['type'] = 'button'; 268 $html_options['onclick'] = "document.location.href='".url_for($internal_uri)."';"; 275 $html_options['onclick'] = "document.location.href=".$url.";"; 269 276 $html_options = _convert_options_to_javascript($html_options); 270 271 return tag('input', $html_options); 272 }277 } 278 279 return tag('input', $html_options); 273 280 } 274 281 … … 333 340 } 334 341 335 function _convert_options_to_javascript($html_options, $ internal_uri = '')342 function _convert_options_to_javascript($html_options, $url = 'this.href') 336 343 { 337 344 // confirm … … 355 362 else if ($confirm && $popup) 356 363 { 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;'; 358 365 } 359 366 else if ($confirm && $post) … … 378 385 else if ($popup) 379 386 { 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;'; 381 388 } 382 389 … … 389 396 } 390 397 391 function _popup_javascript_function($popup, $internal_uri = '') 392 { 393 $url = $internal_uri == '' ? 'this.href' : "'".url_for($internal_uri)."'"; 394 398 function _popup_javascript_function($popup, $url = '') 399 { 395 400 if (is_array($popup)) 396 401 { branches/1.0/test/unit/helper/UrlHelperTest.php
r7804 r8836 43 43 } 44 44 45 $t = new lime_test(2 6, new lime_output_color());45 $t = new lime_test(29, new lime_output_color()); 46 46 47 47 $context = sfContext::getInstance(); … … 61 61 $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'); 62 62 $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 63 70 class testObject 64 71 {

