procesEditor.js 76 KB

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