/[cvs]/nfo/php/libs/org.netfrag.patches/phphtmllib/widgets/EditDataItem.php
ViewVC logotype

Diff of /nfo/php/libs/org.netfrag.patches/phphtmllib/widgets/EditDataItem.php

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.2 by jonen, Fri Apr 4 00:43:22 2003 UTC revision 1.7 by jonen, Sat May 10 18:04:45 2003 UTC
# Line 4  Line 4 
4  ##    $Id$  ##    $Id$
5  ##    -----------------------------------------------------------------------------  ##    -----------------------------------------------------------------------------
6  ##    $Log$  ##    $Log$
7    ##    Revision 1.7  2003/05/10 18:04:45  jonen
8    ##    + added values needed for 'create/add new' links
9    ##
10    ##    Revision 1.6  2003/04/11 00:48:03  joko
11    ##    minor fix: calling parent constructor explicitely by name now, transparency seems not be automagically compatible with inheritance in php ,-)    (non-orthogonal)
12    ##
13    ##    Revision 1.5  2003/04/09 09:59:30  joko
14    ##    fixes regarding modification of decode-function-behavior
15    ##
16    ##    Revision 1.4  2003/04/06 01:41:33  jonen
17    ##    - removed duplicated decode functions
18    ##
19    ##    Revision 1.3  2003/04/04 23:58:02  jonen
20    ##    + saving of items sould now work with new 'GenericSource' structure
21    ##
22  ##    Revision 1.2  2003/04/04 00:43:22  jonen  ##    Revision 1.2  2003/04/04 00:43:22  jonen
23  ##    + complete rework  ##    + complete rework
24  ##  ##
# Line 56  class EditDataItem extends StandardFormC Line 71  class EditDataItem extends StandardFormC
71      // prefetch data      // prefetch data
72      $this->data_prefetch();      $this->data_prefetch();
73    
74      $parent =  get_parent_class($this);      // doesn't work if EditDataItem gets inherited
75      $this->$parent($title, $PHP_SELF, 600);      //$parent = get_parent_class($this);
76        //$this->$parent($title, $PHP_SELF, 600);
77        
78        $this->StandardFormContent($title, $PHP_SELF, 600);
79    
80    }    }
81    
82    function set_data_source(&$source) {    function set_data_source(&$source) {
# Line 95  class EditDataItem extends StandardFormC Line 114  class EditDataItem extends StandardFormC
114          //we want an confirmation page for this form.          //we want an confirmation page for this form.
115          $this->set_confirm();          $this->set_confirm();
116    
117             $utils = php::mkComponent('WebExplorer::utils');
118             $hidden = $this->get_hidden_elements();
119             $options = $this->_options['decode_args'];
120    
121          foreach($this->_datasource->_result as $key => $value) {          foreach($this->_datasource->_result as $key => $value) {
122            if($value) {            if($value) {
123              $validation = TRUE;              $validation = TRUE;
124            } else {            } else {
125              $validation = FALSE;              $validation = FALSE;
126            }            }
127            if(!$this->decode_item_expr($value, $this->_options) && !$this->decode_item_array($value, $this->_options)) {            if(!$utils->decode_item_expr($value, $hidden, $options) && !$utils->decode_item_array($value, $hidden, $options)) {
128              $this->add_element( new FEText($key, $validation, "350px") );              $this->add_element( new FEText($key, $validation, "350px") );
129            }            }
130          }          }
# Line 119  class EditDataItem extends StandardFormC Line 142  class EditDataItem extends StandardFormC
142          //and set the initial values of some of the          //and set the initial values of some of the
143          //form fields.          //form fields.
144    
145             $utils = php::mkComponent('WebExplorer::utils');
146             $hidden = $this->get_hidden_elements();
147             $options = $this->_options['decode_args'];
148    
149        foreach($this->_datasource->_result as $key => $value) {        foreach($this->_datasource->_result as $key => $value) {
150          if(!$this->decode_item_expr($value, $this->_options) && !$this->decode_item_array($value, $this->_options)) {          if(!$utils->decode_item_expr($value, $hidden, $options) && !$utils->decode_item_array($value, $hidden, $options)) {
151            $this->set_element_value($key, $value);            $this->set_element_value($key, $value);
152          }          }
153        }        }
# Line 145  class EditDataItem extends StandardFormC Line 172  class EditDataItem extends StandardFormC
172        foreach($this->_datasource->_result as $key => $value) {        foreach($this->_datasource->_result as $key => $value) {
173          // if item is match by expression we will replace it with an link object            // if item is match by expression we will replace it with an link object  
174          if($this->_options['decode']) {          if($this->_options['decode']) {
175           if($this->decode_item_expr($value)) {             $utils = php::mkComponent('WebExplorer::utils');
176            $table->add_row($key, $this->decode_item_expr($value));             $hidden = $this->get_hidden_elements();
177             $options = $this->_options['decode_args'];
178             $options[label] = $key;
179             $options[parent_guid] = $this->_options['parent']['guid'];
180             $options[parent_class] = $this->_options['parent']['class'];
181             if($utils->decode_item_expr($value, $hidden, $options)) {  
182              $table->add_row($key, $value);  
183           }             }  
184           // if item is an Array we will replace it with an selection form object             // if item is an Array we will replace it with an selection form object  
185           elseif($this->decode_item_array($value) ) {           elseif($utils->decode_item_array($value, $hidden, $options) ) {
186              $table->add_row($key, $this->decode_item_array($value));              $table->add_row($key, $value);
187           } else {           } else {
188             $table->add_row($this->element_label($key), $this->element_form($key));             $table->add_row($this->element_label($key), $this->element_form($key));
189           }           }
# Line 210  class EditDataItem extends StandardFormC Line 243  class EditDataItem extends StandardFormC
243          $td = new TDtag(array("colspan" => 2,          $td = new TDtag(array("colspan" => 2,
244                                "class" => "contentnovertical",                                "class" => "contentnovertical",
245                                "align" => "center"),                                "align" => "center"),
246                          form_submit('ecfedit', "Confirm"),                          form_submit('ecdfe', "Confirm"),
247                          _HTML_SPACE,                          _HTML_SPACE,
248                          $this->add_action("Edit"));                          $this->add_action("Edit"));
249    
# Line 234  class EditDataItem extends StandardFormC Line 267  class EditDataItem extends StandardFormC
267       */       */
268      function confirm_action() {      function confirm_action() {
269    
270             $utils = php::mkComponent('WebExplorer::utils');
271             $hidden = $this->get_hidden_elements();
272             $options = $this->_options['decode_args'];
273    
274          foreach($this->_datasource->_result as $label => $value_old) {          foreach($this->_datasource->_result as $label => $value_old) {
275              print $label . "<br>";            if(!$utils->decode_item_expr($value_old, $hidden, $options) && !$utils->decode_item_array($value_old, $hidden, $options)) {
           if(!$this->decode_item_expr($value_old) && !$this->decode_item_array($value_old)) {  
276              $value_new = $this->_elements[$label]->get_value();              $value_new = $this->_elements[$label]->get_value();
277              $data[$label] = $value_new;              $data[$label] = $value_new;
278            }            }
279          }          }
280            // write new data to datasource
281          $this->_options['data_locator_meta']['action'] = "write";          $this->_options['data_locator_meta']['action'] = "write";
282          $this->_options['data_locator_meta']['data'] = $data;          $this->_options['data_locator_meta']['data'] = $data;
283            // TODO: 'data_prefetch()' will never return ANYTHING!
284            //           Implement some error-handling there or somewhere.
285          $error = $this->data_prefetch();          $error = $this->data_prefetch();
286            
287          //$error = $this->_datasource->set($item);          //$error = $this->_datasource->set($item);
288          if(!$error) {          if(!$error) {
289              // fetch fresh data
290              $this->_options['data_locator_meta']['action'] = "read";
291              // unset previous initialed 'data' var
292              $this->_options['data_locator_meta']['data'] = NULL;
293              $this->data_prefetch();
294            
295            $this->set_action_message($this->_confirm_msg);            $this->set_action_message($this->_confirm_msg);
296            return TRUE;            return TRUE;
297          } else {          } else {
# Line 264  class EditDataItem extends StandardFormC Line 309  class EditDataItem extends StandardFormC
309          $div = new DIVtag( array("style" => "background-color: #eeeeee;".          $div = new DIVtag( array("style" => "background-color: #eeeeee;".
310                                              "padding-top:5px;padding-bottom:5px",                                              "padding-top:5px;padding-bottom:5px",
311                                   "align"=>"center", "nowrap"),                                   "align"=>"center", "nowrap"),
312                             form_submit('ecfedit', "Save"),                             form_submit('ecdfe', "Save"),
313                             _HTML_SPACE,                             _HTML_SPACE,
314                             $this->add_cancel() );                             //$this->add_cancel()
315                               form_submit('ecdfc', "Cancel")
316                               );
317          return $div;          return $div;
318      }      }
319    
320    
321      function get_hidden_elements() {
322        foreach($this->_hidden_elements as $label => $object) {
323    function decode_item_array($item) {        $value = $this->_hidden_elements[$label]->get_value();
324      $options = $this->_options['decode_args'];        $tmp_array[$label] = $value;
     if( is_array($item) ) {  
           //$cur_row_index = $this->_datasource->get_cur_data_index();  
           //$parent_guid = $this->_datasource->_data[$cur_row_index]['guid'];  
           // build list for selection form  
        if($options['form']) {  
           foreach($item as $key => $value) {  
                 $tmp = split($options['seperator'], $value);  
                 $ident = $tmp['1'];  
                 $meta = $tmp['2'];  
                 $list[$key] = $ident;  
                 }  
                 if(is_array($list) ) {  
               $container = container(  
                   form_open( $item[0], $_SERVER["PHP_SELF"], "POST" ),  
                   form_hidden("ecdm", $meta),  
                   form_select("ecdid", $list),  
                   form_submit("submit","view" )  
                   );  
                foreach($this->_hidden_elements as $label => $value) {  
                  $container->add(form_hidden($label, $value));  
                }  
               $container->add(form_close() );  
               $item = $container;  
               }  
         } else {  
           $container = container();  
           foreach($item as $key => $value) {  
                 $tmp = split($options['seperator'], $value);  
                 $ident = $tmp['1'];  
                 $meta = $tmp['2'];  
                 foreach($this->_hidden_elements as $label => $object) {  
                   $value = $this->_hidden_elements[$label]->get_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;  
         }  
               return $item;  
325      }      }
326        return $tmp_array;
327    }    }
328    
   
   function decode_item_expr($item) {  
     $options = $this->_options['decode_args'];  
     if(substr($item, 0, 2) == "o_") {  
           $tmp = split($options['seperator'], $item);  
           $ident = $tmp['1'];  
           $meta = $tmp['2'];  
           foreach($this->_hidden_elements as $label => $object) {  
              $value = $this->_hidden_elements[$label]->get_value();  
              $tmp_array[] = $label . "=" . $value;  
           }  
           $str_hidden = join("&", $tmp_array);  
           $item = html_a($_SERVER["PHP_SELF"] . "?ecdid=" . $ident . "&ecdm=" . $meta . "&" . $str_hidden, "view");  
           return $item;  
     }  
   }  
   
   
329  }  }
330    
331    

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

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