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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.7 - (hide annotations)
Sat May 10 18:04:45 2003 UTC (21 years, 4 months ago) by jonen
Branch: MAIN
Changes since 1.6: +7 -1 lines
+ added values needed for 'create/add new' links

1 jonen 1.1 <?
2     /*
3     ## -----------------------------------------------------------------------------
4 jonen 1.7 ## $Id: EditDataItem.php,v 1.6 2003/04/11 00:48:03 joko Exp $
5 jonen 1.1 ## -----------------------------------------------------------------------------
6 jonen 1.2 ## $Log: EditDataItem.php,v $
7 jonen 1.7 ## Revision 1.6 2003/04/11 00:48:03 joko
8     ## minor fix: calling parent constructor explicitely by name now, transparency seems not be automagically compatible with inheritance in php ,-) (non-orthogonal)
9     ##
10 joko 1.6 ## Revision 1.5 2003/04/09 09:59:30 joko
11     ## fixes regarding modification of decode-function-behavior
12     ##
13 joko 1.5 ## Revision 1.4 2003/04/06 01:41:33 jonen
14     ## - removed duplicated decode functions
15     ##
16 jonen 1.4 ## Revision 1.3 2003/04/04 23:58:02 jonen
17     ## + saving of items sould now work with new 'GenericSource' structure
18     ##
19 jonen 1.3 ## Revision 1.2 2003/04/04 00:43:22 jonen
20     ## + complete rework
21     ##
22 jonen 1.2 ## Revision 1.1 2003/03/27 01:18:06 jonen
23     ## + inital commit (was orginal 'DataItem.php')
24     ##
25 jonen 1.1 ## Revision 1.4 2003/02/27 17:33:14 cvsmax
26     ## + enabled saving of data objects at confirm action
27     ## + fixed bug with POST/GET vars at form confirm
28     ## o ToDo: fix all bugs related to un-wanted hidden form elements
29     ## caused by mixed/duplicated POST/GET vars!
30     ##
31     ## Revision 1.3 2003/02/26 21:37:53 cvsmax
32     ## + reworked to enable linking if item value is an array or special expression
33     ##
34     ## Revision 1.2 2003/02/25 03:46:59 cvsmax
35     ## + refactored complete to work now with phphtmllib FormProcessor/Content
36     ## o ToDo: field validation seems not to work...
37     ##
38     ## Revision 1.1 2003/02/22 17:27:31 cvsmax
39     ## + renamed from DataEdit.php
40     ## + added simple support for class 'FormElementsInterface' which is an interface
41     ## to class 'FormBuilder' by binarycloud
42     ## o ToDo: refactor code to use new (added 21.02.03!) 'FormProcess' classes by phphtmllib
43     ## + class 'DataItem' now extends class 'InfoTable'
44     ##
45     ## Revision 1.1 2003/02/21 03:19:35 cvsmax
46     ## + first init
47     ##
48     ##
49     ## -----------------------------------------------------------------------------
50     */
51    
52     class EditDataItem extends StandardFormContent {
53    
54 jonen 1.2 /**
55     * holds reference to source object.
56     */
57     var $_datasource = NULL;
58    
59     /**
60     * container for arguments needed for e.g. setting the source object.
61     */
62 jonen 1.1 var $_options = array();
63 jonen 1.2
64 jonen 1.1 var $_confirm_msg = "Die Daten wurden erfolgreich gespeichert!";
65    
66 jonen 1.2 function EditDataItem($title, $options = array()) {
67 jonen 1.1 $this->_options = $options;
68 jonen 1.2 // prefetch data
69     $this->data_prefetch();
70 jonen 1.1
71 joko 1.6 // doesn't work if EditDataItem gets inherited
72     //$parent = get_parent_class($this);
73     //$this->$parent($title, $PHP_SELF, 600);
74    
75     $this->StandardFormContent($title, $PHP_SELF, 600);
76    
77 jonen 1.1 }
78    
79     function set_data_source(&$source) {
80 jonen 1.2 $this->_datasource = &$source;
81 jonen 1.1 }
82    
83     function get_data_source() {
84     $initial_locator = php::mkComponent( 'DataSource::Locator', array( adapter_type => 'phpHtmlLib' ) );
85     $proxy = php::mkComponent('DataSource::Generic', $initial_locator, $this->_options['data_locator_meta']);
86     $source = $proxy->get_adapter();
87     $this->set_data_source( &$source );
88     }
89    
90 jonen 1.2 function _check_datasource($function_name) {
91     if ( !is_object($this->_datasource) ) {
92     user_error("DataList::".$function_name."() - DataListSource object is not set");
93     exit;
94     }
95     }
96    
97     function data_prefetch() {
98     $this->get_data_source();
99     $this->_check_datasource("data_prefetch");
100    
101     $this->_datasource->do_query();
102     }
103 jonen 1.1
104     /**
105     * This method gets called EVERY time the object is
106     * created. It is used to build all of the
107     * FormElement objects used in this Form.
108     *
109     */
110     function form_init_elements() {
111     //we want an confirmation page for this form.
112     $this->set_confirm();
113    
114 jonen 1.4 $utils = php::mkComponent('WebExplorer::utils');
115     $hidden = $this->get_hidden_elements();
116     $options = $this->_options['decode_args'];
117    
118 jonen 1.2 foreach($this->_datasource->_result as $key => $value) {
119 jonen 1.1 if($value) {
120     $validation = TRUE;
121     } else {
122     $validation = FALSE;
123     }
124 jonen 1.4 if(!$utils->decode_item_expr($value, $hidden, $options) && !$utils->decode_item_array($value, $hidden, $options)) {
125 jonen 1.1 $this->add_element( new FEText($key, $validation, "350px") );
126     }
127     }
128    
129     }
130    
131     /**
132     * This method is called only the first time the form
133     * page is hit. This enables u to query a DB and
134     * pre populate the FormElement objects with data.
135     *
136     */
137     function form_init_data() {
138     //Pull some valies from the DB
139     //and set the initial values of some of the
140     //form fields.
141    
142 jonen 1.4 $utils = php::mkComponent('WebExplorer::utils');
143     $hidden = $this->get_hidden_elements();
144     $options = $this->_options['decode_args'];
145    
146 jonen 1.2 foreach($this->_datasource->_result as $key => $value) {
147 jonen 1.4 if(!$utils->decode_item_expr($value, $hidden, $options) && !$utils->decode_item_array($value, $hidden, $options)) {
148 jonen 1.1 $this->set_element_value($key, $value);
149     }
150     }
151    
152 jonen 1.2 /* OLD !!
153 jonen 1.1 $post_vars = array_join_merge($_GET, $_POST);
154     foreach ($post_vars as $var => $val) {
155     $this->set_hidden_element_value($var, $val);
156     }
157 jonen 1.2 */
158 jonen 1.1
159     }
160    
161    
162     function form_content() {
163     $this->add_form_block($this->_caption, $this->_dataitem() );
164     }
165    
166     function &_dataitem() {
167     $table = &html_table($this->_width,0,2);
168    
169 jonen 1.2 foreach($this->_datasource->_result as $key => $value) {
170 jonen 1.1 // if item is match by expression we will replace it with an link object
171 jonen 1.2 if($this->_options['decode']) {
172 jonen 1.4 $utils = php::mkComponent('WebExplorer::utils');
173     $hidden = $this->get_hidden_elements();
174     $options = $this->_options['decode_args'];
175 jonen 1.7 $options[label] = $key;
176     $options[parent_guid] = $this->_options['parent']['guid'];
177     $options[parent_class] = $this->_options['parent']['class'];
178 jonen 1.4 if($utils->decode_item_expr($value, $hidden, $options)) {
179 joko 1.5 $table->add_row($key, $value);
180 jonen 1.2 }
181     // if item is an Array we will replace it with an selection form object
182 jonen 1.4 elseif($utils->decode_item_array($value, $hidden, $options) ) {
183 joko 1.5 $table->add_row($key, $value);
184 jonen 1.2 } else {
185     $table->add_row($this->element_label($key), $this->element_form($key));
186     }
187     } else {
188 jonen 1.1 $table->add_row($this->element_label($key), $this->element_form($key));
189     }
190     }
191    
192     return $table;
193     }
194    
195     /**
196     * This method gets called after the FormElement data has
197     * passed the validation. This enables you to validate the
198     * data against some backend mechanism, say a DB.
199     *
200     */
201     function form_backend_validation() {
202     //$this->add_error("Ass", "some bogus error happened");
203     //return FALSE;
204     //foreach($this->raw_data as $key => $value) {
205     // if($this->_elements[$key]->get_value()) {
206     // $this->add_error($key, "empty field!");
207     // return FALSE;
208     // } else {
209     // return TRUE;
210     // }
211     // }
212     $this->set_action("Confirm");
213     return TRUE;
214     }
215    
216    
217     /**
218     * This function is used to show an intermediary
219     * confirmation page. Use this function to
220     * show a confirmation of the data that was
221     * submitted by the user.
222     * This will get called after all of the
223     * form data was successfully validated.
224     * All of the form data will automatically
225     * be created as hidden form fields. All you
226     * have to do is show the data, and a confirm
227     * submit button.
228     *
229     * @return mixed - either raw html, or some
230     * container HTMLTag object.
231     */
232     function form_confirm( ) {
233     $title = "Form Confirmation / " . $this->_options['caption'];
234     $title .="( ".$this->_required_field_marker." ".$this->_required_field_text." )";
235     $table = new InfoTable($title, $this->_width);
236    
237     $this->build_confirm_table( $table );
238    
239     //now add the confirmation button
240     $td = new TDtag(array("colspan" => 2,
241     "class" => "contentnovertical",
242     "align" => "center"),
243 jonen 1.3 form_submit('ecdfe', "Confirm"),
244 jonen 1.1 _HTML_SPACE,
245     $this->add_action("Edit"));
246    
247     if ($this->_cancel_action) {
248     $td->add(_HTML_SPACE, $this->add_cancel());
249     }
250    
251     $table->add_row( $td );
252    
253     return $table;
254     }
255    
256    
257    
258    
259     /**
260     * This method is called ONLY after ALL validation has
261     * passed. This is the method that allows you to
262     * do something with the data, say insert/update records
263     * in the DB.
264     */
265     function confirm_action() {
266    
267 jonen 1.4 $utils = php::mkComponent('WebExplorer::utils');
268     $hidden = $this->get_hidden_elements();
269     $options = $this->_options['decode_args'];
270    
271 jonen 1.2 foreach($this->_datasource->_result as $label => $value_old) {
272 jonen 1.4 if(!$utils->decode_item_expr($value_old, $hidden, $options) && !$utils->decode_item_array($value_old, $hidden, $options)) {
273 jonen 1.1 $value_new = $this->_elements[$label]->get_value();
274 jonen 1.2 $data[$label] = $value_new;
275     }
276 jonen 1.1 }
277 jonen 1.3 // write new data to datasource
278 jonen 1.2 $this->_options['data_locator_meta']['action'] = "write";
279     $this->_options['data_locator_meta']['data'] = $data;
280 jonen 1.3 // TODO: 'data_prefetch()' will never return ANYTHING!
281     // Implement some error-handling there or somewhere.
282 jonen 1.2 $error = $this->data_prefetch();
283 jonen 1.3
284 jonen 1.2 //$error = $this->_datasource->set($item);
285 jonen 1.1 if(!$error) {
286 jonen 1.3 // fetch fresh data
287     $this->_options['data_locator_meta']['action'] = "read";
288     // unset previous initialed 'data' var
289     $this->_options['data_locator_meta']['data'] = NULL;
290     $this->data_prefetch();
291    
292 jonen 1.1 $this->set_action_message($this->_confirm_msg);
293     return TRUE;
294     } else {
295     return FALSE;
296     }
297     }
298    
299 jonen 1.2 /**
300     * This function is used to build the standard
301     * buttons for a form.
302     *
303     * @return ButtonPanel
304     */
305     function form_content_buttons() {
306     $div = new DIVtag( array("style" => "background-color: #eeeeee;".
307     "padding-top:5px;padding-bottom:5px",
308     "align"=>"center", "nowrap"),
309 jonen 1.3 form_submit('ecdfe', "Save"),
310 jonen 1.2 _HTML_SPACE,
311 jonen 1.3 //$this->add_cancel()
312     form_submit('ecdfc', "Cancel")
313     );
314 jonen 1.2 return $div;
315     }
316    
317    
318 jonen 1.4 function get_hidden_elements() {
319     foreach($this->_hidden_elements as $label => $object) {
320     $value = $this->_hidden_elements[$label]->get_value();
321     $tmp_array[$label] = $value;
322 jonen 1.1 }
323 jonen 1.4 return $tmp_array;
324 jonen 1.1 }
325    
326     }
327    
328    
329     ?>

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