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

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.8

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