/[cvs]/nfo/php/libs/org.netfrag.patches/phphtmllib/widgets/GenericGUIDataList.php
ViewVC logotype

Diff of /nfo/php/libs/org.netfrag.patches/phphtmllib/widgets/GenericGUIDataList.php

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.5 by jonen, Tue Apr 8 17:33:22 2003 UTC revision 1.13 by jonen, Thu Oct 7 14:17:50 2004 UTC
# Line 1  Line 1 
1  <?  <?
2  /*  /*
3  ##    -----------------------------------------------------------------------------  ## -------------------------------------------------------------------------
4  ##    $Id$  ##    $Id$
5  ##    -----------------------------------------------------------------------------  ## -------------------------------------------------------------------------
6  ##    $Log$  ##    $Log$
7    ##    Revision 1.13  2004/10/07 14:17:50  jonen
8    ##    + pass filter-values to backend now! (page-control!)
9    ##
10    ##    Revision 1.12  2004/05/06 17:14:35  jonen
11    ##     updated
12    ##
13    ##    Revision 1.11  2003/05/10 17:58:45  jonen
14    ##    + reworked to implement 'create/add new' item
15    ##
16    ##    Revision 1.10  2003/04/18 18:40:02  jonen
17    ##    + fixed bugs at 'actionbar_cell' relating to html-form and js
18    ##
19    ##    Revision 1.9  2003/04/11 00:44:46  joko
20    ##    minor update: shortened seperators
21    ##
22    ##    Revision 1.8  2003/04/09 07:54:42  joko
23    ##    cleaned up decoding part
24    ##
25    ##    Revision 1.7  2003/04/09 00:37:53  jonen
26    ##    + added actionbar
27    ##    + some changes according to request vars
28    ##
29    ##    Revision 1.6  2003/04/08 17:48:31  jonen
30    ##    + bugfix again
31    ##
32  ##    Revision 1.5  2003/04/08 17:33:22  jonen  ##    Revision 1.5  2003/04/08 17:33:22  jonen
33  ##    + fixed problems with hidden form fields(current base URL) at the 'simple search form'  ##    + fixed problems with hidden form fields(current base URL) at the 'simple search form'
34  ##  ##
# Line 28  Line 53 
53  ##    Revision 1.1  2003/03/01 22:57:40  cvsmax  ##    Revision 1.1  2003/03/01 22:57:40  cvsmax
54  ##    + inital commit  ##    + inital commit
55  ##  ##
56  ##  ## -------------------------------------------------------------------------
 ##    -----------------------------------------------------------------------------  
57  */  */
58    
59    
60  /**  /**
61   * Need to make sure we have the DefaultGUIDataList object   * Need to make sure we have the DefaultGUIDataList object
62   */   */
# Line 57  class GenericGUIDataList extends Default Line 82  class GenericGUIDataList extends Default
82    */    */
83    var $_hidden_elements = array();    var $_hidden_elements = array();
84    
85    
86  /**  /**
87    * The constructor is used to pass in some additional    * The constructor is used to pass in some additional
88    * metadata informations as "options".    * metadata informations as "options".
# Line 79  class GenericGUIDataList extends Default Line 105  class GenericGUIDataList extends Default
105    */    */
106    function GenericGUIDataList($title, $width = "100%", $default_orderby='', $default_reverseorder=FALSE, $options = array()) {    function GenericGUIDataList($title, $width = "100%", $default_orderby='', $default_reverseorder=FALSE, $options = array()) {
107      if ($options) { $this->_options = $options; }      if ($options) { $this->_options = $options; }
108    
109        // call parent constructor
110      $parent =  get_parent_class($this);      $parent =  get_parent_class($this);
111      $this->$parent($title, $width = "100%", $default_orderby='', $default_reverseorder=FALSE);      $this->$parent($title, $width = "100%", $default_orderby='', $default_reverseorder=FALSE);
112    }    }
113    
114    
115    function get_data_source( ) {    function get_data_source( ) {
116    
117      // finally: create phpHtmlLib source handle (XyzDataListSource)      // finally: create phpHtmlLib source handle (XyzDataListSource)
# Line 115  class GenericGUIDataList extends Default Line 144  class GenericGUIDataList extends Default
144        // V5:        // V5:
145        //print "options: " . Dumper($this->_options);        //print "options: " . Dumper($this->_options);
146                
147    
148              //HACK 2004-10-07: page-filter done by backend now,
149              //                 filter-values are passed to backend
150          $this->_options['data_locator_meta']['filter']['offset'] = $this->offset();
151          $this->_options['data_locator_meta']['filter']['numrows'] = $this->numrows();
152          $this->_options['data_locator_meta']['filter']['search_field'] = $this->search_field();
153          $this->_options['data_locator_meta']['filter']['search_value'] = $this->search_value();
154          $this->_options['data_locator_meta']['filter']['search_modifier'] = $this->simple_search_modifier_value();
155          
156          //$this->_set("offsetVar", 0);
157          
158        $initial_locator = php::mkComponent( 'DataSource::Locator', array( adapter_type => 'phpHtmlLib' ) );        $initial_locator = php::mkComponent( 'DataSource::Locator', array( adapter_type => 'phpHtmlLib' ) );
159        //print "1st locator: " . Dumper($initial_locator);        //print "1st locator: " . Dumper($initial_locator);
160                
# Line 138  class GenericGUIDataList extends Default Line 178  class GenericGUIDataList extends Default
178        $source = $proxy->get_adapter();        $source = $proxy->get_adapter();
179    
180        // V4:        // V4:
181            //$source = $this->_datasource;              //$source = $this->_datasource;
182          
183        //print "objectlist-source: " . Dumper($source);        //print "objectlist-source: " . Dumper($source);
184        //exit;        //exit;
185    
# Line 156  class GenericGUIDataList extends Default Line 196  class GenericGUIDataList extends Default
196                        
197          //print Dumper($source);          //print Dumper($source);
198            $headers = $source->get_header();            $headers = $source->get_header();
199            //print Dumper($headers);            //print "headers: " . Dumper($headers);
200                        
201            $this->set_title( $this->get_title() . ' - ' . $source->get_total_rows() . ' Einträge' );            $this->set_title( $this->get_title() . ' - ' . $source->get_total_rows() . ' Einträge' );
202                        
203            foreach($headers as $val) {            foreach($headers as $val) {
204                  $this->add_header_item($val, "150", $val, SORTABLE, SEARCHABLE);                  $this->add_header_item($val, "150", $val, SORTABLE, SEARCHABLE);
205      }      }
206        
207    
208  /*  /*
209          $this->add_header_item("Uid", "200", "uid", SORTABLE, SEARCHABLE);          $this->add_header_item("Uid", "200", "uid", SORTABLE, SEARCHABLE);
210          $this->add_header_item("Name", "200", "lastName", SORTABLE, SEARCHABLE, "center");          $this->add_header_item("Name", "200", "lastName", SORTABLE, SEARCHABLE, "center");
211  */  */
212    
213          }          }
214    
215    
# Line 184  class GenericGUIDataList extends Default Line 226  class GenericGUIDataList extends Default
226       * @param int - the column # we are working on.       * @param int - the column # we are working on.
227       * @return TDtag object       * @return TDtag object
228       */       */
229     function wrap_column_item($obj, $col_name) {     function wrap_column_item($obj, $col_name, $row_data) {
230        
231            //print "item: " . Dumper($obj) . "<br>";
232    
233          //make sure its set to something.          //make sure its set to something.
234          if ($obj == '') {          if ($obj == '') {
# Line 221  class GenericGUIDataList extends Default Line 265  class GenericGUIDataList extends Default
265            $utils = php::mkComponent('WebExplorer::utils');            $utils = php::mkComponent('WebExplorer::utils');
266            $hidden = $this->_hidden_elements;            $hidden = $this->_hidden_elements;
267            $options = $this->_options['decode_args'];            $options = $this->_options['decode_args'];
268              $options[label] = $col_name;
269              $options[parent_guid] = $row_data[guid];
270              $options[parent_class] = $this->_options['parent']['class'];
271                        
272            // 1. if item is match by expression we will replace it with an link object              // a) Iterate through the attributes of the item and replace each
273            if ($utils->decode_item_expr($obj, $hidden, $options)) {              // value with an appropriate link object if it has a certain format.
274              $obj = $utils->decode_item_expr($obj, $hidden, $options);              if ($utils->decode_item_expr($obj, $hidden, $options)) {
275            }  
276              // b) Otherwise: If item is an Array we will replace it with a selection form object.
277            // 2. if item is an Array we will replace it with an selection form object              } else {
278            elseif ( $utils->decode_item_array($obj, $hidden, $options) ) {              $utils->decode_item_array($obj, $hidden, $options);
             $obj = $utils->decode_item_array($obj, $hidden, $options);    
279            }            }
280    
281          }          }
# Line 263  class GenericGUIDataList extends Default Line 309  class GenericGUIDataList extends Default
309      }      }
310    
311    
312    
313      /**      /**
314       * This function builds the simple search TD       * This function builds the simple search TD
315       *       *
# Line 279  class GenericGUIDataList extends Default Line 326  class GenericGUIDataList extends Default
326          }          }
327    
328          $container = new ContainerWidget;          $container = new ContainerWidget;
329            
330            // OLD - needed hidden elements are now recognized at 'render()'
331            /*
332            // get current request vars and add them ad hidden items
333            $url_vars = $this->_get_current_url_vars();
334            foreach($url_vars as $label => $value) {
335              $container->push(form_hidden($label, $value));
336            }
337            */
338    
339          if ($cnt == 1) {          if ($cnt == 1) {
340              //user only has 1 field to show.              //user only has 1 field to show.
# Line 307  class GenericGUIDataList extends Default Line 363  class GenericGUIDataList extends Default
363              $container->push(form_hidden($this->_vars["search_fieldVar"], $field));              $container->push(form_hidden($this->_vars["search_fieldVar"], $field));
364          }          }
365    
366          // find variables attached at base URL and add them as hidden fields,          return $container;
367          // so the search method will reach its starting point at deep frameworks      }
368          $base_url = $this->build_base_url();  
369          $url_vars = split("&", $base_url);  
370          $tmp = split("\?", $url_vars[0]);      /**
371          $url_vars[0] = $tmp[1];       * This function builds the data cell action buttons or main actionbar
372         *
373         * @return TDtag;
374         */
375        function _build_actionbar_data_cell() {
376            $td = new TDtag(array("class" => "datalist_title",
377                                  "style" => "padding-left:5px;padding-right:5px;".
378                                  "padding-top:5px;padding-bottom:5px")
379                           );
380    
381            $flag = FALSE;
382            if ($this->_has_action_column("FIRST")) {
383                $flag = TRUE;
384                $td->set_tag_attribute("align", "left");
385            }
386            elseif ($this->_has_action_column("LAST")) {
387                $flag = TRUE;
388                $td->set_tag_attribute("align", "right");
389            }
390    
391            if ($flag && $this->_datasource->get_total_rows()) {
392                $td->push($this->actionbar_cell());
393                $td->push($this->actionbar_cell_new());
394            }
395            else {
396                $td->push("&nbsp;");
397                $td->push($this->actionbar_cell_new());
398            }
399    
400            return $td;
401        }
402    
403    
404        /**
405         * this is the method that builds
406         * the contents for the middle actionbar
407         * td cell.
408         *
409         * @return ContainerWidget object
410         */
411        function actionbar_cell() {
412            $action_list = $this->_options['actionbar']['list'];
413            $action_name = $this->_options['actionbar']['name'];
414    
415            if($action_name && is_array($action_list)) {
416              $action_form = container("Select action", _HTML_SPACE,
417                                 form_select($action_name, $action_list, $this->_options['actionbar']['selected']),
418                                 form_submit("ok","OK" )
419                                 );
420              return $action_form;
421            } else {
422              return _HTML_SPACE;
423            }
424        }
425    
426    
427        /**
428         * this is the method that builds
429         * the contents for the buttons of actionbar
430         * td cell.
431         *
432         * @return ContainerWidget object
433         */
434        function actionbar_cell_new() {
435            $action_buttons = $this->_options['actionbar']['buttons'];
436    
437            if(is_array($action_buttons)) {
438              $action_form = container();
439              foreach($action_buttons as $type) {
440                $action_form->add(
441                                 _HTML_SPACE,
442                                 form_submit($type['name'], $type['value'])
443                                 );
444              }
445              return $action_form;
446            } else {
447              return _HTML_SPACE;
448            }
449        }
450    
451    
452        /*
453         * OLD (depreciated) - this method returns the current requested variables
454         *
455         * @return array
456         */
457        function _get_current_url_vars() {
458            $cur_url_vars = array();
459    
460            // get new LinkBuilder instance
461            $linkbuilder = new LinkBuilder();
462    
463            $url_vars = php::array_join_merge($_GET, $_POST);
464          if(is_array($url_vars)) {          if(is_array($url_vars)) {
465            foreach($url_vars as $value) {            foreach($url_vars as $key => $value) {
466              $var = split("=", $value);                 // if there is an LinkBuilder guid instead of variables, encode it
467              $container->push(form_hidden($var[0], $var[1]));                   if($key == 'lbid') {
468                     $lb_vars = $linkbuilder->load($value);
469                     foreach($lb_vars as $lbkey => $lbval) {
470                       $cur_url_vars[$lbkey] = $lbval;
471                     }
472                   } else {
473                     $cur_url_vars[$key] = $value;
474                   }
475            }            }
476          }          }
477            return $cur_url_vars;
478        }
479    
480          $container->push(form_close() );  
481          return $container;      /**
482         * This function renders the final
483         * widget
484         *
485         */
486        function render($indent_level, $output_debug) {
487    
488            //setup the columns in their sorts
489            $this->setup_columns();
490    
491            //do any data prefetch work
492            //which may be child specific
493            if ( $this->_show_results() ) {
494                $this->data_prefetch();
495            }
496            
497            //This function gives the child class
498            //a chance to build the tables/divs/containers
499            //that will be responsible for the look/feel
500            //of the DataList
501            $this->gui_init();
502    
503            //see if we need to build the search area.
504            if ( $this->is_search_enabled() || $this->is_advanced_search_enabled() ) {
505                $this->_search_table = $this->child_build_search_table();
506                if ( $this->_search_table ) {
507                    $this->set_form_render(TRUE);
508                }
509            }
510    
511            //see if form is needed by the actionbar
512            if($this->_show_actionbar) {
513              $this->set_form_render(TRUE);
514            }
515    
516            if ( $this->get_form_render() ) {
517                $form =  new FORMtag( array("method" => $this->get_form_method(),
518                                            "action" => $this->build_base_url(),
519                                            "name" => $this->get_form_name(),
520                                            "style" => "margin-top: 0px;margin-bottom:0px;") );
521    
522                $target = $this->get_form_target();
523                if ( $target != NULL )
524                    $form->set_tag_attribute("target",$target);
525    
526                $action = $this->get_form_action();
527                if ( $action != NULL )
528                    $form->set_tag_attribute("action",$action);
529    
530                //now build the UI and return it
531                $form->add( $this->build_gui() );
532                
533            } else {
534                $form = container();
535    
536                //now build the UI and return it
537                $form->add( $this->build_gui() );
538            }
539            
540            //add the hidden vars if we are a POST
541            if ($this->get_form_method() == "POST") {
542                $form->add( $this->_build_default_vars() );
543    
544                //build hidden elements needed for data flow control
545                $hidden = $this->_hidden_elements;
546                //print "Hidden: " . Dumper($hidden);
547                if($hidden) {
548                  foreach($hidden as $label => $value) {
549                    $form->add(form_hidden($label, $value));
550                  }
551                }
552    
553            }
554    
555            //add the save vars the user wants.
556            $form->add( $this->_build_save_vars() );
557    
558            //add any javascript required
559            $container = container( $this->_javascript(), $form );
560            return $container->render( $indent_level, $output_debug );
561      }      }
562    
563    
564    
565            function child_add_row_cell($obj, $col_name, $last_in_row_flag, $row_data) {
566            if (!$this->_cur_col_cntr) {
567            //if (!isset($this->_cur_col_cntr)) {
568                $this->_cur_col_cntr = 1;
569                //lets see if we need to add an action column
570                //as the first column.
571                if ($this->_has_action_column("FIRST")) {
572                    //looks like we have a FIRST column actionbar
573                    //lets add it
574                    $this->_data_row->add($this->_build_action_column("FIRST", FALSE, $row_data));
575                }
576                $td = $this->wrap_column_item($obj, $col_name, $row_data);
577                $this->_data_row->add( $td );
578            } else {
579                //show the normal data
580                $td = $this->wrap_column_item($obj, $col_name, $row_data);
581                $this->_data_row->add( $td );
582            }
583    
584                    
585                    if ($last_in_row_flag) {
586                //lets see if we need to add an action column
587                //as the first column.
588                if ($this->_has_action_column("LAST")) {
589                    //looks like we have a LAST column actionbar
590                    //lets add it
591                    $this->_data_row->add($this->_build_action_column("LAST", FALSE, $row_data));
592                }
593    
594    
595    
596                            $this->_data_table->add_row( $this->_data_row );
597                            $this->_data_row = new TRtag;
598                unset( $this->_cur_col_cntr );
599                    } else {
600                $this->_cur_col_cntr++;
601            }
602            }
603    
604  }  }
605  ?>  ?>

Legend:
Removed from v.1.5  
changed lines
  Added in v.1.13

MailToCvsAdmin">MailToCvsAdmin
ViewVC Help
Powered by ViewVC 1.1.26 RSS 2.0 feed