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

features and bug fixes from gocoffeego project

Location:
trunk/trax/vendor/trax/action_view
Files:
5 modified

Legend:

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

    r280 r308  
    134134     */ 
    135135    protected function value() { 
    136         if (array_key_exists($this->object_name, $_REQUEST) 
     136        if (array_key_exists($this->object_name, (array)$_REQUEST) 
    137137            && array_key_exists($this->attribute_name, 
    138                                  $_REQUEST[$this->object_name])) { 
     138                                 (array)$_REQUEST[$this->object_name])) { 
    139139            $value = $_REQUEST[$this->object_name][$this->attribute_name]; 
    140140        } else { 
    141  
    142141            //  Attribute value not found in $_REQUEST.  Find the 
    143142            //  ActiveRecord subclass instance and query it. 
  • 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; 
  • trunk/trax/vendor/trax/action_view/helpers/form_helper.php

    r243 r308  
    131131     */ 
    132132    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)) { 
    135135            $options['name'] = $name_option_exists 
    136136                ? $options['name'] 
    137137                : $this->tag_name_with_index($options['index']); 
    138             $options['id'] = array_key_exists('id', $options) 
     138            $options['id'] = array_key_exists('id', (array)$options) 
    139139                ? $options['id'] 
    140140                : $this->tag_id_with_index($options['index']); 
     
    144144                ? $options['name'] 
    145145                : $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) 
    147147                ? $options['id'] 
    148148                : $this->tag_id_with_index($this->auto_index); 
     
    151151                ? $options['name'] 
    152152                : $this->tag_name(); 
    153             $options['id'] = array_key_exists('id', $options) 
     153            $options['id'] = array_key_exists('id', (array)$options) 
    154154                ? $options['id'] 
    155155                : $this->tag_id(); 
    156156        } 
    157         if(array_key_exists('multiple', $options) && !$name_option_exists) { 
     157        if(array_key_exists('multiple', (array)$options) && !$name_option_exists) { 
    158158            $options['name'] .= "[]";            
    159159        } 
     
    181181     */ 
    182182    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) 
    184184            ? $options["maxlength"] : $this->default_field_options['size']; 
    185         $options["size"] = array_key_exists("size", $options) 
     185        $options["size"] = array_key_exists("size", (array)$options) 
    186186            ? $options["size"]: $default_size; 
    187         $options = array_merge($this->default_field_options, $options); 
     187        $options = array_merge($this->default_field_options, (array)$options); 
    188188        if($field_type == "hidden") { 
    189189            unset($options["size"]); 
     
    191191        $options["type"] = $field_type; 
    192192        if($field_type != "file") { 
    193             $options["value"] = array_key_exists("value", $options) 
     193            $options["value"] = array_key_exists("value", (array)$options) 
    194194                ? $options["value"] : $this->value(); 
    195195        } 
     
    198198                     $this->tag("input", $options), 
    199199                     @array_key_exists($this->attribute_name, 
    200                                       $this->object()->errors) 
     200                                      (array)$this->object()->errors) 
    201201                     ? true : false); 
    202202    } 
     
    226226     */ 
    227227    function to_text_area_tag($options = array()) { 
    228         if (array_key_exists("size", $options)) { 
     228        if (array_key_exists("size", (array)$options)) { 
    229229            $size = explode('x', $options["size"]); 
    230230            $options["cols"] = reset($size); 
     
    232232            unset($options["size"]); 
    233233        } 
    234         $options = array_merge($this->default_text_area_options, $options); 
     234        $options = array_merge($this->default_text_area_options, (array)$options); 
    235235        $options = $this->add_default_name_and_id($options); 
    236236        return $this->error_wrapping( 
     
    238238                              htmlspecialchars($this->value(), ENT_COMPAT), 
    239239                              $options), 
    240            array_key_exists($this->attribute_name,$this->object()->errors) 
     240           array_key_exists($this->attribute_name, (array)$this->object()->errors) 
    241241           ? $this->object()->errors[$this->attribute_name] : false); 
    242242    } 
  • trunk/trax/vendor/trax/action_view/helpers/form_options_helper.php

    r269 r308  
    226226                                      $html_options) { 
    227227        $html_options = $this->add_default_name_and_id($html_options); 
    228         $value = $this->value(); 
     228        $value = isset($options['selected']) ? $options['selected'] : $this->value(); 
    229229        return $this->error_wrapping( 
    230230            $this->content_tag( 
  • trunk/trax/vendor/trax/action_view/helpers/javascript_helper.php

    r282 r308  
    516516            $options['with'] = "Sortable.serialize('{$element_id}')"; 
    517517        } 
    518         if(!$options['onUpdate']) { 
    519             $options['onUpdate'] = "function(){" . $this->remote_function($options) . "}"; 
     518        if(!$options['onDrop']) { 
     519            $options['onDrop'] = "function(){" . $this->remote_function($options) . "}"; 
    520520        } 
    521521        $options = $this->remove_ajax_options($options);