Revision e18349d4
Added by Andreas Kohlbecker about 16 years ago
modules/cdm_dataportal/cdm_taxontree/cdm_taxontree.module | ||
---|---|---|
53 | 53 |
$tree = cdm_taxontree_build_tree($taxonUuid_inFocus); |
54 | 54 |
$block['content'] = theme('cdm_taxontree_block', $tree); |
55 | 55 |
drupal_add_css(drupal_get_path('module', 'cdm_taxontree').'/cdm_taxontree.css'); |
56 |
drupal_add_js(drupal_get_path('module', 'cdm_taxontree').'/cdm_taxontree.js'); |
|
56 |
drupal_add_js(drupal_get_path('module', 'cdm_taxontree').'/js/cdm_taxontree.js'); |
|
57 |
if($taxonUuid_inFocus){ |
|
58 |
drupal_add_js(drupal_get_path('module', 'cdm_taxontree').'/js/jquery.scrollTo.js'); |
|
59 |
drupal_add_js(drupal_get_path('module', 'cdm_taxontree').'/js/jquery.dimensions.js'); |
|
60 |
drupal_add_js(' |
|
61 |
if (Drupal.jsEnabled) { |
|
62 |
$(document).ready(function() |
|
63 |
{ |
|
64 |
//var activeElement = $(\'div.cdm_taxontree_scroller_x .active\'); |
|
65 |
$(\'div.cdm_taxontree_scroller_x\').scrollTo($(\'.active\'));}); |
|
66 |
}', 'inline'); |
|
67 |
} |
|
57 | 68 |
return $block; |
58 | 69 |
} |
59 | 70 |
} |
... | ... | |
90 | 101 |
* @param unknown_type $taxonUuid |
91 | 102 |
* @return unknown |
92 | 103 |
*/ |
93 |
function cdm_taxontree_build_tree($taxonUuid){ |
|
104 |
function cdm_taxontree_build_tree($taxonUuid = null){
|
|
94 | 105 |
|
95 | 106 |
// find the secRefUuid |
96 | 107 |
$secRefUuid = null; |
... | ... | |
304 | 315 |
return $tree; |
305 | 316 |
} |
306 | 317 |
|
318 |
|
|
319 |
/** |
|
320 |
* Replaces the keys of an array of TreeNode instances |
|
321 |
* by the $treeNode->uuid of the single array elements. |
|
322 |
* An sets additional fields |
|
323 |
* |
|
324 |
* @param $resultset array of TreeNode instances as +returned by the cdm web service |
|
325 |
* @param $excluded whether the $resultset is included by a active filter. Is ignored if NULL. |
|
326 |
* @param $expanded whether the children of the nodes in the $resultset are expanded or not. Is ignored if NULL. |
|
327 |
*/ |
|
328 |
function _cdm_resultset2nodelist($resultset, $excluded = null, $expanded = null){ |
|
329 |
|
|
330 |
if(! is_array($resultset)) { |
|
331 |
return false; |
|
332 |
} |
|
333 |
|
|
334 |
$tree = array(); |
|
335 |
foreach($resultset as $treeNode){ |
|
336 |
if(!is_null($excluded)){ |
|
337 |
$treeNode->filter = ($excluded ? 'excluded': 'included'); |
|
338 |
} |
|
339 |
if(!is_null($expanded)){ |
|
340 |
$treeNode->expanded = ($expanded ? 'expanded': 'collapsed'); |
|
341 |
} |
|
342 |
$tree[$treeNode->uuid] = $treeNode; |
|
343 |
} |
|
344 |
return $tree; |
|
345 |
} |
|
346 |
|
|
347 |
|
|
307 | 348 |
function theme_cdm_taxontree_block($tree){ |
308 | 349 |
|
309 | 350 |
$out = ''; |
310 | 351 |
if(cdm_dataportal_filters_active()){ |
311 | 352 |
$out .= theme('cdm_taxontree_contoller', _get_compact_mode()); |
312 | 353 |
} |
313 |
$out .= theme('cdm_taxontree', $tree, !cdm_dataportal_filters_active(), 'cdm_taxontree_concept_switch');
|
|
354 |
$out .= '<div class="cdm_taxontree_scroller_x"><div class="cdm_taxontree_container"><div class="cdm_taxontree_scroller_y"><div class="cdm_taxontree_border">'.theme('cdm_taxontree', $tree, !cdm_dataportal_filters_active(), TRUE, 'cdm_taxontree_node_concept_switch').'</div></div></div></div>';
|
|
314 | 355 |
return $out; |
315 | 356 |
} |
316 | 357 |
|
... | ... | |
331 | 372 |
return $out.'</div>'; |
332 | 373 |
} |
333 | 374 |
|
334 |
function theme_cdm_taxontree($tree, $filterIncludes = null, $tree_node_callback = false){ |
|
375 |
function theme_cdm_taxontree($tree, $filterIncludes = null, $show_filter_switch = false, $tree_node_callback = false){
|
|
335 | 376 |
|
336 | 377 |
if(!is_array($tree)) { |
337 | 378 |
return false; |
... | ... | |
344 | 385 |
|
345 | 386 |
$out = '<ul class="cdm_taxontree">'; |
346 | 387 |
foreach($tree as $node){ |
347 |
$out .= theme('cdm_taxontree_node', $node, $filterIncludes, $tree_node_callback); |
|
388 |
$out .= theme('cdm_taxontree_node', $node, $filterIncludes, $show_filter_switch, $tree_node_callback);
|
|
348 | 389 |
} |
349 | 390 |
$out .= '</ul>'; |
350 | 391 |
return $out; |
351 | 392 |
} |
352 | 393 |
|
353 |
function theme_cdm_taxontree_node($node, $filterIncludes, $tree_node_callback = false){ |
|
394 |
function theme_cdm_taxontree_node($node, $filterIncludes, $show_filter_switch = false, $tree_node_callback = false){
|
|
354 | 395 |
|
355 | 396 |
$is_leaf = !$node->hasChildren || $node->hasChildren == 0; |
356 | 397 |
$is_expanded = isset($node->expanded) && $node->expanded = 'expanded'; |
... | ... | |
372 | 413 |
$cdm_proxy_url = false; |
373 | 414 |
if(!$is_leaf && !$is_expanded && $filter_class != 'filter_excluded'){ |
374 | 415 |
$ws_url = cdm_compose_url(CDM_WS_TREENODE_CHILDREN, array($node->uuid)); |
375 |
$cdm_proxy_url = url('cdm_api/proxy/'.urlencode($ws_url).'/cdm_taxontree/'.($nextLevelIncluded ? 1 : 0).'/'.$tree_node_callback); |
|
416 |
$cdm_proxy_url = url('cdm_api/proxy/'.urlencode($ws_url).'/cdm_taxontree/'.($nextLevelIncluded ? 1 : 0).'/'.($show_filter_switch ? 1 : 0).'/'.$tree_node_callback);
|
|
376 | 417 |
} |
377 | 418 |
|
378 | 419 |
// list item |
... | ... | |
383 | 424 |
.($cdm_proxy_url ? 'title="'.$cdm_proxy_url.'"' : '') |
384 | 425 |
.'>'; |
385 | 426 |
|
427 |
if($show_filter_switch){ |
|
386 | 428 |
// filter icon |
387 |
$out .= theme('cdm_taxontree_filter_switch', $node, $filter_class); |
|
429 |
$out .= theme('cdm_taxontree_node_filter_switch', $node, $filter_class); |
|
430 |
} |
|
388 | 431 |
|
389 | 432 |
// taxon name |
390 | 433 |
$out .= $name; |
... | ... | |
402 | 445 |
return $out; |
403 | 446 |
} |
404 | 447 |
|
405 |
function theme_cdm_taxontree_filter_switch(&$node, $filter_class){ |
|
448 |
function theme_cdm_taxontree_node_filter_switch(&$node, $filter_class){
|
|
406 | 449 |
$out = ''; |
407 | 450 |
|
408 | 451 |
switch($filter_class){ |
... | ... | |
428 | 471 |
return $out; |
429 | 472 |
} |
430 | 473 |
|
431 |
function theme_cdm_taxontree_concept_switch(&$node){ |
|
474 |
function theme_cdm_taxontree_node_concept_switch(&$node){
|
|
432 | 475 |
$out = ''; |
433 | 476 |
|
434 | 477 |
if(isset($node->alternativeConceptRefs[0])){ |
... | ... | |
441 | 484 |
return $out; |
442 | 485 |
} |
443 | 486 |
|
444 |
/** |
|
445 |
* Replaces the keys of an array of TreeNode instances |
|
446 |
* by the $treeNode->uuid of the single array elements. |
|
447 |
* An sets additional fields |
|
448 |
* |
|
449 |
* @param $resultset array of TreeNode instances as +returned by the cdm web service |
|
450 |
* @param $excluded whether the $resultset is included by a active filter. Is ignored if NULL. |
|
451 |
* @param $expanded whether the children of the nodes in the $resultset are expanded or not. Is ignored if NULL. |
|
452 |
*/ |
|
453 |
function _cdm_resultset2nodelist($resultset, $excluded = null, $expanded = null){ |
|
487 |
function theme_cdm_taxontree_node_reference(&$node){ |
|
488 |
|
|
489 |
$out = ' <span class="sec_ref widget_select" style="background-color:#'._uuid_to_rgbhex($node->secUuid).'" title="'.$node->secUuid.'">'.$node->secUuid.'</span>'; |
|
490 |
return $out; |
|
491 |
} |
|
454 | 492 |
|
455 |
if(! is_array($resultset)) { |
|
456 |
return false; |
|
457 |
} |
|
493 |
function cdm_taxontree_widget($default_uuid = false){ |
|
494 |
|
|
495 |
drupal_add_js(drupal_get_path('module', 'cdm_taxontree').'/js/cdm_taxontree_widget.js'); |
|
496 |
|
|
497 |
$out = '<div class="cdm_taxontree_widget">'; |
|
498 |
$out .= '<div class="tree">'.theme('cdm_taxontree', cdm_taxontree_build_tree(), NULL, FALSE, 'cdm_taxontree_node_reference').'</div>'; |
|
499 |
$out .= '<div class="selected_nodes"><label>'.t('Selected Nodes').'</label><ul class="listing"><li><input type="text" class="value_1232-stub" value="1232-stub" /></li></ul></div>'; |
|
500 |
$out .= '</div>'; |
|
501 |
return $out; |
|
502 |
} |
|
458 | 503 |
|
459 |
$tree = array(); |
|
460 |
foreach($resultset as $treeNode){ |
|
461 |
if(!is_null($excluded)){ |
|
462 |
$treeNode->filter = ($excluded ? 'excluded': 'included'); |
|
463 |
} |
|
464 |
if(!is_null($expanded)){ |
|
465 |
$treeNode->expanded = ($expanded ? 'expanded': 'collapsed'); |
|
466 |
} |
|
467 |
$tree[$treeNode->uuid] = $treeNode; |
|
468 |
} |
|
469 |
return $tree; |
|
504 |
|
|
505 |
// --------------------------------------------------- // |
|
506 |
|
|
507 |
function _uuid_to_rgbhex($uuid){ |
|
508 |
|
|
509 |
$xfoot = _str_crossfoot($uuid); |
|
510 |
$h = $xfoot / 2 / 2; |
|
511 |
$h = $h - floor($h); |
|
512 |
$RGB = _hsv_2_rgb($h, 0.45, 1); |
|
513 |
return dechex($RGB['R']).dechex($RGB['G']).dechex($RGB['B']); |
|
470 | 514 |
} |
471 | 515 |
|
516 |
function _str_crossfoot($str) |
|
517 |
{ |
|
518 |
$xfoot = 0; |
|
519 |
for($i=0; $i<strlen($str); $i++) |
|
520 |
{ |
|
521 |
$xfoot = $xfoot + ord($str[$i]); |
|
522 |
} |
|
523 |
return $xfoot; |
|
524 |
} |
|
525 |
|
|
472 | 526 |
|
473 | 527 |
function _cdm_get_taxonuuid(){ |
474 | 528 |
|
... | ... | |
480 | 534 |
} |
481 | 535 |
|
482 | 536 |
return $taxon_uuid; |
537 |
} |
|
538 |
|
|
539 |
function _hsv_2_rgb($H, $S, $V) // HSV Values:Number 0-1 |
|
540 |
{ // RGB Results:Number 0-255 |
|
541 |
$RGB = array(); |
|
542 |
|
|
543 |
if($S == 0) |
|
544 |
{ |
|
545 |
$R = $G = $B = $V * 255; |
|
546 |
} |
|
547 |
else |
|
548 |
{ |
|
549 |
$var_H = $H * 6; |
|
550 |
$var_i = floor( $var_H ); |
|
551 |
$var_1 = $V * ( 1 - $S ); |
|
552 |
$var_2 = $V * ( 1 - $S * ( $var_H - $var_i ) ); |
|
553 |
$var_3 = $V * ( 1 - $S * (1 - ( $var_H - $var_i ) ) ); |
|
554 |
|
|
555 |
if ($var_i == 0) { $var_R = $V ; $var_G = $var_3 ; $var_B = $var_1 ; } |
|
556 |
else if ($var_i == 1) { $var_R = $var_2 ; $var_G = $V ; $var_B = $var_1 ; } |
|
557 |
else if ($var_i == 2) { $var_R = $var_1 ; $var_G = $V ; $var_B = $var_3 ; } |
|
558 |
else if ($var_i == 3) { $var_R = $var_1 ; $var_G = $var_2 ; $var_B = $V ; } |
|
559 |
else if ($var_i == 4) { $var_R = $var_3 ; $var_G = $var_1 ; $var_B = $V ; } |
|
560 |
else { $var_R = $V ; $var_G = $var_1 ; $var_B = $var_2 ; } |
|
561 |
|
|
562 |
$R = $var_R * 255; |
|
563 |
$G = $var_G * 255; |
|
564 |
$B = $var_B * 255; |
|
565 |
} |
|
566 |
|
|
567 |
$RGB['R'] = $R; |
|
568 |
$RGB['G'] = $G; |
|
569 |
$RGB['B'] = $B; |
|
570 |
|
|
571 |
return $RGB; |
|
483 | 572 |
} |
Also available in: Unified diff
taxon tree: autoscroll enabled, tree div enlarges on mousover