ソースを参照

fixed order by in ProcesView

Piotr Labudda 9 年 前
コミット
3e1344b391
2 ファイル変更326 行追加374 行削除
  1. 196 233
      SE/se-lib/Route/UrlAction/ProcesView.php
  2. 130 141
      SE/static/procesView.js

+ 196 - 233
SE/se-lib/Route/UrlAction/ProcesView.php

@@ -12,168 +12,133 @@ class Route_UrlAction_ProcesView extends RouteBase {// TODO: UrlActionBase @see
 
 	public function getAllAjaxAction(){
 		try {
-				$rows = DB::getPDO()->fetchAll("
-					select `ID`, `PARENT_ID`, `DESC`, `OPIS`, `TYPE`, `IF_TRUE_GOTO`, `IF_TRUE_GOTO_FLAG`
-					from CRM_PROCES
-					WHERE `PARENT_ID`>=0
-						AND `A_STATUS` <> 'DELETED'
-						AND `ID` <> `PARENT_ID`
-					ORDER BY `SORT_PRIO` ASC, `ID` DESC
-				");
-				$state = array();
-				foreach($rows as $key => $value){
-					$id = intval($value["ID"]);
-					$parent_id = intval($value["PARENT_ID"]);
-					$state[$id]["ID"] = $value["ID"];
-					$state[$id]["DESC"] = $value["DESC"];
-					$state[$id]["OPIS"] = $value["OPIS"];
-					$state[$id]["TYPE"] = $value["TYPE"];
-					$state[$id]["IF_TRUE_GOTO"] = intval($value["IF_TRUE_GOTO"]);
-					$state[$id]["IF_TRUE_GOTO_FLAG"] = $value["IF_TRUE_GOTO_FLAG"];
-					if(intval($value["PARENT_ID"]) != 0)
-						$state[$id]["PARENT_ID"] = intval($value["PARENT_ID"]);
-					else
-						$state[$id]["PARENT_ID"] = "#";
-					if(!isset($state[$id]["childs"]))
-						$state[$id]["childs"] = array();
-
-					if(!isset($state[$value["PARENT_ID"]])){
-						$state[$parent_id]["childs"] = array();
-					}
-					$temp = array();
-					$temp["ID"] = $id;
-					array_push($state[$parent_id]["childs"], $temp);
-
-				}
-				//print_r($state);
-				Response::sendJsonExit($state);
-			} catch (Exception $e) {
-				UI::alert('danger', "Error: " . $e->getMessage());
+			$rows = DB::getPDO()->fetchAll("
+				select `ID`, `PARENT_ID`, `DESC`, `OPIS`, `TYPE`, `IF_TRUE_GOTO`, `IF_TRUE_GOTO_FLAG`, `SORT_PRIO`
+				from CRM_PROCES
+				WHERE `PARENT_ID`>=0
+					AND `A_STATUS` <> 'DELETED'
+					AND `ID` <> `PARENT_ID`
+				ORDER BY `SORT_PRIO` ASC, `ID` DESC
+			");
+			$state = array();
+			foreach ($rows as $key => $value) {
+				$id = intval($value["ID"]);
+				$parent_id = intval($value["PARENT_ID"]);
+				$state[$id]["ID"] = $value["ID"];
+				$state[$id]["DESC"] = $value["DESC"];
+				$state[$id]["OPIS"] = $value["OPIS"];
+				$state[$id]["TYPE"] = $value["TYPE"];
+				$state[$id]["IF_TRUE_GOTO"] = intval($value["IF_TRUE_GOTO"]);
+				$state[$id]["IF_TRUE_GOTO_FLAG"] = $value["IF_TRUE_GOTO_FLAG"];
+				$state[$id]["PARENT_ID"] = (intval($value["PARENT_ID"]) != 0) ? intval($value["PARENT_ID"]) : "#";
+				$state[$id]["SORT_PRIO"] = $value["SORT_PRIO"];
+				if (!isset($state[$id]["childs"])) $state[$id]["childs"] = array();
+				if (!isset($state[$parent_id]["childs"])) $state[$parent_id]["childs"] = array();
+				$temp = array();
+				$temp["ID"] = $id;
+				array_push($state[$parent_id]["childs"], $temp);
 			}
+			Response::sendJsonExit($state);
+		} catch (Exception $e) {
+			UI::alert('danger', "Error: " . $e->getMessage());
+		}
 	}
 
 	public function getConnectedProcAjaxAction(){
 		try {
-				$id = V::get('id', 0, $_REQUEST, 'int');
-				$rows = DB::getPDO()->fetchAll("
-					SELECT * FROM `CRM_WSKAZNIK` WHERE `ID_ZASOB` = $id AND `A_STATUS` <> 'DELETED'
-				");
-				$state = array();
-				$state["wsk"] = array();
-				foreach($rows as $key => $value){
-					$temp["ID"] = $value["ID"];
-					$temp["ID_PROCES"] = $value["ID_PROCES"];
-					$temp["ID_ZASOB"] = $value["ID_ZASOB"];
-					//print_r($temp);
-
-					array_push($state["wsk"], $temp);
-				}
-				Response::sendJsonExit($state);
-			} catch (Exception $e) {
-				UI::alert('danger', "Error: " . $e->getMessage());
+			$id = V::get('id', 0, $_REQUEST, 'int');
+			$rows = DB::getPDO()->fetchAll("
+				SELECT * FROM `CRM_WSKAZNIK` WHERE `ID_ZASOB` = $id AND `A_STATUS` <> 'DELETED'
+			");
+			$state = array();
+			$state["wsk"] = array();
+			foreach($rows as $key => $value){
+				$temp["ID"] = $value["ID"];
+				$temp["ID_PROCES"] = $value["ID_PROCES"];
+				$temp["ID_ZASOB"] = $value["ID_ZASOB"];
+				array_push($state["wsk"], $temp);
 			}
+			Response::sendJsonExit($state);
+		} catch (Exception $e) {
+			UI::alert('danger', "Error: " . $e->getMessage());
+		}
 	}
 
-
 	public function getDetailsAjaxAction(){
 		try {
-				$id = V::get('id', 0, $_REQUEST, 'int');
-				$rows = DB::getPDO()->fetchAll("
-					SELECT * FROM `CRM_WSKAZNIK` WHERE `ID_PROCES` = $id AND `A_STATUS` <> 'DELETED'
-				");
-				$state = array();
-				$state["wsk"] = array();
-				foreach($rows as $key => $value){
-					$temp["ID"] = $value["ID"];
-					$temp["ID_PROCES"] = $value["ID_PROCES"];
-					$temp["ID_ZASOB"] = $value["ID_ZASOB"];
-					//print_r($temp);
-
-					array_push($state["wsk"], $temp);
-				}
-				$count = DB::getPDO()->fetchAll("
-					SELECT count(*) as imgCount FROM `CRM_IMAGE` WHERE `REMOTE_ID` = $id AND `REMOTE_TABLE` = 'CRM_PROCES'
-				");
-				//print_r($count[0]["c"]);
-				//print_r($state);
-				$state["IMG_COUNT"] = $count[0]["imgCount"];
-				Response::sendJsonExit($state);
-			} catch (Exception $e) {
-				UI::alert('danger', "Error: " . $e->getMessage());
+			$id = V::get('id', 0, $_REQUEST, 'int');
+			$rows = DB::getPDO()->fetchAll("
+				SELECT * FROM `CRM_WSKAZNIK` WHERE `ID_PROCES` = {$id} AND `A_STATUS` <> 'DELETED'
+			");
+			$state = array();
+			$state["wsk"] = array();
+			foreach($rows as $key => $value){
+				$temp["ID"] = $value["ID"];
+				$temp["ID_PROCES"] = $value["ID_PROCES"];
+				$temp["ID_ZASOB"] = $value["ID_ZASOB"];
+				array_push($state["wsk"], $temp);
 			}
+			$count = DB::getPDO()->fetchAll("
+				SELECT count(*) as imgCount FROM `CRM_IMAGE` WHERE `REMOTE_ID` = {$id} AND `REMOTE_TABLE` = 'CRM_PROCES'
+			");
+			$state["IMG_COUNT"] = $count[0]["imgCount"];
+			Response::sendJsonExit($state);
+		} catch (Exception $e) {
+			UI::alert('danger', "Error: " . $e->getMessage());
+		}
 	}
 
 	public function getAllResAjaxAction(){
 		try {
-				$rows = DB::getPDO()->fetchAll("
-					select `ID`, `PARENT_ID`, `DESC`, `OPIS`, `ALIAS_ID`, `TYPE`
-					from CRM_LISTA_ZASOBOW
-					WHERE `PARENT_ID`>=0
-						AND `A_STATUS` <> 'DELETED'
-						AND `ID` <> `PARENT_ID`
-					ORDER BY `SORT_PRIO` ASC, `ID` DESC
-				");
-				$state = array();
-				foreach($rows as $key => $value){
-					$id = intval($value["ID"]);
-					$parent_id = intval($value["PARENT_ID"]);
-					$state[$id]["ALIAS_ID"] = intval($value["ALIAS_ID"]);
-					$state[$id]["ID"] = $value["ID"];
-					$state[$id]["DESC"] = $value["DESC"];
-					$state[$id]["TYPE"] = $value["TYPE"];
-					$state[$id]["OPIS"] = $value["OPIS"];
-					if(intval($value["PARENT_ID"]) != 0)
-						$state[$id]["PARENT_ID"] = intval($value["PARENT_ID"]);
-					else
-						$state[$id]["PARENT_ID"] = "#";
-					if(!isset($state[$id]["childs"]))
-						$state[$id]["childs"] = array();
-
-					if(!isset($state[$value["PARENT_ID"]])){
-						$state[$parent_id]["childs"] = array();
-					}
-					$temp = array();
-					$temp["ID"] = $id;
-					array_push($state[$parent_id]["childs"], $temp);
-
-				}
-				//print_r($state);
-				Response::sendJsonExit($state);
-			} catch (Exception $e) {
-				UI::alert('danger', "Error: " . $e->getMessage());
+			$rows = DB::getPDO()->fetchAll("
+				select `ID`, `PARENT_ID`, `DESC`, `OPIS`, `ALIAS_ID`, `TYPE`
+				from CRM_LISTA_ZASOBOW
+				WHERE `PARENT_ID`>=0
+					AND `A_STATUS` <> 'DELETED'
+					AND `ID` <> `PARENT_ID`
+				ORDER BY `SORT_PRIO` ASC, `ID` DESC
+			");
+			$state = array();
+			foreach ($rows as $key => $value) {
+				$id = intval($value["ID"]);
+				$parent_id = intval($value["PARENT_ID"]);
+				$state[$id]["ALIAS_ID"] = intval($value["ALIAS_ID"]);
+				$state[$id]["ID"] = $value["ID"];
+				$state[$id]["DESC"] = $value["DESC"];
+				$state[$id]["TYPE"] = $value["TYPE"];
+				$state[$id]["OPIS"] = $value["OPIS"];
+				$state[$id]["PARENT_ID"] = (intval($value["PARENT_ID"]) != 0) ? intval($value["PARENT_ID"]) : "#";
+				if (!isset($state[$id]["childs"])) $state[$id]["childs"] = array();
+				if (!isset($state[$value["PARENT_ID"]])) $state[$parent_id]["childs"] = array();
+				$temp = array();
+				$temp["ID"] = $id;
+				array_push($state[$parent_id]["childs"], $temp);
 			}
+			Response::sendJsonExit($state);
+		} catch (Exception $e) {
+			UI::alert('danger', "Error: " . $e->getMessage());
+		}
 	}
 
 	public function handleAuth() {
-		if (!User::logged()) {
-			//throw new HttpException('Unauthorized', 401);
-			User::authByRequest();
-		}
-		// zapisać jsona w sesji
+		if (!User::logged()) User::authByRequest();
 	}
 
 	public function defaultAction() {
-
-
 		UI::gora();
 		UI::menu();
 		try {
-				$start_id = V::get('START_ID', 0, $_REQUEST, 'int');
-				$type = V::get('TYPE', 0, $_REQUEST, 'string');
-				if($type === "zasoby")
-					$type = "res";
-				else
-					$type = "childs";
-				$this->showView($start_id, $type);
+			$start_id = V::get('START_ID', 0, $_REQUEST, 'int');
+			$type = V::get('TYPE', '', $_REQUEST, 'string');
+			$type = ($type == "zasoby") ? "res" : "childs";
+			$this->showView($start_id, $type);
 		} catch (Exception $e) {
 			UI::alert('danger', "Error: " . $e->getMessage());
 		}
-
 		UI::dol();
 	}
 
 	public function showView($start_id, $type) {
-
 		echo "<div class=container-fluid>";
 		echo "<div class=row>";
 		echo "<div class=col-md-12 style=padding-top:15px;><a id=toggleMenu style=cursor:pointer;>Przełącz menu</a><a style=float:right;cursor:pointer; id=toggleView>Przełącz widok</a></div>";
@@ -186,131 +151,129 @@ class Route_UrlAction_ProcesView extends RouteBase {// TODO: UrlActionBase @see
 		echo '<link rel="stylesheet" type="text/css" href="static/sweetalert2.min.css">';
 		echo '<link rel="stylesheet" href="static/jstree-theme/style.min.css" />';
 		echo '<script src="static/jstree.min.js"></script>';
-		echo '<script src="static/procesView.js?v='.time().'"></script>';
+		echo '<script src="static/procesView.js?v=2'.((V::get('DBG', '', $_GET)) ? time() : '').'"></script>';// TODO: static v, only in DBG
     $this->showViewCss();
-
 	}
 
   public function showViewCss() {
-  ?>
-  <style type="text/css">
-  .singleAdv{
-  float:left;
-	padding-bottom:20px;
-	display:block;
-  width:460px;
-  }
+?>
+<style type="text/css">
+.singleAdv{
+float:left;
+padding-bottom:20px;
+display:block;
+width:460px;
+}
 
-	.toggleRoute{
-		text-align:center;
-		margin-top:10px;
-		padding:5px;
-		background-color:#ededed;
-		opacity:0.6;
-		cursor:pointer;
-	}
+.toggleRoute{
+	text-align:center;
+	margin-top:10px;
+	padding:5px;
+	background-color:#ededed;
+	opacity:0.6;
+	cursor:pointer;
+}
 
-	.route{
-		border-style:solid;
-		border-width:2px;
-		padding:5px;
-		display:none;
-		border-radius:2px;
-		border-color:#ededed;
-	}
+.route{
+	border-style:solid;
+	border-width:2px;
+	padding:5px;
+	display:none;
+	border-radius:2px;
+	border-color:#ededed;
+}
 
-	.toggleRoute:hover{
-		opacity:1;
-	}
+.toggleRoute:hover{
+	opacity:1;
+}
 
-	.goto{
+.goto{
 
-	}
+}
 
-	.singleAdvList{
-			overflow-y:scroll;
-	}
+.singleAdvList{
+		overflow-y:scroll;
+}
 
-	.gotoInfo{
-		background-color:#e5a100;
-		color:white;
-		padding:10px;
-		margin-left:50px;
-		font-size:1.0em;
-	}
+.gotoInfo{
+	background-color:#e5a100;
+	color:white;
+	padding:10px;
+	margin-left:50px;
+	font-size:1.0em;
+}
 
-	.gotoWay{
-		background-color:#ededed;
-		padding:10px;
-	}
+.gotoWay{
+	background-color:#ededed;
+	padding:10px;
+}
 
-	.normalChilds{
-		background-color: #ededed;
-	}
+.normalChilds{
+	background-color: #ededed;
+}
 
-	#procCon{
-		display:block;
-		height:100%;
-	}
+#procCon{
+	display:block;
+	height:100%;
+}
 
-  .textTable{
-  	float:left;
-  	width:400px;
+.textTable{
+	float:left;
+	width:400px;
 
-    overflow:hidden;
-  	display:inline-block;
-  }
+  overflow:hidden;
+	display:inline-block;
+}
 
-  .glyph{
-    opacity:0.4;
-  }
-  .glyph:hover{
-    opacity:1;
-  }
+.glyph{
+  opacity:0.4;
+}
+.glyph:hover{
+  opacity:1;
+}
 
-	.detailsTable{
-		color:black;
-		display:inline-block;
-		padding:4px;
-		padding-top:1px;
-		padding-bottom:1px;
-		border-width:1px;
-		border-color:grey;
-	}
+.detailsTable{
+	color:black;
+	display:inline-block;
+	padding:4px;
+	padding-top:1px;
+	padding-bottom:1px;
+	border-width:1px;
+	border-color:grey;
+}
+
+.detailsTable2{
+	color:black;
+	display:inline-block;
+	padding:3px;
+	padding-top:0px;
+	padding-bottom:0px;
+	border-width:1px;
+	border-color:grey;
+	height:24px; line-height:22px; border:1px solid #fff;
+}
 
-	.detailsTable2{
-		color:black;
-		display:inline-block;
-		padding:3px;
-		padding-top:0px;
-		padding-bottom:0px;
+#ulproc{
+    background-color: white;
+    overflow-y: scroll;
+    height: 70% !important;
+		border-style:solid;
 		border-width:1px;
 		border-color:grey;
-		height:24px; line-height:22px; border:1px solid #fff;
-	}
-
-  #ulproc{
-      background-color: white;
-      overflow-y: scroll;
-      height: 70% !important;
-  		border-style:solid;
-  		border-width:1px;
-  		border-color:grey;
-      margin-top: 10px;
-      border-radius: 5px;
-      padding-bottom: 10px;
-      border-style: solid;
-      border-width: 1px;
-      border-color: #e5e5e5;
-      color: black;
-      padding-left: 0px;
-      font-family: tahoma;
-      font-size: 13px;
-  }
+    margin-top: 10px;
+    border-radius: 5px;
+    padding-bottom: 10px;
+    border-style: solid;
+    border-width: 1px;
+    border-color: #e5e5e5;
+    color: black;
+    padding-left: 0px;
+    font-family: tahoma;
+    font-size: 13px;
+}
 #tree { overflow:hidden; border:1px solid #ddd; }
-  </style>
-  <?php
+</style>
+<?php
   }
 
-
 }

+ 130 - 141
SE/static/procesView.js

@@ -32,13 +32,15 @@ $(document).ready(function() {
           break;
       }
       temp["id"] = id;
-      if(TYPE == "childs")
+      if (TYPE == "childs") {
         temp["type"] = "proces";
-      else
-        if(arr[id]["TYPE"] == "STANOWISKO" || arr[id]["TYPE"] == "DZIAL" || arr[id]["TYPE"] == "PODMIOT")
+      } else {
+        if (arr[id]["TYPE"] == "STANOWISKO" || arr[id]["TYPE"] == "DZIAL" || arr[id]["TYPE"] == "PODMIOT") {
           temp["type"] = "stanowiska";
-        else
+        } else {
           temp["type"] = "zasoby";
+        }
+      }
       temp["text"] = "<span class=detailsTable2 " + style + " >" + id + "</span> " + arr[id]["DESC"];
       temp["parent"] = arr[id]["PARENT_ID"];
       data.push(temp);
@@ -48,7 +50,6 @@ $(document).ready(function() {
     return data;
   }
 
-
   $(document).on('keyup', '#search', function(e) {
     if (sTimeout) {
       clearTimeout(sTimeout);
@@ -63,7 +64,7 @@ $(document).ready(function() {
     var tree = $("#tree").jstree(true);
     var id = node.id;
     var items = {};
-    if (node.type === "proces")
+    if (node.type === "proces") {
       items = {
         "ProcesEditor": {
           "separator_before": false,
@@ -89,7 +90,6 @@ $(document).ready(function() {
             window.location = BASE_URL + 'procesy5.php?task=CRM_TESTY_ADD_PYTANIA&id_proces=' + id;
           }
         },
-
         "ProcesMap": {
           "separator_before": false,
           "separator_after": false,
@@ -162,20 +162,21 @@ $(document).ready(function() {
           }
         },
       };
+    }
 
-      if (node.type === "zasoby" || node.type === "stanowiska")
-        items = {
-          "Edit": {
-            "separator_before": false,
-            "separator_after": true,
-            "label": "Edytuj zasób",
-            "action": function(obj) {
-              var zId = id.replace("wsk", "");
-              window.location = BASE_URL + 'index.php?_route=ViewTableAjax&typeName=p5_default_db:CRM_LISTA_ZASOBOW#EDIT/' + zId;
-            }
-          },
-        };
-
+    if (node.type === "zasoby" || node.type === "stanowiska") {
+      items = {
+        "Edit": {
+          "separator_before": false,
+          "separator_after": true,
+          "label": "Edytuj zasób",
+          "action": function(obj) {
+            var zId = id.replace("wsk", "");
+            window.location = BASE_URL + 'index.php?_route=ViewTableAjax&typeName=p5_default_db:CRM_LISTA_ZASOBOW#EDIT/' + zId;
+          }
+        },
+      };
+    }
     return items;
   }
 
@@ -220,7 +221,6 @@ $(document).ready(function() {
         "items": customMenu
       }
     });
-
   }
 
   function renderPanels() {
@@ -231,7 +231,7 @@ $(document).ready(function() {
       $.each(arr, function(i, e){
         createPanel(e["ID"], i, e["TYPE"]);
       });
-    }else{
+    } else {
       createPanel(START_ID, 0, TYPE);
     }
   }
@@ -241,34 +241,32 @@ $(document).ready(function() {
     var temp = {};
     temp["ID"] = id;
     var inherit = $("#depth" + (depth - 1)).data("type");
-    if ("connect" == inherit)
+    if ("connect" == inherit) {
       inherit = "childs";
-
-    if ("aliasChilds" == inherit)
+    }
+    if ("aliasChilds" == inherit) {
       inherit = "res";
-
-    if ("gotoChilds" == inherit)
+    }
+    if ("gotoChilds" == inherit) {
       inherit = "childs";
-
-
-    if (type == "inherit")
+    }
+    if (type == "inherit") {
       type = inherit;
-
-    if (type == "childs" && procesy[id]["childs"].length == 0)
+    }
+    if (type == "childs" && procesy[id]["childs"].length == 0) {
       type = "details";
-
-
-    if (type == "alias")
+    }
+    if (type == "alias") {
       type = "detailsRes";
-
-    if (type == "res" && res[id]["childs"].length == 0)
+    }
+    if (type == "res" && res[id]["childs"].length == 0) {
       type = "detailsRes";
+    }
     temp["TYPE"] = type;
     temp["FOCUS"] = 0;
     state[depth] = temp;
     if(depth > 0)
     state[depth-1]["FOCUS"] = id;
-    //console.log(state);
     renderPanel(depth);
   }
 
@@ -276,46 +274,49 @@ $(document).ready(function() {
     var type = state[depth]["TYPE"];
     var id = state[depth]["ID"];
     var link = BASE_URL + "index.php?_route=UrlAction_ProcesView&_task=getDetailsAjax&id=" + id;
-    if ("connect" == type)
+    if ("connect" == type) {
       link = BASE_URL + "index.php?_route=UrlAction_ProcesView&_task=getConnectedProcAjax&id=" + id;
-      $("#depth" + (depth - 1)).nextAll(".singleAdv").remove();
-      var target = $("<div class=singleAdv data-depth=" + depth + " id=depth" + depth + " data-parent=" + id + " data-type=" + type + " ></div>");
-      target.appendTo("#procCon");
-      $("#procCon").css("width", depth * 460 + 460);
-      $("#ulproc").scrollLeft(depth * 460 + 460);
+    }
+    $("#depth" + (depth - 1)).nextAll(".singleAdv").remove();
+    var target = $('<div class="singleAdv" data-depth="' + depth + '" id="depth' + depth + '" data-parent="' + id + '" data-type="' + type + '"></div>');
+    target.appendTo("#procCon");
+    $("#procCon").css("width", depth * 460 + 460);
+    $("#ulproc").scrollLeft(depth * 460 + 460);
 
     $.get(link, function(exp) {
-
-      //console.log(procesy);
-
-      //console.log(next);
       var result = "";
-
       result += "<li ";
-      if(id != 0){
-        if("childs" == type || "goto" == type || "details" == type)
+      if (id != 0) {
+        if ("childs" == type || "goto" == type || "details" == type) {
           result += "data-opis='" + procesy[id]["OPIS"] + "' data-desc='" + procesy[id]["DESC"] + "'  data-id=" + id + " ";
-        else
+        } else {
           result += "data-opis='" + res[id]["OPIS"] + "' data-desc='" + res[id]["DESC"] + "'  data-id=" + id + " ";
+        }
       }
-      if ("childs" == type)
+      if ("childs" == type) {
         result += "class='list-group-item disabled-item normalChilds'>" + (id == 0 ? "Procesy" : "{" + id + "} Procesy podrzędne");
-      if ("details" == type)
+      }
+      if ("details" == type) {
         result += "class='list-group-item disabled-item normalChilds '>{" + id + "} Szczegóły";
-      if ("res" == type || "alias" == type)
+      }
+      if ("res" == type || "alias" == type) {
         result += "class='list-group-item disabled-item normalChilds'>" + (id == 0 ? "Zasoby" : "[" + id + "] Zasoby podrzędne");
-      if ("detailsRes" == type)
+      }
+      if ("detailsRes" == type) {
         result += "class='list-group-item disabled-item normalChilds'>[" + id + "] Szczegóły";
-      if ("goto" == type)
+      }
+      if ("goto" == type) {
         result += "class='list-group-item disabled-item normalChilds'>{" + id + "} Procesy podrzędne";
-      if ("connect" == type)
+      }
+      if ("connect" == type) {
         result += "class='list-group-item disabled-item normalChilds'>[" + id + "] Procesy powiązane";
+      }
       if(id != 0 && "connect" != type){
         result += "<div style=float:right;><div class='dropdown '>";
 
         if ("goto" == type || "details" == type || "childs" == type) {
-        result += "<span class='glyph glyphicon glyphicon glyphicon-menu-hamburger dropdown-toggle' data-toggle='dropdown' aria-haspopup='true' aria-expanded='true' id='dropdownMenuP" + procesy[id]["ID"] + "'></span>";
-        result += '<ul class="dropdown-menu dropdown-menu-right" style=z-index:100 aria-labelledby="dropdownMenuP' + procesy[id]["ID"] + '">';
+          result += "<span class='glyph glyphicon glyphicon glyphicon-menu-hamburger dropdown-toggle' data-toggle='dropdown' aria-haspopup='true' aria-expanded='true' id='dropdownMenuP" + procesy[id]["ID"] + "'></span>";
+          result += '<ul class="dropdown-menu dropdown-menu-right" style=z-index:100 aria-labelledby="dropdownMenuP' + procesy[id]["ID"] + '">';
         }
         if ("res" == type || "alias" == type || "connect" == type || "detailsRes" == type) {
           result += "<span class='glyph glyphicon glyphicon glyphicon-menu-hamburger dropdown-toggle' data-toggle='dropdown' aria-haspopup='true' aria-expanded='true' id='dropdownMenuR" + res[id]["ID"] + "'></span>";
@@ -342,22 +343,17 @@ $(document).ready(function() {
             result += '<li><a href="' + BASE_URL + 'index.php?_route=ViewTableAjax&typeName=p5_default_db:CRM_LISTA_ZASOBOW#EDIT/' + data["ID"] + '">Edytuj zasób</a></li>';
             result += '<li><a href="" class=connect>Procesy powiązane</a></li>';
           }
-
         result += '</ul>';
         result += "</div><div>";
       }
       result += "</li>";
-
-
       result += "<ul class='singleAdvList list-group' style=margin-bottom:0px;>";
-
       if (("details" == type && "res" != $("#depth" + (depth - 1)).data("type"))) {
         result += getDetails(procesy[id], exp, "proces");
       }
       if (("details" == type && "res" == $("#depth" + (depth - 1)).data("type")) || "detailsRes" == type) {
         result += getDetails(res[id], exp, "res");
       }
-
       if ("childs" == type || "gotoChilds" == type) {
         if (procesy[id]["childs"].length > 0) {
           $.each(procesy[id]["childs"], function(i, e) {
@@ -367,11 +363,9 @@ $(document).ready(function() {
           result += getDetails(procesy[id], exp, "proces");
         }
       }
-
       if ("goto" == type) {
         result += getDetails(procesy[id], exp);
       }
-
       if ("connect" == type) {
         if (exp["wsk"].length > 0) {
           $.each(exp["wsk"], function(i, e) {
@@ -381,7 +375,6 @@ $(document).ready(function() {
           result += "<li class='list-group-item disabled-item list-group-item-danger'>Brak procesów powiązanych.</li>";
         }
       }
-
       if ("res" == type || "aliasChilds" == type) {
         if (res[id]["childs"].length > 0) {
           $.each(res[id]["childs"], function(i, e) {
@@ -391,37 +384,27 @@ $(document).ready(function() {
           result += getDetails(res[id], exp);
         }
       }
-
       if ("alias" == type) {
         result += getDetails(res[id], exp);
       }
-
       result += "</ul></div>";
-
-
       $("#ulproc").scrollTop(0);
       target.html(result);
       $(".singleAdvList").css("height", $(window).height() - 200 + "px");
-
-
     });
-    //console.log(result);
     localStorage.setItem( TYPE, JSON.stringify(state) );
   }
 
   function render() {
     if (panels) {
-      //console.log("panels");
       renderPanels();
     } else {
-      //console.log("drzewo");
       renderTree();
     }
   }
 
   function updateParent(id, parent, item) {
     var link = BASE_URL + 'wfs-data.php/default_db/?SERVICE=WFS&VERSION=1.0.0&SRSNAME=EPSG:3003&';
-
     var req = `
 <Transaction
 xmlns="http://www.opengis.net/wfs"
@@ -453,16 +436,13 @@ xmlns:gml="http://www.opengis.net/gml">
         $.notify("Brak połączenia z bazą danych", "error");
       }
     });
-
   }
 
   $(document).on("click", ".toggleRoute", function(){
-
     var obj = $(this).closest(".singleAdv");
     var id = $(obj).data("parent");
     var type = $(obj).data("type");
-
-    if($(this).data("state") == 0){
+    if ($(this).data("state") == 0) {
       $(this).data("state", 1);
       $(this).text("UKRYJ ŚCIEŻKĘ");
       $(this).parent().find(".route").html("<ul style=list-style:none;padding-left:0px;>"+showTree(id, type, 0)+"</ul>");
@@ -472,7 +452,7 @@ xmlns:gml="http://www.opengis.net/gml">
         depth += 16;
       });
       $(this).parent().find(".route").show();
-    }else{
+    } else {
       $(this).data("state", 0);
       $(this).text("POKAŻ ŚCIEŻKĘ");
       $(this).parent().find(".route").hide();
@@ -481,31 +461,29 @@ xmlns:gml="http://www.opengis.net/gml">
   });
 
   function showTree(id, type, count) {
-      //console.log(count);
-      if(id == "#" || count >= 100)
+    if (id == "#" || count >= 100) return "";
+    if (type == "detailsRes" || type == "alias") {
+      if (typeof res[id]["DESC"] != "undefined") {
+        return showTree(res[id]["PARENT_ID"], "detailsRes", count+1)+"<li style=padding-left:0px;><span class='glyphicon glyphicon-arrow-right'></span> " + res[id]["DESC"] + "</li>";
+      } else {
+        return "";
+      }
+    } else {
+      if (typeof procesy[id]["DESC"] != "undefined") {
+        return showTree(procesy[id]["PARENT_ID"], "detailsProc", count+1)+"<li style=padding-left:0px;><span class='glyphicon glyphicon-arrow-right'></span> " + procesy[id]["DESC"] + "</li>";
+      } else {
         return "";
-      if(type == "detailsRes" || type == "alias")
-        if(typeof res[id]["DESC"] != "undefined")
-          return showTree(res[id]["PARENT_ID"], "detailsRes", count+1)+"<li style=padding-left:0px;><span class='glyphicon glyphicon-arrow-right'></span> " + res[id]["DESC"] + "</li>";
-        else
-          return "";
-      else
-        if(typeof procesy[id]["DESC"] != "undefined")
-          return showTree(procesy[id]["PARENT_ID"], "detailsProc", count+1)+"<li style=padding-left:0px;><span class='glyphicon glyphicon-arrow-right'></span> " + procesy[id]["DESC"] + "</li>";
-        else
-          return "";
+      }
+    }
   }
 
-
-
   function getDetails(e, data, type) {
-
-    //console.log("test", e);
     var result = "";
-    if(type == "proces")
+    if (type == "proces") {
       result += '<div class="panel panel-info" style=margin-bottom:0px;>';
-    else
+    } else {
       result += '<div class="panel panel-success" style=margin-bottom:0px;>';
+    }
     result += '<div class="panel-heading"><h3 class="panel-title">' + e["DESC"] + '</h3></div>';
     result += '<div class="panel-body pbody">';
     result += e["OPIS"];
@@ -538,6 +516,7 @@ xmlns:gml="http://www.opengis.net/gml">
       });
       result += "</ul>";
     }
+
     return result;
   }
 
@@ -548,8 +527,8 @@ xmlns:gml="http://www.opengis.net/gml">
     var parent_id = $(this).data("id");
     var id = procesy[parent_id]["ID"];
     var depth = $(this).closest(".singleAdv").data("depth") + 1;
-
     createPanel(id, depth, "goto");
+
     return false;
   });
 
@@ -560,8 +539,8 @@ xmlns:gml="http://www.opengis.net/gml">
     var parent_id = $(this).data("id");
     var id = res[parent_id]["ID"];
     var depth = $(this).closest(".singleAdv").data("depth") + 1;
-
     createPanel(id, depth, "alias");
+
     return false;
   });
 
@@ -646,23 +625,27 @@ xmlns:gml="http://www.opengis.net/gml">
 
     if (data["ALIAS_ID"] != 0 && type == "res") {
       var id = data["ALIAS_ID"];
-      data = res[id];
-      result += "<li class='list-group-item alias " + (state[depth]["FOCUS"] == data["ID"] ? "list-group-item-info" : "") + "'; ";
-      result += "data-opis='" + data["OPIS"] + "' data-desc='" + data["DESC"] + "'  data-id=" + data["ID"] + " style=border-top-style:none;>";
-      result += "";
-      result += '<div class="textTable">'
-      result += "<span class=gotoInfo><span class='glyphicon glyphicon-arrow-right'></span> ALIAS </span><span class=gotoWay>" + data["ID"] + "</span>";
-      result += "</div>"
-      result += "<div style=float:right;><span class='glyph glyphicon gl glyphicon-triangle-right'></span>";
-      result += "<div class='dropdown '>";
-      result += "<span class='glyph glyphicon glyphicon glyphicon-menu-hamburger dropdown-toggle' data-toggle='dropdown' aria-haspopup='true' aria-expanded='true' id='dropdownMenu" + data["ID"] + "'></span>";
-      result += '<ul class="dropdown-menu dropdown-menu-right" style=z-index:100 aria-labelledby="dropdownMenu' + data["ID"] + '">';
-      result += '<li><a href="' + BASE_URL + 'index.php?_route=ViewTableAjax&typeName=p5_default_db:CRM_LISTA_ZASOBOW#EDIT/' + data["ID"] + '">Edytuj zasób</a></li>';
-      result += '<li><a href="" class=connect>Procesy powiązane</a></li>';
-      result += '<li><a href="" class=details>Szczegóły</a></li>';
-      result += '</ul>';
-      result += "</div>";
-      result += '</div><div class=clearfix></div></blockqoute></li>';
+      if (id in res) {
+        data = res[id];
+        result += "<li class='list-group-item alias " + (state[depth]["FOCUS"] == data["ID"] ? "list-group-item-info" : "") + "'; ";
+        result += "data-opis='" + data["OPIS"] + "' data-desc='" + data["DESC"] + "'  data-id=" + data["ID"] + " style=border-top-style:none;>";
+        result += "";
+        result += '<div class="textTable">'
+        result += "<span class=gotoInfo><span class='glyphicon glyphicon-arrow-right'></span> ALIAS </span><span class=gotoWay>" + data["ID"] + "</span>";
+        result += "</div>"
+        result += "<div style=float:right;><span class='glyph glyphicon gl glyphicon-triangle-right'></span>";
+        result += "<div class='dropdown '>";
+        result += "<span class='glyph glyphicon glyphicon glyphicon-menu-hamburger dropdown-toggle' data-toggle='dropdown' aria-haspopup='true' aria-expanded='true' id='dropdownMenu" + data["ID"] + "'></span>";
+        result += '<ul class="dropdown-menu dropdown-menu-right" style=z-index:100 aria-labelledby="dropdownMenu' + data["ID"] + '">';
+        result += '<li><a href="' + BASE_URL + 'index.php?_route=ViewTableAjax&typeName=p5_default_db:CRM_LISTA_ZASOBOW#EDIT/' + data["ID"] + '">Edytuj zasób</a></li>';
+        result += '<li><a href="" class=connect>Procesy powiązane</a></li>';
+        result += '<li><a href="" class=details>Szczegóły</a></li>';
+        result += '</ul>';
+        result += "</div>";
+        result += '</div><div class=clearfix></div></blockqoute></li>';
+      } else {
+        console.log('BUG ALIAS_ID['+data['ALIAS_ID']+'] in ['+data['ID']+'] not in res', data, res);
+      }
     }
 
     return result;
@@ -679,8 +662,6 @@ xmlns:gml="http://www.opengis.net/gml">
     var parentOfParent_id = $(this).closest(".singleAdv").data("parent");
     var depth = $(this).closest(".singleAdv").data("depth") + 1;
     createPanel(parent_id, depth, "connect");
-
-
   });
 
   $(document).on('click', '.details', function(e) {
@@ -695,10 +676,8 @@ xmlns:gml="http://www.opengis.net/gml">
     var depth = $(this).closest(".singleAdv").data("depth") + 1;
     if ($(this).closest(".list-group-item").hasClass("wsk") || $(this).closest(".singleAdv").data("type") == "res" || $(this).closest(".list-group-item").hasClass("alias")) {
       createPanel(parent_id, depth, "detailsRes");
-      //console.log("detailsRes");
     } else {
       createPanel(parent_id, depth, "details");
-      //console.log("details");
     }
     initSortable();
   });
@@ -736,17 +715,17 @@ xmlns:gml="http://www.opengis.net/gml">
   });
 
   $(document).on('click', '.liProc', function() {
-
     $(this).parents(".singleAdv").find(".active").removeClass("active");
     $(this).parents(".singleAdv").find(".list-group-item-info").removeClass("list-group-item-info");
     $(this).addClass("active");
     var parent_id = $(this).data("id");
     var parentOfParent_id = $(this).closest(".singleAdv").data("parent");
     var depth = $(this).closest(".singleAdv").data("depth") + 1;
-    if ($(this).hasClass("wsk"))
+    if ($(this).hasClass("wsk")) {
       createPanel(parent_id, depth, "res");
-    else
+    } else {
       createPanel(parent_id, depth, "inherit");
+    }
     initSortable();
   });
 
@@ -766,31 +745,41 @@ xmlns:gml="http://www.opengis.net/gml">
     //     updateParent($(ui.item).data("id"),$(ui.item).closest(".singleAdv").data("parent"), this);
     //     },
     // }).disableSelection();
-
   }
 
   function start() {
     var link = BASE_URL + 'index.php?_route=UrlAction_ProcesView&_task=getAllAjax';
     $.get(link, function(data) {
-      //console.log("x");
-      //console.log(data);
-      procesy = data;
-      if (TYPE == "childs")
-        render();
-      //console.log(procesy);
+      procesy = {}
+      for (idx in data) {// FIX childs by SORT_PRIO
+        var d = data[idx]
+        if ('childs' in d) {
+          var dataChilds = d['childs'].map(function (child) {
+            var idChild = child['ID'];
+            var sortPrio = (idChild in data) ? parseInt(data[idChild]['SORT_PRIO']) : 0;
+            return {SORT_PRIO: sortPrio, ID: idChild};
+          });
+          var sortedChilds = dataChilds.sort(function(a, b) {
+            if (a['SORT_PRIO'] == b['SORT_PRIO']) {
+              return a['ID'] - b['ID'];
+            }
+            else {
+              return a['SORT_PRIO'] - b['SORT_PRIO'];
+            }
+          });
+          d['childs'] = sortedChilds;
+        }
+        procesy[idx] = d;
+      }
+      if (TYPE == "childs") render();
     });
     link = BASE_URL + 'index.php?_route=UrlAction_ProcesView&_task=getAllResAjax';
     $.get(link, function(data) {
-      //console.log("x");
-      //console.log(data);
       res = data;
-      if (TYPE == "res")
-        render();
-      //console.log(res);
-
+      if (TYPE == "res") render();
     });
   }
-  start();
 
+  start();
 
 });