procesEditor.js 73 KB

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