procesEditor.js 74 KB

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