/[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.6 - (hide annotations)
Fri Apr 11 00:48:03 2003 UTC (21 years, 5 months ago) by joko
Branch: MAIN
Changes since 1.5: +10 -3 lines
minor fix: calling parent constructor explicitely by name now, transparency seems not be automagically compatible with inheritance in php ,-)    (non-orthogonal)

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

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