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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (hide annotations)
Thu Mar 4 23:10:18 2004 UTC (20 years, 6 months ago) by udo
Branch: MAIN
CVS Tags: HEAD
Changes since 1.1: +31 -5 lines
added hidden elements to container

1 udo 1.1 <?
2     /*
3     ## -----------------------------------------------------------------------------
4 udo 1.2 ## $Id: ExpandEditDataItem.php,v 1.1 2003/11/22 18:40:09 udo Exp $
5 udo 1.1 ## -----------------------------------------------------------------------------
6 udo 1.2 ## $Log: ExpandEditDataItem.php,v $
7     ## Revision 1.1 2003/11/22 18:40:09 udo
8     ## initial commit
9     ##
10 udo 1.1 ## Revision 1.6 2003/05/13 16:24:30 joko
11    
12     ## -----------------------------------------------------------------------------
13     */
14    
15     class ExpandEditDataItem extends InfoTable {
16    
17     /**
18     * holds reference to source object.
19     */
20     var $_datasource = NULL;
21    
22     /**
23     * container for arguments needed for e.g. setting the source object.
24     */
25     var $_options = array();
26    
27     /**
28     * container for hidden elements.
29     */
30     var $_hidden_elements = array();
31    
32     function ExpandEditDataItem($title, $options = array()) {
33     $this->_options = $options;
34    
35     // HACK: hardcode custom options
36     $this->_options['data_locator_meta']['expand'] = 1;
37     $this->_options['decode'] = 0;
38    
39    
40     //print "title: $title<br/>";
41     // print "options:" . Dumper($options) . "<br>";
42    
43     $title .= $this->get_title_addendum();
44    
45     $parent = get_parent_class($this);
46     // debug (WARNNING!!! Sometime an recursive loop happens here
47     // if class $parent is eq current class!!)
48     //print "parent: " . Dumper($parent) . "<br>";
49    
50     $this->$parent($title, $width="100%", "center");
51    
52     // fetch data
53     $this->data_prefetch();
54     }
55    
56    
57     function render($indent_level=1, $output_debug=0) {
58     // init data record entries
59     $this->init_elements();
60     // add form container
61 udo 1.2
62    
63     //$this->get_form_container();
64    
65     $container = container();
66     // form open
67     $container->add(form_open("item_fv", $_SERVER['PHP_SELF'], 'POST'));
68     //hidden items
69     if(is_array($this->_hidden_elements)) {
70     foreach($this->_hidden_elements as $label => $value) {
71     $container->add(form_hidden($label, $value));
72     }
73     }
74    
75    
76 udo 1.1
77     $table = html_table( $this->get_width(), 0,
78     $this->get_cellspacing(),
79     $this->get_cellpadding(),
80     $this->get_align());
81     $table->set_class( "infotable" );
82     $table->add( $this->_build_title() );
83    
84     $row = $this->_build_header();
85     if ($row != NULL) {
86     $table->add_row( $row );
87     }
88    
89     //now go thru the rows of data
90     //and add them
91    
92 udo 1.2 // modified this for expanded view
93 udo 1.1 foreach( $this->data as $row ) {
94    
95     if ((count($row) == 1) && is_object($row[0]) && (is_a($row[0], "TRtag") ||
96     is_a($row[0], "TDtag"))) {
97     $table->add_row( $row[0] );
98     } else {
99     $tr = new TRtag;
100     $cnt = count( $row );
101     foreach( $row as $index => $data ) {
102     if (is_array($data[1])) {
103     $newTable = html_table( 50, 0);
104     foreach ($data as $datakey => $datavalue) {
105     $newTable->add_row($datakey . ":&nbsp;&nbsp;&nbsp;&nbsp;", form_text($datakey, $datavalue['odd']));
106     }
107     $td = $this->_build_td("", "", $index+1, $cnt );
108     $td->add( $newTable );
109     $tr->add( $td );
110     } elseif ($data['event_type']['item_type'] == "sport") {
111     $td = $this->_build_td("", "", $index+1, $cnt );
112     $showstring = $data['event_key'] . ", " . $data['event_type']['item_name'] . ", " . $data['event_class']['item_name'];
113     $td->add($showstring);
114     $tr->add( $td );
115     } else {
116     $td = $this->_build_td("", "", $index+1, $cnt );
117     $td->add( $data );
118     $tr->add( $td );
119     }
120     }
121     $table->add_row( $tr );
122     }
123     }
124 udo 1.2 $container->add($table);
125     // submit button
126     $container->add(form_submit('ecdfe', "edit"));
127    
128     // close form
129     $container->add(form_close());
130    
131     return $container->render($indent_level, $output_debug);
132     // return $table->render($indent_level, $output_debug);
133    
134 udo 1.1 }
135    
136    
137    
138     function set_data_source(&$source) {
139     $this->_datasource = &$source;
140     }
141     function get_data_source() {
142     $initial_locator = php::mkComponent( 'DataSource::Locator', array( adapter_type => 'phpHtmlLib' ) );
143     $proxy = php::mkComponent('DataSource::Generic', $initial_locator, $this->_options['data_locator_meta']);
144     $source = $proxy->get_adapter();
145     $this->set_data_source( &$source );
146     }
147    
148     function _check_datasource($function_name) {
149     if ( !is_object($this->_datasource) ) {
150     user_error("DataList::".$function_name."() - DataListSource object is not set");
151     exit;
152     }
153     }
154    
155     function data_prefetch() {
156     $this->get_data_source();
157     $this->_check_datasource("data_prefetch");
158    
159     $this->_datasource->do_query();
160     }
161    
162     function init_elements() {
163     $result = $this->_datasource->_result;
164     if (is_array($result)) {
165     foreach($result as $key => $value) {
166     // set empty values to 'html spacer' for render
167     // TODO: integer value '0' is interpretted as non-existing value! Hack this!!
168     if(!$value && !is_array($value)) { $value = _HTML_SPACE; }
169     // if decode options are true, trie to decode values(e.g. for inhiterance)
170     if($this->_options['decode']) {
171     $utils = php::mkComponent('WebExplorer::utils');
172     $hidden = $this->_hidden_elements;
173     $options = $this->_options['decode_args'];
174     $options[label] = $key;
175     $options[parent_guid] = $this->_options['parent']['guid'];
176     $options[parent_class] = $this->_options['parent']['class'];
177     // if item is matched by a special expression we will replace it with an html-link object
178     $utils->decode_item_expr($value, $hidden, $options);
179     // if item is an Array we will replace it with an html-link object
180     $utils->decode_item_array($value, $hidden, $options);
181    
182     $this->add_element($key, $value);
183     } else {
184     $this->add_element($key, $value);
185     }
186     }
187     }
188     }
189    
190     function add_element($label, $value) {
191     $this->add_row(span_font10bold($label), $value);
192     }
193    
194     function add_hidden_element($label, $value) {
195     $this->_hidden_elements[$label] = $value;
196     }
197    
198     function get_form_container() {
199     $container = container();
200     // form open
201     $container->add(form_open("item_fv", $_SERVER['PHP_SELF'], 'POST'));
202     //hidden items
203     if(is_array($this->_hidden_elements)) {
204     foreach($this->_hidden_elements as $label => $value) {
205     $container->add(form_hidden($label, $value));
206     }
207     }
208     // submit button
209     $container->add(form_submit('ecdfe', "edit"));
210     // close form
211     $container->add(form_close());
212    
213     // add container to InfoTable
214     $this->add_row(_HTML_SPACE, $container);
215     }
216    
217    
218     // Please visit WebExplorer::Module::DataItem - there is a similar chooser at the top!!!
219     // TODO: abstract this out into some reusable, generic component sometimes (SimpleChooser?)
220     // (also take a look at WebExplorer::Module::DataTree)
221     function get_title_addendum() {
222    
223     // MetaBox / Chooser - resolve / display some links which probably have been declared in some other layer
224     //$this->header = html_span();
225    
226     // Build a header-style MetaBox.
227     // This will get injected into the header of the DataItem.
228     $this->header_box = php::mkComponent('MetaBox', array(
229     box_mode => 'header',
230     caption => $this->_options['caption'],
231     payload => $this->_options['links'],
232     ) );
233    
234     return $this->header_box->render();
235    
236     }
237    
238     }
239    
240    
241     ?>

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