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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.12 - (hide annotations)
Thu May 6 17:14:35 2004 UTC (20 years, 4 months ago) by jonen
Branch: MAIN
Changes since 1.11: +16 -9 lines
 updated

1 jonen 1.1 <?
2     /*
3 joko 1.9 ## -------------------------------------------------------------------------
4 jonen 1.12 ## $Id: GenericGUIDataList.php,v 1.11 2003/05/10 17:58:45 jonen Exp $
5 joko 1.9 ## -------------------------------------------------------------------------
6 jonen 1.2 ## $Log: GenericGUIDataList.php,v $
7 jonen 1.12 ## Revision 1.11 2003/05/10 17:58:45 jonen
8     ## + reworked to implement 'create/add new' item
9     ##
10 jonen 1.11 ## Revision 1.10 2003/04/18 18:40:02 jonen
11     ## + fixed bugs at 'actionbar_cell' relating to html-form and js
12     ##
13 jonen 1.10 ## Revision 1.9 2003/04/11 00:44:46 joko
14     ## minor update: shortened seperators
15     ##
16 joko 1.9 ## Revision 1.8 2003/04/09 07:54:42 joko
17     ## cleaned up decoding part
18     ##
19 joko 1.8 ## Revision 1.7 2003/04/09 00:37:53 jonen
20     ## + added actionbar
21     ## + some changes according to request vars
22     ##
23 jonen 1.7 ## Revision 1.6 2003/04/08 17:48:31 jonen
24     ## + bugfix again
25     ##
26 jonen 1.6 ## Revision 1.5 2003/04/08 17:33:22 jonen
27     ## + fixed problems with hidden form fields(current base URL) at the 'simple search form'
28     ##
29 jonen 1.5 ## Revision 1.4 2003/04/06 01:41:07 jonen
30     ## - removed duplicated decode functions
31     ##
32 jonen 1.4 ## Revision 1.3 2003/04/04 21:26:06 joko
33     ## added comments regarding possible (future) refactoring using the Data::Lift-infrastructure
34     ##
35 joko 1.3 ## Revision 1.2 2003/04/04 00:45:40 jonen
36     ## + reworked decode functions
37     ##
38 jonen 1.2 ## Revision 1.1 2003/03/27 01:17:31 jonen
39     ## + inital commit (was orginal 'ObjectList.inc)
40     ##
41 jonen 1.1 ## Revision 1.1 2003/03/20 04:17:28 jonen
42     ## + initial commit
43     ##
44     ## Revision 1.2 2003/03/02 04:32:22 cvsmax
45     ## + add decode_item functions
46     ##
47     ## Revision 1.1 2003/03/01 22:57:40 cvsmax
48     ## + inital commit
49     ##
50 joko 1.9 ## -------------------------------------------------------------------------
51 jonen 1.1 */
52 joko 1.9
53 jonen 1.1
54     /**
55     * Need to make sure we have the DefaultGUIDataList object
56     */
57     require_once($phphtmllib."/widgets/data_list/DefaultGUIDataList.inc");
58    
59    
60     class GenericGUIDataList extends DefaultGUIDataList {
61    
62     /**
63     * Args needed for object list.
64     * Current use:
65     * - use some bits to create locator metadata (see below)
66     * - use all options to propagate to an AdapterProxy (here: GenericDataSource)
67     * as a query to receive a list of objects as response to a rpc-call.
68     * Todo: glossary: ban "*list* of objects" - it's an object *set* !!! (see CPAN's Set::Object)
69     *
70     */
71     var $_options = NULL;
72    
73 jonen 1.2 /**
74     * Holds a list of hidden elements
75     *
76     */
77     var $_hidden_elements = array();
78    
79 jonen 1.7
80 jonen 1.1 /**
81     * The constructor is used to pass in some additional
82     * metadata informations as "options".
83     * The "locator metadata hash" isn't passed in here
84     * any more. Handling this one occours one level deeper
85     * inside the "GenericDataSource" Proxy.
86     *
87     * It's still possible to set locator metadata directly by
88     * using the optional key 'locator' inside your options hash.
89     * This can be either a DataSource::Locator instance or a plain
90     * hash. However - it gets merged to the master locator
91     * created by GenericDataSource using 'array_join_merge'.
92     *
93     * @param old: LocatorMetadataHash array - layout: array( type => '', metadata => '', dsn => '' )
94     * @param old: Query array - layout: array( type => '', metadata => '', dsn => '' )
95     *
96     * @param new: options array - layout: array( datasource_type => '', [locator => array()] )
97     *
98     *
99     */
100     function GenericGUIDataList($title, $width = "100%", $default_orderby='', $default_reverseorder=FALSE, $options = array()) {
101     if ($options) { $this->_options = $options; }
102 jonen 1.7
103     // call parent constructor
104 jonen 1.1 $parent = get_parent_class($this);
105 jonen 1.7 $this->$parent($title, $width = "100%", $default_orderby='', $default_reverseorder=FALSE);
106 jonen 1.1 }
107    
108 jonen 1.7
109 jonen 1.1 function get_data_source( ) {
110    
111     // finally: create phpHtmlLib source handle (XyzDataListSource)
112    
113     // V1:
114     //$source = new GenericDataSource($this->_locator, $this->_options);
115     //$this->set_data_source( &$source );
116    
117     /*
118     // V2:
119     loadModule("DataSource::GenericDataSource");
120     $source = new DataSource_GenericDataSource($this->_locator, $this->_options);
121     $this->set_data_source( &$source );
122     */
123    
124     // V3:
125     /*
126     $proxy = php::mkComponent('DataSource::GenericDataSource', $this->_locator, $this->_options);
127     $source = &$proxy;
128     $this->set_data_source( &$source );
129     */
130    
131     // V4:
132     /*
133     $proxy = php::mkComponent('DataSource::GenericDataSource', array( proxy => '', adapter => ''), $this->_options);
134     $source = &$proxy;
135     $this->set_data_source( &$source );
136     */
137    
138     // V5:
139     //print "options: " . Dumper($this->_options);
140    
141     $initial_locator = php::mkComponent( 'DataSource::Locator', array( adapter_type => 'phpHtmlLib' ) );
142     //print "1st locator: " . Dumper($initial_locator);
143    
144     // OLD
145     //$proxy = php::mkComponent('DataSource::Generic', $initial_locator, $this->_options);
146    
147     //print "Test Query:";
148     //print Dumper($this->_options['query']);
149     $proxy = php::mkComponent('DataSource::Generic', $initial_locator, $this->_options['data_locator_meta']);
150    
151     // debug
152     //print "Proxy: " . Dumper($proxy);
153    
154     // V1:
155     //$source = &$proxy;
156    
157     // V2:
158     //$source->make_adapter_transparent();
159    
160     // V3:
161     $source = $proxy->get_adapter();
162    
163     // V4:
164 jonen 1.12 //$source = $this->_datasource;
165    
166 jonen 1.1 //print "objectlist-source: " . Dumper($source);
167     //exit;
168    
169     $this->set_data_source( &$source );
170    
171     }
172    
173     function user_setup() {
174    
175     //return;
176    
177     $source = $this->_datasource;
178     //if (!$source) { return; }
179    
180     //print Dumper($source);
181     $headers = $source->get_header();
182     //print Dumper($headers);
183    
184     $this->set_title( $this->get_title() . ' - ' . $source->get_total_rows() . ' Einträge' );
185    
186     foreach($headers as $val) {
187     $this->add_header_item($val, "150", $val, SORTABLE, SEARCHABLE);
188     }
189    
190     /*
191     $this->add_header_item("Uid", "200", "uid", SORTABLE, SEARCHABLE);
192     $this->add_header_item("Name", "200", "lastName", SORTABLE, SEARCHABLE, "center");
193     */
194 jonen 1.11
195 jonen 1.1 }
196    
197    
198     /**
199     * This function ensures that the data we place
200     * in a column is aligned according to what the
201     * user wants.
202     *
203     * @param mixed - $obj - the data for the td.
204     * @param string - $col_name - the name of the column header
205     * for this row to render.
206     * @param int - $odd_row - tells us if this cell lives in
207     * an odd # row (for alternating row colors)
208     * @param int - the column # we are working on.
209     * @return TDtag object
210     */
211 jonen 1.11 function wrap_column_item($obj, $col_name, $row_data) {
212 jonen 1.1
213     //make sure its set to something.
214     if ($obj == '') {
215 joko 1.3 $obj = "&nbsp;";
216 jonen 1.1 }
217 joko 1.3
218     // decode item / mungle item data?
219     // TODO: use Data::Lift here!!! (like already done in YAA::JobList and YAA::JobDetails)
220     elseif ($this->_options['decode']) {
221    
222     // Proposal using Data::Lift: (see YAA::JobList and YAA::JobDetails)
223     // This class will get shorter and better to maintain!
224    
225     // Picture Data::Lift as a container component handling
226     // *specific* en-/decoding stuff for your very core components.
227     // This way we will have almost all "specific mungling code" at one place. nice thing!
228    
229     /*
230    
231     // 1. expr: string -> object (phpHtmlLib-object: 'html_a'-tag)
232     // returns a phpHtmlLib object of class 'Xyz' containing a http-/html-link
233     // pointing to a View of a different - linked/referenced - object (reference-interpolation)
234     $this->lift1 = php::mkComponent('Data::Lift', $obj, array( metatype => 'expression' ) );
235     $obj = $this->lift1->to('phpHtmlLib::html_a');
236    
237     // 2. data: hash -> object (phpHtmlLib-object: 'container'-object containing form)
238     // returns a phpHtmlLib object of class 'Container' containing a html-form made up of
239     // phpHtmlLib form-tags wrapping all attribute-value pairs of the data hash (object-edit)
240     $this->lift2 = php::mkComponent('Data::Lift', $obj, array( metatype => 'item' ) );
241     $obj = $this->lift2->to('phpHtmlLib::form');
242    
243     */
244    
245 jonen 1.4 $utils = php::mkComponent('WebExplorer::utils');
246     $hidden = $this->_hidden_elements;
247     $options = $this->_options['decode_args'];
248 jonen 1.11 $options[label] = $col_name;
249     $options[parent_guid] = $row_data[guid];
250     $options[parent_class] = $this->_options['parent']['class'];
251 jonen 1.4
252 joko 1.8 // a) Iterate through the attributes of the item and replace each
253     // value with an appropriate link object if it has a certain format.
254     if ($utils->decode_item_expr($obj, $hidden, $options)) {
255    
256     // b) Otherwise: If item is an Array we will replace it with a selection form object.
257     } else {
258     $utils->decode_item_array($obj, $hidden, $options);
259 jonen 1.1 }
260 joko 1.3
261 jonen 1.1 }
262 joko 1.3
263 jonen 1.1 //make sure we don't put a right border on the last
264     //column we are working on.
265     //$style = "padding-left: 3px;padding-right:3px;border-top: 1px solid #dddddd;";
266    
267    
268     if ($this->_columns[$col_name]["data_name"] == $this->orderby()) {
269     $style = "background-color: #f4f4f4;";
270     } else {
271     $style = "background-color: #ffffff;";
272     }
273    
274     $align = $this->_columns[$col_name]["align"];
275     $td = new TDtag(array("align" => $align,
276     "style" => $style,
277     "class" => "datalist_data_cell"));
278    
279     if (is_object($obj) && $obj->_tag == "td") {
280     return $obj;
281     } else {
282     $td->add( $obj );
283     }
284     return $td;
285     }
286    
287 jonen 1.2 function add_hidden_element($label, $value) {
288     $this->_hidden_elements[$label] = $value;
289     }
290    
291    
292 jonen 1.11
293 jonen 1.5 /**
294     * This function builds the simple search TD
295     *
296     * @return ContainerWidget
297     */
298     function _build_simple_search_form() {
299    
300     //if there is only 1 item enabled for search
301     //then the search looks simple.
302     $fields = $this->_get_searchable_fields();
303     $cnt = count($fields);
304     if ($cnt == 0) {
305     return NULL;
306     }
307    
308     $container = new ContainerWidget;
309 jonen 1.7
310 jonen 1.11 // OLD - needed hidden elements are now recognized at 'render()'
311     /*
312 jonen 1.7 // get current request vars and add them ad hidden items
313     $url_vars = $this->_get_current_url_vars();
314     foreach($url_vars as $label => $value) {
315     $container->push(form_hidden($label, $value));
316     }
317 jonen 1.11 */
318 jonen 1.5
319     if ($cnt == 1) {
320     //user only has 1 field to show.
321     list($name, $field) = each($fields);
322     $container->push("Find ".$name."&nbsp;&nbsp;");
323     } else {
324     //user has many fields to show.
325     $container->push("Find ",
326     form_select($this->_vars["search_fieldVar"], $fields, $this->search_field()));
327     }
328    
329     if ($this->get_simple_search_modifier()) {
330     //the user wants the search modifier turned on.
331     $container->push($this->_build_simple_search_modifier());
332     }
333    
334     $container->push(form_text($this->_vars["search_valueVar"], $this->search_value_filter($this->search_value()), "20", "100", array("style"=>"vertical-align:middle;")),
335     form_submit($this->get_form_name(), "Search", array("style"=>"vertical-align:middle;")));
336    
337     if ($this->is_advanced_search_enabled()) {
338     $span = html_span(html_a("ass","Advanced Search", "title"));
339     $container->push("&nbsp;", $span);
340     }
341    
342     if ($cnt == 1) {
343     $container->push(form_hidden($this->_vars["search_fieldVar"], $field));
344     }
345    
346 jonen 1.11 return $container;
347     }
348 jonen 1.7
349 jonen 1.11
350     /**
351     * This function builds the data cell action buttons or main actionbar
352     *
353     * @return TDtag;
354     */
355     function _build_actionbar_data_cell() {
356     $td = new TDtag(array("class" => "datalist_title",
357     "style" => "padding-left:5px;padding-right:5px;".
358     "padding-top:5px;padding-bottom:5px")
359     );
360    
361     $flag = FALSE;
362     if ($this->_has_action_column("FIRST")) {
363     $flag = TRUE;
364     $td->set_tag_attribute("align", "left");
365     }
366     elseif ($this->_has_action_column("LAST")) {
367     $flag = TRUE;
368     $td->set_tag_attribute("align", "right");
369     }
370    
371     if ($flag && $this->_datasource->get_total_rows()) {
372     $td->push($this->actionbar_cell());
373     $td->push($this->actionbar_cell_new());
374     }
375     else {
376     $td->push("&nbsp;");
377     $td->push($this->actionbar_cell_new());
378     }
379    
380     return $td;
381 jonen 1.7 }
382    
383    
384     /**
385     * this is the method that builds
386     * the contents for the middle actionbar
387     * td cell.
388     *
389     * @return ContainerWidget object
390     */
391     function actionbar_cell() {
392     $action_list = $this->_options['actionbar']['list'];
393     $action_name = $this->_options['actionbar']['name'];
394    
395     if($action_name && is_array($action_list)) {
396     $action_form = container("Select action", _HTML_SPACE,
397 jonen 1.11 form_select($action_name, $action_list, $this->_options['actionbar']['selected']),
398     form_submit("ok","OK" )
399     );
400     return $action_form;
401     } else {
402     return _HTML_SPACE;
403     }
404     }
405    
406    
407     /**
408     * this is the method that builds
409 jonen 1.12 * the contents for the buttons of actionbar
410 jonen 1.11 * td cell.
411     *
412     * @return ContainerWidget object
413     */
414     function actionbar_cell_new() {
415 jonen 1.12 $action_buttons = $this->_options['actionbar']['buttons'];
416 jonen 1.11
417 jonen 1.12 if(is_array($action_buttons)) {
418     $action_form = container();
419     foreach($action_buttons as $type) {
420     $action_form->add(
421 jonen 1.11 _HTML_SPACE,
422 jonen 1.12 form_submit($type['name'], $type['value'])
423 jonen 1.7 );
424 jonen 1.12 }
425 jonen 1.7 return $action_form;
426     } else {
427     return _HTML_SPACE;
428     }
429     }
430    
431    
432     /*
433 jonen 1.11 * OLD (depreciated) - this method returns the current requested variables
434 jonen 1.7 *
435     * @return array
436     */
437     function _get_current_url_vars() {
438     $cur_url_vars = array();
439    
440     // get new LinkBuilder instance
441     $linkbuilder = new LinkBuilder();
442    
443     $url_vars = php::array_join_merge($_GET, $_POST);
444 jonen 1.5 if(is_array($url_vars)) {
445 jonen 1.7 foreach($url_vars as $key => $value) {
446     // if there is an LinkBuilder guid instead of variables, encode it
447     if($key == 'lbid') {
448     $lb_vars = $linkbuilder->load($value);
449     foreach($lb_vars as $lbkey => $lbval) {
450     $cur_url_vars[$lbkey] = $lbval;
451     }
452     } else {
453     $cur_url_vars[$key] = $value;
454     }
455 jonen 1.5 }
456     }
457 jonen 1.7 return $cur_url_vars;
458 jonen 1.5 }
459 jonen 1.11
460    
461     /**
462     * This function renders the final
463     * widget
464     *
465     */
466     function render($indent_level, $output_debug) {
467    
468     //setup the columns in their sorts
469     $this->setup_columns();
470    
471     //do any data prefetch work
472     //which may be child specific
473     if ( $this->_show_results() ) {
474     $this->data_prefetch();
475     }
476 jonen 1.12
477 jonen 1.11 //This function gives the child class
478     //a chance to build the tables/divs/containers
479     //that will be responsible for the look/feel
480     //of the DataList
481     $this->gui_init();
482    
483     //see if we need to build the search area.
484     if ( $this->is_search_enabled() || $this->is_advanced_search_enabled() ) {
485     $this->_search_table = $this->child_build_search_table();
486     if ( $this->_search_table ) {
487     $this->set_form_render(TRUE);
488     }
489     }
490    
491     //see if form is needed by the actionbar
492     if($this->_show_actionbar) {
493     $this->set_form_render(TRUE);
494     }
495    
496     if ( $this->get_form_render() ) {
497     $form = new FORMtag( array("method" => $this->get_form_method(),
498     "action" => $this->build_base_url(),
499     "name" => $this->get_form_name(),
500     "style" => "margin-top: 0px;margin-bottom:0px;") );
501    
502     $target = $this->get_form_target();
503     if ( $target != NULL )
504     $form->set_tag_attribute("target",$target);
505    
506     $action = $this->get_form_action();
507     if ( $action != NULL )
508     $form->set_tag_attribute("action",$action);
509    
510     //now build the UI and return it
511     $form->add( $this->build_gui() );
512    
513     } else {
514     $form = container();
515    
516     //now build the UI and return it
517     $form->add( $this->build_gui() );
518     }
519    
520     //add the hidden vars if we are a POST
521     if ($this->get_form_method() == "POST") {
522     $form->add( $this->_build_default_vars() );
523    
524     //build hidden elements needed for data flow control
525     $hidden = $this->_hidden_elements;
526     //print "Hidden: " . Dumper($hidden);
527     if($hidden) {
528     foreach($hidden as $label => $value) {
529     $form->add(form_hidden($label, $value));
530     }
531     }
532    
533     }
534    
535     //add the save vars the user wants.
536     $form->add( $this->_build_save_vars() );
537    
538     //add any javascript required
539     $container = container( $this->_javascript(), $form );
540     return $container->render( $indent_level, $output_debug );
541     }
542    
543    
544    
545     function child_add_row_cell($obj, $col_name, $last_in_row_flag, $row_data) {
546     if (!$this->_cur_col_cntr) {
547 jonen 1.12 //if (!isset($this->_cur_col_cntr)) {
548 jonen 1.11 $this->_cur_col_cntr = 1;
549     //lets see if we need to add an action column
550     //as the first column.
551     if ($this->_has_action_column("FIRST")) {
552     //looks like we have a FIRST column actionbar
553     //lets add it
554     $this->_data_row->add($this->_build_action_column("FIRST", FALSE, $row_data));
555     }
556     $td = $this->wrap_column_item($obj, $col_name, $row_data);
557     $this->_data_row->add( $td );
558     } else {
559     //show the normal data
560     $td = $this->wrap_column_item($obj, $col_name, $row_data);
561     $this->_data_row->add( $td );
562     }
563    
564    
565     if ($last_in_row_flag) {
566     //lets see if we need to add an action column
567     //as the first column.
568     if ($this->_has_action_column("LAST")) {
569     //looks like we have a LAST column actionbar
570     //lets add it
571     $this->_data_row->add($this->_build_action_column("LAST", FALSE, $row_data));
572     }
573    
574    
575    
576     $this->_data_table->add_row( $this->_data_row );
577     $this->_data_row = new TRtag;
578     unset( $this->_cur_col_cntr );
579     } else {
580     $this->_cur_col_cntr++;
581     }
582     }
583 jonen 1.1
584     }
585     ?>

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