/[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.3 by joko, Fri Apr 4 21:26:06 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
33    ##    + fixed problems with hidden form fields(current base URL) at the 'simple search form'
34    ##
35    ##    Revision 1.4  2003/04/06 01:41:07  jonen
36    ##    - removed duplicated decode functions
37    ##
38  ##    Revision 1.3  2003/04/04 21:26:06  joko  ##    Revision 1.3  2003/04/04 21:26:06  joko
39  ##    added comments regarding possible (future) refactoring using the Data::Lift-infrastructure  ##    added comments regarding possible (future) refactoring using the Data::Lift-infrastructure
40  ##  ##
# Line 22  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 51  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 73  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 109  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 132  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 150  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 178  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 212  class GenericGUIDataList extends Default Line 262  class GenericGUIDataList extends Default
262                        
263            */            */
264    
265              $utils = php::mkComponent('WebExplorer::utils');
266            // 1. if item is match by expression we will replace it with an link object              $hidden = $this->_hidden_elements;
267            if ($this->decode_item_expr($obj)) {              $options = $this->_options['decode_args'];
268              $obj = $this->decode_item_expr($obj);              $options[label] = $col_name;
269            }            $options[parent_guid] = $row_data[guid];
270              $options[parent_class] = $this->_options['parent']['class'];
271            // 2. if item is an Array we will replace it with an selection form object              
272            elseif ( $this->decode_item_array($obj) ) {            // a) Iterate through the attributes of the item and replace each
273              $obj = $this->decode_item_array($obj);              // value with an appropriate link object if it has a certain format.
274              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              } else {
278                $utils->decode_item_array($obj, $hidden, $options);
279            }            }
280    
281          }          }
# Line 254  class GenericGUIDataList extends Default Line 309  class GenericGUIDataList extends Default
309      }      }
310    
311    
312    // TODO: refactor to Data::Lift - subcomponent: handling will get way more easy!  
313    function decode_item_array($item) {      /**
314      $options = $this->_options['decode_args'];       * This function builds the simple search TD
315      //print "item: " . Dumper($item);       *
316      //print "options: " . Dumper($options);       * @return ContainerWidget
317      if( is_array($item) ) {       */
318            //$cur_row_index = $this->_datasource->get_cur_data_index();      function _build_simple_search_form() {
319            //$parent_guid = $this->_datasource->_data[$cur_row_index]['guid'];  
320            // build list for selection form          //if there is only 1 item enabled for search
321         if($options['form']) {          //then the search looks simple.
322            foreach($item as $key => $value) {          $fields = $this->_get_searchable_fields();
323                  $tmp = split($options['seperator'], $value);          $cnt = count($fields);
324                  $ident = $tmp['1'];          if ($cnt == 0) {
325                  $meta = $tmp['2'];              return NULL;
326                  $list[$key] = $ident;          }
327                  }  
328                  if(is_array($list) ) {          $container = new ContainerWidget;
329                $container = container(          
330                    form_open( $item[0], $_SERVER["PHP_SELF"], "POST" ),          // OLD - needed hidden elements are now recognized at 'render()'
331                    form_hidden("ecdm", $meta),          /*
332                    form_select("ecdid", $list),          // get current request vars and add them ad hidden items
333                    form_submit("submit","view" )          $url_vars = $this->_get_current_url_vars();
334                    );          foreach($url_vars as $label => $value) {
335                 foreach($this->_hidden_elements as $label => $value) {            $container->push(form_hidden($label, $value));
336                   $container->add(form_hidden($label, $value));          }
337                 }          */
338                $container->add(form_close() );  
339                $item = $container;          if ($cnt == 1) {
340                }              //user only has 1 field to show.
341                list($name, $field) = each($fields);
342                $container->push("Find ".$name."&nbsp;&nbsp;");
343          } else {          } else {
344            //print "<b>2</b><br/>";              //user has many fields to show.
345            $container = container();              $container->push("Find ",
346            foreach($item as $key => $value) {                               form_select($this->_vars["search_fieldVar"], $fields, $this->search_field()));
347                  $tmp = split($options['seperator'], $value);          }
348                  $ident = $tmp['1'];  
349                  $meta = $tmp['2'];          if ($this->get_simple_search_modifier()) {
350                       foreach($this->_hidden_elements as $label => $value) {              //the user wants the search modifier turned on.
351                         $tmp_array[] = $label . "=" . $value;              $container->push($this->_build_simple_search_modifier());
352                       }          }
353                       $str_hidden = join("&", $tmp_array);  
354                  $container->add("->", html_a($_SERVER["PHP_SELF"] . "?ecdid=" . $ident . "&ecdm=" . $meta . "&" . $str_hidden, $key . " view"), html_br());                        $container->push(form_text($this->_vars["search_valueVar"], $this->search_value_filter($this->search_value()), "20", "100", array("style"=>"vertical-align:middle;")),
355                             form_submit($this->get_form_name(), "Search", array("style"=>"vertical-align:middle;")));
356    
357            if ($this->is_advanced_search_enabled()) {
358                $span = html_span(html_a("ass","Advanced Search", "title"));
359                $container->push("&nbsp;", $span);
360            }
361    
362            if ($cnt == 1) {
363                $container->push(form_hidden($this->_vars["search_fieldVar"], $field));
364            }
365    
366            return $container;
367        }
368    
369    
370        /**
371         * 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            $item = $container;            return $action_form;
446            } else {
447              return _HTML_SPACE;
448          }          }
               return $item;  
449      }      }
   }  
450    
451    // decodes serialized string representations of object-references  
452    // TODO: refactor to Data::Lift - subcomponent: handling will get way more easy!      /*
453    function decode_item_expr($item) {       * OLD (depreciated) - this method returns the current requested variables
454      $options = $this->_options['decode_args'];       *
455      //print "item: $item<br/>";       * @return array
456      if(substr($item, 0, 2) == "o_") {       */
457            $tmp = split($options['seperator'], $item);      function _get_current_url_vars() {
458            $ident = $tmp['1'];          $cur_url_vars = array();
459            $meta = $tmp['2'];  
460            foreach($this->_hidden_elements as $label => $value) {          // get new LinkBuilder instance
461               $tmp_array[] = $label . "=" . $value;          $linkbuilder = new LinkBuilder();
462    
463            $url_vars = php::array_join_merge($_GET, $_POST);
464            if(is_array($url_vars)) {
465              foreach($url_vars as $key => $value) {
466                   // if there is an LinkBuilder guid instead of variables, encode it
467                   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            $str_hidden = join("&", $tmp_array);          }
477            $item = html_a($_SERVER["PHP_SELF"] . "?ecdid=" . $ident . "&ecdm=" . $meta . "&" . $str_hidden, "view");          return $cur_url_vars;
           return $item;  
478      }      }
479    }  
480    
481        /**
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.3  
changed lines
  Added in v.1.13

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