/[cvs]/nfo/php/libs/com.newsblob.phphtmllib/widgets/data_list/DefaultGUIDataList.inc
ViewVC logotype

Annotation of /nfo/php/libs/com.newsblob.phphtmllib/widgets/data_list/DefaultGUIDataList.inc

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.4 - (hide annotations)
Sat Feb 22 18:02:18 2003 UTC (21 years, 6 months ago) by jonen
Branch: MAIN
Changes since 1.3: +21 -25 lines
+ added abstract functions:
   - _decode_column_item_array($obj)
   - _decode_column_item_expr($obj)
   which have to be overwritten at child class
- moved code at 'wrap_column_item' to '_decode_*'  functions at class ObjectList

1 jonen 1.1 <?php
2    
3     /**
4     *
5     * This file contains the Default DataList child
6     * that has its specific GUI layout/look/feel
7     *
8     * @author Walter A. Boring IV <waboring@buildabetterweb.com>
9     * @package phpHtmlLib
10     *
11     */
12    
13    
14     /**
15     * This class is the Default phpHtmlLib GUI interface
16     * child of the DataList class. This child simply does
17     * the job of rendering the html/layout for a DataList.
18     * You can use this as an example of how to build your
19     * own look/feel for your DataList.
20     *
21     * @author Walter A. Boring IV <waboring@buildabetterweb.com>
22     * @package phpHtmlLib
23     *
24     */
25     class DefaultGUIDatalist extends DataList {
26    
27     function gui_init() {
28     $container = container();
29     $container->add( $this->build_tool_link("first"),
30     $this->build_tool_link("prev"),
31     $this->build_tool_link("next"),
32     $this->build_tool_link("last"),
33     $this->build_tool_link("all"),
34     $this->get_page_info() );
35    
36     $this->_data_table = html_table($this->get_width(),0,0,0,"center");
37     $this->_data_table->set_class("datalist_border");
38    
39     $this->_tool_td = html_td("datalist_title", "right", $container);
40     $this->_tool_td->set_style("padding-top: 5px; padding-right: 5px;");
41     $this->_tool_td->set_tag_attribute("colspan", count($this->_columns)-1);
42    
43     $title = new TDtag(array("align" => "left",
44     "class" => "datalist_title",
45     "style" => "padding-left: 5px;"),
46     $this->get_title() );
47    
48     //add the header tr reference
49     //it will get populated later
50     $this->_header_tr = new TRtag;
51     $this->_data_table->add( new TRtag(array(), $title, $this->_tool_td) );
52     $this->_data_table->add_reference($this->_header_tr);
53    
54     //initialize the first date row
55     $this->_data_row = new TRtag;
56    
57     //enable search
58     $this->search_enable();
59     $this->set_simple_search_modifier();
60    
61     }
62    
63     function child_build_column_header($name, $col, $cnt) {
64     $td = $this->build_column_header($name, $col, $cnt);
65     $this->_header_tr->add( $td );
66     }
67    
68     function child_add_row_cell($obj, $col_name, $last_in_row_flag) {
69     $td = $this->wrap_column_item($obj, $col_name);
70    
71     $this->_data_row->add( $td );
72     if ($last_in_row_flag) {
73     $this->_data_table->add_row( $this->_data_row );
74     $this->_data_row = new TRtag;
75     }
76     }
77    
78     function child_get_gui() {
79     return $this->_data_table;
80     }
81    
82     /**
83     * This function builds the object/text
84     * to be used for a column header. It can
85     * either be an href because its sortable,
86     * or it can just be text, because its not
87     * sortable.
88     *
89     * @param string $col_name - the column name
90     * to build from
91     * the headers.
92     * @param array $col_data - the column's data.
93     * @param int the column # we are working on.
94     * @return mixed - either an Atag object or
95     * raw text.
96     */
97     function build_column_header($col_name, $col_data, $col_num) {
98    
99     $td = new TDtag(array("class"=>"datalist_col_head",
100     "width" => $col_data["size"]));
101    
102     if ($this->_columns[$col_name]["sortable"]) {
103     $col_url = $this->build_column_url($col_name);
104    
105     $td->set_tag_attribute("title","Sort By ".$col_name);
106    
107     $td->push(html_a($col_url, $col_name,"form_link"));
108    
109     if ($this->_columns[$col_name]["data_name"] == $this->orderby()) {
110    
111     if ($this->reverseorder() == "false") {
112     $alt_title = "Sorted in Ascending Order";
113     $img = html_img($this->get_image_path()."/picto_down.gif",11,11,'',$alt_title);
114     $img->set_tag_attribute("style", "padding-left: 5px;margin-left:5px;vertical-align:middle;");
115     $td->push($img);
116     } else {
117     $alt_title = "Sorted in Descending Order";
118     $img = html_img($this->get_image_path()."/picto_up.gif",11,11,'',$alt_title);
119     $img->set_tag_attribute("style", "padding-left: 5px;margin-left:5px;vertical-align:middle;");
120     $td->push($img);
121     }
122     }
123    
124     // we want to highlight the td on mouse over
125     $td->set_tag_attribute("onMouseOver",
126     "javascript:style.cursor='hand';this.className='datalist_col_head_hover';");
127     $td->set_tag_attribute("onMouseOut",
128     "javascript:this.className='datalist_col_head'");
129     $td->set_tag_attribute("onMouseDown",
130     "javascript:this.className='datalist_col_head_clicked'");
131    
132    
133     if ($this->get_form_method() == "POST") {
134     $td->set_tag_attribute("onClick", $col_url);
135     }
136     else {
137     $td->set_tag_attribute("onClick", "javascript:document.location='".$col_url."';");
138     }
139     } else {
140     $td->push($col_name);
141     $td->set_tag_attribute("style", $style."padding-left:5px;padding-right:5px;white-space:nowrap;");
142     }
143    
144     return $td;
145     }
146    
147     /**
148     * This function ensures that the data we place
149     * in a column is aligned according to what the
150     * user wants.
151     *
152     * @param mixed - $obj - the data for the td.
153     * @param string - $col_name - the name of the column header
154     * for this row to render.
155     * @param int - $odd_row - tells us if this cell lives in
156     * an odd # row (for alternating row colors)
157     * @param int - the column # we are working on.
158     * @return TDtag object
159     */
160     function wrap_column_item($obj, $col_name) {
161    
162     //make sure its set to something.
163     if ($obj == '') {
164     $obj = "&nbsp;";
165 jonen 1.4 }
166     // if item is match by expression we will replace it with an link object
167     elseif($this->_decode_column_item_expr($obj)) {
168     $obj = $this->_decode_column_item_expr($obj);
169     }
170     // if item is an Array we will replace it with an selection form object
171     elseif($this->_decode_column_item_array($obj)) {
172     $obj = $this->_decode_column_item_array($obj);
173 jonen 1.2 }
174    
175 jonen 1.1
176     //make sure we don't put a right border on the last
177     //column we are working on.
178     $style = "padding-left: 3px;padding-right:3px;border-top: 1px solid #dddddd;";
179    
180     if ($this->_columns[$col_name]["data_name"] == $this->orderby()) {
181     $style .= "background-color: #f4f4f4;";
182     } else {
183     $style .= "background-color: #ffffff;";
184     }
185    
186     $align = $this->_columns[$col_name]["align"];
187     $td = new TDtag(array("align" => $align,
188     "style" => $style,
189     "class" => "font10"));
190    
191     if (is_object($obj) && $obj->_tag == "td") {
192     return $obj;
193     } else {
194     $td->add( $obj );
195     }
196     return $td;
197     }
198    
199     /**
200     * This builds the table that holds the search
201     * capability.
202     *
203     * @return TABLEtag object.
204     */
205     function child_build_search_table() {
206     //the search capability is enabled.
207     //lets try and build the table.
208     $td_attributes = array("style" => "padding-left: 5px;padding-bottom:4px;".
209     "padding-right:40px;padding-top:4px;".
210     "background-color: #eeeeee;",
211     "align" => "left",
212     "class" => "font10");
213    
214     $table = html_table($this->get_width(),0,0,0,"center");
215    
216     //test to see if they want to render the outer borders
217     $table->set_tag_attribute("style", "border-left: 1px solid #a1a1a1;".
218     "border-right: 1px solid #a1a1a1;");
219    
220     $td = new TDtag($td_attributes);
221    
222     if ($this->search_type() == "advanced") {
223     $td->push($this->_build_advanced_search_form());
224     } else {
225     $td->push($this->_build_simple_search_form());
226     }
227     $table->push_row($td);
228    
229     return container($this->_build_search_title(), $table);
230     }
231    
232     /**
233     * This function builds the search title table
234     *
235     * @return TABLEtag object
236     */
237     function _build_search_title() {
238     //build the title stacked table
239     $title = html_table($this->get_width(), 0, 0, 0, "center");
240    
241     //test to see if they want to render the outer borders
242     $title->set_tag_attribute("style","border: 1px solid #a1a1a1;");
243     $title->push_row(new TDtag(array("class" => "datalist_title",
244     "style" => "color: ".$this->_title_fcolor.";".
245     "background-color: ".$this->_title_color.";"), "&nbsp;Search"));
246    
247     return $title;
248     }
249    
250    
251     /**
252     * This function builds the simple search TD
253     *
254     * @return ContainerWidget
255     */
256     function _build_simple_search_form() {
257    
258     //if there is only 1 item enabled for search
259     //then the search looks simple.
260     $fields = $this->_get_searchable_fields();
261     $cnt = count($fields);
262     if ($cnt == 0) {
263     return NULL;
264     }
265    
266     $container = new ContainerWidget;
267    
268     if ($cnt == 1) {
269     //user only has 1 field to show.
270     list($name, $field) = each($fields);
271     $container->push("Find ".$name."&nbsp;&nbsp;");
272     } else {
273     //user has many fields to show.
274     $container->push("Find ",
275     form_select($this->_search_fieldVar, $fields, $this->search_field()));
276     }
277    
278     if ($this->get_simple_search_modifier()) {
279     //the user wants the search modifier turned on.
280     $container->push($this->_build_simple_search_modifier());
281     }
282    
283     $container->push(form_text($this->_search_valueVar, $this->search_value_filter($this->search_value()), "20", "100", array("style"=>"vertical-align:middle;")),
284     form_submit($this->get_form_name(), "Search", array("style"=>"vertical-align:middle;")));
285    
286     if ($this->is_advanced_search_enabled()) {
287     $span = html_span(html_a("ass","Advanced Search", "title"));
288     $container->push("&nbsp;", $span);
289     }
290    
291     if ($cnt == 1) {
292     $container->push(form_hidden($this->_search_fieldVar, $field));
293     }
294 jonen 1.2
295     $hidden_fields = $this->get_hidden_fields();
296     if(is_array($hidden_fields)) {
297     foreach($hidden_fields as $key => $value) {
298     $container->push(form_hidden($key, $value));
299     }
300     }
301    
302     $container->push(form_close() );
303 jonen 1.1
304     return $container;
305     }
306 jonen 1.2
307    
308     function get_hidden_fields() {
309     user_error("DefaulGUIDataList::get_hidden_fields() - ".
310     "child class must override this method ".
311     "this function should return a hash for hidden fields, if not needed just return" );
312     }
313    
314 jonen 1.4
315     function _decode_column_item_array($obj) {
316     user_error("DefaulGUIDataList::_decode_column_item_array() - ".
317     "child class must override this method ".
318     "this function should decode the column_item if it is a (sub-) array,".
319     "array should e.g. replaced by a select form." );
320     }
321    
322     function _decode_column_item_expr($obj) {
323     user_error("DefaulGUIDataList::_decode_column_item_expr() - ".
324     "child class must override this method ".
325     "this function should decode the column_item, if it is encoded for e.g. objects" );
326     }
327 jonen 1.1 }
328    
329     /**
330     * This class defines the css used by the
331     * FooterNav Object.
332     *
333     * @author Walter A. Boring IV <waboring@buildabetterweb.com>
334     * @package phpHtmlLib
335     */
336     class DefaultGUIDataListCSS extends CSSBuilder {
337    
338     function user_setup() {
339     $this->add_entry(".datalist_col_head", "",
340     array("font-family" => "arial, helvetica, sans-serif",
341     "font-size" => "10pt",
342     "font-weight" => "bold",
343     "color" => "#000000",
344     "background-color" => "#CCCCCC",
345     "text-align" => "left",
346     "white-space" => "nowrap",
347     "height" => "20px",
348     "vertical-align" => "middle",
349     "border-left" => "1px solid white",
350     "border-top" => "1px solid white",
351     "border-right" => "1px solid gray",
352     "border-bottom" => "1px solid gray",
353     "padding-left" => "3px",
354     "padding-right" => "3px") );
355    
356     $this->add_entry(".datalist_col_head", "a.form_link:active,a.form_link:visited,a.form_link:link",
357     array("color" => "#000000",
358     "text-decoration" => "none"));
359    
360     $this->add_entry(".datalist_col_head_hover", "",
361     array("font-family" => "arial, helvetica, sans-serif",
362     "font-size" => "10pt",
363     "font-weight" => "bold",
364     "color" => "#000000",
365     "background-color" => "#dcdcdc",
366     "text-align" => "left",
367     "white-space" => "nowrap",
368     "height" => "20px",
369     "vertical-align" => "middle",
370     "border-left" => "1px solid white",
371     "border-top" => "1px solid white",
372     "border-right" => "1px solid gray",
373     "border-bottom" => "1px solid gray",
374     "padding-left" => "3px",
375     "padding-right" => "3px") );
376    
377     $this->add_entry(".datalist_col_head_clicked", "",
378     array("font-family" => "arial, helvetica, sans-serif",
379     "font-size" => "10pt",
380     "font-weight" => "bold",
381     "color" => "#000000",
382     "background-color" => "#dddddd",
383     "text-align" => "left",
384     "white-space" => "nowrap",
385     "height" => "20px",
386     "vertical-align" => "middle",
387     "border-left" => "1px solid white",
388     "border-top" => "1px solid white",
389     "border-right" => "1px solid gray",
390     "border-bottom" => "1px solid gray",
391     "padding-left" => "3px",
392     "padding-right" => "3px") );
393    
394     $this->add_entry( ".datalist_border", "",
395     array("border" => "1px solid #999999"));
396    
397     $this->add_entry( ".datalist_title", "",
398     array("font-family" => "arial",
399     "font-size" => "10pt",
400     "font-weight" => "bold",
401     "color" => "#FFFFFF",
402     "background-color" => "#999999",
403     "white-space" =>"nowrap"));
404     }
405     }
406     ?>

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