/[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.12 - (show 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 <?
2 /*
3 ## -------------------------------------------------------------------------
4 ## $Id: GenericGUIDataList.php,v 1.11 2003/05/10 17:58:45 jonen Exp $
5 ## -------------------------------------------------------------------------
6 ## $Log: GenericGUIDataList.php,v $
7 ## Revision 1.11 2003/05/10 17:58:45 jonen
8 ## + reworked to implement 'create/add new' item
9 ##
10 ## Revision 1.10 2003/04/18 18:40:02 jonen
11 ## + fixed bugs at 'actionbar_cell' relating to html-form and js
12 ##
13 ## Revision 1.9 2003/04/11 00:44:46 joko
14 ## minor update: shortened seperators
15 ##
16 ## Revision 1.8 2003/04/09 07:54:42 joko
17 ## cleaned up decoding part
18 ##
19 ## Revision 1.7 2003/04/09 00:37:53 jonen
20 ## + added actionbar
21 ## + some changes according to request vars
22 ##
23 ## Revision 1.6 2003/04/08 17:48:31 jonen
24 ## + bugfix again
25 ##
26 ## 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 ## Revision 1.4 2003/04/06 01:41:07 jonen
30 ## - removed duplicated decode functions
31 ##
32 ## Revision 1.3 2003/04/04 21:26:06 joko
33 ## added comments regarding possible (future) refactoring using the Data::Lift-infrastructure
34 ##
35 ## Revision 1.2 2003/04/04 00:45:40 jonen
36 ## + reworked decode functions
37 ##
38 ## Revision 1.1 2003/03/27 01:17:31 jonen
39 ## + inital commit (was orginal 'ObjectList.inc)
40 ##
41 ## 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 ## -------------------------------------------------------------------------
51 */
52
53
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 /**
74 * Holds a list of hidden elements
75 *
76 */
77 var $_hidden_elements = array();
78
79
80 /**
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
103 // call parent constructor
104 $parent = get_parent_class($this);
105 $this->$parent($title, $width = "100%", $default_orderby='', $default_reverseorder=FALSE);
106 }
107
108
109 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 //$source = $this->_datasource;
165
166 //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
195 }
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 function wrap_column_item($obj, $col_name, $row_data) {
212
213 //make sure its set to something.
214 if ($obj == '') {
215 $obj = "&nbsp;";
216 }
217
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 $utils = php::mkComponent('WebExplorer::utils');
246 $hidden = $this->_hidden_elements;
247 $options = $this->_options['decode_args'];
248 $options[label] = $col_name;
249 $options[parent_guid] = $row_data[guid];
250 $options[parent_class] = $this->_options['parent']['class'];
251
252 // 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 }
260
261 }
262
263 //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 function add_hidden_element($label, $value) {
288 $this->_hidden_elements[$label] = $value;
289 }
290
291
292
293 /**
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
310 // OLD - needed hidden elements are now recognized at 'render()'
311 /*
312 // 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 */
318
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 return $container;
347 }
348
349
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 }
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 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 * the contents for the buttons of actionbar
410 * td cell.
411 *
412 * @return ContainerWidget object
413 */
414 function actionbar_cell_new() {
415 $action_buttons = $this->_options['actionbar']['buttons'];
416
417 if(is_array($action_buttons)) {
418 $action_form = container();
419 foreach($action_buttons as $type) {
420 $action_form->add(
421 _HTML_SPACE,
422 form_submit($type['name'], $type['value'])
423 );
424 }
425 return $action_form;
426 } else {
427 return _HTML_SPACE;
428 }
429 }
430
431
432 /*
433 * OLD (depreciated) - this method returns the current requested variables
434 *
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 if(is_array($url_vars)) {
445 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 }
456 }
457 return $cur_url_vars;
458 }
459
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
477 //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 //if (!isset($this->_cur_col_cntr)) {
548 $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
584 }
585 ?>

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