procesEditor.js 88 KB

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