Ver Fonte

added row functions from StorageAcl

Piotr Labudda há 8 anos atrás
pai
commit
831b4f7a33

+ 24 - 5
SE/se-lib/Route/ViewTableAjax.php

@@ -50,11 +50,17 @@ class Route_ViewTableAjax extends RouteBase {
 		$tbl->showTableTools = $this->getLink("tableToolsAjax", [ 'namespace' => $acl->getNamespace() ]);
 		$tbl->useUserTableFilter = $this->getLink("getUserTableFilterAjax");
 		$tbl->setLabel($tblLabel);
-		$tbl->addRowFunction('edit');
-		$tbl->addRowFunction('hist');
-		$tbl->addRowFunction('files');
-		$tbl->addRowFunction('cp');
-		$tbl->addRowFunction('msgs');
+		if (method_exists($acl, 'getGuiRowFunctions')) {
+			foreach ($acl->getGuiRowFunctions() as $funKey => $funParams) {
+				$tbl->addRowFunction($funKey, $funParams);
+			}
+		} else {
+			$tbl->addRowFunction('edit');
+			$tbl->addRowFunction('hist');
+			$tbl->addRowFunction('files');
+			$tbl->addRowFunction('cp');
+			$tbl->addRowFunction('msgs');
+		}
 		return $tbl;
 	}
 
@@ -1520,4 +1526,17 @@ class Route_ViewTableAjax extends RouteBase {
 		];
 	}
 
+	function executeRowFunctionAction() { UI::layout([ $this, 'executeRowFunction' ]); }
+	function executeRowFunction() {
+		$namespace = V::get('namespace', '', $_GET);
+		$name = V::get('name', '', $_GET);
+		$pk = V::get('pk', '', $_GET);
+		if (!$namespace) throw new Exception("Missing namespace");
+		if (!$name) throw new Exception("Missing name");
+		if (!$pk) throw new Exception("Missing pk");
+		$acl = ACL::getAclByNamespace($namespace);
+		if (!method_exists($acl, 'executeGuiRowFunction')) throw new Exception("Function executeGuiRowFunction not defined for '{$namespace}'");
+		$acl->executeGuiRowFunction($name, $pk);
+	}
+
 }

+ 34 - 0
SE/se-lib/Schema/PrzypomnijStorageAcl.php

@@ -859,4 +859,38 @@ class Schema_PrzypomnijStorageAcl extends Core_AclSimpleSchemaBase {
 		return $fltrs;
 	}
 
+	function getGuiRowFunctions() { // @return array
+		return [
+			'row_edit' => [ 'href' => Router::getRoute('ViewTableAjax')->getLink('executeRowFunction', [ 'name' => "edit", 'namespace' => $this->getNamespace(), 'pk' => "{0}" ]),
+				'ico' => 'glyphicon glyphicon-pencil',
+				'title' => 'Edytuj powiązany rekord',
+				'class' => "btn btn-xs btn-link"
+			],
+			'project_edit' => [ 'href' => Router::getRoute('ViewTableAjax')->getLink('executeRowFunction', [ 'name' => "project", 'namespace' => $this->getNamespace(), 'pk' => "{0}" ]),
+				'ico' => 'glyphicon glyphicon-folder-close',
+				'title' => 'Edytuj powiązany projekt',
+				'class' => "btn btn-xs btn-link"
+			],
+		];
+	}
+	function executeGuiRowFunction($name, $pk) {
+		switch ($name) {
+			case 'edit': $this->executeGuiRowFunctionEdit($pk);
+			case 'project': $this->executeGuiRowFunctionProject($pk);
+			default: throw new Exception("Not implemented GuiRowFunction name='{$name}' for '" . $this->getNamespace() . "'");
+		}
+	}
+	function executeGuiRowFunctionEdit($pk) {
+		list($tableName, $id) = explode(".", $pk);
+		Lib::loadClass('Response');
+		Response::sendRedirect( Router::getRoute('ViewTableAjax')->getLink('', [ 'namespace' => "default_db/{$tableName}" ]) . "#EDIT/{$id}" );
+	}
+	function executeGuiRowFunctionProject($pk) {
+		list($tableName, $id) = explode(".", $pk);
+		$idProject = DB::getPDO()->fetchValue(" select PROJECT__ID from `_PRZYPOMNIJ_ITEMS` where feature_id = :feature_id ", [ ':feature_id' => $pk ]);
+		if (!$idProject) throw new Exception("Brak przypisanego projektu");
+		Lib::loadClass('Response');
+		Response::sendRedirect( Router::getRoute('ViewTableAjax')->getLink('', [ 'namespace' => "default_db/IN7_MK_BAZA_DYSTRYBUCJI" ]) . "#EDIT/{$idProject}" );
+	}
+
 }

+ 86 - 87
SE/se-lib/TableAjax.php.TableAjax.js

@@ -742,99 +742,98 @@ var TableAjax = function() {
 	priv.popoverCellMoreFunctions = function(e) {
 		e.preventDefault();
 		e.stopPropagation();
+		if (!e.data || !e.data.rowPK) {
+			if (priv.options.debug) console.log('NO data');
+			return false;
+		}
 		if (priv.options.debug) console.log('TableAjax::popoverCellMoreFunctions: rowPK', e.data.rowPK, 'moreFunctions', e.data.more, 'rowFunctions', e.data.rowFunctions);
-		if ('rowPK' in e.data && e.data.rowPK > 0) {
-			var lastId = _popoverCell.data('rowid'),
-					lastCol = _popoverCell.data('col'),
-					rowPK = e.data.rowPK,
-					moreFunctions = e.data.more,
-					rowFunctions = e.data.rowFunctions,
-					funcListNode
-			;
-
-			if (lastId == e.data.rowPK && lastCol == 'moreFunctions') {
-				//_popoverCellCurrent.popover('toggle');
-			}
-			else {
-				if (_popoverCellCurrent) {
-					_popoverCellCurrent.popover('destroy');
-				}
+		var lastId = _popoverCell.data('rowid');
+		var lastCol = _popoverCell.data('col');
+		var rowPK = e.data.rowPK;
+		var moreFunctions = e.data.more;
+		var rowFunctions = e.data.rowFunctions;
+		var funcListNode;
+
+		if (lastId == e.data.rowPK && lastCol == 'moreFunctions') {
+			//_popoverCellCurrent.popover('toggle');
+			return;
+		}
 
-				_popoverCell.data('rowid', rowPK);
-				_popoverCell.data('col', 'rowFunctions');
-				_popoverCell.empty();
-				funcListNode = $('<ul class="list-unstyled popoverRowFunctions"></ul>').appendTo(_popoverCell);
-
-				moreFunctions.forEach(function(funcName) {
-					var funcItemNode = $('<li></li>').appendTo(funcListNode),
-							funObj = rowFunctions[funcName],
-							funcNode = p5UI_TableAjax_generateFunctionNode(funObj, rowPK, {ico: true, label: true})
-					;
-					funcNode.addClass('func_name-' + funcName);
-					funcItemNode.append(funcNode);
-				});
-				{ // TODO: id namesapce is AntAcl [ and has ref fields or back ref ]
-					var funcItemNode = $('<li></li>').appendTo(funcListNode)
-					var funObj = {
-						ico: 'glyphicon glyphicon-random',
-						label: 'Przeglądaj powiązania',
-						href: 'index.php?_route=RefGraph&namespace=' + priv.options.namespace + '&primaryKey=' + rowPK,
-						// onclick: function (e) { // TODO: open in
-						// 	console.log('TODO: przeglądaj powiązania')
-						// }
-					}
-					var funcNode = p5UI_TableAjax_generateFunctionNode(funObj, rowPK, { ico: true, label: true })
-					funcItemNode.append(funcNode);
-				}
+		if (_popoverCellCurrent) {
+			_popoverCellCurrent.popover('destroy');
+		}
 
-				_popoverCell.append('<div class="popoverCellContent" style="white-space:normal"></div>');
+		_popoverCell.data('rowid', rowPK);
+		_popoverCell.data('col', 'rowFunctions');
+		_popoverCell.empty();
+		funcListNode = $('<ul class="list-unstyled popoverRowFunctions"></ul>').appendTo(_popoverCell);
 
-				_popoverCellCurrent = jQuery(e.currentTarget);
-				// title : '<span class="text-info"><strong>title</strong></span> <button type="button" id="close" class="close">&times;</button>'
-				var opts = {
-					container: 'body',
-					placement: 'right',
-					trigger: 'click',
-					template: '',
-					html: true,
-					content: _popoverCell.html()
-				}
-				opts.template += '<div class="popover" role="tooltip" style="max-width:600px;width:440px;">';
-				{
-					opts.template += '<div class="arrow"></div>';
-					//opts.template += '<h3 class="popover-title"></h3>';
-					opts.template += '<div style="display:block;position:relative;">';
-					{
-						opts.template += '<div class="popover-title">';
-						opts.template += '</div>';
-						opts.template += '<button type="button" class="close" onclick="return hidePopover();" style="position:absolute;right:8px;top:6px;">&times;</button>';
-					}
-					opts.template += '</div>';
-					opts.template += '<div class="popover-content"></div>';
-				}
+		moreFunctions.forEach(function(funcName) {
+			var funcItemNode = $('<li></li>').appendTo(funcListNode),
+					funObj = rowFunctions[funcName],
+					funcNode = p5UI_TableAjax_generateFunctionNode(funObj, rowPK, {ico: true, label: true})
+			;
+			funcNode.addClass('func_name-' + funcName);
+			funcItemNode.append(funcNode);
+		});
+		if (3 === priv.options.namespace.split('/').length) { // if namesapce is AntAcl [ and has ref fields or back ref ]
+			var funcItemNode = $('<li></li>').appendTo(funcListNode)
+			var funObj = {
+				ico: 'glyphicon glyphicon-random',
+				label: 'Przeglądaj powiązania',
+				href: 'index.php?_route=RefGraph&namespace=' + priv.options.namespace + '&primaryKey=' + rowPK,
+				// onclick: function (e) { // TODO: open in
+				// 	console.log('TODO: przeglądaj powiązania')
+				// }
+			}
+			var funcNode = p5UI_TableAjax_generateFunctionNode(funObj, rowPK, { ico: true, label: true })
+			funcItemNode.append(funcNode);
+		}
+
+		_popoverCell.append('<div class="popoverCellContent" style="white-space:normal"></div>');
+
+		_popoverCellCurrent = jQuery(e.currentTarget);
+		// title : '<span class="text-info"><strong>title</strong></span> <button type="button" id="close" class="close">&times;</button>'
+		var opts = {
+			container: 'body',
+			placement: 'right',
+			trigger: 'click',
+			template: '',
+			html: true,
+			content: _popoverCell.html()
+		}
+		opts.template += '<div class="popover" role="tooltip" style="max-width:600px;width:440px;">';
+		{
+			opts.template += '<div class="arrow"></div>';
+			//opts.template += '<h3 class="popover-title"></h3>';
+			opts.template += '<div style="display:block;position:relative;">';
+			{
+				opts.template += '<div class="popover-title">';
 				opts.template += '</div>';
+				opts.template += '<button type="button" class="close" onclick="return hidePopover();" style="position:absolute;right:8px;top:6px;">&times;</button>';
+			}
+			opts.template += '</div>';
+			opts.template += '<div class="popover-content"></div>';
+		}
+		opts.template += '</div>';
+
+		_popoverCellCurrent.popover(opts);
+		_popoverCellCurrent.on('shown.bs.popover', function(e) {
+			if (!_popoverCellCurrent) return;
+			var popoverNodeId = _popoverCellCurrent.attr('aria-describedby');
+			if (!popoverNodeId) return;
+			var popover$Node = jQuery('#' + popoverNodeId);
+			if (!popover$Node.length) return;
+			var arrow$Node = popover$Node.children('.arrow');
+			if (arrow$Node.length) {
+				var posTop = parseFloat(arrow$Node.css('top'));
+				arrow$Node.css('top', '' + posTop + 'px')
+			}
+			popover$Node.find('.popoverCellContent').html('<p class="text-muted">Pobieranie funkcji...<p>');
+			priv.ajaxLoadMoreFunctionsCell(rowPK);
+		});
+		_popoverCellCurrent.popover('show');
 
-				_popoverCellCurrent.popover(opts);
-				_popoverCellCurrent.on('shown.bs.popover', function(e) {
-					if (!_popoverCellCurrent) return;
-					var popoverNodeId = _popoverCellCurrent.attr('aria-describedby');
-					if (!popoverNodeId) return;
-					var popover$Node = jQuery('#' + popoverNodeId);
-					if (!popover$Node.length) return;
-					var arrow$Node = popover$Node.children('.arrow');
-					if (arrow$Node.length) {
-						var posTop = parseFloat(arrow$Node.css('top'));
-						arrow$Node.css('top', '' + posTop + 'px')
-					}
-					popover$Node.find('.popoverCellContent').html('<p class="text-muted">Pobieranie funkcji...<p>');
-					priv.ajaxLoadMoreFunctionsCell(rowPK);
-				});
-				_popoverCellCurrent.popover('show');
-			}
-		} else {
-			if (priv.options.debug) console.log('NO data');
-			return false;
-		}
 		return;
 	};