Sfoglia il codice sorgente

added backRef filter to TableAjax

Piotr Labudda 8 anni fa
parent
commit
05424c2e3c
2 ha cambiato i file con 58 aggiunte e 6 eliminazioni
  1. 23 3
      SE/se-lib/Route/ViewTableAjax.php
  2. 35 3
      SE/se-lib/TableAjax.php

+ 23 - 3
SE/se-lib/Route/ViewTableAjax.php

@@ -15,9 +15,19 @@ Lib::loadClass('UserProfile');
 
 class Route_ViewTableAjax extends RouteBase {
 
-	public function getTableAjaxWidget($acl) {
+	public function getTableAjaxWidget($acl, $backRefFilter) {
 		$syncUrl = $this->getLink('', [ 'namespace' => $acl->getNamespace() ]);
 		$tbl = new TableAjax($acl);
+		$tbl->setRootUrl($syncUrl);
+		if (!empty($backRefFilter['namespace']) && !empty($backRefFilter['primaryKey'])) {
+			$tbl->setBackRefFilter($backRefFilter);
+			$syncUrl = $this->getLink('', [
+				'namespace' => $acl->getNamespace(),
+				'backRefNS' => $backRefFilter['namespace'],
+				'backRefPK' => $backRefFilter['primaryKey'],
+				'backRefField' => $backRefFilter['fieldName'],
+			]);
+		}
 		$tblLabel = $acl->getNamespace();
 		if ('default_db' == $acl->getSourceName()) {
 			$tblLabel = array();
@@ -69,7 +79,12 @@ class Route_ViewTableAjax extends RouteBase {
 				}
 			}
 
-			$tbl = $this->getTableAjaxWidget($acl);
+			$backRefFilter = [
+				'namespace' => V::get('backRefNS', '', $_GET),
+				'primaryKey' => V::get('backRefPK', '', $_GET),
+				'fieldName' => V::get('backRefField', '', $_GET),
+			];
+			$tbl = $this->getTableAjaxWidget($acl, $backRefFilter);
 			$tbl->setFilterInit($filterInit);
 			if (!empty($forceFilterInit)) $tbl->setForceFilterInit($forceFilterInit);
 			echo $tbl->render();
@@ -714,7 +729,12 @@ class Route_ViewTableAjax extends RouteBase {
 		$namespace = V::get('namespace', '', $_REQUEST, 'word');
 		if (!$namespace) throw new HttpException("Bad Request - missing namespace", 400);
 		$acl = Core_AclHelper::getAclByNamespace($namespace);
-		$tbl = $this->getTableAjaxWidget($acl);
+		$backRefFilter = [
+			'namespace' => V::get('backRefNS', '', $_REQUEST),
+			'primaryKey' => V::get('backRefPK', '', $_REQUEST),
+			'fieldName' => V::get('backRefField', '', $_REQUEST),
+		];
+		$tbl = $this->getTableAjaxWidget($acl, $backRefFilter);
 		Response::sendTryCatchJson(array($tbl, 'ajaxData'), $args = $_GET);
 	}
 

+ 35 - 3
SE/se-lib/TableAjax.php

@@ -52,9 +52,8 @@ class TableAjax extends ViewAjax {
 		}
 	}
 
-	public function setSyncUrl($syncUrl) {
-		$this->syncUrl = $syncUrl;
-	}
+	public function setSyncUrl($syncUrl) { $this->syncUrl = $syncUrl; }
+	public function setRootUrl($rootUrl) { $this->rootUrl = $rootUrl; }
 
 	private function _hasStateFilterInit() {
 		return array_key_exists($this->_htmlID, $_SESSION['TableAjax_Cache']) && array_key_exists('_filterInit', $_SESSION['TableAjax_Cache'][$this->_htmlID]);
@@ -122,6 +121,10 @@ class TableAjax extends ViewAjax {
 		$this->_pageSizes = $pageSizes;
 	}
 
+	public function setBackRefFilter($backRefFilter) {
+		$this->_backRefFilter = $backRefFilter;
+	}
+
 	public function setFilterInit($filterInit) {
 		if ($this->_hasStateFilterInit()) {
 			return;
@@ -455,6 +458,23 @@ class TableAjax extends ViewAjax {
 					<a class="pull-right" style="padding:0 20px 0 0;" href="<?= "index.php?_route=GeoreferencesManager"; ?>"><i class="glyphicon glyphicon glyphicon-wrench"></i> Zarządzaj punktami</a>
 				<?php endif; ?>
 			</ul>
+			<?php
+				if ($this->_backRefFilter) {
+					echo UI::h('div', [ 'class' => "container" ], [
+						UI::h('div', [ 'class' => "alert alert-info" ], [
+							"Rekordy powiązane z rekordem {$this->_backRefFilter['primaryKey']} z ",
+							UI::h('a', [
+								'href' => "index.php?_route=ViewTableAjax&namespace={$this->_backRefFilter['namespace']}",
+							], $this->_backRefFilter['namespace']),
+							" - ",
+							UI::h('a', [
+								'href' => $this->rootUrl,
+								'style' => "color:red",
+							], "usuń filtr"),
+						]),
+					]);
+				}
+			?>
 			<div id="<?= $this->_htmlID; ?>"></div>
 		</div>
 		<?php
@@ -1136,6 +1156,13 @@ class TableAjax extends ViewAjax {
 				}
 				if ('ref' === columnProps.type) showTooltip = false;
 				if ('ref' === columnProps.type) cellNode.css('padding', "3px")
+				if ('ref' === columnProps.type) console.log('renderRow rowPK('+rowPK+') columnProps', columnProps)
+				if ('ref' === columnProps.type) cellNode.html('<a href="index.php?_route=ViewTableAjax' +
+					'&namespace=' + columnProps.xsdRefNsPrefix.replace('__x3A__', '/') + '/' + columnProps.xsdRefType +
+					'&backRefNS=' + priv.options.namespace +
+					'&backRefPK=' + rowPK +
+					'&backRefField=' + columnProps.column +
+					'">przeglądaj</a>')
 
 				if (i > 1 && priv.options.longDesc) {// TODO: use better check for columns: functions and pk
 					cellNode.addClass('tbl-short-txt');
@@ -5474,6 +5501,11 @@ jQuery(document).ready(function(){
 			}
 		}
 
+		if ($this->_backRefFilter) {
+			$params['__backRef'] = $this->_backRefFilter;
+			DBG::log($params, 'array', '$params __backRef');
+		}
+
 		$filters = new stdClass();
 		$filters->currSortCol = $currSortCol;
 		$filters->currSortFlip = $currSortFlip;