Przeglądaj źródła

U Table ref view

Piotr Labudda 5 lat temu
rodzic
commit
b2da694337
1 zmienionych plików z 108 dodań i 14 usunięć
  1. 108 14
      tools/Bocian.php.view.js

+ 108 - 14
tools/Bocian.php.view.js

@@ -3012,16 +3012,11 @@ function loadMoreRecordFunctions(event, node, rowPK, namespace) {
 		return response.json()
 	}).then(function (json) {
 		var funcListWrap = $('<div></div>')
-		var funcListNode = $('<ul class="list-unstyled popoverRowFunctions"></ul>').appendTo(funcListWrap)
 
 		if (_node === RECORD_MORE_FUNCTIONS_OPENED_NODE) {
 			if (json && 'success' === json.type && json.rowFunctions && json.rowFunctions.length > 0) {
-				json.rowFunctions.forEach(function(funObj) {
-					var funcNode = p5UI_TableAjax_generateFunctionNode(funObj, _rowPK, {ico: true, label: true});
-					var funcItemNode = jQuery('<li></li>')
-					funcItemNode.append(funcNode)
-					funcListNode.append(funcItemNode)
-				});
+				var popoverContent = generateViewMoreRecordFunctions(json.rowFunctions, namespace, _rowPK);
+				popoverContent.appendTo(funcListWrap);
 			}
 		}
 
@@ -3050,14 +3045,113 @@ function loadMoreRecordFunctions(event, node, rowPK, namespace) {
 	})
 }
 
-var p5UI_TableAjax_generateFunctionNode = function(funObj, rowPK, props) {
+function generateViewMoreRecordFunctions(rowFunctions, namespace, rowPK) {
+	var popoverContent;
+	var funcNodesToUpdate = [];
+
+	if (!rowFunctions.length) {
+		popoverContent = $('<p class="text-muted">Brak dodatkowych funkcji</p>');
+	} else if (3 === namespace.split('/').length) { // if namesapce is AntAcl [ and has ref fields or back ref ]
+		popoverContent = $('<ul class="list-unstyled"></ul>');
+		var rowFunctionsByType = rowFunctions.reduce(function (ret, funObj) {
+			if (
+				'Powiązania od ' === funObj.label.substr(0, 'Powiązania od '.length)
+				|| 'Powiązania do ' === funObj.label.substr(0, 'Powiązania do '.length)
+			) {
+				if (funObj.total > 0) {
+					ret.refConnections.push(funObj);
+				} else {
+					ret.refEmptyConnections.push(funObj);
+				}
+			} else {
+				ret.others.push(funObj);
+			}
+			return ret;
+			// href: "https://biuro.biall-net.pl/dev-pl/se-master/index.php?_route=ViewTableAjax&namespace=default_db/BI_audit_KRS/BI_audit_KRS&childRefNS=default_db/BI_audit_KRS/BI_audit_KRS&childRefPK=2068689"
+			// ico: "glyphicon glyphicon-random"
+			// label: "Powiązania od 'KRS' <span class="badge">0</span>"
+			// title: "Powiązania od 'Audyt / KRS' (0)"
+		}, { refConnections: [], refEmptyConnections: [], others: [] });
+
+		rowFunctionsByType.others.forEach(function (funObj) {
+			var funcNode = p5UI_TableAjax_generateFunctionNode(funObj, rowPK, { ico: true, label: true });
+			if (funObj.id) {
+				funcNodesToUpdate.push({ id: funObj.id, node: funcNode });
+			} else {
+				var funcItemNode = $('<li></li>').appendTo(popoverContent);
+				funcItemNode.append(funcNode);
+			}
+		});
+
+		if (!rowFunctionsByType.refConnections.length) {
+			$('<li>Brak powiązań</li>').appendTo(popoverContent);
+		} else {
+			var refConnItemNode = $('<li style="margin-top:10px"><i class="glyphicon glyphicon-random"></i> <b>Powiązania</b></li>').appendTo(popoverContent);
+			{
+				var funObj = {
+					// ico: 'glyphicon glyphicon-random',
+					label: 'przeglądaj',
+					title: "Przeglądaj powiązania",
+					href: 'index.php?_route=RefGraph&namespace=' + 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 })
+				refConnItemNode.append(" - ");
+				refConnItemNode.append(funcNode);
+			}
+			var refConnFuncList = $('<ul class="list-unstyled" style="margin-left:20px"></ul>').appendTo(refConnItemNode);
+			rowFunctionsByType.refConnections.forEach(function (funObj) {
+				var refFunObj = Object.assign({}, funObj, {
+					// ico: null,
+					label: funObj.label.substr('Powiązania '.length),
+				});
+				var funcNode = p5UI_TableAjax_generateFunctionNode(refFunObj, rowPK, { ico: true, label: true });
+				var funcItemNode = $('<li></li>').appendTo(refConnFuncList);
+				funcItemNode.append(funcNode);
+			})
+		}
+		if (rowFunctionsByType.refEmptyConnections.length) {
+			var refConnItemNode = $('<li style="margin-top:10px; opacity:0.7"></li>').appendTo(popoverContent);
+			var emptyRefsDetailsNode = $('<details></details>').appendTo(refConnItemNode);
+			// $('<summary><i class="glyphicon glyphicon-random"></i> Pozostałe powiązania</summary>').appendTo(emptyRefsDetailsNode);
+			$('<summary style="cursor:pointer">Pozostałe powiązania ...</summary>').appendTo(emptyRefsDetailsNode);
+			var refConnFuncList = $('<ul class="list-unstyled" style="margin-left:20px"></ul>').appendTo(emptyRefsDetailsNode);
+			rowFunctionsByType.refEmptyConnections.forEach(function (funObj) {
+				var refFunObj = Object.assign({}, funObj, {
+					// ico: null,
+					label: funObj.label.substr('Powiązania '.length),
+				});
+				var funcNode = p5UI_TableAjax_generateFunctionNode(refFunObj, rowPK, { ico: true, label: true });
+				var funcItemNode = $('<li></li>').appendTo(refConnFuncList);
+				funcItemNode.append(funcNode);
+			})
+		}
+	} else {
+		popoverContent = $('<ul class="list-unstyled"></ul>');
+		rowFunctions.forEach(function (funObj) {
+			var funcNode = p5UI_TableAjax_generateFunctionNode(funObj, rowPK, { ico: true, label: true });
+			if (funObj.id) {
+				funcNodesToUpdate.push({ id: funObj.id, node: funcNode });
+			} else {
+				var funcItemNode = $('<li></li>').appendTo(popoverContent);
+				funcItemNode.append(funcNode);
+			}
+		});
+	}
+
+	return popoverContent;
+}
+
+function p5UI_TableAjax_generateFunctionNode(funObj, rowPK, props) {
+	if (!rowPK) throw "Missing primaryKey in p5UI_TableAjax_generateFunctionNode";
 	var defaultsProps = {
-				ico: true,
-				label: false
-			},
-			props = jQuery.extend({}, defaultsProps, props);
-			funcNode = $('<a href="#" style="margin:0 2px;"></a>')
-	;
+		ico: true,
+		label: false
+	};
+	var props = jQuery.extend({}, defaultsProps, props);
+	var funcNode = $('<a href="#" style="margin:0 2px;"></a>');
 	if ('href' in funObj) funcNode.attr('href', p5Utils__format(funObj.href, [rowPK]));
 	if (props.ico) {
 		if ('ico' in funObj) funcNode.append('<span class="' + funObj.ico + '"></span>');