/[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.11 by jonen, Sat May 10 17:58:45 2003 UTC
# Line 1  Line 1 
1  <?  <?
2  /*  /*
3  ##    -----------------------------------------------------------------------------  ## -------------------------------------------------------------------------
4  ##    $Id$  ##    $Id$
5  ##    -----------------------------------------------------------------------------  ## -------------------------------------------------------------------------
6  ##    $Log$  ##    $Log$
7    ##    Revision 1.11  2003/05/10 17:58:45  jonen
8    ##    + reworked to implement 'create/add new' item
9    ##
10    ##    Revision 1.10  2003/04/18 18:40:02  jonen
11    ##    + fixed bugs at 'actionbar_cell' relating to html-form and js
12    ##
13    ##    Revision 1.9  2003/04/11 00:44:46  joko
14    ##    minor update: shortened seperators
15    ##
16    ##    Revision 1.8  2003/04/09 07:54:42  joko
17    ##    cleaned up decoding part
18    ##
19    ##    Revision 1.7  2003/04/09 00:37:53  jonen
20    ##    + added actionbar
21    ##    + some changes according to request vars
22    ##
23    ##    Revision 1.6  2003/04/08 17:48:31  jonen
24    ##    + bugfix again
25    ##
26    ##    Revision 1.5  2003/04/08 17:33:22  jonen
27    ##    + fixed problems with hidden form fields(current base URL) at the 'simple search form'
28    ##
29    ##    Revision 1.4  2003/04/06 01:41:07  jonen
30    ##    - removed duplicated decode functions
31    ##
32  ##    Revision 1.3  2003/04/04 21:26:06  joko  ##    Revision 1.3  2003/04/04 21:26:06  joko
33  ##    added comments regarding possible (future) refactoring using the Data::Lift-infrastructure  ##    added comments regarding possible (future) refactoring using the Data::Lift-infrastructure
34  ##  ##
# Line 22  Line 47 
47  ##    Revision 1.1  2003/03/01 22:57:40  cvsmax  ##    Revision 1.1  2003/03/01 22:57:40  cvsmax
48  ##    + inital commit  ##    + inital commit
49  ##  ##
50  ##  ## -------------------------------------------------------------------------
 ##    -----------------------------------------------------------------------------  
51  */  */
52    
53    
54  /**  /**
55   * Need to make sure we have the DefaultGUIDataList object   * Need to make sure we have the DefaultGUIDataList object
56   */   */
# Line 51  class GenericGUIDataList extends Default Line 76  class GenericGUIDataList extends Default
76    */    */
77    var $_hidden_elements = array();    var $_hidden_elements = array();
78    
79    
80  /**  /**
81    * The constructor is used to pass in some additional    * The constructor is used to pass in some additional
82    * metadata informations as "options".    * metadata informations as "options".
# Line 73  class GenericGUIDataList extends Default Line 99  class GenericGUIDataList extends Default
99    */    */
100    function GenericGUIDataList($title, $width = "100%", $default_orderby='', $default_reverseorder=FALSE, $options = array()) {    function GenericGUIDataList($title, $width = "100%", $default_orderby='', $default_reverseorder=FALSE, $options = array()) {
101      if ($options) { $this->_options = $options; }      if ($options) { $this->_options = $options; }
102    
103        // call parent constructor
104      $parent =  get_parent_class($this);      $parent =  get_parent_class($this);
105      $this->$parent($title, $width = "100%", $default_orderby='', $default_reverseorder=FALSE);      $this->$parent($title, $width = "100%", $default_orderby='', $default_reverseorder=FALSE);    
106    }    }
107    
108    
109    function get_data_source( ) {    function get_data_source( ) {
110    
111      // finally: create phpHtmlLib source handle (XyzDataListSource)      // finally: create phpHtmlLib source handle (XyzDataListSource)
# Line 162  class GenericGUIDataList extends Default Line 191  class GenericGUIDataList extends Default
191          $this->add_header_item("Uid", "200", "uid", SORTABLE, SEARCHABLE);          $this->add_header_item("Uid", "200", "uid", SORTABLE, SEARCHABLE);
192          $this->add_header_item("Name", "200", "lastName", SORTABLE, SEARCHABLE, "center");          $this->add_header_item("Name", "200", "lastName", SORTABLE, SEARCHABLE, "center");
193  */  */
194    
195          }          }
196    
197    
# Line 178  class GenericGUIDataList extends Default Line 208  class GenericGUIDataList extends Default
208       * @param int - the column # we are working on.       * @param int - the column # we are working on.
209       * @return TDtag object       * @return TDtag object
210       */       */
211     function wrap_column_item($obj, $col_name) {     function wrap_column_item($obj, $col_name, $row_data) {
212    
213          //make sure its set to something.          //make sure its set to something.
214          if ($obj == '') {          if ($obj == '') {
# Line 212  class GenericGUIDataList extends Default Line 242  class GenericGUIDataList extends Default
242                        
243            */            */
244    
245              $utils = php::mkComponent('WebExplorer::utils');
246            // 1. if item is match by expression we will replace it with an link object              $hidden = $this->_hidden_elements;
247            if ($this->decode_item_expr($obj)) {              $options = $this->_options['decode_args'];
248              $obj = $this->decode_item_expr($obj);              $options[label] = $col_name;
249            }            $options[parent_guid] = $row_data[guid];
250              $options[parent_class] = $this->_options['parent']['class'];
251            // 2. if item is an Array we will replace it with an selection form object              
252            elseif ( $this->decode_item_array($obj) ) {            // a) Iterate through the attributes of the item and replace each
253              $obj = $this->decode_item_array($obj);              // value with an appropriate link object if it has a certain format.
254              if ($utils->decode_item_expr($obj, $hidden, $options)) {
255    
256              // b) Otherwise: If item is an Array we will replace it with a selection form object.
257              } else {
258                $utils->decode_item_array($obj, $hidden, $options);
259            }            }
260    
261          }          }
# Line 254  class GenericGUIDataList extends Default Line 289  class GenericGUIDataList extends Default
289      }      }
290    
291    
292    // TODO: refactor to Data::Lift - subcomponent: handling will get way more easy!  
293    function decode_item_array($item) {      /**
294      $options = $this->_options['decode_args'];       * This function builds the simple search TD
295      //print "item: " . Dumper($item);       *
296      //print "options: " . Dumper($options);       * @return ContainerWidget
297      if( is_array($item) ) {       */
298            //$cur_row_index = $this->_datasource->get_cur_data_index();      function _build_simple_search_form() {
299            //$parent_guid = $this->_datasource->_data[$cur_row_index]['guid'];  
300            // build list for selection form          //if there is only 1 item enabled for search
301         if($options['form']) {          //then the search looks simple.
302            foreach($item as $key => $value) {          $fields = $this->_get_searchable_fields();
303                  $tmp = split($options['seperator'], $value);          $cnt = count($fields);
304                  $ident = $tmp['1'];          if ($cnt == 0) {
305                  $meta = $tmp['2'];              return NULL;
306                  $list[$key] = $ident;          }
307                  }  
308                  if(is_array($list) ) {          $container = new ContainerWidget;
309                $container = container(          
310                    form_open( $item[0], $_SERVER["PHP_SELF"], "POST" ),          // OLD - needed hidden elements are now recognized at 'render()'
311                    form_hidden("ecdm", $meta),          /*
312                    form_select("ecdid", $list),          // get current request vars and add them ad hidden items
313                    form_submit("submit","view" )          $url_vars = $this->_get_current_url_vars();
314                    );          foreach($url_vars as $label => $value) {
315                 foreach($this->_hidden_elements as $label => $value) {            $container->push(form_hidden($label, $value));
316                   $container->add(form_hidden($label, $value));          }
317                 }          */
318                $container->add(form_close() );  
319                $item = $container;          if ($cnt == 1) {
320                }              //user only has 1 field to show.
321                list($name, $field) = each($fields);
322                $container->push("Find ".$name."&nbsp;&nbsp;");
323          } else {          } else {
324            //print "<b>2</b><br/>";              //user has many fields to show.
325            $container = container();              $container->push("Find ",
326            foreach($item as $key => $value) {                               form_select($this->_vars["search_fieldVar"], $fields, $this->search_field()));
327                  $tmp = split($options['seperator'], $value);          }
328                  $ident = $tmp['1'];  
329                  $meta = $tmp['2'];          if ($this->get_simple_search_modifier()) {
330                       foreach($this->_hidden_elements as $label => $value) {              //the user wants the search modifier turned on.
331                         $tmp_array[] = $label . "=" . $value;              $container->push($this->_build_simple_search_modifier());
332                       }          }
333                       $str_hidden = join("&", $tmp_array);  
334                  $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;")),
335            }                           form_submit($this->get_form_name(), "Search", array("style"=>"vertical-align:middle;")));
336            $item = $container;  
337            if ($this->is_advanced_search_enabled()) {
338                $span = html_span(html_a("ass","Advanced Search", "title"));
339                $container->push("&nbsp;", $span);
340          }          }
341                return $item;  
342            if ($cnt == 1) {
343                $container->push(form_hidden($this->_vars["search_fieldVar"], $field));
344            }
345    
346            return $container;
347      }      }
   }  
348    
349    // decodes serialized string representations of object-references  
350    // TODO: refactor to Data::Lift - subcomponent: handling will get way more easy!      /**
351    function decode_item_expr($item) {       * This function builds the data cell action buttons or main actionbar
352      $options = $this->_options['decode_args'];       *
353      //print "item: $item<br/>";       * @return TDtag;
354      if(substr($item, 0, 2) == "o_") {       */
355            $tmp = split($options['seperator'], $item);      function _build_actionbar_data_cell() {
356            $ident = $tmp['1'];          $td = new TDtag(array("class" => "datalist_title",
357            $meta = $tmp['2'];                                "style" => "padding-left:5px;padding-right:5px;".
358            foreach($this->_hidden_elements as $label => $value) {                                "padding-top:5px;padding-bottom:5px")
359               $tmp_array[] = $label . "=" . $value;                         );
360    
361            $flag = FALSE;
362            if ($this->_has_action_column("FIRST")) {
363                $flag = TRUE;
364                $td->set_tag_attribute("align", "left");
365            }
366            elseif ($this->_has_action_column("LAST")) {
367                $flag = TRUE;
368                $td->set_tag_attribute("align", "right");
369            }
370    
371            if ($flag && $this->_datasource->get_total_rows()) {
372                $td->push($this->actionbar_cell());
373                $td->push($this->actionbar_cell_new());
374            }
375            else {
376                $td->push("&nbsp;");
377                $td->push($this->actionbar_cell_new());
378            }
379    
380            return $td;
381        }
382    
383    
384        /**
385         * this is the method that builds
386         * the contents for the middle actionbar
387         * td cell.
388         *
389         * @return ContainerWidget object
390         */
391        function actionbar_cell() {
392            $action_list = $this->_options['actionbar']['list'];
393            $action_name = $this->_options['actionbar']['name'];
394    
395            if($action_name && is_array($action_list)) {
396              $action_form = container("Select action", _HTML_SPACE,
397                                 form_select($action_name, $action_list, $this->_options['actionbar']['selected']),
398                                 form_submit("ok","OK" )
399                                 );
400              return $action_form;
401            } else {
402              return _HTML_SPACE;
403            }
404        }
405    
406    
407        /**
408         * this is the method that builds
409         * the contents for the 'create new' actionbar
410         * td cell.
411         *
412         * @return ContainerWidget object
413         */
414        function actionbar_cell_new() {
415            $action_create = $this->_options['actionbar']['create'];
416    
417            if(is_array($action_create)) {
418              $action_form = container(
419                                 _HTML_SPACE,
420                                 form_submit($action_create['name'], $action_create['value'])
421                                 );
422              return $action_form;
423            } else {
424              return _HTML_SPACE;
425            }
426        }
427    
428    
429        /*
430         * OLD (depreciated) - this method returns the current requested variables
431         *
432         * @return array
433         */
434        function _get_current_url_vars() {
435            $cur_url_vars = array();
436    
437            // get new LinkBuilder instance
438            $linkbuilder = new LinkBuilder();
439    
440            $url_vars = php::array_join_merge($_GET, $_POST);
441            if(is_array($url_vars)) {
442              foreach($url_vars as $key => $value) {
443                   // if there is an LinkBuilder guid instead of variables, encode it
444                   if($key == 'lbid') {
445                     $lb_vars = $linkbuilder->load($value);
446                     foreach($lb_vars as $lbkey => $lbval) {
447                       $cur_url_vars[$lbkey] = $lbval;
448                     }
449                   } else {
450                     $cur_url_vars[$key] = $value;
451                   }
452            }            }
453            $str_hidden = join("&", $tmp_array);          }
454            $item = html_a($_SERVER["PHP_SELF"] . "?ecdid=" . $ident . "&ecdm=" . $meta . "&" . $str_hidden, "view");          return $cur_url_vars;
           return $item;  
455      }      }
456    }  
457    
458        /**
459         * This function renders the final
460         * widget
461         *
462         */
463        function render($indent_level, $output_debug) {
464    
465            //setup the columns in their sorts
466            $this->setup_columns();
467    
468            //do any data prefetch work
469            //which may be child specific
470            if ( $this->_show_results() ) {
471                $this->data_prefetch();
472            }
473    
474            //This function gives the child class
475            //a chance to build the tables/divs/containers
476            //that will be responsible for the look/feel
477            //of the DataList
478            $this->gui_init();
479    
480            //see if we need to build the search area.
481            if ( $this->is_search_enabled() || $this->is_advanced_search_enabled() ) {
482                $this->_search_table = $this->child_build_search_table();
483                if ( $this->_search_table ) {
484                    $this->set_form_render(TRUE);
485                }
486            }
487    
488            //see if form is needed by the actionbar
489            if($this->_show_actionbar) {
490              $this->set_form_render(TRUE);
491            }
492    
493            if ( $this->get_form_render() ) {
494                $form =  new FORMtag( array("method" => $this->get_form_method(),
495                                            "action" => $this->build_base_url(),
496                                            "name" => $this->get_form_name(),
497                                            "style" => "margin-top: 0px;margin-bottom:0px;") );
498    
499                $target = $this->get_form_target();
500                if ( $target != NULL )
501                    $form->set_tag_attribute("target",$target);
502    
503                $action = $this->get_form_action();
504                if ( $action != NULL )
505                    $form->set_tag_attribute("action",$action);
506    
507                //now build the UI and return it
508                $form->add( $this->build_gui() );
509                
510            } else {
511                $form = container();
512    
513                //now build the UI and return it
514                $form->add( $this->build_gui() );
515            }
516            
517            //add the hidden vars if we are a POST
518            if ($this->get_form_method() == "POST") {
519                $form->add( $this->_build_default_vars() );
520    
521                //build hidden elements needed for data flow control
522                $hidden = $this->_hidden_elements;
523                //print "Hidden: " . Dumper($hidden);
524                if($hidden) {
525                  foreach($hidden as $label => $value) {
526                    $form->add(form_hidden($label, $value));
527                  }
528                }
529    
530            }
531    
532            //add the save vars the user wants.
533            $form->add( $this->_build_save_vars() );
534    
535            //add any javascript required
536            $container = container( $this->_javascript(), $form );
537            return $container->render( $indent_level, $output_debug );
538        }
539    
540    
541    
542            function child_add_row_cell($obj, $col_name, $last_in_row_flag, $row_data) {
543            if (!$this->_cur_col_cntr) {
544                $this->_cur_col_cntr = 1;
545                //lets see if we need to add an action column
546                //as the first column.
547                if ($this->_has_action_column("FIRST")) {
548                    //looks like we have a FIRST column actionbar
549                    //lets add it
550                    $this->_data_row->add($this->_build_action_column("FIRST", FALSE, $row_data));
551                }
552                $td = $this->wrap_column_item($obj, $col_name, $row_data);
553                $this->_data_row->add( $td );
554            } else {
555                //show the normal data
556                $td = $this->wrap_column_item($obj, $col_name, $row_data);
557                $this->_data_row->add( $td );
558            }
559    
560                    
561                    if ($last_in_row_flag) {
562                //lets see if we need to add an action column
563                //as the first column.
564                if ($this->_has_action_column("LAST")) {
565                    //looks like we have a LAST column actionbar
566                    //lets add it
567                    $this->_data_row->add($this->_build_action_column("LAST", FALSE, $row_data));
568                }
569    
570    
571    
572                            $this->_data_table->add_row( $this->_data_row );
573                            $this->_data_row = new TRtag;
574                unset( $this->_cur_col_cntr );
575                    } else {
576                $this->_cur_col_cntr++;
577            }
578            }
579    
580  }  }
581  ?>  ?>

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

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