/[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.10 by jonen, Fri Apr 18 18:40:02 2003 UTC
# Line 1  Line 1 
1  <?  <?
2  /*  /*
3  ##    -----------------------------------------------------------------------------  ## -------------------------------------------------------------------------
4  ##    $Id$  ##    $Id$
5  ##    -----------------------------------------------------------------------------  ## -------------------------------------------------------------------------
6  ##    $Log$  ##    $Log$
7    ##    Revision 1.10  2003/04/18 18:40:02  jonen
8    ##    + fixed bugs at 'actionbar_cell' relating to html-form and js
9    ##
10    ##    Revision 1.9  2003/04/11 00:44:46  joko
11    ##    minor update: shortened seperators
12    ##
13    ##    Revision 1.8  2003/04/09 07:54:42  joko
14    ##    cleaned up decoding part
15    ##
16    ##    Revision 1.7  2003/04/09 00:37:53  jonen
17    ##    + added actionbar
18    ##    + some changes according to request vars
19    ##
20    ##    Revision 1.6  2003/04/08 17:48:31  jonen
21    ##    + bugfix again
22    ##
23    ##    Revision 1.5  2003/04/08 17:33:22  jonen
24    ##    + fixed problems with hidden form fields(current base URL) at the 'simple search form'
25    ##
26    ##    Revision 1.4  2003/04/06 01:41:07  jonen
27    ##    - removed duplicated decode functions
28    ##
29    ##    Revision 1.3  2003/04/04 21:26:06  joko
30    ##    added comments regarding possible (future) refactoring using the Data::Lift-infrastructure
31    ##
32    ##    Revision 1.2  2003/04/04 00:45:40  jonen
33    ##    + reworked decode functions
34    ##
35  ##    Revision 1.1  2003/03/27 01:17:31  jonen  ##    Revision 1.1  2003/03/27 01:17:31  jonen
36  ##    + inital commit (was orginal 'ObjectList.inc)  ##    + inital commit (was orginal 'ObjectList.inc)
37  ##  ##
# Line 16  Line 44 
44  ##    Revision 1.1  2003/03/01 22:57:40  cvsmax  ##    Revision 1.1  2003/03/01 22:57:40  cvsmax
45  ##    + inital commit  ##    + inital commit
46  ##  ##
47  ##  ## -------------------------------------------------------------------------
 ##    -----------------------------------------------------------------------------  
48  */  */
49    
50    
51  /**  /**
52   * Need to make sure we have the DefaultGUIDataList object   * Need to make sure we have the DefaultGUIDataList object
53   */   */
# Line 39  class GenericGUIDataList extends Default Line 67  class GenericGUIDataList extends Default
67    */    */
68    var $_options = NULL;    var $_options = NULL;
69    
70     /**
71      * Holds a list of hidden elements
72      *
73      */
74      var $_hidden_elements = array();
75    
76    
77  /**  /**
78    * The constructor is used to pass in some additional    * The constructor is used to pass in some additional
79    * metadata informations as "options".    * metadata informations as "options".
# Line 61  class GenericGUIDataList extends Default Line 96  class GenericGUIDataList extends Default
96    */    */
97    function GenericGUIDataList($title, $width = "100%", $default_orderby='', $default_reverseorder=FALSE, $options = array()) {    function GenericGUIDataList($title, $width = "100%", $default_orderby='', $default_reverseorder=FALSE, $options = array()) {
98      if ($options) { $this->_options = $options; }      if ($options) { $this->_options = $options; }
99    
100        // call parent constructor
101      $parent =  get_parent_class($this);      $parent =  get_parent_class($this);
102      $this->$parent($title, $width = "100%", $default_orderby='', $default_reverseorder=FALSE);      $this->$parent($title, $width = "100%", $default_orderby='', $default_reverseorder=FALSE);    
103    }    }
104    
105    
106    function get_data_source( ) {    function get_data_source( ) {
107    
108      // finally: create phpHtmlLib source handle (XyzDataListSource)      // finally: create phpHtmlLib source handle (XyzDataListSource)
# Line 170  class GenericGUIDataList extends Default Line 208  class GenericGUIDataList extends Default
208    
209          //make sure its set to something.          //make sure its set to something.
210          if ($obj == '') {          if ($obj == '') {
211              $obj = "&nbsp;";            $obj = "&nbsp;";
212          }          }
213          // if item is match by expression we will replace it with an link object            
214          elseif($this->_options['decode']) {          // decode item / mungle item data?
215           if($this->decode_item_expr($obj)) {            // TODO: use Data::Lift here!!! (like already done in YAA::JobList and YAA::JobDetails)
216            $obj = $this->decode_item_expr($obj);            elseif ($this->_options['decode']) {
217            }    
218            // if item is an Array we will replace it with an selection form object              // Proposal using Data::Lift: (see YAA::JobList and YAA::JobDetails)
219            elseif($this->decode_item_array($obj) ) {            // This class will get shorter and better to maintain!
220              $obj = $this->decode_item_array($obj);              
221              // Picture Data::Lift as a container component handling
222              // *specific* en-/decoding stuff for your very core components.
223              // This way we will have almost all "specific mungling code" at one place. nice thing!
224              
225              /*
226    
227              // 1. expr: string -> object (phpHtmlLib-object: 'html_a'-tag)
228                // returns a phpHtmlLib object of class 'Xyz' containing a http-/html-link
229                // pointing to a View of a different - linked/referenced - object (reference-interpolation)
230                $this->lift1 = php::mkComponent('Data::Lift', $obj, array( metatype => 'expression' ) );
231                $obj = $this->lift1->to('phpHtmlLib::html_a');
232    
233              // 2. data: hash -> object (phpHtmlLib-object: 'container'-object containing form)
234                // returns a phpHtmlLib object of class 'Container' containing a html-form made up of
235                // phpHtmlLib form-tags wrapping all attribute-value pairs of the data hash (object-edit)
236                $this->lift2 = php::mkComponent('Data::Lift', $obj, array( metatype => 'item' ) );
237                $obj = $this->lift2->to('phpHtmlLib::form');
238              
239              */
240    
241              $utils = php::mkComponent('WebExplorer::utils');
242              $hidden = $this->_hidden_elements;
243              $options = $this->_options['decode_args'];
244              
245              // a) Iterate through the attributes of the item and replace each
246              // value with an appropriate link object if it has a certain format.
247              if ($utils->decode_item_expr($obj, $hidden, $options)) {
248    
249              // b) Otherwise: If item is an Array we will replace it with a selection form object.
250              } else {
251                $utils->decode_item_array($obj, $hidden, $options);
252            }            }
253    
254          }          }
255    
256          //make sure we don't put a right border on the last          //make sure we don't put a right border on the last
257          //column we are working on.          //column we are working on.
258          //$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 277  class GenericGUIDataList extends Default
277          return $td;          return $td;
278      }      }
279    
280    function decode_item_array($item) {      function add_hidden_element($label, $value) {
281      $options = $this->_options['decode_args'];        $this->_hidden_elements[$label] = $value;
282      if( is_array($item) ) {      }
283            //$cur_row_index = $this->_datasource->get_cur_data_index();  
284            //$parent_guid = $this->_datasource->_data[$cur_row_index]['guid'];  
285            // build list for selection form      /**
286         if($options['form']) {       * This function builds the simple search TD
287            foreach($item as $key => $value) {       *
288                  $tmp = split($options['seperator'], $value);       * @return ContainerWidget
289                  $ident = $tmp['1'];       */
290                  $meta = $tmp['2'];      function _build_simple_search_form() {
291                  $list[$key] = $ident;  
292                  }          //if there is only 1 item enabled for search
293                  if(is_array($list) ) {          //then the search looks simple.
294                $container = container(          $fields = $this->_get_searchable_fields();
295                    form_open( $item[0], $_SERVER["PHP_SELF"], "POST" ),          $cnt = count($fields);
296                    form_open("ecdm", $meta),          if ($cnt == 0) {
297                    form_select("ecdid", $list),              return NULL;
298                    form_submit("submit","view" )          }
299                    );  
300                 foreach($this->_hidden_items as $label => $value) {          $container = new ContainerWidget;
301                   $container->add(form_hidden($label, $value));          
302                 }          // get current request vars and add them ad hidden items
303                $container->add(form_close() );          $url_vars = $this->_get_current_url_vars();
304                $item = $container;          foreach($url_vars as $label => $value) {
305                }            $container->push(form_hidden($label, $value));
306            }
307    
308            if ($cnt == 1) {
309                //user only has 1 field to show.
310                list($name, $field) = each($fields);
311                $container->push("Find ".$name."&nbsp;&nbsp;");
312          } else {          } else {
313            $container = container();              //user has many fields to show.
314            foreach($item as $key => $value) {              $container->push("Find ",
315                  $tmp = split($options['seperator'], $value);                               form_select($this->_vars["search_fieldVar"], $fields, $this->search_field()));
                 $ident = $tmp['1'];  
                 $meta = $tmp['2'];  
                      foreach($this->_hidden_items as $label => $value) {  
                        $tmp_array[] = $label . "=" . $value;  
                      }  
                      $str_hidden = join("&", $tmp_array);  
                 $container->add("->", html_a($_SERVER["PHP_SELF"] . "?ecdid=" . $ident . "&ecdm=" . $meta . $str_hidden, $key . " view"), html_br());                
           }  
           $item = $container;  
316          }          }
317                return $item;  
318            if ($this->get_simple_search_modifier()) {
319                //the user wants the search modifier turned on.
320                $container->push($this->_build_simple_search_modifier());
321            }
322    
323            $container->push(form_text($this->_vars["search_valueVar"], $this->search_value_filter($this->search_value()), "20", "100", array("style"=>"vertical-align:middle;")),
324                             form_submit($this->get_form_name(), "Search", array("style"=>"vertical-align:middle;")));
325    
326            if ($this->is_advanced_search_enabled()) {
327                $span = html_span(html_a("ass","Advanced Search", "title"));
328                $container->push("&nbsp;", $span);
329            }
330    
331            if ($cnt == 1) {
332                $container->push(form_hidden($this->_vars["search_fieldVar"], $field));
333            }
334    
335    
336            //$container->push(form_close() );
337            return $container;
338      }      }
   }  
339    
340    function decode_item_expr($item) {  
341      $options = $this->_options['decode_args'];      /**
342      if(substr($item, 0, 2) == "o_") {       * this is the method that builds
343            $tmp = split($options['seperator'], $item);       * the contents for the middle actionbar
344            $ident = $tmp['1'];       * td cell.
345            $meta = $tmp['2'];       *
346            foreach($this->_hidden_items as $label => $value) {       * @return ContainerWidget object
347               $tmp_array[] = $label . "=" . $value;       */
348        function actionbar_cell() {
349            $action_list = $this->_options['actionbar']['list'];
350            $action_name = $this->_options['actionbar']['name'];
351    
352            if($action_name && is_array($action_list)) {
353              $action_form = container("Select action", _HTML_SPACE,
354                                 form_select($action_name, $action_list),
355                                 form_submit("ok","OK" )                            
356                                 );
357              return $action_form;
358            } else {
359              return _HTML_SPACE;
360            }
361        }
362    
363    
364        /*
365         * this method returns the current requested variables
366         *
367         * @return array
368         */
369        function _get_current_url_vars() {
370            $cur_url_vars = array();
371    
372            // get new LinkBuilder instance
373            $linkbuilder = new LinkBuilder();
374    
375            $url_vars = php::array_join_merge($_GET, $_POST);
376            if(is_array($url_vars)) {
377              foreach($url_vars as $key => $value) {
378                   // if there is an LinkBuilder guid instead of variables, encode it
379                   if($key == 'lbid') {
380                     $lb_vars = $linkbuilder->load($value);
381                     foreach($lb_vars as $lbkey => $lbval) {
382                       $cur_url_vars[$lbkey] = $lbval;
383                     }
384                   } else {
385                     $cur_url_vars[$key] = $value;
386                   }
387            }            }
388            $str_hidden = join("&", $tmp_array);          }
389            $item = html_a($_SERVER["PHP_SELF"] . "?ecdid=" . $guid . "&ecdm=" . $meta . $str_hidden, "view");          return $cur_url_vars;
           return $item;  
390      }      }
   }  
391    
392  }  }
393  ?>  ?>

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.10

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