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

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

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