/[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.1 by jonen, Thu Mar 27 01:17:31 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
33    ##    added comments regarding possible (future) refactoring using the Data::Lift-infrastructure
34    ##
35    ##    Revision 1.2  2003/04/04 00:45:40  jonen
36    ##    + reworked decode functions
37    ##
38  ##    Revision 1.1  2003/03/27 01:17:31  jonen  ##    Revision 1.1  2003/03/27 01:17:31  jonen
39  ##    + inital commit (was orginal 'ObjectList.inc)  ##    + inital commit (was orginal 'ObjectList.inc)
40  ##  ##
# Line 16  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 39  class GenericGUIDataList extends Default Line 70  class GenericGUIDataList extends Default
70    */    */
71    var $_options = NULL;    var $_options = NULL;
72    
73     /**
74      * Holds a list of hidden elements
75      *
76      */
77      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 61  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 150  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 166  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 == '') {
215              $obj = "&nbsp;";            $obj = "&nbsp;";
216          }          }
217          // if item is match by expression we will replace it with an link object            
218          elseif($this->_options['decode']) {          // decode item / mungle item data?
219           if($this->decode_item_expr($obj)) {            // TODO: use Data::Lift here!!! (like already done in YAA::JobList and YAA::JobDetails)
220            $obj = $this->decode_item_expr($obj);            elseif ($this->_options['decode']) {
221            }    
222            // if item is an Array we will replace it with an selection form object              // Proposal using Data::Lift: (see YAA::JobList and YAA::JobDetails)
223            elseif($this->decode_item_array($obj) ) {            // This class will get shorter and better to maintain!
224              $obj = $this->decode_item_array($obj);              
225              // Picture Data::Lift as a container component handling
226              // *specific* en-/decoding stuff for your very core components.
227              // This way we will have almost all "specific mungling code" at one place. nice thing!
228              
229              /*
230    
231              // 1. expr: string -> object (phpHtmlLib-object: 'html_a'-tag)
232                // returns a phpHtmlLib object of class 'Xyz' containing a http-/html-link
233                // pointing to a View of a different - linked/referenced - object (reference-interpolation)
234                $this->lift1 = php::mkComponent('Data::Lift', $obj, array( metatype => 'expression' ) );
235                $obj = $this->lift1->to('phpHtmlLib::html_a');
236    
237              // 2. data: hash -> object (phpHtmlLib-object: 'container'-object containing form)
238                // returns a phpHtmlLib object of class 'Container' containing a html-form made up of
239                // phpHtmlLib form-tags wrapping all attribute-value pairs of the data hash (object-edit)
240                $this->lift2 = php::mkComponent('Data::Lift', $obj, array( metatype => 'item' ) );
241                $obj = $this->lift2->to('phpHtmlLib::form');
242              
243              */
244    
245              $utils = php::mkComponent('WebExplorer::utils');
246              $hidden = $this->_hidden_elements;
247              $options = $this->_options['decode_args'];
248              $options[label] = $col_name;
249              $options[parent_guid] = $row_data[guid];
250              $options[parent_class] = $this->_options['parent']['class'];
251              
252              // a) Iterate through the attributes of the item and replace each
253              // 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          }          }
262    
263          //make sure we don't put a right border on the last          //make sure we don't put a right border on the last
264          //column we are working on.          //column we are working on.
265          //$style = "padding-left: 3px;padding-right:3px;border-top: 1px solid #dddddd;";          //$style = "padding-left: 3px;padding-right:3px;border-top: 1px solid #dddddd;";
# Line 207  class GenericGUIDataList extends Default Line 284  class GenericGUIDataList extends Default
284          return $td;          return $td;
285      }      }
286    
287    function decode_item_array($item) {      function add_hidden_element($label, $value) {
288      $options = $this->_options['decode_args'];        $this->_hidden_elements[$label] = $value;
289      if( is_array($item) ) {      }
290            //$cur_row_index = $this->_datasource->get_cur_data_index();  
291            //$parent_guid = $this->_datasource->_data[$cur_row_index]['guid'];  
292            // build list for selection form  
293         if($options['form']) {      /**
294            foreach($item as $key => $value) {       * This function builds the simple search TD
295                  $tmp = split($options['seperator'], $value);       *
296                  $ident = $tmp['1'];       * @return ContainerWidget
297                  $meta = $tmp['2'];       */
298                  $list[$key] = $ident;      function _build_simple_search_form() {
299                  }  
300                  if(is_array($list) ) {          //if there is only 1 item enabled for search
301                $container = container(          //then the search looks simple.
302                    form_open( $item[0], $_SERVER["PHP_SELF"], "POST" ),          $fields = $this->_get_searchable_fields();
303                    form_open("ecdm", $meta),          $cnt = count($fields);
304                    form_select("ecdid", $list),          if ($cnt == 0) {
305                    form_submit("submit","view" )              return NULL;
306                    );          }
307                 foreach($this->_hidden_items as $label => $value) {  
308                   $container->add(form_hidden($label, $value));          $container = new ContainerWidget;
309                 }          
310                $container->add(form_close() );          // OLD - needed hidden elements are now recognized at 'render()'
311                $item = $container;          /*
312                }          // get current request vars and add them ad hidden items
313            $url_vars = $this->_get_current_url_vars();
314            foreach($url_vars as $label => $value) {
315              $container->push(form_hidden($label, $value));
316            }
317            */
318    
319            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            $container = container();              //user has many fields to show.
325            foreach($item as $key => $value) {              $container->push("Find ",
326                  $tmp = split($options['seperator'], $value);                               form_select($this->_vars["search_fieldVar"], $fields, $this->search_field()));
327                  $ident = $tmp['1'];          }
328                  $meta = $tmp['2'];  
329                       foreach($this->_hidden_items as $label => $value) {          if ($this->get_simple_search_modifier()) {
330                         $tmp_array[] = $label . "=" . $value;              //the user wants the search modifier turned on.
331                       }              $container->push($this->_build_simple_search_modifier());
332                       $str_hidden = join("&", $tmp_array);          }
333                  $container->add("->", html_a($_SERVER["PHP_SELF"] . "?ecdid=" . $ident . "&ecdm=" . $meta . $str_hidden, $key . " view"), html_br());                
334            }          $container->push(form_text($this->_vars["search_valueVar"], $this->search_value_filter($this->search_value()), "20", "100", array("style"=>"vertical-align:middle;")),
335            $item = $container;                           form_submit($this->get_form_name(), "Search", array("style"=>"vertical-align:middle;")));
336    
337            if ($this->is_advanced_search_enabled()) {
338                $span = html_span(html_a("ass","Advanced Search", "title"));
339                $container->push("&nbsp;", $span);
340            }
341    
342            if ($cnt == 1) {
343                $container->push(form_hidden($this->_vars["search_fieldVar"], $field));
344          }          }
345                return $item;  
346            return $container;
347        }
348    
349    
350        /**
351         * This function builds the data cell action buttons or main actionbar
352         *
353         * @return TDtag;
354         */
355        function _build_actionbar_data_cell() {
356            $td = new TDtag(array("class" => "datalist_title",
357                                  "style" => "padding-left:5px;padding-right:5px;".
358                                  "padding-top:5px;padding-bottom:5px")
359                           );
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    function decode_item_expr($item) {  
384      $options = $this->_options['decode_args'];      /**
385      if(substr($item, 0, 2) == "o_") {       * this is the method that builds
386            $tmp = split($options['seperator'], $item);       * the contents for the middle actionbar
387            $ident = $tmp['1'];       * td cell.
388            $meta = $tmp['2'];       *
389            foreach($this->_hidden_items as $label => $value) {       * @return ContainerWidget object
390               $tmp_array[] = $label . "=" . $value;       */
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=" . $guid . "&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.1  
changed lines
  Added in v.1.11

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