Browse Source

updated processEditor

Piotr Labudda 9 years ago
parent
commit
23341436fd
2 changed files with 251 additions and 129 deletions
  1. 111 11
      SE/se-lib/Route/UrlAction/ProcesEditor.php
  2. 140 118
      SE/static/procesEditor.js

+ 111 - 11
SE/se-lib/Route/UrlAction/ProcesEditor.php

@@ -5,9 +5,85 @@ Lib::loadClass('ProcesHelper');
 Lib::loadClass('Config');
 Lib::loadClass('UI');
 Lib::loadClass('Request');
+Lib::loadClass('Response');
 
 class Route_UrlAction_ProcesEditor extends RouteBase {// TODO: UrlActionBase @see Route_UrlAction
 
+	public function getResByParentAjaxAction(){
+		try {
+			if(!isset($_GET['parent_id'])) throw new Exception("ID is not set.");
+				$parent_id = DB::getPDO()->quote($_GET['parent_id'], PDO::PARAM_INT);
+				$rows = DB::getPDO()->fetchAll("
+					select g.*, p1.ID as p1_ID, p1.DESC as p1_DESC,p2.ID as p2_ID, p2.DESC as p2_DESC, p3.ID as p3_ID, p3.DESC as p3_DESC
+					from CRM_LISTA_ZASOBOW g
+						left join CRM_LISTA_ZASOBOW p1 on(p1.ID = g.PARENT_ID)
+						left join CRM_LISTA_ZASOBOW p2 on(p2.ID = p1.PARENT_ID)
+						left join CRM_LISTA_ZASOBOW p3 on(p3.ID = p2.PARENT_ID)
+					where g.`PARENT_ID` = ".$parent_id." ORDER BY g.SORT_PRIO
+				");
+				Response::sendJsonExit($rows);
+			} catch (Exception $e) {
+				UI::alert('danger', "Error: " . $e->getMessage());
+			}
+	}
+
+	public function getResAjaxAction(){
+		try {
+			if(!isset($_GET['word'])) throw new Exception("word is not set.");
+				$word = DB::getPDO()->quote("%".$_GET['word']."%", PDO::PARAM_STR);
+
+			$filter = isset($_GET['filter']) ? (int)$_GET['filter'] : 0;
+
+
+			$sqlFilter = "";
+			switch($filter){
+				case 2: $sqlFilter = "AND (g.`TYPE` = 'TABELA' OR g.`TYPE` = 'KOMORKA')";break;
+				case 1: $sqlFilter = "AND (g.`TYPE` = 'STANOWISKO' OR g.`TYPE` = 'DZIAL' OR g.`TYPE` = 'PODMIOT')";break;
+			}
+				$rows = DB::getPDO()->fetchAll("
+					select g.*, p1.ID as p1_ID, p1.DESC as p1_DESC,p2.ID as p2_ID, p2.DESC as p2_DESC, p3.ID as p3_ID, p3.DESC as p3_DESC
+					from CRM_LISTA_ZASOBOW g
+						left join CRM_LISTA_ZASOBOW p1 on(p1.ID = g.PARENT_ID)
+						left join CRM_LISTA_ZASOBOW p2 on(p2.ID = p1.PARENT_ID)
+						left join CRM_LISTA_ZASOBOW p3 on(p3.ID = p2.PARENT_ID)
+					where (g.`DESC` LIKE ".$word." OR g.`ID` LIKE ".$word.")
+						".$sqlFilter."
+					LIMIT 0,100
+				");
+				Response::sendJsonExit($rows);
+			} catch (Exception $e) {
+				UI::alert('danger', "Error: " . $e->getMessage());
+			}
+	}
+
+	public function getSingleResAjaxAction(){
+
+		try {
+			if (!isset($_POST['data'])) throw new Exception("data is not set.");
+			$data = $_POST['data'];
+			$sqlWhereIdIn = array();
+			foreach ($data as $value) {
+        $sqlWhereIdIn[] = DB::getPDO()->quote($value, PDO::PARAM_INT);
+                        }
+        $sqlWhereIdIn = (!empty($sqlWhereIdIn)) ? "g.ID in(" . implode(", ", $sqlWhereIdIn) . ")" : "1=1";
+			$rows = DB::getPDO()->fetchAll("
+			select g.*, p1.ID as p1_ID, p1.DESC as p1_DESC,p2.ID as p2_ID, p2.DESC as p2_DESC, p3.ID as p3_ID, p3.DESC as p3_DESC
+			from CRM_LISTA_ZASOBOW g
+			  left join CRM_LISTA_ZASOBOW p1 on(p1.ID = g.PARENT_ID)
+			  left join CRM_LISTA_ZASOBOW p2 on(p2.ID = p1.PARENT_ID)
+				left join CRM_LISTA_ZASOBOW p3 on(p3.ID = p2.PARENT_ID)
+			where {$sqlWhereIdIn}");
+				Response::sendJsonExit($rows);
+
+			} catch (Exception $e) {
+				UI::alert('danger', "Error: " . $e->getMessage());
+			}
+
+
+
+
+	}
+
 	public function handleAuth() {
 		if (!User::logged()) {
 			//throw new HttpException('Unauthorized', 401);
@@ -37,10 +113,11 @@ class Route_UrlAction_ProcesEditor extends RouteBase {// TODO: UrlActionBase @se
 
 		echo "<div id=wrapper class=toggled>";
 		echo "<div id='sidebar-wrapper'><div id=side>";
+
 		echo "";
 		echo "</div></div>";
 		echo "<div id='page-content-wrapper'><div class=col-xs-1 id=left style='width:40px;'>";
-		echo "<button class='lButton btn btn-default' id=btnZasoby><p>Zasoby</p></button><button class='lButton btn btn-default' style=top:315px; id=btnProcesy><p>Procesy</p></button>";
+		echo "<button class='lButton btn btn-default' id=btnZasoby style=top:150px; ><p>Zasoby</p></button><button class='lButton btn btn-default' style=top:315px; id=btnProcesy><p>Procesy</p></button>";
 		echo "</div><div class=col-xs-11 id=main>";
 
 		echo '<center>Uruchamianie aplikacji.</center>';
@@ -62,6 +139,21 @@ class Route_UrlAction_ProcesEditor extends RouteBase {// TODO: UrlActionBase @se
 
 }
 
+.treeInfo{
+	overflow: hidden;
+  text-align: right;
+	display:inline-block;
+	color:grey;
+	font-size:0.9em;
+
+  white-space: nowrap;
+  max-width: 90%;
+}
+
+.treeInfo div{
+	float:right;
+}
+
 #left{
 	padding:0px;
 }
@@ -71,9 +163,8 @@ class Route_UrlAction_ProcesEditor extends RouteBase {// TODO: UrlActionBase @se
 }
 
 .lButton{
-
-	position:fixed;
-    top:150px;
+	-webkit-transform: translate3d(0,0,0);
+    position:fixed;
     padding:0px;
 		outline:none;
     margin:0px;
@@ -112,7 +203,7 @@ class Route_UrlAction_ProcesEditor extends RouteBase {// TODO: UrlActionBase @se
     transition: all 0.5s ease;
 }
 #wrapper.toggled {
-    padding-left: 300px;
+    padding-left: 600px;
 }
 #side {
     padding: 15px;
@@ -141,6 +232,15 @@ ul {
 	height:23px;
 }
 
+.tree{
+	color:grey;
+	text-overflow:ellipsis;
+	white-space:nowrap;
+  overflow:hidden;
+	display:block;
+	cursor:pointer;
+}
+
 .detailsTable2{
 	color:grey;
 	display:block;
@@ -307,11 +407,11 @@ width:290px;
 }
 #sidebar-wrapper {
     position: fixed;
-    left: 300px;
+    left: 600px;
     width: 0;
     height: 100%;
     color: white;
-    margin-left: -300px;
+    margin-left: -600px;
     overflow-y: auto;
     background: #222;
     -webkit-transition: all 0.5s ease;
@@ -320,7 +420,7 @@ width:290px;
     transition: all 0.5s ease;
 }
 #wrapper.toggled #sidebar-wrapper {
-    width: 300px;
+    width: 600px;
 }
 #page-content-wrapper {
     width: 100%;
@@ -331,17 +431,17 @@ width:290px;
 }
 #wrapper.toggled #page-content-wrapper {
     position: absolute;
-    margin-right: -300px;
+    margin-right: -600px;
 }
 
     #wrapper {
-        padding-left: 300px;
+        padding-left: 600px;
     }
     #wrapper.toggled {
         padding-left: 0 !important;
     }
     #sidebar-wrapper {
-        width: 300px;
+        width: 600px;
     }
     #wrapper.toggled #sidebar-wrapper {
         width: 0 !important;

+ 140 - 118
SE/static/procesEditor.js

@@ -8,6 +8,7 @@ $(document).ready(function() {
     var generatedId = new Array();
     var deletedRes = new Array();
     var dialog = 0;
+    var zasobTree = new Array();
 
     var perms = [
         [1, "Kto wykonuje", "X"],
@@ -56,6 +57,7 @@ $(document).ready(function() {
     var newRes = 0;
 
 
+
     function loadResources() {
         $("#main").html("<center>Pobieranie danych o zasobach.</center>");
         //console.log("res!");
@@ -108,77 +110,63 @@ $(document).ready(function() {
 
                 });
                 //console.log(res);
-                var sFiltr2 = "";
-
-                var link2 = BASE_URL + 'wfs-data.php/default_db/?SERVICE=WFS&VERSION=1.0.0&REQUEST=GetFeature&TYPENAME=p5_default_db:CRM_LISTA_ZASOBOW&SRSNAME=EPSG:3003&sortBy=SORT_PRIO+A,ID';
+                var sFiltr2 = [];
 
-                sFiltr2 += `
-            <GetFeature xmlns="http://www.opengis.net/wfs/2.0"
-            xmlns:p5_default_db="` + BASE_URL + `wfs/default_db"
-            xmlns:ogc="http://www.opengis.net/ogc"
-            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-            service="WFS"
-            version="2.0.2"
-            xsi:schemaLocation="http://www.opengis.net/wfs/2.0 http://schemas.opengis.net/wfs/2.0/wfs.xsd">
-            <ogc:Filter>
-            <ogc:Or>`;
+                var link2 = BASE_URL+"index.php?_route=UrlAction_ProcesEditor&_task=getSingleResAjax";
                 $.each(res, function(index, value) {
                     var id = res[index]["ID_ZASOB"];
-                    sFiltr2 += `
-              <ogc:PropertyIsEqualTo>
-              <ogc:PropertyName>ID</ogc:PropertyName>
-              <ogc:Literal>` + id + `</ogc:Literal>
-              </ogc:PropertyIsEqualTo>`;
-
+                    sFiltr2.push(id);
                 });
-
-                sFiltr2 += `
-            </ogc:Or>
-            </ogc:Filter>
-            </GetFeature>`;
+                //sFiltr2 = JSON.stringify(sFiltr2);
                 //console.log(sFiltr2);
                 //console.log(link2);
                 var zasobInfo = new Array();
-                $.ajax({
-                    url: link2,
-                    data: sFiltr2,
-                    type: 'POST',
-                    contentType: "text/xml",
-                    dataType: "xml",
-                    success: function(data2) {
-                        //console.log("data");
-                        //console.log(data2);
-                        $.each($(data2).find("featureMember"), function() {
-                            //console.log();
-                            zasobInfo[$(this).find("ID").text()] = new Array();
-                            zasobInfo[$(this).find("ID").text()]["DESC"] = $(this).find("DESC").text();
-                            zasobInfo[$(this).find("ID").text()]["OPIS"] = $(this).find("OPIS").text();
-                            zasobInfo[$(this).find("ID").text()]["TYPE"] = $(this).find("TYPE").text();
-                        });
-                        //console.log(res);
-                        $.each(res, function(index, value) {
-                            var type;
-                            if (zasobInfo[res[index]["ID_ZASOB"]]["TYPE"] == "DZIAL" || zasobInfo[res[index]["ID_ZASOB"]]["TYPE"] == "STANOWISKO" || zasobInfo[res[index]["ID_ZASOB"]]["TYPE"] == "PODMIOT") {
-                                type = "prof";
-                            } else {
-                                type = "res";
-                            }
-                            var id = res[index]["ID_PROCES"];
-
-                            var temp = {};
-                            temp["id_zasob"] = res[index]["ID_ZASOB"]
-                            temp["id"] = res[index]["ID"];
-                            temp["id_przypadek"] = res[index]["ID_PRZYPADEK"];
-                            temp["komentarz"] = res[index]["OPIS_ZASOB"];
-                            temp["desc"] = zasobInfo[res[index]["ID_ZASOB"]]["DESC"];
-                            temp["opis"] = zasobInfo[res[index]["ID_ZASOB"]]["OPIS"];
-                            //console.log(temp);
-                            state[getIndexById(id)][type].push(temp);
-
-                        });
-                        $("#main").html("<center>Generowanie widoku.</center>");
-                        render(state, $("#main"));
+                $.post(link2, {data: sFiltr2}, function(data2){
+                  //console.log("data");
+                  console.log(data2);
+
+                  $.each(data2, function(i, e) {
+
+                      zasobInfo[e["ID"]] = new Array();
+                      zasobInfo[e["ID"]]["DESC"] = e["DESC"];
+                      zasobInfo[e["ID"]]["OPIS"] = e["OPIS"];
+                      zasobInfo[e["ID"]]["TYPE"] = e["TYPE"];
+                      zasobInfo[e["ID"]]["TREE"] = [];
+                      for(var i=3;i>0;i--){
+                        if(e["p"+i+"_ID"] != null){
+                          var temp = {};
+                          temp["ID"] = e["p"+i+"_ID"];
+                          temp["DESC"] = e["p"+i+"_DESC"];
+                          zasobInfo[e["ID"]]["TREE"].push(temp);
+                        }
                     }
+                  });
+                  //console.log(res);
+                  $.each(res, function(index, value) {
+                      var type;
+                      if (zasobInfo[res[index]["ID_ZASOB"]]["TYPE"] == "DZIAL" || zasobInfo[res[index]["ID_ZASOB"]]["TYPE"] == "STANOWISKO" || zasobInfo[res[index]["ID_ZASOB"]]["TYPE"] == "PODMIOT") {
+                          type = "prof";
+                      } else {
+                          type = "res";
+                      }
+                      var id = res[index]["ID_PROCES"];
+
+                      var temp = {};
+                      temp["id_zasob"] = res[index]["ID_ZASOB"]
+                      temp["id"] = res[index]["ID"];
+                      temp["id_przypadek"] = res[index]["ID_PRZYPADEK"];
+                      temp["komentarz"] = res[index]["OPIS_ZASOB"];
+                      temp["desc"] = zasobInfo[res[index]["ID_ZASOB"]]["DESC"];
+                      temp["opis"] = zasobInfo[res[index]["ID_ZASOB"]]["OPIS"];
+                      temp["tree"] = zasobInfo[res[index]["ID_ZASOB"]]["TREE"];
+                      //console.log(temp);
+                      state[getIndexById(id)][type].push(temp);
+
+                  });
+                  $("#main").html("<center>Generowanie widoku.</center>");
+                  render(state, $("#main"));
+
+                    //}
                 });
             }
         });
@@ -443,9 +431,7 @@ $(document).ready(function() {
                 permsOpt = permsOpt + "<option value=" + value[0] + " selected=selected>[" + value[2] + "] " + value[1] + "</option>";
             else
                 permsOpt = permsOpt + "<option value=" + value[0] + ">[" + value[2] + "] " + value[1] + "</option>";
-
-
-        })
+        });
         swal({
             showCancelButton: true,
             title: 'Uprawnienia',
@@ -622,6 +608,8 @@ $(document).ready(function() {
         updateAll();
     });
 
+
+
     $(document).on('click', '#btnZasoby', function(e) {
         e.preventDefault();
         $(".lButton").removeClass("btn-primary");
@@ -654,6 +642,7 @@ $(document).ready(function() {
             procesy();
             $("#wrapper").removeClass("toggled");
             $(this).addClass("btn-primary");
+
             dialog = 2;
         } else if (dialog == 2) {
             $("#wrapper").addClass("toggled");
@@ -752,7 +741,7 @@ $(document).ready(function() {
             return;
 
         var action = $(this).parents(".drop").find(".hdesc");
-        console.log(action);
+        //console.log(action);
         if ($(action).find("textarea").length == 0) {
 
             //alert($(action).text());
@@ -894,6 +883,8 @@ $(document).ready(function() {
 
     });
 
+
+
     $(document).on('click', '.showMore', function() {
         var target = $(this).parent().find(".more");
         var id = $(this).data("id");
@@ -911,13 +902,22 @@ $(document).ready(function() {
             $(target).parent().find(".gIco").removeClass("glyphicon-chevron-down");
             $(target).parent().find(".gIco").addClass("glyphicon-chevron-up");
 
-            var link = BASE_URL + 'wfs-data.php/default_db/?SERVICE=WFS&VERSION=1.0.0&REQUEST=GetFeature&TYPENAME=p5_default_db:CRM_LISTA_ZASOBOW&SRSNAME=EPSG:3003&Filter=<ogc:Filter><ogc:And><ogc:PropertyIsEqualTo><ogc:PropertyName>PARENT_ID</ogc:PropertyName><ogc:Literal>' + id + '</ogc:Literal></ogc:PropertyIsEqualTo><ogc:PropertyIsEqualTo><ogc:PropertyName>TYPE</ogc:PropertyName><ogc:Literal>KOMORKA</ogc:Literal></ogc:PropertyIsEqualTo></ogc:And></ogc:Filter>&sortBy=SORT_PRIO+A,ID';
+            var link = BASE_URL+"index.php?_route=UrlAction_ProcesEditor&_task=getResByParentAjax&parent_id="+id;
             //console.log(link);
             $.get(link, function(data) {
-                $.each($(data).find("featureMember"), function() {
-                    if ($(this).find("ID").text() != 0) {
+                $.each(data, function(i, e) {
+                    if (e["ID"] != 0) {
                         var type = 0;
-                        $(target).append("<div class='dragStyle drag dragStyle hov' data-id=" + $(this).find("ID").text() + " data-type=" + type + " data-desc='" + $(this).find("DESC").text() + "' data-opis='" + $(this).find("OPIS").text() + "'>" + $(this).find("DESC").text() + " [" + $(this).find("ID").text() + "]</div>");
+                        $(target).append("<div class='dragStyle drag dragStyle hov' data-id=" + e["ID"] + " data-type=" + type + " data-desc='" + e["DESC"]+ "' data-opis='" + e["OPIS"] + "'>" + e["DESC"] + " [" + e["ID"] + "]</div>");
+                        for(var i=3;i>0;i--){
+                          if(e["p"+i+"_ID"] != null){
+                            var temp = {};
+                            temp["ID"] = e["p"+i+"_ID"];
+                            temp["DESC"] = e["p"+i+"_DESC"];
+                            zasobTree[e["ID"]] = [];
+                            zasobTree[e["ID"]].push(temp);
+                          }
+                        }
                         $('.drag').draggable({
                             appendTo: 'body',
                             helper: 'clone',
@@ -925,11 +925,8 @@ $(document).ready(function() {
                             distance: 0,
                             cursor: "copy"
                         });
-
                     }
                 });
-
-
             });
         }
     });
@@ -941,9 +938,6 @@ $(document).ready(function() {
 
         link = BASE_URL + 'wfs-data.php/default_db/?SERVICE=WFS&VERSION=1.0.0&REQUEST=GetFeature&TYPENAME=p5_default_db:CRM_PROCES&SRSNAME=EPSG:3003&Filter=<ogc:Filter><ogc:Or><ogc:PropertyIsLike wildCard="*" singleChar="^" escapeChar="!"><ogc:PropertyName>ID</ogc:PropertyName><ogc:Literal>*' + id + '*</ogc:Literal></ogc:PropertyIsLike><ogc:PropertyIsLike wildCard="*" singleChar="%23" escapeChar="!"><ogc:PropertyName>DESC</ogc:PropertyName><ogc:Literal>*' + id + '*</ogc:Literal></ogc:PropertyIsLike></ogc:Or></ogc:Filter>&maxFeatures=100';
 
-
-
-
         $.get(link, function(data) {
             var side = $("#side");
             //console.log(data);
@@ -975,47 +969,37 @@ $(document).ready(function() {
     function searchRes() {
         var id = lastSearch;
         var link;
-        //console.log("Szukam");
-        switch (filtr) {
-            case 0:
-                link = BASE_URL + 'wfs-data.php/default_db/?SERVICE=WFS&VERSION=1.0.0&REQUEST=GetFeature&TYPENAME=p5_default_db:CRM_LISTA_ZASOBOW&SRSNAME=EPSG:3003&Filter=<ogc:Filter><ogc:Or><ogc:PropertyIsLike wildCard="*" singleChar="^" escapeChar="!"><ogc:PropertyName>ID</ogc:PropertyName><ogc:Literal>*' + id + '*</ogc:Literal></ogc:PropertyIsLike><ogc:PropertyIsLike wildCard="*" singleChar="%23" escapeChar="!"><ogc:PropertyName>DESC</ogc:PropertyName><ogc:Literal>*' + id + '*</ogc:Literal></ogc:PropertyIsLike></ogc:Or></ogc:Filter>&maxFeatures=100';
-                break;
-            case 1:
-                link = BASE_URL + 'wfs-data.php/default_db/?SERVICE=WFS&VERSION=1.0.0&REQUEST=GetFeature&TYPENAME=p5_default_db:CRM_LISTA_ZASOBOW&SRSNAME=EPSG:3003&Filter=<ogc:Filter><ogc:And><ogc:Or><ogc:PropertyIsLike wildCard="*" singleChar="^" escapeChar="!"><ogc:PropertyName>ID</ogc:PropertyName><ogc:Literal>*' + id + '*</ogc:Literal></ogc:PropertyIsLike><ogc:PropertyIsLike wildCard="*" singleChar="%23" escapeChar="!"><ogc:PropertyName>DESC</ogc:PropertyName><ogc:Literal>*' + id + '*</ogc:Literal></ogc:PropertyIsLike></ogc:Or><ogc:Or><ogc:PropertyIsEqualTo><ogc:PropertyName>TYPE</ogc:PropertyName><ogc:Literal>STANOWISKO</ogc:Literal></ogc:PropertyIsEqualTo><ogc:PropertyIsEqualTo><ogc:PropertyName>TYPE</ogc:PropertyName><ogc:Literal>PODMIOT</ogc:Literal></ogc:PropertyIsEqualTo><ogc:PropertyIsEqualTo><ogc:PropertyName>TYPE</ogc:PropertyName><ogc:Literal>DZIAL</ogc:Literal></ogc:PropertyIsEqualTo></ogc:Or></ogc:And></ogc:Filter>&maxFeatures=100';
-                break;
-            case 2:
-                link = BASE_URL + 'wfs-data.php/default_db/?SERVICE=WFS&VERSION=1.0.0&REQUEST=GetFeature&TYPENAME=p5_default_db:CRM_LISTA_ZASOBOW&SRSNAME=EPSG:3003&Filter=<ogc:Filter><ogc:And><ogc:Or><ogc:PropertyIsLike wildCard="*" singleChar="^" escapeChar="!"><ogc:PropertyName>ID</ogc:PropertyName><ogc:Literal>*' + id + '*</ogc:Literal></ogc:PropertyIsLike><ogc:PropertyIsLike wildCard="*" singleChar="%23" escapeChar="!"><ogc:PropertyName>DESC</ogc:PropertyName><ogc:Literal>*' + id + '*</ogc:Literal></ogc:PropertyIsLike></ogc:Or><ogc:Or><ogc:PropertyIsEqualTo><ogc:PropertyName>TYPE</ogc:PropertyName><ogc:Literal>KOMORKA</ogc:Literal></ogc:PropertyIsEqualTo><ogc:PropertyIsEqualTo><ogc:PropertyName>TYPE</ogc:PropertyName><ogc:Literal>TABELA</ogc:Literal></ogc:PropertyIsEqualTo></ogc:Or></ogc:And></ogc:Filter>&maxFeatures=100&sortBy=TYPE+A';
-                //console.log(link);
-                break;
-            default:
-                link = "";
-
-        }
-
+        link = BASE_URL+"index.php?_route=UrlAction_ProcesEditor&_task=getResAjax&word="+id+"&filter="+filtr;
+        console.log(link);
 
 
         $.get(link, function(data) {
             var side = $("#side");
             //console.log(data);
             $(side).find("#ulcon").empty();
-
-            $.each($(data).find("featureMember"), function() {
-                if ($(this).find("ID").text() * 1 == 0) {
-                    $(side).find("#ulcon").append("<div><center>Brak wyników wyszukiwania</center></div>");
-                    return;
+            if(data.length == 0)
+              $(side).find("#ulcon").append("<div><center>Brak wyników wyszukiwania</center></div>");
+            $.each(data, function(i, e) {
+                var tree = "";
+                for(var i=3;i>0;i--){
+                  if(e["p"+i+"_ID"] != null){
+                    var temp = {};
+                    temp["ID"] = e["p"+i+"_ID"];
+                    temp["DESC"] = e["p"+i+"_DESC"];
+                    zasobTree[e["ID"]] = [];
+                    zasobTree[e["ID"]].push(temp);
+                    tree += e["p"+i+"_DESC"] + (i>1 ? " <span class='glyphicon glyphicon-triangle-right'></span>" : "");
+                  }
                 }
+                console.log(e["TYPE"]);
                 var type = 0;
-                if ($(this).find("TYPE").text() == "DZIAL" || $(this).find("TYPE").text() == "PODMIOT" || $(this).find("TYPE").text() == "STANOWISKO")
+                if (e["TYPE"] == "DZIAL" || e["TYPE"] == "PODMIOT" || e["TYPE"] == "STANOWISKO")
                     type = 1;
-                if (filtr != 2 || $(this).find("TYPE").text() != "TABELA")
-                    $(side).find("#ulcon").append("<div class='drag dragStyle hov' data-id=" + $(this).find("ID").text() + " data-type=" + type + " data-desc='" + $(this).find("DESC").text() + "' data-opis='" + $(this).find("OPIS").text() + "'>" + $(this).find("DESC").text() + " [" + $(this).find("ID").text() + "]</div>");
+                if (filtr != 2 || e["TYPE"] != "TABELA")
+                    $(side).find("#ulcon").append("<div class='drag dragStyle hov' data-id=" + e["ID"] + " data-type=" + type + " data-desc='" + e["DESC"] + "' data-opis='" + e["OPIS"] + "'><span class=treeInfo ><div>"+tree+"</div></span><br>" + e["DESC"] + " [" + e["ID"] + "]</div>");
                 else {
-                    $(side).find("#ulcon").append("<div ><span  class='drag dragStyle click' data-id=" + $(this).find("ID").text() + " data-type=" + type + " data-desc='" + $(this).find("DESC").text() + "' data-opis='" + $(this).find("OPIS").text() + "'> # </span>  <div style=width:80%;float:left; data-id=" + $(this).find("ID").text() + " class=showMore><span class=tabelaName>" + $(this).find("DESC").text() + "</span> [" + $(this).find("ID").text() + "]</div><span class='gIco glyphicon glyphicon-chevron-down' style:float:left;></span><div style=clear:both;></div><div class=more ></div></div>");
+                    $(side).find("#ulcon").append("<div ><span  class='drag dragStyle click' data-id=" + e["ID"] + " data-type=" + type + " data-desc='" + e["DESC"] + "' data-opis='" + e["OPIS"] + "'> # </span>  <div style=width:80%;float:left; data-id=" + e["ID"] + " class=showMore><span class=tabelaName><span class=treeInfo ><div>"+tree + "</div></span><br>" + e["DESC"] + "</span> [" + e["ID"] + "]</div><span class='gIco glyphicon glyphicon-chevron-down' style:float:left;></span><div style=clear:both;></div><div class=more ></div></div>");
                 }
-
-
-
-
             });
             $('.drag').draggable({
                 appendTo: 'body',
@@ -1098,8 +1082,7 @@ $(document).ready(function() {
     function procesy() {
         var side = $("#side");
         $(side).empty();
-        $("#sidebar-wrapper").css("width", "600px");
-        $("#wrapper").css("padding-left", "600px");
+
         //$(side).append("<h3>Zarządzaj zasobami<h3>");
 
 
@@ -1158,7 +1141,9 @@ $(document).ready(function() {
                 var type = 0;
                 if ($(this).find("TYPE").text() == "DZIAL" || $(this).find("TYPE").text() == "PODMIOT" || $(this).find("TYPE").text() == "STANOWISKO")
                     type = 1;
-                result += "<div class='list-group-item drag liAdv' data-typename='" + $(this).find("TYPE").text() + "' data-id=" + $(this).find("ID").text() + " data-type=" + type + " data-desc='" + $(this).find("DESC").text() + "' data-opis='" + $(this).find("OPIS").text() + "'  title='" + $(this).find("DESC").text() + "'><div class=textTable2><span class=handle> # </span>" + $(this).find("DESC").text() + "</div><div class='glyphicon glyphicon-triangle-right' style=opacity:0.4;float:right;></div><div class=clearfix></div><div class=detailsTable2>[" + $(this).find("ID").text() + "] " + $(this).find("TYPE").text() + "</div></div>";
+                result += "<div class='list-group-item drag liAdv' data-typename='" + $(this).find("TYPE").text() + "' data-id=" + $(this).find("ID").text() + " data-type=" + type + " data-desc='" + $(this).find("DESC").text() + "' data-opis='" + $(this).find("OPIS").text() + "'  title='" + $(this).find("DESC").text() + "'><div class=textTable2><span class=handle> # </span>" + $(this).find("DESC").text() + "</div>";
+                result += "<div class='glyphicon glyphicon-triangle-right' style=opacity:0.4;float:right;></div>";
+                result += "<div class=clearfix></div><div class=detailsTable2>[" + $(this).find("ID").text() + "] " + $(this).find("TYPE").text() + "</div></div>";
             });
             if (!childs) {
                 result += '<div class="panel panel-primary">';
@@ -1192,8 +1177,6 @@ $(document).ready(function() {
     function zasoby() {
         var side = $("#side");
         $(side).empty();
-        $("#sidebar-wrapper").css("width", "600px");
-        $("#wrapper").css("padding-left", "600px");
         //$(side).append("<h3>Zarządzaj zasobami<h3>");
 
 
@@ -1307,6 +1290,7 @@ $(document).ready(function() {
                 });
             }
         }).then(function(result) {
+            console.log(zasobTree);
             //console.log("Dodaj zasob " + ui.draggable.data("id") + " do " + $(target).data("id") + " i uprawnienia id " + result[0] + " komentarz: " + result[1]); //
             newRes--;
             var temp = {};
@@ -1317,6 +1301,7 @@ $(document).ready(function() {
             temp["changed"] = true;
             temp["opis"] = ui.draggable.data("opis");
             temp["desc"] = ui.draggable.data("desc");
+            temp["tree"] = zasobTree[temp["id_zasob"]];
             var id = $(target).data("id");
             if (ui.draggable.data("type") == 1) {
                 state[getIndexById(id)]["prof"].push(temp);
@@ -1501,6 +1486,33 @@ $(document).ready(function() {
         });
         //console.log("########");
     }*/
+    $(document).on('click', '.stateOff', function() {
+      $(this).closest(".mx").prev(".tree").show();
+      $(this).closest(".mx").remove();
+
+
+    });
+
+    $(document).on('click', '.tree', function() {
+      var type;
+      if($(this).closest("ul").hasClass("resources")){
+        type = "res";
+      }else {
+        type = "prof"
+      }
+      var id = getIndexById($(this).closest(".drop").data("id"));
+      var resId = getResById(id, $(this).closest(".liRes").data("id"), type);
+      $(this).hide();
+      showTree(state[id][type][resId]["tree"], $(this));
+    });
+
+    function showTree(arr, target){
+      result = "";
+      $.each(arr, function(i, x){
+        result += "<li style=padding-left:"+i*16+"px;><span class='glyphicon glyphicon-arrow-right'></span> "+x["DESC"]+"</li>";
+      });
+      $(target).after("<div class=mx><div class=stateOff><span class='glyphicon glyphicon-chevron-up'></span></div> <ul style=padding-left:0px;>"+result+"</ul></div>");
+    }
 
     function render(arr, target) {
         stepsGenerator();
@@ -1524,7 +1536,8 @@ $(document).ready(function() {
                 if (i != state.length - 1)
                     result += "<span class='glyphicon glyphicon-arrow-down ico dArrow' aria-hidden='true' title='Przesuń krok w dół'></span>";
             } else {
-      }
+
+            }
             result += "<span class='hDescAdd glyphicon glyphicon-edit ico' title='Edytuj tytuł'></span>";
             result += "<div class='clearfix'></div>";
 
@@ -1547,7 +1560,7 @@ $(document).ready(function() {
                     anyProf = true;
                 }
 
-                result += "<li style=padding-top:5px;paddig-bottom:5px; class='liRes' data-zasob=" + e2["id_zasob"] + " data-id=" + e2["id"] + " data-przypadek=" + e2["id_przypadek"] + " data-komentarz='" + e2["komentarz"] + "'><div class=row>";
+                result += "<li style=padding-top:5px;padding-bottom:5px; class='liRes' data-zasob=" + e2["id_zasob"] + " data-id=" + e2["id"] + " data-przypadek=" + e2["id_przypadek"] + " data-komentarz='" + e2["komentarz"] + "'><div class=row>";
                 result += "<div class=col-sm-2 style=text-align:right;>";
                 if (i2 != 0)
                     result += "<span class='glyphicon glyphicon-arrow-up uArrowRes' title='Przesuń wskaźnik w górę' aria-hidden='true'></span>";
@@ -1555,7 +1568,12 @@ $(document).ready(function() {
                     result += "<span class='glyphicon glyphicon-arrow-down dArrowRes' title='Przesuń wskaźnik w dół' aria-hidden='true'></span>";
                 result += "<span aria-hidden='true' class='glyphicon glyphicon-edit btnEdit' title='Edytuj wskaźnik' style=font-size:12px;></span><span class='glyphicon glyphicon-remove-sign delRes' title='Usuń wskaźnik' style=font-size:12px; aria-hidden='true' ></span>";
                 result += "</div>";
-                result += "<div class='col-sm-10 changable " + (e2["changed"] ? "changed" : "") + " '><b>" + e2["desc"] + "</b> " + e2["opis"] + " [" + e2["id_zasob"] + "] </div>";
+                result += "<div class='col-sm-10 changable " + (e2["changed"] ? "changed" : "") + " '><b>" + e2["desc"] + "</b> " + e2["opis"] + " [" + e2["id_zasob"] + "] <br><span class=tree>";
+                result += "<span class=state><span class='glyphicon glyphicon-chevron-down'></span></span> ";
+                $.each(e2["tree"], function(i, x){
+                  result += x["DESC"] + (i<e2["tree"].length-1 ? " <span class='glyphicon glyphicon-triangle-right'></span>" : "");
+                });
+                result += "<div class=moreInfo></div></span></div>";
 
 
                 result += "</div></li>";
@@ -1570,7 +1588,7 @@ $(document).ready(function() {
                   result += "<div class=row><div class=col-sm-2 style=font-size:1.2em;text-align:right;opacity:1>Użyte zasoby</div></div><ul class=resources style=padding:0;>";
                   anyRes = true;
               }
-              result += "<li style=padding-top:5px;paddig-bottom:5px; class='liRes' data-zasob=" + e2["id_zasob"] + " data-id=" + e2["id"] + " data-przypadek=" + e2["id_przypadek"] + " data-komentarz='" + e2["komentarz"] + "'><div class=row>";
+              result += "<li style=padding-top:5px;padding-bottom:5px; class='liRes' data-zasob=" + e2["id_zasob"] + " data-id=" + e2["id"] + " data-przypadek=" + e2["id_przypadek"] + " data-komentarz='" + e2["komentarz"] + "'><div class=row>";
               result += "<div class=col-sm-2 style=text-align:right;>";
               if (i2 != 0)
                   result += "<span class='glyphicon glyphicon-arrow-up uArrowRes' title='Przesuń wskaźnik w górę' aria-hidden='true'></span>";
@@ -1578,8 +1596,12 @@ $(document).ready(function() {
                   result += "<span class='glyphicon glyphicon-arrow-down dArrowRes' title='Przesuń wskaźnik w dół' aria-hidden='true'></span>";
               result += "<span aria-hidden='true' class='glyphicon glyphicon-edit btnEdit' title='Edytuj wskaźnik' style=font-size:12px;></span><span class='glyphicon glyphicon-remove-sign delRes' title='Usuń wskaźnik' style=font-size:12px; aria-hidden='true' ></span>";
               result += "</div>";
-              result += "<div class='col-sm-10 changable " + (e2["changed"] ? "changed" : "") + " '><b>" + e2["desc"] + "</b> " + e2["opis"] + " [" + e2["id_zasob"] + "] </div>";
-
+              result += "<div class='col-sm-10 changable " + (e2["changed"] ? "changed" : "") + " '><b>" + e2["desc"] + "</b> " + e2["opis"] + " [" + e2["id_zasob"] + "] <br><span class=tree>";
+              result += "<span class=state><span class='glyphicon glyphicon-chevron-down'></span></span> ";
+              $.each(e2["tree"], function(i, x){
+                result += x["DESC"] + (i<e2["tree"].length-1 ? "<span class='glyphicon glyphicon-triangle-right'></span> " : "");
+              });
+              result += "</span></div>";
 
               result += "</div></li>";
             });