Przeglądaj źródła

added ViewTableAjax route with typeName arg

Piotr Labudda 9 lat temu
rodzic
commit
bac93306c4

+ 17 - 9
SE/se-lib/ProcesMenu.php

@@ -327,17 +327,25 @@ jQuery(document).ready(function() {
 		$tbls = $userAcl->getTablesAcl();
 		$urls = $userAcl->getUrls();
 
-		$outMenus = array();
+		$outMenus = array();// typeName => label (order by label)
+		$rawOutMenus = array();
+		$labelsOutMenus = array();
 		$outBtnsMenus = array();
+		$typeNameToIdZasob = array();// $typeName => $idZasob
 		if (!empty($tbls)) {
 			foreach ($tbls as $kZasobID => $vTblAcl) {
-				$outMenus[$kZasobID] = $vTblAcl->getLongLabel();
+				$tblName = $vTblAcl->getName();
+				$typeName = "p5_default_db:{$tblName}";
+				$labelsOutMenus[$typeName] = $vTblAcl->getLongLabel();
+				$rawOutMenus[$typeName] = strtolower($vTblAcl->getLongRawLabel());
+				$typeNameToIdZasob[$typeName] = $kZasobID;
 				if ($userAcl->getPermsFiltrProcesId()) {
-					$outBtnsMenus[$kZasobID] = $vTblAcl->getRawLabel();
+					$outBtnsMenus[$typeName] = $vTblAcl->getRawLabel();
 				}
 			}
 		}
-		asort($outMenus);
+		asort($rawOutMenus);
+		foreach ($rawOutMenus as $typeName => $rawLongLabel) $outMenus[$typeName] = $labelsOutMenus[$typeName];
 		if ($userAcl->getPermsFiltrProcesId()) {
 			asort($outBtnsMenus);
 		}
@@ -437,11 +445,11 @@ jQuery(document).ready(function() {
 				<li class="dropdown<?php if ($active == 'menu') echo ' active'; ?>">
 					<a href="#" class="dropdown-toggle" data-toggle="dropdown">Menu <b class="caret"></b></a>
 					<ul class="dropdown-menu" id="SE-menu-tables">
-						<?php foreach ($outMenus as $kZasobID => $vName) : ?>
+						<?php foreach ($outMenus as $typeName => $vName) : $kZasobID = $typeNameToIdZasob[$typeName]; ?>
 							<li>
-								<a href="index.php?MENU_INIT=VIEWTABLE_AJAX&ZASOB_ID=<?php echo $kZasobID; ?>">
-									<i class="bookmark-item-add-<?php echo $kZasobID; ?> bookmark-item-add glyphicon glyphicon-star-empty" title="Add to favorites" data-zasobid="<?php echo $kZasobID; ?>"></i>
-									<i class="bookmark-item-rem-<?php echo $kZasobID; ?> bookmark-item-rem glyphicon glyphicon-star" style="display:none" title="Remove from favorites" data-zasobid="<?php echo $kZasobID; ?>"></i>
+								<a href="index.php?_route=ViewTableAjax&typeName=<?= $typeName; ?>">
+									<i class="bookmark-item-add-<?= $kZasobID; ?> bookmark-item-add glyphicon glyphicon-star-empty" title="Add to favorites" data-zasobid="<?= $kZasobID; ?>"></i>
+									<i class="bookmark-item-rem-<?= $kZasobID; ?> bookmark-item-rem glyphicon glyphicon-star" style="display:none" title="Remove from favorites" data-zasobid="<?= $kZasobID; ?>"></i>
 									<?php echo $vName; ?>
 								</a>
 							</li>
@@ -940,7 +948,7 @@ jQuery(document).ready(function() {
 						l.addClass('btn-default');
 					}
 					if (item.type == 'menu') {
-						l.attr('href', 'index.php?MENU_INIT=VIEWTABLE_AJAX&ZASOB_ID=' + item.id);
+						l.attr('href', 'index.php?_route=ViewTableAjax&typeName=' + 'p5_default_db:' + item.name);
 						if ('label' in item && item.label.length > 0) {
 							label = item.label;
 							title = item.label + ' (' + item.name + ')';

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

@@ -0,0 +1,79 @@
+<?php
+
+Lib::loadClass('RouteBase');
+Lib::loadClass('ProcesHelper');
+Lib::loadClass('TableAjax');
+// Lib::loadClass('Request');
+// Lib::loadClass('Response');
+Lib::loadClass('UI');
+
+class Route_ViewTableAjax extends RouteBase {
+
+	public function defaultAction() {
+		UI::gora();
+		UI::menu();
+		try {
+
+			$typeName = V::get('typeName', '', $_GET, 'word');
+			if (!$typeName) throw new Exception("Wrong param typeName");
+			$tblAcl = $this->getAclFromTypeName($typeName, $forceTblAclInit = ('1' == V::get('_force', '', $_GET)));
+
+			$forceFilterInit = array();
+			$filterInit = new stdClass();
+			$filterInit->currSortCol = 'ID';
+			$filterInit->currSortFlip = 'desc';
+			foreach ($_GET as $k => $v) {
+				if (strlen($k) > 3 && substr($k, 0, 2) == 'f_' && !empty($v)) {// filter prefix
+					$filterInit->$k = $v;
+				}
+				else if (strlen($k) > 4 && substr($k, 0, 3) == 'sf_' && !empty($v)) {// special filter prefix
+					$filterInit->$k = $v;
+				}
+				else if (strlen($k) > 4 && substr($k, 0, 3) == 'ff_' && !empty($v)) {// force filter prefix
+					$fldName = substr($k, 3);
+					$forceFilterInit[$fldName] = $v;
+				}
+			}
+
+			$tbl = new TableAjax($tblAcl);
+			$tblLabel = array();
+			$zasobObj = ProcesHelper::getZasobTableInfo($tblAcl->getID());
+			if (!$zasobObj) throw new Exception("Zasob TABELA ID=" . $tblAcl->getID() . " nie istnieje");
+			if (!empty($zasobObj->DESC_PL)) $tblLabel []= $zasobObj->DESC_PL;
+			if (!empty($zasobObj->OPIS))    $tblLabel []= $zasobObj->OPIS;
+			$tblLabel = implode(" - ", $tblLabel);
+			$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());
+			UI::endContainer();
+		}
+		UI::dol();
+	}
+
+	/**
+	 * @param string $typeName - 'p5_default_db:TEST_PERMS'
+	 */
+	public function getAclFromTypeName($typeName, $forceTblAclInit) {
+		$userAcl = User::getAcl();
+		$userAcl->fetchGroups();
+		$typeEx = explode(':', $typeName);
+		if (2 != count($typeEx)) throw new Exception("Could not get acl for '{$typeName}' - syntax error");
+		if ('p5_' != substr($typeEx[0], 0, 3)) throw new Exception("Could not get acl for '{$typeName}' - prefix error");
+		$sourceName = substr($typeEx[0], 3);
+		$objName = $typeEx[1];
+		$acl = $userAcl->getObjectAcl($sourceName, $objName);
+		if (!$acl) throw new Exception("Could not get acl for '{$typeName}'");
+		$acl->init($forceTblAclInit);
+		return $acl;
+	}
+
+}

+ 9 - 0
SE/se-lib/TableAcl.php

@@ -122,6 +122,15 @@ class TableAcl {
 		return $longLabel;
 	}
 
+	public function getLongRawLabel($posLimit = 30) {
+		$longLabel = $this->getRawLabel($posLimit);
+		$opis = $this->_opis;
+		if ($longLabel != $this->_name) {
+			$longLabel .= ' ' . $this->_name;
+		}
+		return $longLabel;
+	}
+
 	public function setDB($db) {
 		$this->_db = $db;
 	}

+ 7 - 5
SE/se-lib/TableAjax.php

@@ -11,6 +11,8 @@ Lib::loadClass('ProcesHelper');
 Lib::loadClass('Router');
 Lib::loadClass('Route_UrlAction');
 
+// TODO: change all links: MENU_INIT=VIEWTABLE_AJAX&ZASOB_ID={idZasob} to _route=ViewTableAjax&typeName=p5_default_db:{tableName}
+
 class TableAjax extends ViewAjax {
 
 	private $_cnf = '';// Column
@@ -3071,8 +3073,8 @@ var p5UI_TableAjax_generateFunctionNode = function(funObj, rowPK, props) {
 				success: function(req){
 					if (_.get(req, 'data.tbl_id') > 0) {
 						var addHtml = '';
-						for(var i in req.data.items){
-							var url = 'index.php?MENU_INIT=VIEWTABLE_AJAX';
+						for (var i in req.data.items) {
+							var url = 'index.php?MENU_INIT=VIEWTABLE_AJAX';// TODO: change to _route=ViewTableAjax&typeName=p5_default_db:{tblName}
 							url += '&ZASOB_ID=' + req.data.tbl_id;
 							url += '&f_' + req.data.fld_name + '=' + req.data.items[i].id;
 							url += '&_hash=' + Math.random().toString(36).substring(2);
@@ -3662,7 +3664,7 @@ function <?php echo $jsToogleFiltrProcesuFunctionName; ?>(n) {
 			function _viewProcesInitListItem(pInitId, gotoIds, pInitList) {
 				var label = pInitList[pInitId];
 				var jsInfo = "window.open('procesy5.php?task=PROCES_VIEW_LIST&id_proces=" + pInitId + "&HIDE_PANEL=0&show_big_img=1&group_stanowiska=1');return false;";
-				var out = '<a href="index.php?FUNCTION_INIT=MENU_SELECT_PROCES&_action=setPermsByProces&id_proces=' + pInitId + '&MENU_INIT=VIEWTABLE_AJAX&ZASOB_ID=<?php echo $this->_zasobID; ?>" title="' + "{" + pInitId + "} " + label + '">';
+				var out = '<a href="index.php?FUNCTION_INIT=MENU_SELECT_PROCES&_action=setPermsByProces&id_proces=' + pInitId + '&MENU_INIT=VIEWTABLE_AJAX&ZASOB_ID=<?php echo $this->_zasobID; ?>" title="' + "{" + pInitId + "} " + label + '">';// TODO: change to _route=ViewTableAjax&typeName=p5_default_db:{tblName}
 					out += ' <i class="glyphicon glyphicon-info-sign"';
 						out += ' onclick="' + jsInfo + '"';
 						out += ' style="color:#aaa;"';
@@ -3676,7 +3678,7 @@ function <?php echo $jsToogleFiltrProcesuFunctionName; ?>(n) {
 				var label = pInitList[gotoId];
 				var jsInfo = "window.open('procesy5.php?task=PROCES_VIEW_LIST&id_proces=" + gotoId + "&HIDE_PANEL=0&show_big_img=1&group_stanowiska=1');return false;";
 				var out = '';
-				out += '<a href="index.php?FUNCTION_INIT=MENU_SELECT_PROCES&_action=setPermsByProces&id_proces=' + gotoId + '&MENU_INIT=VIEWTABLE_AJAX&ZASOB_ID=<?php echo $this->_zasobID; ?>" title="' + "{" + gotoId + "} " + label + '">';
+				out += '<a href="index.php?FUNCTION_INIT=MENU_SELECT_PROCES&_action=setPermsByProces&id_proces=' + gotoId + '&MENU_INIT=VIEWTABLE_AJAX&ZASOB_ID=<?php echo $this->_zasobID; ?>" title="' + "{" + gotoId + "} " + label + '">';// TODO: change to _route=ViewTableAjax&typeName=p5_default_db:{tblName}
 					out += ' <span style="padding:10px;"></span>';
 					out += ' <i class="glyphicon glyphicon-arrow-right" style="color:#aaa"></i>';
 					out += ' <i class="glyphicon glyphicon-info-sign"';
@@ -3692,7 +3694,7 @@ function <?php echo $jsToogleFiltrProcesuFunctionName; ?>(n) {
 				var label = pInitList[gotoLvl2Id];
 				var jsInfo = "window.open('procesy5.php?task=PROCES_VIEW_LIST&id_proces=" + gotoLvl2Id + "&HIDE_PANEL=0&show_big_img=1&group_stanowiska=1');return false;";
 				var out = '';
-				out += '<a href="index.php?FUNCTION_INIT=MENU_SELECT_PROCES&_action=setPermsByProces&id_proces=' + gotoLvl2Id + '&MENU_INIT=VIEWTABLE_AJAX&ZASOB_ID=<?php echo $this->_zasobID; ?>" title="' + "{" + gotoLvl2Id + "} " + label + '">';
+				out += '<a href="index.php?FUNCTION_INIT=MENU_SELECT_PROCES&_action=setPermsByProces&id_proces=' + gotoLvl2Id + '&MENU_INIT=VIEWTABLE_AJAX&ZASOB_ID=<?php echo $this->_zasobID; ?>" title="' + "{" + gotoLvl2Id + "} " + label + '">';// TODO: change to _route=ViewTableAjax&typeName=p5_default_db:{tblName}
 					out += ' <span style="padding:20px;"></span>';
 					out += ' <i class="glyphicon glyphicon-arrow-right" style="color:#aaa"></i>';
 					out += ' <i class="glyphicon glyphicon-info-sign"';

+ 9 - 0
SE/se-lib/UI.php

@@ -165,6 +165,15 @@ class UI {
 <?php
 	}
 
+	public static function startContainer() { echo '<div class="container">' . "\n"; }
+	public static function endContainer() { echo '</div>' . "\n"; }
+	public static function startTag($tag, $attrs = array()) {
+		$outAttrs = '';
+		foreach ($attrs as $attrName => $val) $outAttrs .= " {$attrName}=\"{$val}\"";
+		echo '<' . $tag . $outAttrs . '>';
+	}
+	public static function endTag($tag) { echo '</' . $tag . '>'; }
+
 	public static function jsAjaxTable($params) {
 
 	}