diff options
| author | Greg Roach <fisharebest@gmail.com> | 2014-05-01 12:10:47 +0100 |
|---|---|---|
| committer | Greg Roach <fisharebest@gmail.com> | 2014-05-01 12:13:26 +0100 |
| commit | 0c252e23242bf218f4899b71b965b6a2f9b63d91 (patch) | |
| tree | 20a861ff1890b739fa8a159865bd51fcc415a169 | |
| parent | 23d12619cce7144016c79b4da61cc29ce6a2eca2 (diff) | |
| download | webtrees-0c252e23242bf218f4899b71b965b6a2f9b63d91.tar.gz webtrees-0c252e23242bf218f4899b71b965b6a2f9b63d91.tar.bz2 webtrees-0c252e23242bf218f4899b71b965b6a2f9b63d91.zip | |
Interactive tree/allpartners button only works in full-screen mode
| -rw-r--r-- | library/WT/Filter.php | 7 | ||||
| -rw-r--r-- | modules_v3/tree/class_treeview.php | 39 | ||||
| -rw-r--r-- | modules_v3/tree/js/treeview.js | 25 |
3 files changed, 31 insertions, 40 deletions
diff --git a/library/WT/Filter.php b/library/WT/Filter.php index 2eacb87b23..fa523b0d34 100644 --- a/library/WT/Filter.php +++ b/library/WT/Filter.php @@ -259,6 +259,13 @@ class WT_Filter { } ////////////////////////////////////////////////////////////////////////////// + // Validate COOKIE requests + ////////////////////////////////////////////////////////////////////////////// + public static function cookie($variable, $regexp=null, $default=null) { + return self::_input(INPUT_COOKIE, $variable, $regexp, $default); + } + + ////////////////////////////////////////////////////////////////////////////// // Cross-Site Request Forgery tokens - ensure that the user is submitting // a form that was generated by the current session. ////////////////////////////////////////////////////////////////////////////// diff --git a/modules_v3/tree/class_treeview.php b/modules_v3/tree/class_treeview.php index 4a18739eb9..f6cf96732c 100644 --- a/modules_v3/tree/class_treeview.php +++ b/modules_v3/tree/class_treeview.php @@ -24,8 +24,8 @@ if (!defined('WT_WEBTREES')) { } class TreeView { - var $name; - var $allPartners; + private $name; + private $allPartners; /** * Treeview Constructor @@ -33,18 +33,7 @@ class TreeView { */ function __construct($name='tree') { $this->name = $name; - - // Read if all partners must be shown or not - $allPartners = WT_Filter::get('allPartners'); - // if allPartners not specified in url, we try to read the cookie - if ($allPartners == '') { - if (isset($_COOKIE['allPartners'])) - $allPartners = $_COOKIE['allPartners']; - else - $allPartners = 'true'; // That is now the default value - } - $allPartners = ($allPartners == 'true' ? true : false); - $this->allPartners = $allPartners; + $this->allPartners = WT_Filter::cookie('allPartners', 'true|false', 'true'); } /** @@ -54,19 +43,17 @@ class TreeView { * @param int $generations number of generations to draw */ public function drawViewport(WT_Individual $rootPerson, $generations) { - global $GEDCOM, $controller; - if (WT_SCRIPT_NAME == 'individual.php') { - $path = 'individual.php?pid='.$rootPerson->getXref().'&ged='.$GEDCOM.'&allPartners='.($this->allPartners ? "false" : "true").'#tree'; + $path = $rootPerson->getHtmlUrl(); } else { - $path = 'module.php?mod=tree&mod_action=treeview&rootid='.$rootPerson->getXref().'&allPartners='.($this->allPartners ? "false" : "true"); + $path = 'module.php?mod=tree&mod_action=treeview&rootid=' . $rootPerson->getXref(); } $r = '<a name="tv_content"></a><div id="'.$this->name.'_out" class="tv_out">'; // Add the toolbar $r.='<div id="tv_tools" class="noprint"><ul>'. '<li id="tvbCompact" class="tv_button"><img src="'.WT_STATIC_URL.WT_MODULES_DIR.'tree/images/compact.png" alt="'.WT_I18N::translate('Use compact layout').'" title="'.WT_I18N::translate('Use compact layout').'"></li>'. - '<li class="tv_button'.($this->allPartners ? ' tvPressed' : '').'"><a class="icon-sfamily" href="'.$path.'" title="'.WT_I18N::translate('Show all spouses and ancestors').'"></a></li>'; + '<li id="tvbAllPartners" class="tv_button' . ($this->allPartners === 'true' ? ' tvPressed' : '') . '"><a class="icon-sfamily" href="' . $path . '" title="'.WT_I18N::translate('Show all spouses and ancestors').'"></a></li>'; // Hidden loading image $r.='<li class="tv_button" id="'.$this->name.'_loading"><i class="icon-loading-small"></i></li></ul>'; $r.='</div><h2 id="tree-title">'. @@ -75,7 +62,7 @@ class TreeView { $parent = null; $r.=$this->drawPerson($rootPerson, $generations, 0, $parent, '', true); $r.='</div></div>'; // Close the tv_in and the tv_out div - return array($r, 'var '.$this->name.'Handler = new TreeViewHandler("'.$this->name.'", '.($this->allPartners ? 'true' : 'false').');'); + return array($r, 'var ' . $this->name . 'Handler = new TreeViewHandler("' . $this->name.'");'); } /** @@ -132,7 +119,7 @@ class TreeView { */ private function getPersonDetails($personGroup, $individual, $family) { $r = $this->getThumbnail($personGroup, $individual); - $r .= '<a class="tv_link" href="'.$individual->getHtmlUrl().'">'.$individual->getFullName().'</a> <a href="module.php?mod=tree&mod_action=treeview&allPartners='.($this->allPartners ? 'true' : 'false').'&rootid='.$individual->getXref().'" title="'.WT_I18N::translate('Interactive tree of %s', strip_tags($individual->getFullName())).'" class="icon-button_indi tv_link tv_treelink"></a>'; + $r .= '<a class="tv_link" href="'.$individual->getHtmlUrl().'">'.$individual->getFullName().'</a> <a href="module.php?mod=tree&mod_action=treeview&rootid='.$individual->getXref().'" title="'.WT_I18N::translate('Interactive tree of %s', strip_tags($individual->getFullName())).'" class="icon-button_indi tv_link tv_treelink"></a>'; foreach ($individual->getFacts(WT_EVENTS_BIRT, true) as $fact) { $r .= $fact->summary(); } @@ -211,7 +198,7 @@ class TreeView { global $TEXT_DIRECTION; if ($gen < 0 || empty($person)) { - return; + return ''; } if (!empty($pfamily)) { $partner = $pfamily->getSpouse($person); @@ -247,13 +234,13 @@ class TreeView { foreach ($sfams as $famid=>$family) { $p = $family->getSpouse($person); if ($p) { - if (($p === $partner) || $this->allPartners) { + if (($p === $partner) || $this->allPartners === 'true') { $pf = $p->getPrimaryChildFamily(); if (!empty($pf)) { $fop[] = Array($pf->getHusband(), $pf); } $r .= $this->drawPersonName($p, $dashed); - if (!$this->allPartners) { + if ($this->allPartners !== 'true') { break; // we can stop here the foreach loop } $dashed = 'dashed'; @@ -288,7 +275,7 @@ class TreeView { $nb = count($fop); foreach($fop as $p) { $n++; - $u = ($unique ? 'c' : ($n == $nb || empty($p[1]) || !$this->allPartners ? 'b' : 'h')); + $u = ($unique ? 'c' : ($n == $nb || empty($p[1]) || $this->allPartners === 'true' ? 'h' : 'b')); $r .= '<tr><td '.($gen == 0 ? ' abbr="p'.$p[1]->getXref().'@'.$u.'"' : '').'>'.$this->drawPerson($p[0], $gen-1, 1, $p[1], $u).'</td></tr>'; } } @@ -310,7 +297,7 @@ class TreeView { * @param $dashed if = 'dashed' print dashed top border to separate multiple spuses */ private function drawPersonName($p, $dashed='') { - if ($this->allPartners) { + if ($this->allPartners === 'true') { $f = $p->getPrimaryChildFamily(); if ($f) { switch ($p->getSex()) { diff --git a/modules_v3/tree/js/treeview.js b/modules_v3/tree/js/treeview.js index c02f0611c1..87e7efd88e 100644 --- a/modules_v3/tree/js/treeview.js +++ b/modules_v3/tree/js/treeview.js @@ -17,7 +17,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -function TreeViewHandler(treeviewInstance, allPartners) { +function TreeViewHandler(treeviewInstance) { this.treeview = jQuery("#" + treeviewInstance + "_in"); this.loadingImage = jQuery("#" + treeviewInstance + "_loading"); this.toolbox = jQuery("#tv_tools"); @@ -25,9 +25,8 @@ function TreeViewHandler(treeviewInstance, allPartners) { this.zoom = 100; // in percent this.boxWidth = 180; // default family box width this.boxExpandedWidth = 250; // default expanded family box width - this.cookieDays = 360; // lifetime of preferences memory, in days + this.cookieDays = 3; // lifetime of preferences memory, in days this.ajaxUrl = "module.php?mod=tree&instance=" + treeviewInstance + - "&allPartners=" + (allPartners ? "true" : "false") + "&mod_action="; this.container = this.treeview.parent(); // Store the container element ("#" + treeviewInstance + "_out") @@ -41,10 +40,6 @@ function TreeViewHandler(treeviewInstance, allPartners) { if (readCookie("compact") == "true") { tv.compact(); } - // set/reset the cookie allPartners - if (readCookie("allPartners") != allPartners) { - createCookie("allPartners", allPartners, this.cookieDays); - } // Define the draggables tv.treeview.draggable({ @@ -60,6 +55,12 @@ function TreeViewHandler(treeviewInstance, allPartners) { tv.compact(); } }); + // If we click the "hide/show all partners" button, toggle the setting before reloading the page + tv.toolbox.find("#tvbAllPartners").each(function(index, tvAllPartners) { + tvAllPartners.onclick = function() { + createCookie("allPartners", readCookie("allPartners") === "true" ? "false" : "true", tv.cookieDays); + } + }); tv.toolbox.find("#tvbOpen").each(function(index, tvbOpen) { var b = jQuery(tvbOpen, tv.toolbox); tvbOpen.onclick = function() { @@ -90,7 +91,6 @@ function TreeViewHandler(treeviewInstance, allPartners) { }); tv.centerOnRoot(); // fire ajax update if needed, which call setComplete() when all is loaded - return false; } /** * Class TreeView setLoading method @@ -176,7 +176,7 @@ TreeViewHandler.prototype.updateTree = function(center, button) { tv.treeview.find(".tv_box").css("width", "auto"); } tv.updating = true; // avoid an unuseful recursive call when all requested persons are loaded - if (center == true) { + if (center) { tv.centerOnRoot(); } if (button) { @@ -203,7 +203,7 @@ TreeViewHandler.prototype.updateTree = function(center, button) { }; /** - * Class TreeView compacte method + * Class TreeView compact method */ TreeViewHandler.prototype.compact = function() { var tv = this; @@ -341,7 +341,4 @@ function readCookie(name) { } } return null; -} -function eraseCookie(name) { - createCookie(name,"",-1); -} +}
\ No newline at end of file |
