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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.13 - (show annotations)
Thu Oct 7 14:17:50 2004 UTC (19 years, 11 months ago) by jonen
Branch: MAIN
Changes since 1.12: +20 -3 lines
+ pass filter-values to backend now! (page-control!)

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

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