Parcourir la source

loadData by syncUrl in TableAjax

Piotr Labudda il y a 9 ans
Parent
commit
7158b64dee
2 fichiers modifiés avec 39 ajouts et 41 suppressions
  1. 37 39
      SE/se-lib/Route/ViewTableAjax.php
  2. 2 2
      SE/se-lib/TableAjax.php

+ 37 - 39
SE/se-lib/Route/ViewTableAjax.php

@@ -10,9 +10,34 @@ Lib::loadClass('Api_WfsNs');
 Lib::loadClass('Core_AclHelper');
 Lib::loadClass('Route_UrlAction');
 Lib::loadClass('Router');
+Lib::loadClass('Typespecial');
+Lib::loadClass('UserProfile');
 
 class Route_ViewTableAjax extends RouteBase {
 
+	public function getTableAjaxWidget($acl) {
+		$syncUrl = Request::getPathUri() . 'index.php?_route=ViewTableAjax&namespace=' . $acl->getNamespace();
+		$tbl = new TableAjax($acl);
+		$tblLabel = $acl->getNamespace();
+		if ('default_db' == $acl->getSourceName()) {
+			$tblLabel = array();
+			$zasobObj = ProcesHelper::getZasobTableInfo($acl->getID());
+			if (!$zasobObj) throw new Exception("Zasob TABELA ID=" . $acl->getID() . " nie istnieje");
+			if (!empty($zasobObj->DESC_PL)) $tblLabel []= $zasobObj->DESC_PL;
+			if (!empty($zasobObj->OPIS))    $tblLabel []= $zasobObj->OPIS;
+			$tblLabel = implode(" - ", $tblLabel);
+		}
+		$tbl->setSyncUrl($syncUrl);
+		$tbl->setLabel($tblLabel);
+		$tbl->setFilterInit($filterInit);
+		$tbl->addRowFunction('edit');
+		$tbl->addRowFunction('hist');
+		$tbl->addRowFunction('files');
+		$tbl->addRowFunction('cp');
+		$tbl->addRowFunction('msgs');
+		return $tbl;
+	}
+
 	public function defaultAction() {
 		UI::gora();
 		UI::menu();
@@ -42,16 +67,9 @@ class Route_ViewTableAjax extends RouteBase {
 				}
 			}
 
-			$tbl = new TableAjax($acl);
-			$tblLabel = $typeName;
-			if ('default_db' == $acl->getSourceName()) {
-				$tblLabel = array();
-				$zasobObj = ProcesHelper::getZasobTableInfo($acl->getID());
-				if (!$zasobObj) throw new Exception("Zasob TABELA ID=" . $acl->getID() . " nie istnieje");
-				if (!empty($zasobObj->DESC_PL)) $tblLabel []= $zasobObj->DESC_PL;
-				if (!empty($zasobObj->OPIS))    $tblLabel []= $zasobObj->OPIS;
-				$tblLabel = implode(" - ", $tblLabel);
-			}
+			$tbl = $this->getTableAjaxWidget($acl);
+			if (!empty($forceFilterInit)) $tbl->setForceFilterInit($forceFilterInit);
+			echo $tbl->render();
 
 			if (DBG::isActive() && V::get('DBG_ACL', '', $_GET)) {// test load perms
 				Lib::loadClass('DebugExecutionTime');
@@ -103,17 +121,6 @@ class Route_ViewTableAjax extends RouteBase {
 				$dbgExecTime->printDebug();
 				UI::endContainer();
 			}
-
-			$tbl->setSyncUrl(Request::getPathUri() . 'index.php?_route=ViewTableAjax&namespace=' . $acl->getNamespace());
-			$tbl->setLabel($tblLabel);
-			$tbl->setFilterInit($filterInit);
-			if (!empty($forceFilterInit)) $tbl->setForceFilterInit($forceFilterInit);
-			$tbl->addRowFunction('edit');
-			$tbl->addRowFunction('hist');
-			$tbl->addRowFunction('files');
-			$tbl->addRowFunction('cp');
-			$tbl->addRowFunction('msgs');
-			echo $tbl->render();
 		} catch (Exception $e) {
 			UI::startContainer();
 			UI::alert('danger', "<strong>Wystąpiły błędy!</strong> " . $e->getMessage());
@@ -255,24 +262,7 @@ class Route_ViewTableAjax extends RouteBase {
 		$namespace = V::get('namespace', '', $args, 'word');
 		if (!$namespace) throw new HttpException("Bad Request - missing namespace", 400);
 		$acl = Core_AclHelper::getAclByNamespace($namespace);
-		$tbl = new TableAjax($acl);
-		$tblLabel = $typeName;
-		if ('default_db' == $acl->getSourceName()) {
-			$tblLabel = array();
-			$zasobObj = ProcesHelper::getZasobTableInfo($acl->getID());
-			if (!$zasobObj) throw new Exception("Zasob TABELA ID=" . $acl->getID() . " nie istnieje");
-			if (!empty($zasobObj->DESC_PL)) $tblLabel []= $zasobObj->DESC_PL;
-			if (!empty($zasobObj->OPIS))    $tblLabel []= $zasobObj->OPIS;
-			$tblLabel = implode(" - ", $tblLabel);
-		}
-
-		$tbl->setSyncUrl(Request::getPathUri() . 'index.php?_route=ViewTableAjax&namespace=' . $acl->getNamespace());
-		$tbl->setLabel($tblLabel);
-		$tbl->addRowFunction('edit');
-		$tbl->addRowFunction('hist');
-		$tbl->addRowFunction('files');
-		$tbl->addRowFunction('cp');
-		$tbl->addRowFunction('msgs');
+		$tbl = $this->getTableAjaxWidget($acl);
 		$tbl->sendAjaxEdit($id, $args);
 	}
 	public function editSaveAjaxAction() {
@@ -318,6 +308,14 @@ class Route_ViewTableAjax extends RouteBase {
 		return $response;
 	}
 
+	public function loadDataAjaxAction() {
+		$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);
+		Response::sendTryCatchJson(array($tbl, 'ajaxData'), $args = $_GET);
+	}
+
 	/**
 	 * @param string $typeName - 'p5_default_db:TEST_PERMS'
 	 */

+ 2 - 2
SE/se-lib/TableAjax.php

@@ -3180,7 +3180,7 @@ var p5UI_TableAjax_generateFunctionNode = function(funObj, rowPK, props) {
 			_uiNode$Table.parent().parent().addClass('AjaxTable-loading');
 
 			$.ajax({
-				url: 'index-ajax.php?_zasobID=<?php echo $this->_zasobID; ?>&_cls=<?php echo __CLASS__; ?>&_hash=<?php echo $this->_htmlID; ?>',
+				url: '<?= $this->syncUrl; ?>&_hash=<?= $this->_htmlID; ?>&_task=loadDataAjax',
 				type: 'GET',
 				dataType: 'json',
 				contentType: "application/json; charset=utf-8",
@@ -5759,7 +5759,7 @@ jQuery(document).ready(function(){
 		exit;
 	}
 
-	private function ajaxData($args) {
+	public function ajaxData($args) {
 		$DBG = ('1' == V::get('DBG', '', $_REQUEST));
 
 		$pageSize = V::get('pageSize', $this->_pageSize, $args, 'int');