Piotr Labudda пре 8 година
родитељ
комит
59e0210b70
3 измењених фајлова са 117 додато и 10 уклоњено
  1. 30 0
      SE/se-lib/Route/ViewTableAjax.php
  2. 35 10
      SE/se-lib/TableAjax.php
  3. 52 0
      SE/se-lib/TableAjax.php.tableTools.js

+ 30 - 0
SE/se-lib/Route/ViewTableAjax.php

@@ -29,6 +29,7 @@ class Route_ViewTableAjax extends RouteBase {
 		}
 		$tbl->setSyncUrl($syncUrl);
 		$tbl->showProcesInitFiltr = $this->getLink("procesInitFiltrAjax", [ 'namespace' => $acl->getNamespace() ]);
+		$tbl->showTableTools = $this->getLink("tableToolsAjax", [ 'namespace' => $acl->getNamespace() ]);
 		$tbl->useUserTableFilter = $this->getLink("getUserTableFilterAjax");
 		$tbl->setLabel($tblLabel);
 		$tbl->addRowFunction('edit');
@@ -925,4 +926,33 @@ class Route_ViewTableAjax extends RouteBase {
 		];
 	}
 
+	public function tableToolsAjaxAction() {
+		Response::sendTryCatchJson([$this, 'tableToolsAjax'], $args = $_GET);
+	}
+	public function tableToolsAjax($args) { // ajaxFileRemove
+		$namespace = V::get('namespace', '', $args, 'word');
+		if (!$namespace) throw new Exception("Missing namespace");
+		$acl = Core_AclHelper::getAclByNamespace($namespace, $forceTblAclInit = ('1' == V::get('_force', '', $_GET)));
+
+		$listUrlFunctions = Route_UrlAction::getTableFunctions($acl->getID(), $idRecord = 0, $acl->getName(), User::getLogin());
+		DBG::log($listUrlFunctions, 'array', "\$listUrlFunctions");
+
+		return [
+			'type' => "success",
+			'msg' => 'ok',
+			'body' => [
+				'tableTools' => array_values(array_map(function ($urlFunction) {
+					return [
+						'url' => $urlFunction['baseLink'],
+						'label' => $urlFunction['label'],
+						// TODO: $urlFunction['link_target'] // "_blank"
+						// ? $urlFunction['name']
+					];
+				}, array_filter($listUrlFunctions, function ($urlFunction) {
+					return empty($urlFunction['cell_id_params']);
+				}))),
+			],
+		];
+	}
+
 }

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

@@ -24,6 +24,7 @@ class TableAjax extends ViewAjax {
 	public $_filterInit = null;
 	public $_forceFilterInit = null;
 	public $showProcesInitFiltr = null;
+	public $showTableTools = null;
 	public $useUserTableFilter = false;
 	public $syncUrl = null;
 
@@ -391,6 +392,7 @@ class TableAjax extends ViewAjax {
 		$hasPermCreate = Core_AclHelper::hasCreatePerms($acl);
 
 		$jsToogleFiltrProcesuFunctionName = 'tableAjaxToggleFiltrProcesInit';
+		$jsToogleTableToolsFunctionName = 'tableAjaxToggleTableTools';
 		ob_start();
 		$this->renderStatic($tblAjaxMap);
 		UI::startContainer();
@@ -415,10 +417,10 @@ class TableAjax extends ViewAjax {
 				if ($this->showProcesInitFiltr) {
 					echo UI::h('div', [ 'class' => "btn-group pull-right" ], [
 						UI::h('a', [ 'class' => "btn btn-xs btn-info dropdown-toggle",
-							 'data-toggle' => "dropdown",
-							 'href' => "#",
-							 'title' => "Uruchom filtr procesu powiązanego z tabelą " . $this->getLabel(),
-							 'onclick' => "return {$jsToogleFiltrProcesuFunctionName}(this);",
+							'data-toggle' => "dropdown",
+							'href' => "#",
+							'title' => "Uruchom filtr procesu powiązanego z tabelą " . $this->getLabel(),
+							'onclick' => "return {$jsToogleFiltrProcesuFunctionName}(this);",
 						 ], "Filtr procesu <span class=\"caret\"></span>"),
 						UI::h('ul', [ 'class' => "dropdown-menu pull-left", 'style' => "max-height:250px;overflow:auto;" ], [
 							UI::h('li', [ 'class' => "disabled" ], [
@@ -427,6 +429,22 @@ class TableAjax extends ViewAjax {
 						]),
 					]);
 				}
+				if ($this->showTableTools) {
+					echo UI::h('div', [ 'class' => "btn-group pull-right" ], [
+						UI::h('a', [ 'class' => "btn btn-xs btn-default dropdown-toggle",
+							'style' => "margin-right:16px",
+							'data-toggle' => "dropdown",
+							'href' => "#",
+							'title' => "Narzędzia powiązane z tabelą " . $this->getLabel(),
+							'onclick' => "return {$jsToogleTableToolsFunctionName}(this);",
+						 ], "Narzędzia <span class=\"caret\"></span>"),
+						UI::h('ul', [ 'class' => "dropdown-menu pull-left", 'style' => "max-height:250px;overflow:auto;" ], [
+							UI::h('li', [ 'class' => "disabled" ], [
+								UI::h('a', [ 'href' => "#", 'onclick' => "return false;" ], " loading ... "),
+							]),
+						]),
+					]);
+				}
 				?>
 				<?php if ($this->_tbl == 'IN7_MK_BAZA_DYSTRYBUCJI') : ?>
 					<a class="pull-right" style="padding:0 20px 0 0;" href="<?= "index.php?MENU_INIT=TREEJS&ZASOB_ID={$this->_zasobID}"; ?>"><i class="glyphicon glyphicon-eye-open"></i> Drzewo</a>
@@ -442,12 +460,19 @@ class TableAjax extends ViewAjax {
 		<?php
 		UI::inlineJS(__FILE__ . '.generateFunctionNode.js');
 		UI::inlineJS(__FILE__ . '.GeomField.js');
-		$clsName = __CLASS__;
-		UI::inlineJS(__FILE__ . '.procesInitFiltr.js', [
-			'JS_FUNCTION_NAME' => $jsToogleFiltrProcesuFunctionName,
-			'URL_GET_PROCES_INIT_FILTR' => $this->showProcesInitFiltr,
-			'ID_ZASOB' => $this->_zasobID,
-		]);
+		if ($this->showProcesInitFiltr) {
+			UI::inlineJS(__FILE__ . '.procesInitFiltr.js', [
+				'JS_FUNCTION_NAME' => $jsToogleFiltrProcesuFunctionName,
+				'URL_GET_PROCES_INIT_FILTR' => $this->showProcesInitFiltr,
+				'ID_ZASOB' => $this->_zasobID,
+			]);
+		}
+		if ($this->showTableTools) {
+			UI::inlineJS(__FILE__ . '.tableTools.js', [
+				'JS_FUNCTION_NAME' => $jsToogleTableToolsFunctionName,
+				'URL_GET_TABLE_TOOLS' => $this->showTableTools,
+			]);
+		}
 		?>
 		<script>
 (function($, undefined) {

+ 52 - 0
SE/se-lib/TableAjax.php.tableTools.js

@@ -0,0 +1,52 @@
+// @require variables:
+if ('undefined' === typeof JS_FUNCTION_NAME) throw "Missing JS_FUNCTION_NAME";
+if ('undefined' === typeof URL_GET_TABLE_TOOLS) throw "Missing URL_GET_TABLE_TOOLS";
+
+function toggleTableTools(n) {
+	var $n = jQuery(n);
+	var $ul = $n.next();
+	if ($n.data('fetched')) return false;
+
+	function renderTableToolsData(tableTools) {
+		var procesInitMapHtml = '';
+		if (!tableTools) {
+			return '<li><a href="#">' + "Brak danych" + '</a></li>';
+		} else if (!tableTools.length) {
+			return '<li><a href="#">' + "Brak narzędzi dla tej tabeli" + '</a></li>';
+		} else {
+			return tableTools.map(function (tool) {
+				return '<li><a href="' + tool.url + '">' + tool.label + '</a></li>';
+			})
+		}
+		return procesInitMapHtml;
+	}
+
+	window.fetch(URL_GET_TABLE_TOOLS, {
+		method: 'GET',
+		credentials: 'same-origin',
+	}).then(function (response) {
+		return response.json()
+	}).then(function (data) {
+		var type = data.type || null
+		var msg = data.msg || "Error"
+		var tableTools = (data.body && data.body.tableTools) ? data.body.tableTools : null
+		if (type) {
+			if ('success' == type) {
+				$ul.html(renderTableToolsData(tableTools));
+			} else if ('error' == type) {
+				$ul.html('<li><a href="#">' + msg + '</a></li>');
+			} else {
+				$ul.html('<li><a href="#">Wystapił błąd podczas pobierania listy narzędzi</a></li>');
+			}
+		} else {
+			$ul.html('<li><a href="#">Wystapił błąd podczas pobierania listy narzędzi</a></li>');
+		}
+		$n.data('fetched', true);
+	}).catch(function (e) {
+		console.warn(e)
+	})
+	return false;
+}
+
+
+global[JS_FUNCTION_NAME] = toggleTableTools