/[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.14 - (show annotations)
Mon Nov 15 16:51:48 2004 UTC (19 years, 9 months ago) by jonen
Branch: MAIN
CVS Tags: HEAD
Changes since 1.13: +8 -2 lines
+ added var 'numrows' to constructor args

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

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