procesEditor.js 69 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765
  1. var changes = false;
  2. $(document).ready(function() {
  3. $("#main").after('<div class="col-xs-1 col-xs-offset-7" id="buttons"></div>');
  4. $("#buttons").after("<button type=button id=saveBtn class='btn btn-primary text-center' style=margin-left:5px;>Opublikuj zmiany</button>");
  5. $("#buttons").after("<button type=button id=clearBtn style=display:none; class='btn btn-danger text-center' >Cofnij zmiany</button>");
  6. var deletedId = new Array();
  7. var generatedId = new Array();
  8. var deletedRes = new Array();
  9. var dialog = 0;
  10. var zasobTree = new Array();
  11. var perms = [
  12. [1, "Kto wykonuje", "X"],
  13. [2, "Tylko do odczytu", "R"],
  14. [3, "Odczyt, zapis, wykonanie", "R,W,X"],
  15. [4, "Odczyt, zapis, wykonanie, tworzenie", "R,W,X,C"],
  16. [5, "Odczyt i wykonanie", "R,X"],
  17. [6, "Tylko do odczytu", "R"],
  18. [7, "MAPA PROCESU - opis mapy procesu", ""],
  19. [9, "Tylko do tworzenia rekordu", "C"],
  20. [10, "Tylko tworzenie i czytanie rekordów bez edycji", "R,X,C"],
  21. [11, "Tylko edycja rekordu - ustalanie nowej wartosci", "W"],
  22. [12, "Tylko edycja i dodanie rekordu - ustalanie nowej wartosci", "W,C"],
  23. [13, "Nowy rekord i edycja z pominieciem A_ADM_COMPANY", "R,W,X,C,S"],
  24. [14, "Widok tylko swoich danych z rekordu", "W,O"],
  25. [15, "Edycja rekordów dla super admina", "R,W,C,S"],
  26. [16, "Widok i dodawanie rekordów tylko dla swojego ADM_COMPANY", "C,O"],
  27. [17, "Super widok wszystkich rekordow niezaleznie od uprawnien rekordu", "R,V"],
  28. [18, "Administracja Edycja i widok wszystkich rekordow z pominieciem A", "R,W,X,S,V"],
  29. [19, "Administracja Edycja Tworzenie i widok wszystkich rekordow z pom", "R,W,X,C,S,V"],
  30. [20, "Export", "R,X,E"],
  31. [21, "Widzenie tylko swoich rekordów", "O"]
  32. ];
  33. var gotoType = [
  34. ["GOTO", "Przejdź do procesu"],
  35. ["GOTO_AND_RETURN", "Przejdź do procesu i wróć"],
  36. ["FORK", "FORK"]
  37. ];
  38. var state = [];
  39. var loaded = true;
  40. var tab = new Array(); //tablica kolejnosci
  41. //var mainProces_id = 1; //id procesu glownego. Potem bedzie przypisywane z linku
  42. var actSite = "none";
  43. showPreview();
  44. var filtr = 0;
  45. var selectedArea = false;
  46. var sZasoby;
  47. var sProcesy;
  48. var lastSearch = "";
  49. var newSteps = 0;
  50. var newRes = 0;
  51. function loadResources() {
  52. $("#main").html("<center>Pobieranie danych o zasobach.</center>");
  53. //console.log("res!");
  54. var res = new Array();
  55. var sFiltr = "";
  56. var link = BASE_URL + 'wfs-data.php/default_db/?SERVICE=WFS&VERSION=1.0.0&REQUEST=GetFeature&TYPENAME=p5_default_db:CRM_WSKAZNIK&SRSNAME=EPSG:3003&sortBy=SORT_PRIO+A,ID';
  57. //console.log("link "+link);
  58. sFiltr += `
  59. <GetFeature xmlns="http://www.opengis.net/wfs/2.0"
  60. xmlns:p5_default_db="` + BASE_URL + `wfs/default_db"
  61. xmlns:ogc="http://www.opengis.net/ogc"
  62. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  63. service="WFS"
  64. version="2.0.2"
  65. xsi:schemaLocation="http://www.opengis.net/wfs/2.0 http://schemas.opengis.net/wfs/2.0/wfs.xsd">
  66. <ogc:Filter>
  67. <ogc:And>
  68. <ogc:Or>`;
  69. $.each(state, function(i, e) {
  70. var id = e["id"];
  71. sFiltr += '<ogc:PropertyIsEqualTo><ogc:PropertyName>ID_PROCES</ogc:PropertyName><ogc:Literal>' + id + '</ogc:Literal></ogc:PropertyIsEqualTo>';
  72. });
  73. sFiltr += '</ogc:Or><ogc:Not><ogc:PropertyIsEqualTo><ogc:PropertyName>A_STATUS</ogc:PropertyName><ogc:Literal>DELETED</ogc:Literal></ogc:PropertyIsEqualTo></ogc:Not></ogc:And></ogc:Filter></GetFeature>';
  74. //console.log("x "+sFiltr);
  75. $.ajax({
  76. url: link,
  77. data: sFiltr,
  78. type: 'POST',
  79. contentType: "text/xml",
  80. dataType: "xml",
  81. success: function(data) {
  82. //console.log(data);
  83. $.each($(data).find("featureMember"), function() {
  84. if ($(this).find("ID").text() == 0)
  85. return;
  86. var result = new Array();
  87. result["ID"] = $(this).find("ID").text();
  88. result["ID_ZASOB"] = $(this).find("ID_ZASOB").text();
  89. result["ID_PROCES"] = $(this).find("ID_PROCES").text();
  90. result["SORT_PRIO"] = $(this).find("SORT_PRIO").text();
  91. result["ID_PRZYPADEK"] = $(this).find("ID_PRZYPADEK").text();
  92. result["OPIS_ZASOB"] = $(this).find("OPIS_ZASOB").text();
  93. res.push(result);
  94. });
  95. //console.log(res);
  96. var sFiltr2 = [];
  97. var link2 = BASE_URL+"index.php?_route=UrlAction_ProcesEditor&_task=getSingleResAjax";
  98. $.each(res, function(index, value) {
  99. var id = res[index]["ID_ZASOB"];
  100. sFiltr2.push(id);
  101. });
  102. //sFiltr2 = JSON.stringify(sFiltr2);
  103. //console.log(sFiltr2);
  104. //console.log(link2);
  105. var zasobInfo = new Array();
  106. $.post(link2, {data: sFiltr2}, function(data2){
  107. //console.log("data");
  108. console.log(data2);
  109. $.each(data2, function(i, e) {
  110. zasobInfo[e["ID"]] = new Array();
  111. zasobInfo[e["ID"]]["DESC"] = e["DESC"];
  112. zasobInfo[e["ID"]]["OPIS"] = e["OPIS"];
  113. zasobInfo[e["ID"]]["TYPE"] = e["TYPE"];
  114. zasobInfo[e["ID"]]["TREE"] = [];
  115. for(var i=3;i>0;i--){
  116. if(e["p"+i+"_ID"] != null){
  117. var temp = {};
  118. temp["ID"] = e["p"+i+"_ID"];
  119. temp["DESC"] = e["p"+i+"_DESC"];
  120. zasobInfo[e["ID"]]["TREE"].push(temp);
  121. }
  122. }
  123. });
  124. //console.log(res);
  125. $.each(res, function(index, value) {
  126. var type;
  127. if (zasobInfo[res[index]["ID_ZASOB"]]["TYPE"] == "DZIAL" || zasobInfo[res[index]["ID_ZASOB"]]["TYPE"] == "STANOWISKO" || zasobInfo[res[index]["ID_ZASOB"]]["TYPE"] == "PODMIOT") {
  128. type = "prof";
  129. } else {
  130. type = "res";
  131. }
  132. var id = res[index]["ID_PROCES"];
  133. var temp = {};
  134. temp["id_zasob"] = res[index]["ID_ZASOB"]
  135. temp["id"] = res[index]["ID"];
  136. temp["id_przypadek"] = res[index]["ID_PRZYPADEK"];
  137. temp["komentarz"] = res[index]["OPIS_ZASOB"];
  138. temp["desc"] = zasobInfo[res[index]["ID_ZASOB"]]["DESC"];
  139. temp["opis"] = zasobInfo[res[index]["ID_ZASOB"]]["OPIS"];
  140. temp["tree"] = zasobInfo[res[index]["ID_ZASOB"]]["TREE"];
  141. //console.log(temp);
  142. state[getIndexById(id)][type].push(temp);
  143. });
  144. $("#main").html("<center>Generowanie widoku.</center>");
  145. render(state, $("#main"));
  146. //}
  147. });
  148. }
  149. });
  150. }
  151. $(document).ajaxStop(function() {
  152. if (loaded)
  153. return;
  154. //alert("OK");
  155. loaded = true;
  156. //$(".drop").find("dl").hide();
  157. loadResources();
  158. });
  159. $(document).on('click', '#clearBtn', function() {
  160. swal({
  161. title: 'Cofnij zmiany',
  162. text: "Czy chcesz cofnąć wszystkie niezapisane zmiany?",
  163. type: 'warning',
  164. showCancelButton: true,
  165. confirmButtonColor: '#3085d6',
  166. cancelButtonColor: '#d33',
  167. cancelButtonText: "Anuluj",
  168. confirmButtonText: 'Cofnij zmiany'
  169. }).then(function() {
  170. localStorage.removeItem("state" + mainProces_id);
  171. $.notify("Niezapisane zmiany zostały wycofane.", "success");
  172. showPreview();
  173. //Parent_id = -1,
  174. }).catch(function(e) {})
  175. });
  176. //Saveaction
  177. $(document).on('click', '#saveBtn', function() {
  178. $("#saveBtn").prop('disabled', true);
  179. $.notify("Rozpoczęto zapisywanie. Nie zamykaj tego okna", "info");
  180. //console.log("Saving has been started");
  181. var genReq = `
  182. <Transaction
  183. xmlns="http://www.opengis.net/wfs"
  184. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  185. version="1.0.0"
  186. service="WFS"
  187. xmlns:p5_default_db="` + BASE_URL + `wfs/default_db/CRM_PROCES"
  188. xsi:schemaLocation="` + BASE_URL + `wfs/default_db/CRM_PROCES ` + BASE_URL + `dev-pl/se-feature-api/wfs.php/xml/wfs/default_db/CRM_PROCES/?SERVICE=WFS&amp;VERSION=1.0.0&amp;REQUEST=DescribeFeatureType&amp;TYPENAME=p5_default_db:CRM_PROCES&amp;SRSNAME=EPSG:4326&amp;"
  189. xmlns:gml="http://www.opengis.net/gml">
  190. `;
  191. $.each(state, function(i, e) {
  192. if (e['id'] < 0) {
  193. genReq += `
  194. <Insert xmlns="http://www.opengis.net/wfs">
  195. <CRM_PROCES xmlns="` + BASE_URL + `wfs/default_db/CRM_PROCES">
  196. <PARENT_ID xmlns="` + BASE_URL + `wfs/default_db/CRM_PROCES">-1</PARENT_ID>
  197. </CRM_PROCES>
  198. </Insert>`;
  199. }
  200. });
  201. genReq += '</Transaction>';
  202. //console.log("genReq: " + genReq)
  203. var link = BASE_URL + 'wfs-data.php/default_db/?SERVICE=WFS&VERSION=1.0.0&SRSNAME=EPSG:3003&';
  204. //console.log(link);
  205. $.ajax({
  206. url: link,
  207. data: genReq,
  208. type: 'POST',
  209. contentType: "text/xml",
  210. dataType: "text",
  211. success: function(data) {
  212. //console.log("x: " + data);
  213. $(data).find("[fid]").each(function(i, e) {
  214. var newId = $(e).attr("fid").substr($(e).attr("fid").indexOf('.') + 1);
  215. generatedId.push(newId);
  216. });
  217. var i = 0;
  218. var newIdTab = Array();
  219. //console.log(generatedId);
  220. $.each(state, function(z, e) {
  221. if (e["id"] < 0) {
  222. newIdTab[e["id"]] = generatedId[i];
  223. //console.log("he:" + generatedId[i]);
  224. i++;
  225. }
  226. });
  227. //console.log(newIdTab);
  228. var request = `
  229. <Transaction
  230. xmlns="http://www.opengis.net/wfs"
  231. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  232. version="1.0.0"
  233. service="WFS"
  234. xmlns:p5_default_db="` + BASE_URL + `wfs/default_db/CRM_PROCES"
  235. xsi:schemaLocation="` + BASE_URL + `wfs/default_db/CRM_PROCES ` + BASE_URL + `dev-pl/se-feature-api/wfs.php/xml/wfs/default_db/CRM_PROCES/?SERVICE=WFS&amp;VERSION=1.0.0&amp;REQUEST=DescribeFeatureType&amp;TYPENAME=p5_default_db:CRM_PROCES&amp;SRSNAME=EPSG:4326&amp;"
  236. xmlns:gml="http://www.opengis.net/gml">
  237. `;
  238. $.each(state, function(i, e) {
  239. request += `
  240. <Insert xmlns="http://www.opengis.net/wfs">
  241. <CRM_PROCES xmlns="` + BASE_URL + `wfs/default_db/CRM_PROCES">
  242. `;
  243. if (e["id"] >= 0)
  244. request += '<ID xmlns="' + BASE_URL + 'wfs/default_db/CRM_PROCES">' + e["id"] + '</ID>';
  245. else
  246. request += '<ID xmlns="' + BASE_URL + 'wfs/default_db/CRM_PROCES">' + newIdTab[e["id"]] + '</ID>';
  247. if (e["parent_id"] != false) {
  248. if (e["parent_id"] >= 0)
  249. request += '<PARENT_ID xmlns="' + BASE_URL + 'wfs/default_db/CRM_PROCES">' + e["parent_id"] + '</PARENT_ID>';
  250. else
  251. request += '<PARENT_ID xmlns="' + BASE_URL + 'wfs/default_db/CRM_PROCES">' + newIdTab[e["parent_id"]] + '</PARENT_ID>';
  252. request += '<SORT_PRIO xmlns="' + BASE_URL + 'wfs/default_db/CRM_PROCES">' + e["SORT_PRIO"] + '</SORT_PRIO>';
  253. }
  254. if (typeof e["goto"] !== typeof undefined && e["goto"]["id"] !== null && e["goto"]["id"] !== 0 && e["goto"]["id"] !== "") {
  255. request += '<IF_TRUE_GOTO xmlns="' + BASE_URL + 'wfs/default_db/CRM_PROCES">' + e["goto"]["id"] + '</IF_TRUE_GOTO>';
  256. request += '<IF_TRUE_GOTO_FLAG xmlns="' + BASE_URL + 'wfs/default_db/CRM_PROCES">' + e["goto"]["flag"] + '</IF_TRUE_GOTO_FLAG>';
  257. } else {
  258. request += '<IF_TRUE_GOTO xmlns="' + BASE_URL + 'wfs/default_db/CRM_PROCES">0</IF_TRUE_GOTO>';
  259. request += '<IF_TRUE_GOTO_FLAG xmlns="' + BASE_URL + 'wfs/default_db/CRM_PROCES"></IF_TRUE_GOTO_FLAG>';
  260. }
  261. request += '<DESC xmlns="' + BASE_URL + 'wfs/default_db/CRM_PROCES">' + e["desc"] + '</DESC>';
  262. request += '<OPIS xmlns="' + BASE_URL + 'wfs/default_db/CRM_PROCES">' + e["opis"] + '</OPIS>';
  263. request += `
  264. </CRM_PROCES>
  265. </Insert>
  266. `;
  267. var id;
  268. if (e["id"] >= 0)
  269. id = e["id"];
  270. else
  271. id = newIdTab[e["id"]];
  272. var sort_prio = 0;
  273. $.each(e["prof"].concat(e["res"]), function(iR, eR) {
  274. sort_prio++;
  275. request += `
  276. <Insert xmlns="http://www.opengis.net/wfs">
  277. <CRM_WSKAZNIK xmlns="` + BASE_URL + `wfs/default_db/CRM_WSKAZNIK">
  278. `;
  279. if (eR["id"] >= 0) {
  280. request += '<ID xmlns="' + BASE_URL + 'wfs/default_db/CRM_WSKAZNIK">' + eR["id"] + '</ID>';
  281. }
  282. request += '<ID_ZASOB xmlns="' + BASE_URL + 'wfs/default_db/CRM_WSKAZNIK">' + eR["id_zasob"] + '</ID_ZASOB>';
  283. request += '<ID_PROCES xmlns="' + BASE_URL + 'wfs/default_db/CRM_WSKAZNIK">' + id + '</ID_PROCES>';
  284. request += '<ID_PRZYPADEK xmlns="' + BASE_URL + 'wfs/default_db/CRM_WSKAZNIK">' + eR["id_przypadek"] + '</ID_PRZYPADEK>';
  285. var opis = eR["komentarz"];
  286. opis = opis.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;').replace(/'/g, '&apos;');
  287. request += '<SORT_PRIO xmlns="' + BASE_URL + 'wfs/default_db/CRM_WSKAZNIK">' + sort_prio + '</SORT_PRIO>';
  288. request += '<OPIS_ZASOB xmlns="' + BASE_URL + 'wfs/default_db/CRM_WSKAZNIK">' + opis + '</OPIS_ZASOB>';
  289. request += `
  290. </CRM_WSKAZNIK>
  291. </Insert>
  292. `;
  293. });
  294. });
  295. $.each(deletedId, function(key, value) {
  296. request += `
  297. <Insert xmlns="http://www.opengis.net/wfs">
  298. <CRM_PROCES xmlns="` + BASE_URL + `wfs/default_db/CRM_PROCES">
  299. `;
  300. request += '<ID xmlns="' + BASE_URL + 'wfs/default_db/CRM_PROCES">' + value + '</ID>';
  301. request += '<PARENT_ID xmlns="' + BASE_URL + 'wfs/default_db/CRM_PROCES">-1</PARENT_ID>';
  302. request += '<A_STATUS xmlns="' + BASE_URL + 'wfs/default_db/CRM_PROCES">DELETED</A_STATUS>';
  303. request += `
  304. </CRM_PROCES>
  305. </Insert>
  306. `;
  307. });
  308. $.each(deletedRes, function(key, value) {
  309. request += `
  310. <Insert xmlns="http://www.opengis.net/wfs">
  311. <CRM_WSKAZNIK xmlns="` + BASE_URL + `wfs/default_db/CRM_WSKAZNIK">
  312. `;
  313. request += '<ID xmlns="' + BASE_URL + 'wfs/default_db/CRM_WSKAZNIK">' + value + '</ID>';
  314. request += '<A_STATUS xmlns="' + BASE_URL + 'wfs/default_db/CRM_WSKAZNIK">DELETED</A_STATUS>';
  315. request += `
  316. </CRM_WSKAZNIK>
  317. </Insert>
  318. `;
  319. });
  320. request += '</Transaction>';
  321. //console.log(request);
  322. $.ajax({
  323. url: link,
  324. data: request,
  325. type: 'POST',
  326. contentType: "text/xml",
  327. dataType: "text",
  328. success: function(data) {
  329. //console.log(data);
  330. deletedRes = [];
  331. deletedId = [];
  332. //console.log(data);
  333. localStorage.removeItem("state" + mainProces_id);
  334. showPreview();
  335. $.notify("Zmiany zostały zapisane na serwerze.", "success");
  336. $("#saveBtn").prop('disabled', false);
  337. },
  338. error: function(xhr, ajaxOptions, thrownError) {
  339. $.notify("Brak połączenia z bazą danych", "error");
  340. }
  341. });
  342. },
  343. error: function(xhr, ajaxOptions, thrownError) {
  344. $.notify("Brak połączenia z bazą danych", "error");
  345. }
  346. });
  347. });
  348. $(document).on('click', '.btnEdit', function() {
  349. var parentIndex = getIndexById($(this).parents(".drop").data("id"));
  350. var type;
  351. if ($(this).parents("li").closest(".professions").length > 0)
  352. type = "prof";
  353. else
  354. type = "res";
  355. var zasobIndex = getResById(parentIndex, $(this).parents("li").data("id"), type);
  356. //console.log(zasobIndex);
  357. var permsOpt = "";
  358. $.each(perms, function(key, value) {
  359. if (state[parentIndex][type][zasobIndex]["id_przypadek"] == value[0])
  360. permsOpt = permsOpt + "<option value=" + value[0] + " selected=selected>[" + value[2] + "] " + value[1] + "</option>";
  361. else
  362. permsOpt = permsOpt + "<option value=" + value[0] + ">[" + value[2] + "] " + value[1] + "</option>";
  363. });
  364. swal({
  365. showCancelButton: true,
  366. title: 'Uprawnienia',
  367. html: 'Uprawnienia<br><select class=form-control id="swal-input1">' + permsOpt + '</select>' +
  368. 'Komentarz<br><input class=form-control id="swal-input2" class="swal2-input" value="' + state[parentIndex][type][zasobIndex]["komentarz"] + '">',
  369. preConfirm: function() {
  370. return new Promise(function(resolve) {
  371. resolve([
  372. $('#swal-input1').val(),
  373. $('#swal-input2').val()
  374. ]);
  375. });
  376. }
  377. }).then(function(result) {
  378. state[parentIndex][type][zasobIndex]["id_przypadek"] = result[0];
  379. state[parentIndex][type][zasobIndex]["komentarz"] = result[1];
  380. state[parentIndex][type][zasobIndex]["changed"] = true;
  381. updateAll();
  382. }).catch(function(e) {})
  383. });
  384. //Buttony i ich zadania
  385. $(document).on('click', '.step', function() {
  386. newSteps--;
  387. var main = false;
  388. var temp = {};
  389. if ($(this).parents(".drop").data("id") === mainProces_id)
  390. main = true;
  391. $(this).parents(".drop").after("<div class='drop container-fluid' id='proc" + newSteps + "'></div>");
  392. temp["id"] = newSteps;
  393. temp["desc"] = "";
  394. temp["opis"] = "";
  395. var index = getIndexById($(this).parents(".drop").data("id"));
  396. //console.log(state[index]["depth"]);
  397. temp["step"] = 0;
  398. temp["prof"] = new Array();
  399. temp["res"] = new Array();
  400. temp["C-desc"] = true;
  401. temp["C-opis"] = true;
  402. temp["stepDesc"] = "";
  403. if (!main) {
  404. temp["parent_id"] = state[index]["parent_id"];
  405. temp["depth"] = state[index]["depth"];
  406. } else {
  407. temp["parent_id"] = mainProces_id;
  408. temp["depth"] = 1;
  409. }
  410. state.splice(index + 1, 0, temp);
  411. stepsGenerator();
  412. updateAll();
  413. });
  414. $(document).on('keyup', '#sProcesy', function() {
  415. if ($(this).val() != lastSearch) {
  416. lastSearch = $(this).val();
  417. clearTimeout(sProcesy);
  418. sProcesy = setTimeout(function() {
  419. if (lastSearch == "")
  420. procesy();
  421. else
  422. searchProc();
  423. }, 300);
  424. }
  425. });
  426. $(document).on('keyup', '#sZasoby', function() {
  427. if ($(this).val() != lastSearch) {
  428. lastSearch = $(this).val();
  429. clearTimeout(sZasoby);
  430. sZasoby = setTimeout(function() {
  431. if (filtr === 0 && lastSearch == "")
  432. zasoby();
  433. else
  434. searchRes();
  435. }, 300);
  436. }
  437. });
  438. function arraymove(arr, fromIndex, toIndex) {
  439. //console.log("move " + fromIndex + " " + toIndex);
  440. var element = [];
  441. var element = arr[fromIndex];
  442. arr.splice(fromIndex, 1);
  443. arr.splice(toIndex, 0, element);
  444. }
  445. $(document).on('click', '.uArrowRes', function() {
  446. var parent = getIndexById(($(this).parents(".drop").data("id")));
  447. //alert(parent);
  448. if ($(this).closest(".professions").length > 0)
  449. type = "prof";
  450. else
  451. type = "res";
  452. var id = getResById(parent, $(this).closest("li").data("id"), type);
  453. //alert(id);
  454. //console.log(state);
  455. arraymove(state[parent][type], id, id - 1);
  456. updateAll();
  457. });
  458. $(document).on('click', '.dArrowRes', function() {
  459. var parent = getIndexById(($(this).parents(".drop").data("id")));
  460. //alert(parent);
  461. if ($(this).closest(".professions").length > 0)
  462. type = "prof";
  463. else
  464. type = "res";
  465. var id = getResById(parent, $(this).closest("li").data("id"), type);
  466. //alert(id);
  467. arraymove(state[parent][type], id, id + 1);
  468. updateAll();
  469. });
  470. $(document).on('click', '.uArrow', function() {
  471. var id = $(this).parents(".drop").data("id");
  472. var index = getIndexById(id);
  473. arraymove(state, index, index - 1);
  474. updateAll();
  475. });
  476. $(document).on('click', '.dArrow', function() {
  477. var id = $(this).parents(".drop").data("id");
  478. var index = getIndexById(id);
  479. //console.log("id " + id + " index" + index);
  480. arraymove(state, index, index + 1);
  481. updateAll();
  482. });
  483. $(document).on('click', '.rArrow', function() {
  484. var id = $(this).parents(".drop").data("id");
  485. state[getIndexById(id)]["depth"]++;
  486. //var depthWidth = 20 * $(node).data("depth");
  487. // $(node).css("padding-left", depthWidth + "px");
  488. updateAll();
  489. });
  490. $(document).on('click', '.lArrow', function() {
  491. var id = $(this).parents(".drop").data("id");
  492. state[getIndexById(id)]["depth"]--;
  493. //var depthWidth = 20 * $(node).data("depth");
  494. // $(node).css("padding-left", depthWidth + "px");
  495. updateAll();
  496. });
  497. $(document).on('click', '#btnZasoby', function(e) {
  498. e.preventDefault();
  499. $(".lButton").removeClass("btn-primary");
  500. if (dialog == 0) {
  501. zasoby();
  502. $(this).addClass("btn-primary");
  503. $("#wrapper").removeClass("toggled");
  504. dialog = 1;
  505. } else if (dialog == 1) {
  506. $("#wrapper").addClass("toggled");
  507. dialog = 0;
  508. } else {
  509. $("#wrapper").addClass("toggled");
  510. $(this).addClass("btn-primary");
  511. setTimeout(function() {
  512. zasoby();
  513. $("#wrapper").removeClass("toggled");
  514. }, 500);
  515. dialog = 1;
  516. }
  517. });
  518. $(document).on('click', '#btnProcesy', function(e) {
  519. e.preventDefault();
  520. $(".lButton").removeClass("btn-primary");
  521. if (dialog == 0) {
  522. procesy();
  523. $("#wrapper").removeClass("toggled");
  524. $(this).addClass("btn-primary");
  525. dialog = 2;
  526. } else if (dialog == 2) {
  527. $("#wrapper").addClass("toggled");
  528. dialog = 0;
  529. } else {
  530. $("#wrapper").addClass("toggled");
  531. $(this).addClass("btn-primary");
  532. setTimeout(function() {
  533. procesy();
  534. $("#wrapper").removeClass("toggled");
  535. }, 500);
  536. dialog = 2;
  537. }
  538. });
  539. $(document).on('click', 'body', function() {
  540. if (selectedArea != false) {
  541. var content = $(selectedArea).val();
  542. var id = (selectedArea).parents(".drop").data("id");
  543. if ($(selectedArea).parent().hasClass("hdesc")) {
  544. state[getIndexById(id)]["desc"] = content;
  545. state[getIndexById(id)]["C-desc"] = true;
  546. }
  547. if ($(selectedArea).parent().hasClass("sdesc")) {
  548. state[getIndexById(id)]["opis"] = content;
  549. state[getIndexById(id)]["C-opis"] = true;
  550. }
  551. selectedArea = false;
  552. updateAll();
  553. }
  554. });
  555. $(document).on('click', '.hdesc', function() {
  556. if ($(this).find("textarea").is(selectedArea))
  557. return false;
  558. });
  559. $(document).on('click', '.sdesc', function() {
  560. if ($(this).find("textarea").is(selectedArea))
  561. return false;
  562. });
  563. $(document).on('dblclick', '.sdesc', function() {
  564. if (selectedArea)
  565. return;
  566. if ($(this).find("textarea").length == 0) {
  567. var content = $(this).html();
  568. $(this).empty();
  569. $(this).append("<textarea>" + content + "</textarea>");
  570. selectedArea = $(this).find("textarea");
  571. }
  572. });
  573. $(document).on('click', '.sDescAdd', function() {
  574. if (selectedArea)
  575. return;
  576. var action = $(this).parents(".drop").find(".sdesc");
  577. if ($(action).find("textarea").length == 0) {
  578. //alert($(action).text());
  579. $(action).html("<textarea placeholder='Opis kroku'>"+$(action).text()+"</textarea>");
  580. selectedArea = $(action).find("textarea");
  581. return false;
  582. }
  583. });
  584. $(document).on('click', '.hDescAdd', function() {
  585. if (selectedArea)
  586. return;
  587. var action = $(this).parents(".drop").find(".hdesc");
  588. //console.log(action);
  589. if ($(action).find("textarea").length == 0) {
  590. //alert($(action).text());
  591. $(action).html("<textarea placeholder='Tytuł kroku'>"+$(action).text()+"</textarea>");
  592. selectedArea = $(action).find("textarea");
  593. return false;
  594. }
  595. });
  596. $(document).on('dblclick', '.hdesc', function() {
  597. if ($(this).find("textarea").length == 0) {
  598. var content = $(this).html();
  599. $(this).empty();
  600. $(this).append("<textarea>" + content + "</textarea>");
  601. selectedArea = $(this).find("textarea");
  602. }
  603. });
  604. $(document).on('click', '.del', function() {
  605. var id = $(this).parents(".drop").data("id");
  606. var index = getIndexById(id);
  607. swal({
  608. title: 'Usuwanie kroku',
  609. text: "Czy napewno chcesz usunąć ten krok?",
  610. type: 'warning',
  611. showCancelButton: true,
  612. confirmButtonColor: '#3085d6',
  613. cancelButtonColor: '#d33',
  614. cancelButtonText: "Anuluj",
  615. confirmButtonText: 'Tak, usuń ten krok'
  616. }).then(function() {
  617. state.splice(index, 1);
  618. deletedId.push(id);
  619. updateAll();
  620. //Parent_id = -1,
  621. }).catch(function(e) {})
  622. });
  623. $(document).on('click', '.delGoto', function() {
  624. //var parent = $(this).parents(".drop");
  625. var id = $(this).parents("li").data("id");
  626. var parent = getIndexById($(this).parents(".drop").data("id"));
  627. swal({
  628. title: 'Usuwanie bramki',
  629. text: "Czy napewno chcesz usunąć tę bramkę?",
  630. type: 'warning',
  631. showCancelButton: true,
  632. confirmButtonColor: '#3085d6',
  633. cancelButtonColor: '#d33',
  634. cancelButtonText: "Anuluj",
  635. confirmButtonText: 'Tak, usuń tę bramkę'
  636. }).then(function() {
  637. state[parent]["goto"] = {
  638. id: "",
  639. flag: ""
  640. };
  641. updateAll();
  642. //Parent_id = -1,
  643. }).catch(function(e) {})
  644. });
  645. $(document).on('click', '.delRes', function() {
  646. //var parent = $(this).parents(".drop");
  647. var id = $(this).parents("li").data("id");
  648. var parent = getIndexById($(this).parents(".drop").data("id"));
  649. var type;
  650. if ($(this).closest(".professions").length > 0)
  651. type = "prof";
  652. else
  653. type = "res";
  654. var index = getResById(parent, id, type);
  655. swal({
  656. title: 'Usuwanie wskaźnika',
  657. text: "Czy napewno chcesz usunąć ten wskaźnik?",
  658. type: 'warning',
  659. showCancelButton: true,
  660. confirmButtonColor: '#3085d6',
  661. cancelButtonColor: '#d33',
  662. cancelButtonText: "Anuluj",
  663. confirmButtonText: 'Tak, usuń ten wskaźnik'
  664. }).then(function() {
  665. deletedRes.push(id);
  666. state[parent][type].splice(index, 1);
  667. updateAll();
  668. //Parent_id = -1,
  669. }).catch(function(e) {})
  670. });
  671. //
  672. $(document).on('click', '.fbutton', function(e) {
  673. e.preventDefault();
  674. $(".fbutton").removeClass("btn-success");
  675. if ($(this).data("type") == filtr) {
  676. filtr = 0;
  677. //console.log("Odznaczono");
  678. } else {
  679. filtr = $(this).data("type");
  680. $(this).addClass("btn-success");
  681. }
  682. if (filtr === 0)
  683. $("#xBtn").prop("disabled", true);
  684. else
  685. $("#xBtn").prop("disabled", false);
  686. if (filtr === 0) {
  687. zasoby();
  688. } else
  689. searchRes();
  690. });
  691. $(document).on('click', '.showMore', function() {
  692. var target = $(this).parent().find(".more");
  693. var id = $(this).data("id");
  694. if ($(target).parent().hasClass("resSelected")) {
  695. $(".more").empty();
  696. $(target).parent().removeClass("resSelected");
  697. $(target).parent().find(".gIco").addClass("glyphicon-chevron-down");
  698. $(target).parent().find(".gIco").removeClass("glyphicon-chevron-up");
  699. } else {
  700. $(".more").parent().removeClass("resSelected");
  701. $(".more").parent().find(".gIco").addClass("glyphicon-chevron-down");
  702. $(".more").parent().find(".gIco").removeClass("glyphicon-chevron-up");
  703. $(".more").empty();
  704. $(target).parent().addClass("resSelected");
  705. $(target).parent().find(".gIco").removeClass("glyphicon-chevron-down");
  706. $(target).parent().find(".gIco").addClass("glyphicon-chevron-up");
  707. var link = BASE_URL+"index.php?_route=UrlAction_ProcesEditor&_task=getResByParentAjax&parent_id="+id;
  708. //console.log(link);
  709. $.get(link, function(data) {
  710. $.each(data, function(i, e) {
  711. if (e["ID"] != 0) {
  712. var type = 0;
  713. $(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>");
  714. for(var i=3;i>0;i--){
  715. if(e["p"+i+"_ID"] != null){
  716. var temp = {};
  717. temp["ID"] = e["p"+i+"_ID"];
  718. temp["DESC"] = e["p"+i+"_DESC"];
  719. zasobTree[e["ID"]] = [];
  720. zasobTree[e["ID"]].push(temp);
  721. }
  722. }
  723. $('.drag').draggable({
  724. appendTo: 'body',
  725. helper: 'clone',
  726. stack: "div",
  727. distance: 0,
  728. cursor: "copy"
  729. });
  730. }
  731. });
  732. });
  733. }
  734. });
  735. function searchProc() {
  736. var id = lastSearch;
  737. var link;
  738. //console.log("Szukam");
  739. 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';
  740. $.get(link, function(data) {
  741. var side = $("#side");
  742. //console.log(data);
  743. $(side).find("#ulproc").empty();
  744. $.each($(data).find("featureMember"), function() {
  745. if ($(this).find("ID").text() * 1 == 0) {
  746. $(side).find("#ulcon").append("<div><center>Brak wyników wyszukiwania</center></div>");
  747. return;
  748. }
  749. $(side).find("#ulproc").append("<div class='dragStyle drag dragStyle hov' data-droptype=1 data-id=" + $(this).find("ID").text() + " > " + $(this).find("DESC").text() + " [" + $(this).find("ID").text() + "]</div>");
  750. $('.drag').draggable({
  751. appendTo: 'body',
  752. helper: 'clone',
  753. stack: "div",
  754. distance: 0,
  755. cursor: "copy"
  756. });
  757. });
  758. });
  759. }
  760. function searchRes() {
  761. var id = lastSearch;
  762. var link;
  763. link = BASE_URL+"index.php?_route=UrlAction_ProcesEditor&_task=getResAjax&word="+id+"&filter="+filtr;
  764. console.log(link);
  765. $.get(link, function(data) {
  766. var side = $("#side");
  767. //console.log(data);
  768. $(side).find("#ulcon").empty();
  769. if(data.length == 0)
  770. $(side).find("#ulcon").append("<div><center>Brak wyników wyszukiwania</center></div>");
  771. $.each(data, function(i, e) {
  772. var tree = "";
  773. for(var i=3;i>0;i--){
  774. if(e["p"+i+"_ID"] != null){
  775. var temp = {};
  776. temp["ID"] = e["p"+i+"_ID"];
  777. temp["DESC"] = e["p"+i+"_DESC"];
  778. zasobTree[e["ID"]] = [];
  779. zasobTree[e["ID"]].push(temp);
  780. tree += e["p"+i+"_DESC"] + (i>1 ? " <span class='glyphicon glyphicon-triangle-right'></span>" : "");
  781. }
  782. }
  783. console.log(e["TYPE"]);
  784. var type = 0;
  785. if (e["TYPE"] == "DZIAL" || e["TYPE"] == "PODMIOT" || e["TYPE"] == "STANOWISKO")
  786. type = 1;
  787. if (filtr != 2 || e["TYPE"] != "TABELA")
  788. $(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>");
  789. else {
  790. $(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>");
  791. }
  792. });
  793. $('.drag').draggable({
  794. appendTo: 'body',
  795. helper: 'clone',
  796. stack: "div",
  797. distance: 0,
  798. cursor: "copy"
  799. });
  800. $(".drop").droppable({
  801. tolerance: 'pointer',
  802. accept: '.drag',
  803. hoverClass: "activeDrop",
  804. drop: function(event, ui) {
  805. if (ui.draggable.data("dropType") == 1)
  806. addProces(ui, this);
  807. else
  808. addResource(ui, this);
  809. }
  810. });
  811. });
  812. }
  813. $(document).on('click', '.liProc', function() {
  814. $(this).parents(".singleAdv").nextAll(".singleAdv").remove();
  815. $(this).parents(".singleAdv").find(".active").removeClass("active");
  816. $(this).find(".glyphicon").removeClass("glyphicon-triangle-right");
  817. $(this).find(".glyphicon").addClass("glyphicon-refresh");
  818. $(this).find(".glyphicon").addClass("anim-refresh");
  819. $(this).addClass("active");
  820. var parent = this;
  821. var parent_id = $(this).data("id");
  822. var 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:PropertyIsEqualTo><ogc:PropertyName>PARENT_ID</ogc:PropertyName><ogc:Literal>' + parent_id + '</ogc:Literal></ogc:PropertyIsEqualTo></ogc:Filter>';
  823. var result = "";
  824. var depth = $(this).parents(".singleAdv").data("depth") + 1;
  825. $("#procCon").css("width", depth * 290 + 290);
  826. $(this).parents(".singleAdv").after("<div class='singleAdv list-group' data-depth=" + depth + " id=depth" + depth + "></div>");
  827. //console.log(link);
  828. var childs = true;
  829. $.get(link, function(data) {
  830. $(data).find("featureMember").each(function() {
  831. if ($(this).find("ID").text() == 0) {
  832. childs = false;
  833. return;
  834. }
  835. var type = 0;
  836. result += "<div class='list-group-item drag liProc' data-opis='" + $(this).find("OPIS").text() + "' data-desc='" + $(this).find("DESC").text() + "' data-droptype=1 data-id=" + $(this).find("ID").text() + " ><div class=textTable><span class=handle> # </span>" + $(this).find("DESC").text() + "</div><div class=detailsTable>[" + $(this).find("ID").text() + "]</div><div class='glyphicon glyphicon-triangle-right' style=opacity:0.4;float:right;></div><div class=clearfix></div></div>";
  837. });
  838. if (!childs) {
  839. result += '<div class="panel panel-primary">';
  840. result += '<div class="panel-heading"><h3 class="panel-title">[' + $(parent).data('id') + '] ' + $(parent).data("desc") + '</h3></div>';
  841. result += '<div class="panel-body pbody">';
  842. result += '<b>Opis: </b>' + $(parent).data("opis");
  843. result += '</div>';
  844. result += '</div>'
  845. }
  846. $("#depth" + depth).html(result);
  847. $('.drag').draggable({
  848. appendTo: 'body',
  849. handle: '.handle',
  850. helper: 'clone',
  851. stack: "div",
  852. distance: 0,
  853. cursor: "copy"
  854. });
  855. $(parent).find(".glyphicon").addClass("glyphicon-triangle-right");
  856. $(parent).find(".glyphicon").removeClass("glyphicon-refresh");
  857. $(parent).find(".glyphicon").removeClass("anim-refresh");
  858. $("#ulproc").scrollLeft(depth * 290 + 290);
  859. $("#ulproc").scrollTop(0);
  860. });
  861. });
  862. function procesy() {
  863. var side = $("#side");
  864. $(side).empty();
  865. //$(side).append("<h3>Zarządzaj zasobami<h3>");
  866. $(side).append("<div class='form-group' ><input type='text' class=form-control id=sProcesy placeholder='Szukaj procesów'></div>");
  867. $(side).append("<div id=ulproc><div id=procCon></div></div>");
  868. $(side).find("#procCon").append("<div class='singleAdv list-group' data-depth=0 id=depth0></div>");
  869. $(side).find("#procCon").append("<div class=clearfix></div>");
  870. var 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:PropertyIsEqualTo><ogc:PropertyName>PARENT_ID</ogc:PropertyName><ogc:Literal>0</ogc:Literal></ogc:PropertyIsEqualTo></ogc:Filter>&sortBy=SORT_PRIO+A,ID';
  871. var result = "";
  872. $.get(link, function(data) {
  873. //console.log(data);
  874. $(data).find("featureMember").each(function() {
  875. var type = 0;
  876. result += "<div class='drag list-group-item liProc' data-droptype=1 data-opis='" + $(this).find("OPIS").text() + "' data-desc='" + $(this).find("DESC").text() + "' data-id=" + $(this).find("ID").text() + " ><div class=textTable><span class=handle> # </span>" + $(this).find("DESC").text() + "</div><div class=detailsTable> [" + $(this).find("ID").text() + "]</div><div class='glyphicon glyphicon-triangle-right' style=opacity:0.4;float:right;></div><div class=clearfix></div></div>";
  877. });
  878. $("#depth0").html(result);
  879. $('.drag').draggable({
  880. appendTo: 'body',
  881. handle: '.handle',
  882. helper: 'clone',
  883. stack: "div",
  884. distance: 0,
  885. cursor: "copy"
  886. });
  887. });
  888. }
  889. $(document).on('click', '.liAdv', function() {
  890. $(this).find(".glyphicon").removeClass("glyphicon-triangle-right");
  891. $(this).find(".glyphicon").addClass("glyphicon-refresh");
  892. $(this).parents(".singleAdv").nextAll(".singleAdv").remove();
  893. $(this).parents(".singleAdv").find(".active").removeClass("active");
  894. $(this).addClass("active");
  895. var parent = this;
  896. var parent_id = $(this).data("id");
  897. 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:PropertyIsEqualTo><ogc:PropertyName>PARENT_ID</ogc:PropertyName><ogc:Literal>' + parent_id + '</ogc:Literal></ogc:PropertyIsEqualTo></ogc:Filter>&sortBy=SORT_PRIO+A,ID';
  898. var result = "";
  899. var depth = $(this).parents(".singleAdv").data("depth") + 1;
  900. $("#advCon").css("width", depth * 290 + 290);
  901. $(this).parents(".singleAdv").after("<div class='singleAdv list-group' data-depth=" + depth + " id=depth" + depth + "></div>");
  902. //console.log(link);
  903. var childs = true;
  904. $.get(link, function(data) {
  905. $(data).find("featureMember").each(function() {
  906. if ($(this).find("ID").text() == 0) {
  907. childs = false;
  908. return;
  909. }
  910. var type = 0;
  911. if ($(this).find("TYPE").text() == "DZIAL" || $(this).find("TYPE").text() == "PODMIOT" || $(this).find("TYPE").text() == "STANOWISKO")
  912. type = 1;
  913. 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>";
  914. result += "<div class='glyphicon glyphicon-triangle-right' style=opacity:0.4;float:right;></div>";
  915. result += "<div class=clearfix></div><div class=detailsTable2>[" + $(this).find("ID").text() + "] " + $(this).find("TYPE").text() + "</div></div>";
  916. });
  917. if (!childs) {
  918. result += '<div class="panel panel-primary">';
  919. result += '<div class="panel-heading"><h3 class="panel-title">[' + $(parent).data('id') + '] ' + $(parent).data("desc") + '</h3></div>';
  920. result += '<div class="panel-body pbody">';
  921. result += '<b>Opis: </b>' + $(parent).data("opis");
  922. result += '<br><b>Typ: </b>' + $(parent).data("typename");
  923. result += '</div>';
  924. result += '</div>'
  925. }
  926. $("#depth" + depth).html(result);
  927. $('.drag').draggable({
  928. appendTo: 'body',
  929. handle: '.handle',
  930. helper: 'clone',
  931. stack: "div",
  932. distance: 0,
  933. cursor: "copy"
  934. });
  935. $(parent).find(".glyphicon").addClass("glyphicon-triangle-right");
  936. $(parent).find(".glyphicon").removeClass("glyphicon-refresh");
  937. $("#ulcon").scrollLeft(depth * 290 + 290);
  938. $("#ulcon").scrollTop(0);
  939. });
  940. });
  941. function zasoby() {
  942. var side = $("#side");
  943. $(side).empty();
  944. //$(side).append("<h3>Zarządzaj zasobami<h3>");
  945. $(side).append("<div class='form-group' ><input type='text' class=form-control id=sZasoby placeholder='Szukaj zasobów'></div>");
  946. $(side).append("<div class='btn-group' style=width:100% id=filtry></div>");
  947. $("#filtry").append("<button type='button' data-type=1 class='fbutton btn btn-default input-block-level ' style=width:40%>Stanowiska</button>");
  948. $("#filtry").append("<button type='button' data-type=2 class='fbutton btn btn-default input-block-level ' style=width:40%>Komórki</button>");
  949. $("#filtry").append("<button type='button' data-type=0 class='fbutton btn btn-danger input-block-level' id=xBtn style=width:20% disabled>X</button>");
  950. $(side).append("<div id=ulcon><div id=advCon></div></div>");
  951. $(side).find("#advCon").append("<div class='singleAdv list-group' data-depth=0 id=depth0></div>");
  952. $(side).find("#advCon").append("<div class=clearfix></div>");
  953. 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:PropertyIsEqualTo><ogc:PropertyName>PARENT_ID</ogc:PropertyName><ogc:Literal>0</ogc:Literal></ogc:PropertyIsEqualTo></ogc:Filter>&sortBy=SORT_PRIO+A,ID';
  954. var result = "";
  955. $.get(link, function(data) {
  956. //console.log(data);
  957. $(data).find("featureMember").each(function() {
  958. var type = 0;
  959. if ($(this).find("TYPE").text() == "DZIAL" || $(this).find("TYPE").text() == "PODMIOT" || $(this).find("TYPE").text() == "STANOWISKO")
  960. type = 1;
  961. result += "<div class='drag list-group-item 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; style=float:left;></div><div class=clearfix></div><div class=detailsTable2>[" + $(this).find("ID").text() + "] " + $(this).find("TYPE").text() + "</div></div>";
  962. });
  963. $("#depth0").html(result);
  964. $('.drag').draggable({
  965. appendTo: 'body',
  966. handle: '.handle',
  967. helper: 'clone',
  968. stack: "div",
  969. distance: 0,
  970. cursor: "copy"
  971. });
  972. });
  973. //$(side).find("#ulcon").append("<div class='drag' data-id=1 data-type=1 >[STANOWISKO] Ulotkarz</div>");
  974. //$(side).find("#ulcon").append("<div class='drag' data-id=2 data-type=1 >[STANOWISKO] Programista PHP</div>");
  975. //$(side).find("#ulcon").append("<div class='drag' data-id=3 data-type=2 >[ZASÓB] Komputer</div>");
  976. }
  977. function addProces(ui, target) {
  978. var id = $(target).data("id");
  979. var gotoOpt = "";
  980. $.each(gotoType, function(key, value) {
  981. gotoOpt += "<option value=" + value[0] + ">" + value[1] + "</option>";
  982. })
  983. swal({
  984. showCancelButton: true,
  985. cancelButtonText: "Anuluj",
  986. title: 'Typ łącza',
  987. html: (typeof state[getIndexById(id)]["goto"] !== typeof undefined && state[getIndexById(id)]["goto"]["id"] != null && state[getIndexById(id)]["goto"]["id"] != 0 ? '<span class=class="alert alert-warning"><strong>Uwaga!</strong> Nowe łącze nadpisze już istniejące łącze.</span><br>' : "") + '<br><select class=form-control id="swal-input1">' + gotoOpt + '</select>',
  988. preConfirm: function() {
  989. return new Promise(function(resolve) {
  990. resolve([
  991. $('#swal-input1').val()
  992. ]);
  993. });
  994. }
  995. }).then(function(result) {
  996. //console.log("Dodaj zasob " + ui.draggable.data("id") + " do " + $(target).data("id") + " i uprawnienia id " + result[0] + " komentarz: " + result[1]); //
  997. newRes--;
  998. var temp = {};
  999. temp["flag"] = result[0];
  1000. temp["id"] = ui.draggable.data("id");
  1001. //console.log(temp);
  1002. //console.log(state[getIndexById(id)]);
  1003. state[getIndexById(id)]["goto"] = temp;
  1004. updateAll();
  1005. }).catch(function(e) {})
  1006. }
  1007. function addResource(ui, target) {
  1008. var permsOpt = "";
  1009. $.each(perms, function(key, value) {
  1010. permsOpt = permsOpt + "<option value=" + value[0] + ">[" + value[2] + "] " + value[1] + "</option>";
  1011. })
  1012. swal({
  1013. showCancelButton: true,
  1014. cancelButtonText: "Anuluj",
  1015. title: 'Uprawnienia',
  1016. html: 'Uprawnienia<br><select class=form-control id="swal-input1">' + permsOpt + '</select>' +
  1017. 'Komentarz<br><input class=form-control id="swal-input2" class="swal2-input">',
  1018. preConfirm: function() {
  1019. return new Promise(function(resolve) {
  1020. resolve([
  1021. $('#swal-input1').val(),
  1022. $('#swal-input2').val()
  1023. ]);
  1024. });
  1025. }
  1026. }).then(function(result) {
  1027. console.log(zasobTree);
  1028. //console.log("Dodaj zasob " + ui.draggable.data("id") + " do " + $(target).data("id") + " i uprawnienia id " + result[0] + " komentarz: " + result[1]); //
  1029. newRes--;
  1030. var temp = {};
  1031. temp["id_zasob"] = ui.draggable.data("id");
  1032. temp["id"] = newRes;
  1033. temp["id_przypadek"] = result[0];
  1034. temp["komentarz"] = result[1];
  1035. temp["changed"] = true;
  1036. temp["opis"] = ui.draggable.data("opis");
  1037. temp["desc"] = ui.draggable.data("desc");
  1038. temp["tree"] = zasobTree[temp["id_zasob"]];
  1039. var id = $(target).data("id");
  1040. if (ui.draggable.data("type") == 1) {
  1041. state[getIndexById(id)]["prof"].push(temp);
  1042. } else {
  1043. state[getIndexById(id)]["res"].push(temp);
  1044. }
  1045. updateAll();
  1046. }).catch(function(e) {})
  1047. }
  1048. //Najwazniejsza funkcja odpalana po kazdej zmianie. Sprawdza, czy wszystkie funkcje maja rodzica,
  1049. //jezeli nie to przesuwa w lewo obiekt
  1050. //Odpowiada tez za ukrywanie guzikow i wywowalanie funkcji generacji krokow
  1051. function updateAll() {
  1052. $.each(state, function(i, e) {
  1053. var pid = getParentNode(e["id"]);
  1054. if (pid != "NONE" && pid != false && pid != e["parent_id"]) {
  1055. e["parent_id"] = pid;
  1056. //console.log("Ustawiono nowe parent_id na " + e["parent_id"] + " dla " + e["id"]); //
  1057. } else if (pid === false) {
  1058. e["depth"]--;
  1059. //var depthWidth = 20 * $(node).data("depth");
  1060. //$(node).css("padding-left", depthWidth + "px");
  1061. updateAll();
  1062. return;
  1063. }
  1064. if (checkParentNode(e["id"], "right") === false) {
  1065. $(this).find(".rArrow").hide();
  1066. } else {
  1067. $(this).find(".rArrow").show();
  1068. }
  1069. if (checkParentNode(e["id"], "left") === false) {
  1070. $(this).find(".lArrow").hide();
  1071. } else {
  1072. $(this).find(".lArrow").show();
  1073. }
  1074. if (i == 1)
  1075. $(this).find(".uArrow").hide();
  1076. else
  1077. $(this).find(".uArrow").show();
  1078. if (i == state.length - 1) {
  1079. $(this).find(".dArrow").hide();
  1080. } else {
  1081. $(this).find(".dArrow").show();
  1082. }
  1083. });
  1084. //console.log(JSON.stringify(state));
  1085. changes = true;
  1086. $("#clearBtn").show();
  1087. localStorage.setItem("state" + mainProces_id, JSON.stringify(state));
  1088. localStorage.setItem("newStep" + mainProces_id, newSteps);
  1089. localStorage.setItem("newRes" + mainProces_id, newRes);
  1090. localStorage.setItem("deletedId" + mainProces_id, JSON.stringify(deletedId));
  1091. localStorage.setItem("deletedRes" + mainProces_id, JSON.stringify(deletedRes));
  1092. localStorage.setItem("date" + mainProces_id, moment().format("YYYY-MM-DD HH:mm:ss"));
  1093. render(state, $("#main"));
  1094. }
  1095. //Generuje kroki, sprawdza tez czy kolejnosc krokow w danym rodzicow zostala zmieniona
  1096. //Jezeli tak to mozna wyslac ajaxem zmiane kolejnosci dla sort_prio
  1097. function stepsGenerator() {
  1098. $.each(state, function(i, e) {
  1099. e["step"] = 0;
  1100. if (i == 0)
  1101. e["stepDesc"] = "";
  1102. else {
  1103. var iParent = getIndexById(e["parent_id"]);
  1104. //console.log("Generowanie step dla "+e["id"]);
  1105. //console.log("iParent "+iParent);
  1106. state[iParent]["step"] += 1;
  1107. //console.log(state[iParent]["step"]);
  1108. e["SORT_PRIO"] = state[iParent]["step"];
  1109. e["stepDesc"] = state[iParent]["stepDesc"] + state[iParent]["step"] + ". ";
  1110. }
  1111. });
  1112. }
  1113. //Na potrzeby guzikow dorobilem funkcje sprawdzajaca id rodzica po przesunieciu (przewidywanie).
  1114. //Jezeli nie znajdzie zwraca false, a wtedy blokuje sie odpowiednia strzalka
  1115. function checkParentNode(id, check) {
  1116. var x = getIndexById(id);
  1117. var y = x;
  1118. //console.log(tab);
  1119. var result = false;
  1120. while (x > 0) {
  1121. x--;
  1122. if (check == "right")
  1123. if (state[x]["depth"] == state[y]["depth"]) {
  1124. result = state[x]["id"];
  1125. break;
  1126. }
  1127. if (check == "left")
  1128. if (state[x]["depth"] == state[y]["depth"] - 2) {
  1129. result = state[x]["id"];
  1130. break;
  1131. }
  1132. if (check == "right" && state[x]["depth"] < state[y]["depth"])
  1133. break;
  1134. }
  1135. return result;
  1136. }
  1137. //Zwraca id rodzica, jezeli nie ma zwraca false
  1138. function getParentNode(id) {
  1139. var x = getIndexById(id);
  1140. var y = x;
  1141. if (x == 0)
  1142. return "NONE";
  1143. var result = false;
  1144. while (x > 0) {
  1145. x--;
  1146. if (state[x]["depth"] == state[y]["depth"] - 1) {
  1147. result = state[x]["id"];
  1148. break;
  1149. }
  1150. if (state[x]["depth"] - state[y]["depth"] == -2)
  1151. break;
  1152. }
  1153. return result;
  1154. }
  1155. function getResById(index, id, type) {
  1156. var result = state[index][type].length - 1;
  1157. $.each(state[index][type], function(i, e) {
  1158. //console.log(e["id"]);
  1159. //console.log(id);
  1160. if (e["id"] == id) {
  1161. //console.log("Zwraca "+i);
  1162. result = i;
  1163. return false;
  1164. }
  1165. });
  1166. return result;
  1167. }
  1168. function getIndexById(id) {
  1169. //console.log("Szuka"+id);
  1170. var result = state.length - 1;
  1171. $.each(state, function(i, e) {
  1172. //console.log(e["id"]);
  1173. //console.log(id);
  1174. if (e["id"] == id) {
  1175. //console.log("Zwraca "+i);
  1176. result = i;
  1177. return false;
  1178. }
  1179. });
  1180. return result;
  1181. }
  1182. /*function logState() {
  1183. //console.log("########");
  1184. $.each(state, function(i, e) {
  1185. //console.log(i + ": " + e["id"]);
  1186. });
  1187. //console.log("########");
  1188. }*/
  1189. $(document).on('click', '.stateOff', function() {
  1190. $(this).closest(".mx").prev(".tree").show();
  1191. $(this).closest(".mx").remove();
  1192. });
  1193. $(document).on('click', '.tree', function() {
  1194. var type;
  1195. if($(this).closest("ul").hasClass("resources")){
  1196. type = "res";
  1197. }else {
  1198. type = "prof"
  1199. }
  1200. var id = getIndexById($(this).closest(".drop").data("id"));
  1201. var resId = getResById(id, $(this).closest(".liRes").data("id"), type);
  1202. $(this).hide();
  1203. showTree(state[id][type][resId]["tree"], $(this));
  1204. });
  1205. function showTree(arr, target){
  1206. result = "";
  1207. $.each(arr, function(i, x){
  1208. result += "<li style=padding-left:"+i*16+"px;><span class='glyphicon glyphicon-arrow-right'></span> "+x["DESC"]+"</li>";
  1209. });
  1210. $(target).after("<div class=mx><div class=stateOff><span class='glyphicon glyphicon-chevron-up'></span></div> <ul style=padding-left:0px;>"+result+"</ul></div>");
  1211. }
  1212. function render(arr, target) {
  1213. stepsGenerator();
  1214. var result = "";
  1215. console.log(arr);
  1216. $.each(arr, function(i, e) {
  1217. result += "<div class='drop container-fluid' data-id=" + e["id"] + " id='proc" + e["id"] + "'>";
  1218. result += "<div class='col-xs-1 options' style=text-align:right;padding-top:2px; id=opt" + e["id"] + ">";
  1219. if (i > 0) {
  1220. result += "<span class='glyphicon glyphicon-remove-sign ico del' title='Usuń krok' aria-hidden='true'></span>";
  1221. //Arrows
  1222. if (checkParentNode(e["id"], "right") !== false)
  1223. result += "<span class='glyphicon glyphicon-arrow-right ico rArrow' aria-hidden='true' title='Przesuń krok w prawo'></span>";
  1224. if (checkParentNode(e["id"], "left") !== false)
  1225. result += "<span class='glyphicon glyphicon-arrow-left ico lArrow' aria-hidden='true' title='Przesuń krok w lewo'></span>";
  1226. if (i != 1)
  1227. result += "<span class='glyphicon glyphicon-arrow-up ico uArrow' aria-hidden='true' title='Przesuń krok w górę'></span>";
  1228. if (i != state.length - 1)
  1229. result += "<span class='glyphicon glyphicon-arrow-down ico dArrow' aria-hidden='true' title='Przesuń krok w dół'></span>";
  1230. } else {
  1231. }
  1232. result += "<span class='hDescAdd glyphicon glyphicon-edit ico' title='Edytuj tytuł'></span>";
  1233. result += "<div class='clearfix'></div>";
  1234. if (e["opis"] == "")
  1235. result += "<span class=sDescAdd>Dodaj opis</span>";
  1236. else
  1237. result += "<span class=sDescAdd>Edytuj opis</span>";
  1238. result += "</div>";
  1239. result += "<div class='col-xs-10 desc' id='desc" + e["id"] + "' ><h4 class='changable " + (e["C-desc"] ? "changed" : "") + "'><span class='stepDesc'>" + e["stepDesc"] + "</span><span class=hdesc>" + e["desc"] + "</span> <span class=ids>{" + (e["id"] >= 0 ? e["id"] : "?") + "}</span></h4><span class='sdesc changable " + (e["C-opis"] ? "changed" : "") + "'>" + e["opis"] + "</span>";
  1240. // }
  1241. // if ($(this).find("OPIS").text() == "") {
  1242. // $("#proc" + $(this).find("ID").text()).find(".sdesc").after("<span class=sDescAdd>Dodaj opis</span>");
  1243. // }
  1244. result += "<div class='clearfix'></div>";
  1245. var anyProf = false;
  1246. $.each(e["prof"], function(i2, e2) {
  1247. if (!anyProf) {
  1248. result += "<div class=row><div class=col-sm-2 style=font-size:1.2em;text-align:right;opacity:1>Stanowiska</div></div><ul class=professions style=padding:0;>";
  1249. anyProf = true;
  1250. }
  1251. 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>";
  1252. result += "<div class=col-sm-2 style=text-align:right;>";
  1253. if (i2 != 0)
  1254. result += "<span class='glyphicon glyphicon-arrow-up uArrowRes' title='Przesuń wskaźnik w górę' aria-hidden='true'></span>";
  1255. if (i2 != e["prof"].length - 1)
  1256. result += "<span class='glyphicon glyphicon-arrow-down dArrowRes' title='Przesuń wskaźnik w dół' aria-hidden='true'></span>";
  1257. 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>";
  1258. result += "</div>";
  1259. result += "<div class='col-sm-10 changable " + (e2["changed"] ? "changed" : "") + " '><b>" + e2["desc"] + "</b> " + e2["opis"] + " [" + e2["id_zasob"] + "] <br><span class=tree>";
  1260. result += "<span class=state><span class='glyphicon glyphicon-chevron-down'></span></span> ";
  1261. $.each(e2["tree"], function(i, x){
  1262. result += x["DESC"] + (i<e2["tree"].length-1 ? " <span class='glyphicon glyphicon-triangle-right'></span>" : "");
  1263. });
  1264. result += "<div class=moreInfo></div></span></div>";
  1265. result += "</div></li>";
  1266. });
  1267. if (anyProf) {
  1268. result += "</ul>";
  1269. }
  1270. var anyRes = false;
  1271. $.each(e["res"], function(i2, e2) {
  1272. if (!anyRes) {
  1273. 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;>";
  1274. anyRes = true;
  1275. }
  1276. 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>";
  1277. result += "<div class=col-sm-2 style=text-align:right;>";
  1278. if (i2 != 0)
  1279. result += "<span class='glyphicon glyphicon-arrow-up uArrowRes' title='Przesuń wskaźnik w górę' aria-hidden='true'></span>";
  1280. if (i2 != e["prof"].length - 1)
  1281. result += "<span class='glyphicon glyphicon-arrow-down dArrowRes' title='Przesuń wskaźnik w dół' aria-hidden='true'></span>";
  1282. 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>";
  1283. result += "</div>";
  1284. result += "<div class='col-sm-10 changable " + (e2["changed"] ? "changed" : "") + " '><b>" + e2["desc"] + "</b> " + e2["opis"] + " [" + e2["id_zasob"] + "] <br><span class=tree>";
  1285. result += "<span class=state><span class='glyphicon glyphicon-chevron-down'></span></span> ";
  1286. $.each(e2["tree"], function(i, x){
  1287. result += x["DESC"] + (i<e2["tree"].length-1 ? "<span class='glyphicon glyphicon-triangle-right'></span> " : "");
  1288. });
  1289. result += "</span></div>";
  1290. result += "</div></li>";
  1291. });
  1292. if (anyRes) {
  1293. result += "</ul>";
  1294. }
  1295. if (typeof e["goto"] !== typeof undefined && e["goto"]["id"] != null && e["goto"]["id"] != 0) {
  1296. var name;
  1297. switch (e["goto"]["flag"]) {
  1298. case "GOTO":
  1299. name = "Przejdź do procesu " + e["goto"]["id"] + ".";
  1300. break;
  1301. case "GOTO_AND_RETURN":
  1302. name = "Przejdź do procesu " + e["goto"]["id"] + ", a następnie wróć.";
  1303. break;
  1304. case "FORK":
  1305. name = "&mdash; FORK" + e["goto"]["id"];
  1306. break;
  1307. default:
  1308. name = e["goto"]["id"];
  1309. }
  1310. result += "<span style=color:grey; class=goto>&mdash; " + name + "</span> <span class='glyphicon glyphicon-remove-sign delGoto' title='Usuń GOTO' style=font-size:12px; aria-hidden='true' ></span>";
  1311. }
  1312. result += "<br><span class=step>Dodaj nowy krok</span>";
  1313. result += "</div>"
  1314. result += "</div>";
  1315. });
  1316. //console.log(result);
  1317. $(target).html(result);
  1318. $('.drag').draggable({
  1319. appendTo: 'body',
  1320. helper: 'clone',
  1321. stack: "div",
  1322. distance: 0,
  1323. cursor: "copy"
  1324. });
  1325. $(".drop").droppable({
  1326. tolerance: 'pointer',
  1327. accept: '.drag',
  1328. zIndex: 0,
  1329. hoverClass: "activeDrop",
  1330. drop: function(event, ui) {
  1331. if (ui.draggable.data("droptype") == 1)
  1332. addProces(ui, this);
  1333. else
  1334. addResource(ui, this);
  1335. }
  1336. });
  1337. }
  1338. function genTree(parent_id) {
  1339. //logState();
  1340. var 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:PropertyIsEqualTo><ogc:PropertyName>PARENT_ID</ogc:PropertyName><ogc:Literal>' + parent_id + '</ogc:Literal></ogc:PropertyIsEqualTo></ogc:Or></ogc:Filter>&sortBy=SORT_PRIO+A,ID';
  1341. //console.log(link);
  1342. $.ajax({
  1343. url: link,
  1344. success: function(data) {
  1345. //console.log(data);
  1346. var i = 0;
  1347. $.each($(data).find("featureMember"), function() {
  1348. var temp = {};
  1349. if ($(this).find("ID").text() == "0")
  1350. return;
  1351. var parentIndex = getIndexById(parent_id);
  1352. temp["id"] = $(this).find("ID").text();
  1353. temp["desc"] = $(this).find("DESC").text();
  1354. temp["opis"] = $(this).find("OPIS").text();
  1355. temp["parent_id"] = $(this).find("PARENT_ID").text();
  1356. temp["depth"] = state[parentIndex]["depth"] + 1;
  1357. temp["step"] = 0;
  1358. temp["changes"] = {};
  1359. temp["prof"] = new Array();
  1360. temp["res"] = new Array();
  1361. temp["goto"] = {};
  1362. temp["goto"]["id"] = $(this).find("IF_TRUE_GOTO").text();
  1363. temp["goto"]["flag"] = $(this).find("IF_TRUE_GOTO_FLAG").text();
  1364. temp["stepDesc"] = "";
  1365. i++;
  1366. state.splice(parentIndex + i, 0, temp);
  1367. genTree($(this).find("ID").text());
  1368. });
  1369. }
  1370. });
  1371. }
  1372. //Pierwszy render, tworzy potrzebna strukture
  1373. function showPreview() {
  1374. changes = false;
  1375. $("#clearBtn").hide();
  1376. lastSearch = "";
  1377. filtr = 0;
  1378. selectedArea = false;
  1379. state = [];
  1380. if (false && localStorage.getItem("state" + mainProces_id) !== null) {
  1381. state = JSON.parse(localStorage.getItem("state" + mainProces_id));
  1382. newSteps = localStorage.getItem("newStep" + mainProces_id);
  1383. newRes = localStorage.getItem("newRes" + mainProces_id);
  1384. deletedId = JSON.parse(localStorage.getItem("deletedId" + mainProces_id));
  1385. deletedRes = JSON.parse(localStorage.getItem("deletedRes" + mainProces_id));
  1386. //console.log("z");
  1387. //console.log(localStorage.getItem("state" + mainProces_id));
  1388. $.notify("Wczytano niezapisany stan z " + localStorage.getItem("date" + mainProces_id), "info");
  1389. //console.log(state);
  1390. render(state, $("#main"));
  1391. loaded = true;
  1392. } else {
  1393. $("#main").html("<center>Synchronizowanie danych z serwerem.</center>");
  1394. newSteps = 0;
  1395. newRes = 0;
  1396. deletedId = [];
  1397. deletedRes = [];
  1398. var id = mainProces_id;
  1399. var 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:PropertyIsEqualTo><ogc:PropertyName>ID</ogc:PropertyName><ogc:Literal>' + id + '</ogc:Literal></ogc:PropertyIsEqualTo></ogc:Or></ogc:Filter>';
  1400. //console.log(link);
  1401. $.get(link, function(data) {
  1402. var temp = {};
  1403. loaded = false;
  1404. temp["id"] = mainProces_id;
  1405. temp["depth"] = 0;
  1406. temp["parent_id"] = false;
  1407. temp["step"] = 0;
  1408. temp["goto"] = {};
  1409. temp["goto"]["id"] = $(data).find("featureMember").find("IF_TRUE_GOTO").text();
  1410. temp["goto"]["flag"] = $(data).find("featureMember").find("IF_TRUE_GOTO_FLAG").text();
  1411. temp["changes"] = {};
  1412. temp["stepDesc"] = "";
  1413. temp["prof"] = new Array();
  1414. temp["res"] = new Array();
  1415. temp["desc"] = $(data).find("featureMember").find("DESC").text();
  1416. temp["opis"] = $(data).find("featureMember").find("OPIS").text()
  1417. tab.push(mainProces_id);
  1418. state[0] = temp;
  1419. genTree(mainProces_id);
  1420. });
  1421. actSite = "preview";
  1422. }
  1423. }
  1424. });
  1425. function unloadPage() {
  1426. if (changes)
  1427. return "";
  1428. }
  1429. window.onbeforeunload = unloadPage;