Show
Ignore:
Timestamp:
03/19/09 10:40:34 (3 years ago)
Author:
john
Message:

features and bug fixes from gocoffeego project

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/trax/vendor/trax/action_view/helpers/active_record_helper.php

    r277 r308  
    138138        $this->object_name = $object_name; 
    139139        $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)) { 
    142142            return $this->content_tag("div", $prepend_text . (is_array($errors) ? current($errors) : $errors) . $append_text, array('class' => $css_class)); 
    143143        } 
     
    164164        } 
    165165        $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()) { 
    168168            $id = isset($options['id']) ? $options['id'] : "ErrorExplanation"; 
    169169            $class = isset($options['class']) ? $options['class'] : "ErrorExplanation"; 
     
    173173            $header_sub_message = isset($options['header_sub_message']) ? 
    174174                $options['header_sub_message'] : "There were problems with the following fields:"; 
    175                 
     175                 
    176176            return $this->content_tag("div", 
    177177                $this->content_tag( 
    178178                    $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)) 
    180180                ) . 
    181181                $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);'), '')), 
    183183                array("id" => $id, "class" => $class) 
    184184            ); 
     
    482482     *  @todo Document this API 
    483483     */ 
    484     function pagination_limit_select($object_name_or_object, $default_text = "per page:") { 
     484    function pagination_limit_select($object_name_or_object, $options = array()) { 
    485485 
    486486        if(is_object($object_name_or_object)) { 
     
    495495 
    496496        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            }            
    497510            $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}\"> 
    499512                    <option value=\"$object->rows_per_page\" selected>$default_text</option> 
    500513                    <option value=10>10</option> 
     
    519532     *  @uses rows_per_page 
    520533     */ 
    521     function pagination_links($object_name_or_object) { 
     534    function pagination_links($object_name_or_object, $options = array()) { 
    522535         
    523536        if(is_object($object_name_or_object)) { 
     
    530543            return null;     
    531544        } 
     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 
    532578            
    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\">"; 
    534582        /* 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 .= "&nbsp;"; 
     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 .= "&nbsp;"; 
     620        } 
     621        $html .= "</div>"; 
    552622        if($object->pages < $object->display) { 
    553623            $object->display = $object->pages; 
     
    574644            $end = $object->pages; 
    575645        } 
    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 
    578649        if($end != 1) { 
     650            $selected_class = $selected_class ? $link_class." ".$selected_class : $selected_class; 
    579651            for($i=$start; $i<=$end; $i++) { 
    580652                if($i == $object->page) { 
    581                     $html .= "<span class=\"pageList\"><b>".$i."</b></span>"; 
     653                    $html .= "<span class=\"{$selected_class}\">".$i."</span>"; 
    582654                } 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                    }                     
    589669                } 
    590670                $html .= " "; 
    591671            } 
    592672        } 
    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 .= "&nbsp;"; 
     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 .= "&nbsp;"; 
     713        } 
     714        $html .= "</div>"; 
     715        $html .= "</div>\n"; 
    612716 
    613717        return $html;