Changeset 308 for trunk/trax/vendor/trax/action_view
- Timestamp:
- 03/19/09 10:40:34 (3 years ago)
- Location:
- trunk/trax/vendor/trax/action_view
- Files:
-
- 5 modified
-
helpers.php (modified) (1 diff)
-
helpers/active_record_helper.php (modified) (8 diffs)
-
helpers/form_helper.php (modified) (9 diffs)
-
helpers/form_options_helper.php (modified) (1 diff)
-
helpers/javascript_helper.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/trax/vendor/trax/action_view/helpers.php
r280 r308 134 134 */ 135 135 protected function value() { 136 if (array_key_exists($this->object_name, $_REQUEST)136 if (array_key_exists($this->object_name, (array)$_REQUEST) 137 137 && array_key_exists($this->attribute_name, 138 $_REQUEST[$this->object_name])) {138 (array)$_REQUEST[$this->object_name])) { 139 139 $value = $_REQUEST[$this->object_name][$this->attribute_name]; 140 140 } else { 141 142 141 // Attribute value not found in $_REQUEST. Find the 143 142 // ActiveRecord subclass instance and query it. -
trunk/trax/vendor/trax/action_view/helpers/active_record_helper.php
r277 r308 138 138 $this->object_name = $object_name; 139 139 $this->attribute_name = $attribute_name; 140 $object = $this-> controller_object->$object_name;141 if( $errors = $object->errors[$attribute_name]) {140 $object = $this->object($object_name); 141 if(is_object($object) && $errors = $object->errors_on($attribute_name)) { 142 142 return $this->content_tag("div", $prepend_text . (is_array($errors) ? current($errors) : $errors) . $append_text, array('class' => $css_class)); 143 143 } … … 164 164 } 165 165 $this->object_name = $object_name; 166 $object = $this-> controller_object->$object_name;167 if( !empty($object->errors)) {166 $object = $this->object($object_name); 167 if(is_object($object) && $errors = $object->errors_full_messages()) { 168 168 $id = isset($options['id']) ? $options['id'] : "ErrorExplanation"; 169 169 $class = isset($options['class']) ? $options['class'] : "ErrorExplanation"; … … 173 173 $header_sub_message = isset($options['header_sub_message']) ? 174 174 $options['header_sub_message'] : "There were problems with the following fields:"; 175 175 176 176 return $this->content_tag("div", 177 177 $this->content_tag( 178 178 $header_tag, 179 sprintf($header_message, Inflector::pluralize("error", count($ object->errors)), Inflector::humanize($object_name))179 sprintf($header_message, Inflector::pluralize("error", count($errors)), Inflector::humanize($object_name)) 180 180 ) . 181 181 $this->content_tag("p", $header_sub_message) . 182 $this->content_tag("ul", array_reduce($ object->errors, create_function('$v,$w', 'return ($v ? $v : "") . content_tag("li", $w);'), '')),182 $this->content_tag("ul", array_reduce($errors, create_function('$v,$w', 'return ($v ? $v : "") . content_tag("li", $w);'), '')), 183 183 array("id" => $id, "class" => $class) 184 184 ); … … 482 482 * @todo Document this API 483 483 */ 484 function pagination_limit_select($object_name_or_object, $ default_text = "per page:") {484 function pagination_limit_select($object_name_or_object, $options = array()) { 485 485 486 486 if(is_object($object_name_or_object)) { … … 495 495 496 496 if($object->pages > 0) { 497 $base_url = isset($options['base_url']) ? $options['base_url'] : ''; 498 $update = isset($options['update']) ? $options['update'] : ''; 499 $extra_params = isset($options['extra_params']) ? "&".$options['extra_params'] : 500 ($object->paging_extra_params ? "&".$object->paging_extra_params : ''); 501 $default_text = isset($options['default_text']) ? $options['default_text'] : "per page:"; 502 if($update && $base_url) { 503 $on_change = remote_function(array( 504 "update" => $update, 505 "url" => "{$base_url}?per_page=' + this.options[this.selectedIndex].value + '".escape_javascript($extra_params)."'" 506 )); 507 } else { 508 $on_change = "document.location = '{$base_url}?per_page=' + this.options[this.selectedIndex].value + '".escape_javascript($extra_params)."'"; 509 } 497 510 $html .= " 498 <select name=\"per_page\" onChange=\" document.location = '?".escape_javascript($object->paging_extra_params)."&per_page=' + this.options[this.selectedIndex].value;\">511 <select name=\"per_page\" onChange=\"{$on_change}\"> 499 512 <option value=\"$object->rows_per_page\" selected>$default_text</option> 500 513 <option value=10>10</option> … … 519 532 * @uses rows_per_page 520 533 */ 521 function pagination_links($object_name_or_object ) {534 function pagination_links($object_name_or_object, $options = array()) { 522 535 523 536 if(is_object($object_name_or_object)) { … … 530 543 return null; 531 544 } 545 546 $first_text = isset($options['first_text']) ? $options['first_text'] : "<<"; 547 $last_text = isset($options['last_text']) ? $options['last_text'] : ">>"; 548 $prev_text = isset($options['prev_text']) ? $options['prev_text'] : "<"; 549 $next_text = isset($options['next_text']) ? $options['next_text'] : ">"; 550 $link_class = isset($options['link_class']) ? $options['link_class'] : "pagingLink"; 551 $selected_class = isset($options['selected_class']) ? $options['selected_class'] : "pagingSelected"; 552 $base_url = isset($options['base_url']) ? $options['base_url'] : ''; 553 $update = isset($options['update']) ? $options['update'] : ''; 554 $extra_params = isset($options['extra_params']) ? "&".$options['extra_params'] : 555 ($object->paging_extra_params ? "&".$object->paging_extra_params : ''); 556 557 $first_width = "width:".(isset($options['first_width']) ? $options['first_width'] : '20')."px;"; # size in pixels 558 $first_width = ( 559 ( isset($options['first_text']) && isset($options['first_width']) ) || 560 ( !isset($options['first_text']) && !isset($options['first_width']) ) 561 ) ? $first_width : ''; 562 $last_width = "width:".(isset($options['last_width']) ? $options['last_width'] : '20')."px;"; # size in pixels 563 $last_width = ( 564 ( isset($options['last_text']) && isset($options['last_width']) ) || 565 ( !isset($options['last_text']) && !isset($options['last_width']) ) 566 ) ? $last_width : ''; 567 $prev_width = "width:".(isset($options['prev_width']) ? $options['prev_width'] : '10')."px;"; # size in pixels 568 $prev_width = ( 569 ( isset($options['prev_text']) && isset($options['prev_width']) ) || 570 ( !isset($options['prev_text']) && !isset($options['prev_width']) ) 571 ) ? $prev_width : ''; 572 $next_width = "width:".(isset($options['next_width']) ? $options['next_width'] : '10')."px;"; # size in pixels 573 $next_width = ( 574 ( isset($options['next_text']) && isset($options['next_width']) ) || 575 ( !isset($options['next_text']) && !isset($options['next_width']) ) 576 ) ? $next_width : ''; 577 $pages_width = isset($options['fixed_pages']) ? "width:".$options['fixed_pages']."px;" : ''; # size in pixels 532 578 533 //$html = "<pre>".print_r($object,1); 579 580 $html .= "<div class=\"pagingContaniner\" style=\"display:inline\">"; 581 $html .= "<div class=\"pagingFirst\" style=\"{$first_width}text-align:left;display:inline;float:left\">"; 534 582 /* Print the first and previous page links if necessary */ 535 if(($object->page != 1) && ($object->page)) { 536 $html .= link_to("<<", 537 "?$object->paging_extra_params&page=1&per_page=$object->rows_per_page", 538 array( 539 "class" => "pageList", 540 "title" => "First page" 541 ))." "; 542 } 543 if(($object->page-1) > 0) { 544 $html .= link_to("<", 545 "?$object->paging_extra_params&page=".($object->page-1)."&per_page=$object->rows_per_page", 546 array( 547 "class" => "pageList", 548 "title" => "Previous Page" 549 )); 550 } 551 583 if(($object->page != 1) && ($object->page) && $first_text) { 584 if($update && $base_url) { 585 $html .= link_to_remote($first_text, array( 586 "update" => $update, 587 "url" => "{$base_url}?page=1&per_page={$object->rows_per_page}{$extra_params}" 588 ), array( 589 "class" => $link_class, 590 "title" => "First page" 591 ))." "; 592 } else { 593 $html .= link_to($first_text, "{$base_url}?page=1&per_page={$object->rows_per_page}{$extra_params}", array( 594 "class" => $link_class, 595 "title" => "First page" 596 ))." "; 597 } 598 } else { 599 $html .= " "; 600 } 601 $html .= "</div>"; 602 $html .= "<div class=\"pagingPrev\" style=\"{$prev_width}text-align:left;display:inline;float:left\">"; 603 if(($object->page-1) > 0 && $prev_text) { 604 if($update && $base_url) { 605 $html .= link_to_remote($prev_text, array( 606 "update" => $update, 607 "url" => "{$base_url}?page=".($object->page-1)."&per_page={$object->rows_per_page}{$extra_params}" 608 ), array( 609 "class" => $link_class, 610 "title" => "Previous page" 611 )); 612 } else { 613 $html .= link_to($prev_text, "{$base_url}?page=".($object->page-1)."&per_page={$object->rows_per_page}{$extra_params}", array( 614 "class" => $link_class, 615 "title" => "Previous page" 616 )); 617 } 618 } else { 619 $html .= " "; 620 } 621 $html .= "</div>"; 552 622 if($object->pages < $object->display) { 553 623 $object->display = $object->pages; … … 574 644 $end = $object->pages; 575 645 } 576 577 /* Print the numeric page list; make the current page unlinked and bold */ 646 647 $html .= "<div class=\"pagingPages\" style=\"{$pages_width}text-align:center;display:inline;float:left;padding:0px 5px\">"; 648 # Print the numeric page list; make the current page unlinked and bold 578 649 if($end != 1) { 650 $selected_class = $selected_class ? $link_class." ".$selected_class : $selected_class; 579 651 for($i=$start; $i<=$end; $i++) { 580 652 if($i == $object->page) { 581 $html .= "<span class=\" pageList\"><b>".$i."</b></span>";653 $html .= "<span class=\"{$selected_class}\">".$i."</span>"; 582 654 } else { 583 $html .= link_to($i, 584 "?$object->paging_extra_params&page=$i&per_page=$object->rows_per_page", 585 array( 586 "class" => "pageList", 587 "title" => "Page $i" 588 )); 655 if($update && $base_url) { 656 $html .= link_to_remote($i, array( 657 "update" => $update, 658 "url" => "{$base_url}?page={$i}&per_page={$object->rows_per_page}{$extra_params}" 659 ), array( 660 "class" => $link_class, 661 "title" => "Page $i" 662 )); 663 } else { 664 $html .= link_to($i, "{$base_url}?page={$i}&per_page={$object->rows_per_page}{$extra_params}", array( 665 "class" => $link_class, 666 "title" => "Page $i" 667 )); 668 } 589 669 } 590 670 $html .= " "; 591 671 } 592 672 } 593 594 /* Print the Next and Last page links if necessary */ 595 if(($object->page+1) <= $object->pages) { 596 $html .= link_to(">", 597 "?$object->paging_extra_params&page=".($object->page+1)."&per_page=$object->rows_per_page", 598 array( 599 "class" => "pageList", 600 "title" => "Next Page" 601 )); 602 } 603 if(($object->page != $object->pages) && ($object->pages != 0)) { 604 $html .= link_to(">>", 605 "?$object->paging_extra_params&page=".$object->pages."&per_page=$object->rows_per_page", 606 array( 607 "class" => "pageList", 608 "title" => "Last Page" 609 )); 610 } 611 $html .= "\n"; 673 $html .= "</div>"; 674 $html .= "<div class=\"pagingNext\" style=\"{$next_width}text-align:right;display:inline;float:left\">"; 675 # Print the Next and Last page links if necessary 676 if(($object->page+1) <= $object->pages && $next_text) { 677 if($update && $base_url) { 678 $html .= link_to_remote($next_text, array( 679 "update" => $update, 680 "url" => "{$base_url}?page=".($object->page+1)."&per_page={$object->rows_per_page}{$extra_params}" 681 ), array( 682 "class" => $link_class, 683 "title" => "Next Page" 684 )); 685 } else { 686 $html .= link_to($next_text, "{$base_url}?page=".($object->page+1)."&per_page={$object->rows_per_page}{$extra_params}", array( 687 "class" => $link_class, 688 "title" => "Next Page" 689 )); 690 } 691 } else { 692 $html .= " "; 693 } 694 $html .= "</div>"; 695 $html .= "<div class=\"pagingLast\" style=\"{$last_width}text-align:right;display:inline;float:left\">"; 696 if(($object->page != $object->pages) && ($object->pages != 0) && $last_text) { 697 if($update && $base_url) { 698 $html .= link_to_remote($last_text, array( 699 "update" => $update, 700 "url" => "{$base_url}?page=".$object->pages."&per_page={$object->rows_per_page}{$extra_params}" 701 ), array( 702 "class" => $link_class, 703 "title" => "Last Page" 704 )); 705 } else { 706 $html .= link_to($last_text, "{$base_url}?page=".$object->pages."&per_page={$object->rows_per_page}{$extra_params}", array( 707 "class" => $link_class, 708 "title" => "Last Page" 709 )); 710 } 711 } else { 712 $html .= " "; 713 } 714 $html .= "</div>"; 715 $html .= "</div>\n"; 612 716 613 717 return $html; -
trunk/trax/vendor/trax/action_view/helpers/form_helper.php
r243 r308 131 131 */ 132 132 function add_default_name_and_id($options) { 133 $name_option_exists = array_key_exists('name', $options);134 if(array_key_exists("index", $options)) {133 $name_option_exists = array_key_exists('name', (array)$options); 134 if(array_key_exists("index", (array)$options)) { 135 135 $options['name'] = $name_option_exists 136 136 ? $options['name'] 137 137 : $this->tag_name_with_index($options['index']); 138 $options['id'] = array_key_exists('id', $options)138 $options['id'] = array_key_exists('id', (array)$options) 139 139 ? $options['id'] 140 140 : $this->tag_id_with_index($options['index']); … … 144 144 ? $options['name'] 145 145 : $this->tag_name_with_index($this->auto_index); 146 $options['id'] = array_key_exists('id', $options)146 $options['id'] = array_key_exists('id', (array)$options) 147 147 ? $options['id'] 148 148 : $this->tag_id_with_index($this->auto_index); … … 151 151 ? $options['name'] 152 152 : $this->tag_name(); 153 $options['id'] = array_key_exists('id', $options)153 $options['id'] = array_key_exists('id', (array)$options) 154 154 ? $options['id'] 155 155 : $this->tag_id(); 156 156 } 157 if(array_key_exists('multiple', $options) && !$name_option_exists) {157 if(array_key_exists('multiple', (array)$options) && !$name_option_exists) { 158 158 $options['name'] .= "[]"; 159 159 } … … 181 181 */ 182 182 function to_input_field_tag($field_type, $options = array()) { 183 $default_size = array_key_exists("maxlength", $options)183 $default_size = array_key_exists("maxlength", (array)$options) 184 184 ? $options["maxlength"] : $this->default_field_options['size']; 185 $options["size"] = array_key_exists("size", $options)185 $options["size"] = array_key_exists("size", (array)$options) 186 186 ? $options["size"]: $default_size; 187 $options = array_merge($this->default_field_options, $options);187 $options = array_merge($this->default_field_options, (array)$options); 188 188 if($field_type == "hidden") { 189 189 unset($options["size"]); … … 191 191 $options["type"] = $field_type; 192 192 if($field_type != "file") { 193 $options["value"] = array_key_exists("value", $options)193 $options["value"] = array_key_exists("value", (array)$options) 194 194 ? $options["value"] : $this->value(); 195 195 } … … 198 198 $this->tag("input", $options), 199 199 @array_key_exists($this->attribute_name, 200 $this->object()->errors)200 (array)$this->object()->errors) 201 201 ? true : false); 202 202 } … … 226 226 */ 227 227 function to_text_area_tag($options = array()) { 228 if (array_key_exists("size", $options)) {228 if (array_key_exists("size", (array)$options)) { 229 229 $size = explode('x', $options["size"]); 230 230 $options["cols"] = reset($size); … … 232 232 unset($options["size"]); 233 233 } 234 $options = array_merge($this->default_text_area_options, $options);234 $options = array_merge($this->default_text_area_options, (array)$options); 235 235 $options = $this->add_default_name_and_id($options); 236 236 return $this->error_wrapping( … … 238 238 htmlspecialchars($this->value(), ENT_COMPAT), 239 239 $options), 240 array_key_exists($this->attribute_name, $this->object()->errors)240 array_key_exists($this->attribute_name, (array)$this->object()->errors) 241 241 ? $this->object()->errors[$this->attribute_name] : false); 242 242 } -
trunk/trax/vendor/trax/action_view/helpers/form_options_helper.php
r269 r308 226 226 $html_options) { 227 227 $html_options = $this->add_default_name_and_id($html_options); 228 $value =$this->value();228 $value = isset($options['selected']) ? $options['selected'] : $this->value(); 229 229 return $this->error_wrapping( 230 230 $this->content_tag( -
trunk/trax/vendor/trax/action_view/helpers/javascript_helper.php
r282 r308 516 516 $options['with'] = "Sortable.serialize('{$element_id}')"; 517 517 } 518 if(!$options['on Update']) {519 $options['on Update'] = "function(){" . $this->remote_function($options) . "}";518 if(!$options['onDrop']) { 519 $options['onDrop'] = "function(){" . $this->remote_function($options) . "}"; 520 520 } 521 521 $options = $this->remove_ajax_options($options);
