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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.6 - (hide annotations)
Tue May 13 16:24:30 2003 UTC (21 years, 4 months ago) by joko
Branch: MAIN
Changes since 1.5: +30 -1 lines
title addendum
MetaBox - header style

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

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