/[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.14 by jonen, Mon Nov 15 16:51:48 2004 UTC
# Line 1  Line 1 
1  <?  <?
2  /*  /*
3  ##    -----------------------------------------------------------------------------  ## -------------------------------------------------------------------------
4  ##    $Id$  ##    $Id$
5  ##    -----------------------------------------------------------------------------  ## -------------------------------------------------------------------------
6  ##    $Log$  ##    $Log$
7    ##    Revision 1.14  2004/11/15 16:51:48  jonen
8    ##    + added var 'numrows' to constructor args
9    ##
10    ##    Revision 1.13  2004/10/07 14:17:50  jonen
11    ##    + pass filter-values to backend now! (page-control!)
12    ##
13    ##    Revision 1.12  2004/05/06 17:14:35  jonen
14    ##     updated
15    ##
16    ##    Revision 1.11  2003/05/10 17:58:45  jonen
17    ##    + reworked to implement 'create/add new' item
18    ##
19    ##    Revision 1.10  2003/04/18 18:40:02  jonen
20    ##    + fixed bugs at 'actionbar_cell' relating to html-form and js
21    ##
22    ##    Revision 1.9  2003/04/11 00:44:46  joko
23    ##    minor update: shortened seperators
24    ##
25    ##    Revision 1.8  2003/04/09 07:54:42  joko
26    ##    cleaned up decoding part
27    ##
28    ##    Revision 1.7  2003/04/09 00:37:53  jonen
29    ##    + added actionbar
30    ##    + some changes according to request vars
31    ##
32    ##    Revision 1.6  2003/04/08 17:48:31  jonen
33    ##    + bugfix again
34    ##
35    ##    Revision 1.5  2003/04/08 17:33:22  jonen
36    ##    + fixed problems with hidden form fields(current base URL) at the 'simple search form'
37    ##
38    ##    Revision 1.4  2003/04/06 01:41:07  jonen
39    ##    - removed duplicated decode functions
40    ##
41  ##    Revision 1.3  2003/04/04 21:26:06  joko  ##    Revision 1.3  2003/04/04 21:26:06  joko
42  ##    added comments regarding possible (future) refactoring using the Data::Lift-infrastructure  ##    added comments regarding possible (future) refactoring using the Data::Lift-infrastructure
43  ##  ##
# Line 22  Line 56 
56  ##    Revision 1.1  2003/03/01 22:57:40  cvsmax  ##    Revision 1.1  2003/03/01 22:57:40  cvsmax
57  ##    + inital commit  ##    + inital commit
58  ##  ##
59  ##  ## -------------------------------------------------------------------------
 ##    -----------------------------------------------------------------------------  
60  */  */
61    
62    
63  /**  /**
64   * Need to make sure we have the DefaultGUIDataList object   * Need to make sure we have the DefaultGUIDataList object
65   */   */
# Line 51  class GenericGUIDataList extends Default Line 85  class GenericGUIDataList extends Default
85    */    */
86    var $_hidden_elements = array();    var $_hidden_elements = array();
87    
88    
89  /**  /**
90    * The constructor is used to pass in some additional    * The constructor is used to pass in some additional
91    * metadata informations as "options".    * metadata informations as "options".
# Line 71  class GenericGUIDataList extends Default Line 106  class GenericGUIDataList extends Default
106    *    *
107    *    *
108    */    */
109    function GenericGUIDataList($title, $width = "100%", $default_orderby='', $default_reverseorder=FALSE, $options = array()) {    function GenericGUIDataList($title, $width = "100%", $default_orderby='', $default_reverseorder=FALSE, $num_rows=10, $options = array()) {
110      if ($options) { $this->_options = $options; }      if ($options) { $this->_options = $options; }
111    
112        $this->set_numrows($num_rows);
113    
114        // call parent constructor
115      $parent =  get_parent_class($this);      $parent =  get_parent_class($this);
116      $this->$parent($title, $width = "100%", $default_orderby='', $default_reverseorder=FALSE);      $this->$parent($title, $width = "100%", $default_orderby='', $default_reverseorder=FALSE);
117        
118    }    }
119    
120    
121    function get_data_source( ) {    function get_data_source( ) {
122    
123      // finally: create phpHtmlLib source handle (XyzDataListSource)      // finally: create phpHtmlLib source handle (XyzDataListSource)
# Line 109  class GenericGUIDataList extends Default Line 150  class GenericGUIDataList extends Default
150        // V5:        // V5:
151        //print "options: " . Dumper($this->_options);        //print "options: " . Dumper($this->_options);
152                
153    
154              //HACK 2004-10-07: page-filter done by backend now,
155              //                 filter-values are passed to backend
156          $this->_options['data_locator_meta']['filter']['offset'] = $this->offset();
157          $this->_options['data_locator_meta']['filter']['numrows'] = $this->numrows();
158          $this->_options['data_locator_meta']['filter']['search_field'] = $this->search_field();
159          $this->_options['data_locator_meta']['filter']['search_value'] = $this->search_value();
160          $this->_options['data_locator_meta']['filter']['search_modifier'] = $this->simple_search_modifier_value();
161          
162          //$this->_set("offsetVar", 0);
163          
164        $initial_locator = php::mkComponent( 'DataSource::Locator', array( adapter_type => 'phpHtmlLib' ) );        $initial_locator = php::mkComponent( 'DataSource::Locator', array( adapter_type => 'phpHtmlLib' ) );
165        //print "1st locator: " . Dumper($initial_locator);        //print "1st locator: " . Dumper($initial_locator);
166                
# Line 132  class GenericGUIDataList extends Default Line 184  class GenericGUIDataList extends Default
184        $source = $proxy->get_adapter();        $source = $proxy->get_adapter();
185    
186        // V4:        // V4:
187            //$source = $this->_datasource;              //$source = $this->_datasource;
188          
189        //print "objectlist-source: " . Dumper($source);        //print "objectlist-source: " . Dumper($source);
190        //exit;        //exit;
191    
# Line 150  class GenericGUIDataList extends Default Line 202  class GenericGUIDataList extends Default
202                        
203          //print Dumper($source);          //print Dumper($source);
204            $headers = $source->get_header();            $headers = $source->get_header();
205            //print Dumper($headers);            //print "headers: " . Dumper($headers);
206                        
207            $this->set_title( $this->get_title() . ' - ' . $source->get_total_rows() . ' Einträge' );            $this->set_title( $this->get_title() . ' - ' . $source->get_total_rows() . ' Einträge' );
208                        
209            foreach($headers as $val) {            foreach($headers as $val) {
210                  $this->add_header_item($val, "150", $val, SORTABLE, SEARCHABLE);                  $this->add_header_item($val, "150", $val, SORTABLE, SEARCHABLE);
211      }      }
212        
213    
214  /*  /*
215          $this->add_header_item("Uid", "200", "uid", SORTABLE, SEARCHABLE);          $this->add_header_item("Uid", "200", "uid", SORTABLE, SEARCHABLE);
216          $this->add_header_item("Name", "200", "lastName", SORTABLE, SEARCHABLE, "center");          $this->add_header_item("Name", "200", "lastName", SORTABLE, SEARCHABLE, "center");
217  */  */
218    
219          }          }
220    
221    
# Line 178  class GenericGUIDataList extends Default Line 232  class GenericGUIDataList extends Default
232       * @param int - the column # we are working on.       * @param int - the column # we are working on.
233       * @return TDtag object       * @return TDtag object
234       */       */
235     function wrap_column_item($obj, $col_name) {     function wrap_column_item($obj, $col_name, $row_data) {
236        
237            //print "item: " . Dumper($obj) . "<br>";
238    
239          //make sure its set to something.          //make sure its set to something.
240          if ($obj == '') {          if ($obj == '') {
# Line 212  class GenericGUIDataList extends Default Line 268  class GenericGUIDataList extends Default
268                        
269            */            */
270    
271              $utils = php::mkComponent('WebExplorer::utils');
272            // 1. if item is match by expression we will replace it with an link object              $hidden = $this->_hidden_elements;
273            if ($this->decode_item_expr($obj)) {              $options = $this->_options['decode_args'];
274              $obj = $this->decode_item_expr($obj);              $options[label] = $col_name;
275            }            $options[parent_guid] = $row_data[guid];
276              $options[parent_class] = $this->_options['parent']['class'];
277            // 2. if item is an Array we will replace it with an selection form object              
278            elseif ( $this->decode_item_array($obj) ) {            // a) Iterate through the attributes of the item and replace each
279              $obj = $this->decode_item_array($obj);              // value with an appropriate link object if it has a certain format.
280              if ($utils->decode_item_expr($obj, $hidden, $options)) {
281    
282              // b) Otherwise: If item is an Array we will replace it with a selection form object.
283              } else {
284                $utils->decode_item_array($obj, $hidden, $options);
285            }            }
286    
287          }          }
# Line 254  class GenericGUIDataList extends Default Line 315  class GenericGUIDataList extends Default
315      }      }
316    
317    
318    // TODO: refactor to Data::Lift - subcomponent: handling will get way more easy!  
319    function decode_item_array($item) {      /**
320      $options = $this->_options['decode_args'];       * This function builds the simple search TD
321      //print "item: " . Dumper($item);       *
322      //print "options: " . Dumper($options);       * @return ContainerWidget
323      if( is_array($item) ) {       */
324            //$cur_row_index = $this->_datasource->get_cur_data_index();      function _build_simple_search_form() {
325            //$parent_guid = $this->_datasource->_data[$cur_row_index]['guid'];  
326            // build list for selection form          //if there is only 1 item enabled for search
327         if($options['form']) {          //then the search looks simple.
328            foreach($item as $key => $value) {          $fields = $this->_get_searchable_fields();
329                  $tmp = split($options['seperator'], $value);          $cnt = count($fields);
330                  $ident = $tmp['1'];          if ($cnt == 0) {
331                  $meta = $tmp['2'];              return NULL;
332                  $list[$key] = $ident;          }
333                  }  
334                  if(is_array($list) ) {          $container = new ContainerWidget;
335                $container = container(          
336                    form_open( $item[0], $_SERVER["PHP_SELF"], "POST" ),          // OLD - needed hidden elements are now recognized at 'render()'
337                    form_hidden("ecdm", $meta),          /*
338                    form_select("ecdid", $list),          // get current request vars and add them ad hidden items
339                    form_submit("submit","view" )          $url_vars = $this->_get_current_url_vars();
340                    );          foreach($url_vars as $label => $value) {
341                 foreach($this->_hidden_elements as $label => $value) {            $container->push(form_hidden($label, $value));
342                   $container->add(form_hidden($label, $value));          }
343                 }          */
344                $container->add(form_close() );  
345                $item = $container;          if ($cnt == 1) {
346                }              //user only has 1 field to show.
347                list($name, $field) = each($fields);
348                $container->push("Find ".$name."&nbsp;&nbsp;");
349          } else {          } else {
350            //print "<b>2</b><br/>";              //user has many fields to show.
351            $container = container();              $container->push("Find ",
352            foreach($item as $key => $value) {                               form_select($this->_vars["search_fieldVar"], $fields, $this->search_field()));
353                  $tmp = split($options['seperator'], $value);          }
354                  $ident = $tmp['1'];  
355                  $meta = $tmp['2'];          if ($this->get_simple_search_modifier()) {
356                       foreach($this->_hidden_elements as $label => $value) {              //the user wants the search modifier turned on.
357                         $tmp_array[] = $label . "=" . $value;              $container->push($this->_build_simple_search_modifier());
358                       }          }
359                       $str_hidden = join("&", $tmp_array);  
360                  $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;")),
361                             form_submit($this->get_form_name(), "Search", array("style"=>"vertical-align:middle;")));
362    
363            if ($this->is_advanced_search_enabled()) {
364                $span = html_span(html_a("ass","Advanced Search", "title"));
365                $container->push("&nbsp;", $span);
366            }
367    
368            if ($cnt == 1) {
369                $container->push(form_hidden($this->_vars["search_fieldVar"], $field));
370            }
371    
372            return $container;
373        }
374    
375    
376        /**
377         * This function builds the data cell action buttons or main actionbar
378         *
379         * @return TDtag;
380         */
381        function _build_actionbar_data_cell() {
382            $td = new TDtag(array("class" => "datalist_title",
383                                  "style" => "padding-left:5px;padding-right:5px;".
384                                  "padding-top:5px;padding-bottom:5px")
385                           );
386    
387            $flag = FALSE;
388            if ($this->_has_action_column("FIRST")) {
389                $flag = TRUE;
390                $td->set_tag_attribute("align", "left");
391            }
392            elseif ($this->_has_action_column("LAST")) {
393                $flag = TRUE;
394                $td->set_tag_attribute("align", "right");
395            }
396    
397            if ($flag && $this->_datasource->get_total_rows()) {
398                $td->push($this->actionbar_cell());
399                $td->push($this->actionbar_cell_new());
400            }
401            else {
402                $td->push("&nbsp;");
403                $td->push($this->actionbar_cell_new());
404            }
405    
406            return $td;
407        }
408    
409    
410        /**
411         * this is the method that builds
412         * the contents for the middle actionbar
413         * td cell.
414         *
415         * @return ContainerWidget object
416         */
417        function actionbar_cell() {
418            $action_list = $this->_options['actionbar']['list'];
419            $action_name = $this->_options['actionbar']['name'];
420    
421            if($action_name && is_array($action_list)) {
422              $action_form = container("Select action", _HTML_SPACE,
423                                 form_select($action_name, $action_list, $this->_options['actionbar']['selected']),
424                                 form_submit("ok","OK" )
425                                 );
426              return $action_form;
427            } else {
428              return _HTML_SPACE;
429            }
430        }
431    
432    
433        /**
434         * this is the method that builds
435         * the contents for the buttons of actionbar
436         * td cell.
437         *
438         * @return ContainerWidget object
439         */
440        function actionbar_cell_new() {
441            $action_buttons = $this->_options['actionbar']['buttons'];
442    
443            if(is_array($action_buttons)) {
444              $action_form = container();
445              foreach($action_buttons as $type) {
446                $action_form->add(
447                                 _HTML_SPACE,
448                                 form_submit($type['name'], $type['value'])
449                                 );
450            }            }
451            $item = $container;            return $action_form;
452            } else {
453              return _HTML_SPACE;
454          }          }
               return $item;  
455      }      }
   }  
456    
457    // decodes serialized string representations of object-references  
458    // TODO: refactor to Data::Lift - subcomponent: handling will get way more easy!      /*
459    function decode_item_expr($item) {       * OLD (depreciated) - this method returns the current requested variables
460      $options = $this->_options['decode_args'];       *
461      //print "item: $item<br/>";       * @return array
462      if(substr($item, 0, 2) == "o_") {       */
463            $tmp = split($options['seperator'], $item);      function _get_current_url_vars() {
464            $ident = $tmp['1'];          $cur_url_vars = array();
465            $meta = $tmp['2'];  
466            foreach($this->_hidden_elements as $label => $value) {          // get new LinkBuilder instance
467               $tmp_array[] = $label . "=" . $value;          $linkbuilder = new LinkBuilder();
468    
469            $url_vars = php::array_join_merge($_GET, $_POST);
470            if(is_array($url_vars)) {
471              foreach($url_vars as $key => $value) {
472                   // if there is an LinkBuilder guid instead of variables, encode it
473                   if($key == 'lbid') {
474                     $lb_vars = $linkbuilder->load($value);
475                     foreach($lb_vars as $lbkey => $lbval) {
476                       $cur_url_vars[$lbkey] = $lbval;
477                     }
478                   } else {
479                     $cur_url_vars[$key] = $value;
480                   }
481            }            }
482            $str_hidden = join("&", $tmp_array);          }
483            $item = html_a($_SERVER["PHP_SELF"] . "?ecdid=" . $ident . "&ecdm=" . $meta . "&" . $str_hidden, "view");          return $cur_url_vars;
           return $item;  
484      }      }
485    }  
486    
487        /**
488         * This function renders the final
489         * widget
490         *
491         */
492        function render($indent_level, $output_debug) {
493    
494            //setup the columns in their sorts
495            $this->setup_columns();
496    
497            //do any data prefetch work
498            //which may be child specific
499            if ( $this->_show_results() ) {
500                $this->data_prefetch();
501            }
502            
503            //This function gives the child class
504            //a chance to build the tables/divs/containers
505            //that will be responsible for the look/feel
506            //of the DataList
507            $this->gui_init();
508    
509            //see if we need to build the search area.
510            if ( $this->is_search_enabled() || $this->is_advanced_search_enabled() ) {
511                $this->_search_table = $this->child_build_search_table();
512                if ( $this->_search_table ) {
513                    $this->set_form_render(TRUE);
514                }
515            }
516    
517            //see if form is needed by the actionbar
518            if($this->_show_actionbar) {
519              $this->set_form_render(TRUE);
520            }
521    
522            if ( $this->get_form_render() ) {
523                $form =  new FORMtag( array("method" => $this->get_form_method(),
524                                            "action" => $this->build_base_url(),
525                                            "name" => $this->get_form_name(),
526                                            "style" => "margin-top: 0px;margin-bottom:0px;") );
527    
528                $target = $this->get_form_target();
529                if ( $target != NULL )
530                    $form->set_tag_attribute("target",$target);
531    
532                $action = $this->get_form_action();
533                if ( $action != NULL )
534                    $form->set_tag_attribute("action",$action);
535    
536                //now build the UI and return it
537                $form->add( $this->build_gui() );
538                
539            } else {
540                $form = container();
541    
542                //now build the UI and return it
543                $form->add( $this->build_gui() );
544            }
545            
546            //add the hidden vars if we are a POST
547            if ($this->get_form_method() == "POST") {
548                $form->add( $this->_build_default_vars() );
549    
550                //build hidden elements needed for data flow control
551                $hidden = $this->_hidden_elements;
552                //print "Hidden: " . Dumper($hidden);
553                if($hidden) {
554                  foreach($hidden as $label => $value) {
555                    $form->add(form_hidden($label, $value));
556                  }
557                }
558    
559            }
560    
561            //add the save vars the user wants.
562            $form->add( $this->_build_save_vars() );
563    
564            //add any javascript required
565            $container = container( $this->_javascript(), $form );
566            return $container->render( $indent_level, $output_debug );
567        }
568    
569    
570    
571            function child_add_row_cell($obj, $col_name, $last_in_row_flag, $row_data) {
572            if (!$this->_cur_col_cntr) {
573            //if (!isset($this->_cur_col_cntr)) {
574                $this->_cur_col_cntr = 1;
575                //lets see if we need to add an action column
576                //as the first column.
577                if ($this->_has_action_column("FIRST")) {
578                    //looks like we have a FIRST column actionbar
579                    //lets add it
580                    $this->_data_row->add($this->_build_action_column("FIRST", FALSE, $row_data));
581                }
582                $td = $this->wrap_column_item($obj, $col_name, $row_data);
583                $this->_data_row->add( $td );
584            } else {
585                //show the normal data
586                $td = $this->wrap_column_item($obj, $col_name, $row_data);
587                $this->_data_row->add( $td );
588            }
589    
590                    
591                    if ($last_in_row_flag) {
592                //lets see if we need to add an action column
593                //as the first column.
594                if ($this->_has_action_column("LAST")) {
595                    //looks like we have a LAST column actionbar
596                    //lets add it
597                    $this->_data_row->add($this->_build_action_column("LAST", FALSE, $row_data));
598                }
599    
600    
601    
602                            $this->_data_table->add_row( $this->_data_row );
603                            $this->_data_row = new TRtag;
604                unset( $this->_cur_col_cntr );
605                    } else {
606                $this->_cur_col_cntr++;
607            }
608            }
609    
610  }  }
611  ?>  ?>

Legend:
Removed from v.1.3  
changed lines
  Added in v.1.14

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