فهرست منبع

fixed bug in loadResources in procedEditor

Piotr Labudda 9 سال پیش
والد
کامیت
d58600bb4f
2فایلهای تغییر یافته به همراه93 افزوده شده و 120 حذف شده
  1. 1 1
      SE/se-lib/Route/UrlAction/ProcesEditor.php
  2. 92 119
      SE/static/procesEditor.js

+ 1 - 1
SE/se-lib/Route/UrlAction/ProcesEditor.php

@@ -118,7 +118,7 @@ class Route_UrlAction_ProcesEditor extends RouteBase {// TODO: UrlActionBase @se
 		</div>
 		<script>var BASE_URL = '<?= Request::getPathUri(); ?>';var mainProces_id = <?= $id; ?>;</script>
 		<script src="static/sweetalert2.min.js"></script>
-		<script src="static/procesEditor.js?v=12"></script>
+		<script src="static/procesEditor.js?v=13"></script>
 <?php
 	}
 

+ 92 - 119
SE/static/procesEditor.js

@@ -56,8 +56,6 @@ $(document).ready(function() {
     var newSteps = 0;
     var newRes = 0;
 
-
-
     function loadResources() {
         $("#main").html("<center>Pobieranie danych o zasobach.</center>");
         //console.log("res!");
@@ -140,36 +138,38 @@ $(document).ready(function() {
                       }
                     });
                     //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"));
                   })
                   .fail(function(xhr) {
                     if (xhr.responseJSON && xhr.responseJSON.msg && xhr.responseJSON.type) jQuery.notify(xhr.responseJSON.msg, xhr.responseJSON.type);
                     else jQuery.notify("Wystąpił nieznany błąd", 'error');
                   });
+                } else {
+                  $("#main").html("<center>Generowanie widoku.</center>");
+                  render(state, $("#main"));
                 }
-
-                $.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"));
             }
         });
     }
@@ -184,7 +184,6 @@ $(document).ready(function() {
 
     });
     $(document).on('click', '#clearBtn', function() {
-
         swal({
             title: 'Cofnij zmiany',
             text: "Czy chcesz cofnąć wszystkie niezapisane zmiany?",
@@ -201,7 +200,6 @@ $(document).ready(function() {
 
             //Parent_id = -1,
         }).catch(function(e) {})
-
     });
     //Saveaction
     $(document).on('click', '#saveBtn', function() {
@@ -221,7 +219,6 @@ $(document).ready(function() {
 
         $.each(state, function(i, e) {
             if (e['id'] < 0) {
-
                 genReq += `
             <Insert xmlns="http://www.opengis.net/wfs">
             <CRM_PROCES xmlns="` + BASE_URL + `wfs/default_db/CRM_PROCES">
@@ -245,8 +242,6 @@ $(document).ready(function() {
                 $(data).find("[fid]").each(function(i, e) {
                     var newId = $(e).attr("fid").substr($(e).attr("fid").indexOf('.') + 1);
                     generatedId.push(newId);
-
-
                 });
 
                 var i = 0;
@@ -259,11 +254,9 @@ $(document).ready(function() {
                         //console.log("he:" + generatedId[i]);
                         i++;
                     }
-
                 });
                 //console.log(newIdTab);
 
-
                 var request = `
             <Transaction
             xmlns="http://www.opengis.net/wfs"
@@ -292,8 +285,6 @@ $(document).ready(function() {
                         else
                             request += '<PARENT_ID xmlns="' + BASE_URL + 'wfs/default_db/CRM_PROCES">' + newIdTab[e["parent_id"]] + '</PARENT_ID>';
 
-
-
                         request += '<SORT_PRIO xmlns="' + BASE_URL + 'wfs/default_db/CRM_PROCES">' + e["SORT_PRIO"] + '</SORT_PRIO>';
                     }
                     if (typeof e["goto"] !== typeof undefined && e["goto"]["id"] !== null && e["goto"]["id"] !== 0 && e["goto"]["id"] !== "") {
@@ -306,8 +297,6 @@ $(document).ready(function() {
 
                     request += '<DESC xmlns="' + BASE_URL + 'wfs/default_db/CRM_PROCES">' + e["desc"] + '</DESC>';
                     request += '<OPIS xmlns="' + BASE_URL + 'wfs/default_db/CRM_PROCES">' + e["opis"] + '</OPIS>';
-
-
                     request += `
     </CRM_PROCES>
   </Insert>
@@ -317,12 +306,9 @@ $(document).ready(function() {
                         id = e["id"];
                     else
                         id = newIdTab[e["id"]];
-
-
                     var sort_prio = 0;
                     $.each(e["prof"].concat(e["res"]), function(iR, eR) {
                         sort_prio++;
-
                         request += `
   <Insert xmlns="http://www.opengis.net/wfs">
     <CRM_WSKAZNIK xmlns="` + BASE_URL + `wfs/default_db/CRM_WSKAZNIK">
@@ -342,11 +328,8 @@ $(document).ready(function() {
 </CRM_WSKAZNIK>
 </Insert>
 `;
-
-
                     });
                 });
-
                 $.each(deletedId, function(key, value) {
                     request += `
     <Insert xmlns="http://www.opengis.net/wfs">
@@ -356,13 +339,10 @@ $(document).ready(function() {
                     request += '<ID xmlns="' + BASE_URL + 'wfs/default_db/CRM_PROCES">' + value + '</ID>';
                     request += '<PARENT_ID xmlns="' + BASE_URL + 'wfs/default_db/CRM_PROCES">-1</PARENT_ID>';
                     request += '<A_STATUS xmlns="' + BASE_URL + 'wfs/default_db/CRM_PROCES">DELETED</A_STATUS>';
-
                     request += `
     </CRM_PROCES>
   </Insert>
     `;
-
-
                 });
 
                 $.each(deletedRes, function(key, value) {
@@ -373,13 +353,10 @@ $(document).ready(function() {
 
                     request += '<ID xmlns="' + BASE_URL + 'wfs/default_db/CRM_WSKAZNIK">' + value + '</ID>';
                     request += '<A_STATUS xmlns="' + BASE_URL + 'wfs/default_db/CRM_WSKAZNIK">DELETED</A_STATUS>';
-
                     request += `
     </CRM_WSKAZNIK>
   </Insert>
     `;
-
-
                 });
 
                 request += '</Transaction>';
@@ -412,12 +389,8 @@ $(document).ready(function() {
                 $.notify("Brak połączenia z bazą danych", "error");
             }
         });
-
-
-
     });
 
-
     $(document).on('click', '.btnEdit', function() {
         var parentIndex = getIndexById($(this).parents(".drop").data("id"));
         var type;
@@ -730,7 +703,7 @@ $(document).ready(function() {
         if ($(action).find("textarea").length == 0) {
 
             //alert($(action).text());
-            $(action).html("<textarea placeholder='Opis kroku'>"+$(action).text()+"</textarea>");
+            $(action).html("<textarea placeholder='Opis kroku'>" + $(action).text() + "</textarea>");
 
             selectedArea = $(action).find("textarea");
             return false;
@@ -748,7 +721,7 @@ $(document).ready(function() {
 
             //alert($(action).text());
 
-            $(action).html("<textarea placeholder='Tytuł kroku'>"+$(action).text()+"</textarea>");
+            $(action).html("<textarea placeholder='Tytuł kroku'>" + $(action).text() + "</textarea>");
 
             selectedArea = $(action).find("textarea");
             return false;
@@ -904,21 +877,21 @@ $(document).ready(function() {
             $(target).parent().find(".gIco").removeClass("glyphicon-chevron-down");
             $(target).parent().find(".gIco").addClass("glyphicon-chevron-up");
 
-            var link = BASE_URL+"index.php?_route=UrlAction_ProcesEditor&_task=getResByParentAjax&parent_id="+id;
+            var link = BASE_URL + "index.php?_route=UrlAction_ProcesEditor&_task=getResByParentAjax&parent_id=" + id;
             //console.log(link);
             $.get(link, function(data) {
                 $.each(data, function(i, e) {
                     if (e["ID"] != 0) {
                         var type = 0;
-                        $(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);
-                          }
+                        $(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',
@@ -971,7 +944,7 @@ $(document).ready(function() {
     function searchRes() {
         var id = lastSearch;
         var link;
-        link = BASE_URL+"index.php?_route=UrlAction_ProcesEditor&_task=getResAjax&word="+id+"&filter="+filtr;
+        link = BASE_URL + "index.php?_route=UrlAction_ProcesEditor&_task=getResAjax&word=" + id + "&filter=" + filtr;
         // console.log(link);
 
 
@@ -979,28 +952,28 @@ $(document).ready(function() {
             var side = $("#side");
             //console.log(data);
             $(side).find("#ulcon").empty();
-            if(data.length == 0)
-              $(side).find("#ulcon").append("<div><center>Brak wyników wyszukiwania</center></div>");
+            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>" : "");
-                  }
+                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 (e["TYPE"] == "DZIAL" || e["TYPE"] == "PODMIOT" || e["TYPE"] == "STANOWISKO")
                     type = 1;
                 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>");
+                    $(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=" + 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>");
+                    $(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({
@@ -1489,31 +1462,31 @@ $(document).ready(function() {
         //console.log("########");
     }*/
     $(document).on('click', '.stateOff', function() {
-      $(this).closest(".mx").prev(".tree").show();
-      $(this).closest(".mx").remove();
+        $(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));
+        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 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) {
@@ -1572,8 +1545,8 @@ $(document).ready(function() {
                 result += "</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>" : "");
+                $.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>";
 
@@ -1586,26 +1559,26 @@ $(document).ready(function() {
             }
             var anyRes = false;
             $.each(e["res"], function(i2, e2) {
-              if (!anyRes) {
-                  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;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>";
-              if (i2 != e["prof"].length - 1)
-                  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"] + "] <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>";
+                if (!anyRes) {
+                    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;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>";
+                if (i2 != e["prof"].length - 1)
+                    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"] + "] <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>";
             });
             if (anyRes) {
                 result += "</ul>";