procesEditor.js 75 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670
  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. // xsi:schemaLocation="` + BASE_URL + `wfs/default_db/CRM_PROCES ` + BASE_URL + `dev-pl/se-feature-api/wfs.php/xml/wfs/default_db/CRM_PROCES/?SERVICE=WFS&amp;VERSION=1.0.0&amp;REQUEST=DescribeFeatureType&amp;TYPENAME=p5_default_db:CRM_PROCES&amp;SRSNAME=EPSG:4326&amp;"
  345. $.each(state, function(i, e) {
  346. request += `
  347. <Insert xmlns="http://www.opengis.net/wfs">
  348. <CRM_PROCES xmlns="` + BASE_WFS_URL + `/default_db">
  349. `;
  350. if (e["id"] >= 0)
  351. request += '<ID xmlns="' + BASE_WFS_URL + '/default_db">' + e["id"] + '</ID>';
  352. else
  353. request += '<ID xmlns="' + BASE_WFS_URL + '/default_db">' + newIdTab[e["id"]] + '</ID>';
  354. if (e["parent_id"] != false) {
  355. if (e["parent_id"] >= 0)
  356. request += '<PARENT_ID xmlns="' + BASE_WFS_URL + '/default_db">' + e["parent_id"] + '</PARENT_ID>';
  357. else
  358. request += '<PARENT_ID xmlns="' + BASE_WFS_URL + '/default_db">' + newIdTab[e["parent_id"]] + '</PARENT_ID>';
  359. request += '<SORT_PRIO xmlns="' + BASE_WFS_URL + '/default_db">' + e["SORT_PRIO"] + '</SORT_PRIO>';
  360. }
  361. if (typeof e["goto"] !== typeof undefined && e["goto"]["id"] !== null && e["goto"]["id"] !== 0 && e["goto"]["id"] !== "") {
  362. request += '<IF_TRUE_GOTO xmlns="' + BASE_WFS_URL + '/default_db">' + e["goto"]["id"] + '</IF_TRUE_GOTO>';
  363. request += '<IF_TRUE_GOTO_FLAG xmlns="' + BASE_WFS_URL + '/default_db">' + e["goto"]["flag"] + '</IF_TRUE_GOTO_FLAG>';
  364. } else {
  365. request += '<IF_TRUE_GOTO xmlns="' + BASE_WFS_URL + '/default_db">0</IF_TRUE_GOTO>';
  366. request += '<IF_TRUE_GOTO_FLAG xmlns="' + BASE_WFS_URL + '/default_db"></IF_TRUE_GOTO_FLAG>';
  367. }
  368. request += '<DESC xmlns="' + BASE_WFS_URL + '/default_db">' + cData(e["desc"]) + '</DESC>';
  369. request += '<OPIS xmlns="' + BASE_WFS_URL + '/default_db">' + cData(e["opis"]) + '</OPIS>';
  370. request += `
  371. </CRM_PROCES>
  372. </Insert>
  373. `;
  374. var id;
  375. if (e["id"] >= 0)
  376. id = e["id"];
  377. else
  378. id = newIdTab[e["id"]];
  379. var sort_prio = 0;
  380. $.each(e["prof"].concat(e["res"]), function(iR, eR) {
  381. sort_prio++;
  382. request += `
  383. <Insert xmlns="http://www.opengis.net/wfs">
  384. <CRM_WSKAZNIK xmlns="` + BASE_WFS_URL + `/default_db">
  385. `;
  386. if (eR["id"] >= 0) {
  387. request += '<ID xmlns="' + BASE_WFS_URL + '/default_db">' + eR["id"] + '</ID>';
  388. }
  389. request += '<ID_ZASOB xmlns="' + BASE_WFS_URL + '/default_db">' + eR["id_zasob"] + '</ID_ZASOB>';
  390. request += '<ID_PROCES xmlns="' + BASE_WFS_URL + '/default_db">' + id + '</ID_PROCES>';
  391. request += '<ID_PRZYPADEK xmlns="' + BASE_WFS_URL + '/default_db">' + eR["id_przypadek"] + '</ID_PRZYPADEK>';
  392. var opis = eR["komentarz"];
  393. opis = opis.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;').replace(/'/g, '&apos;');
  394. request += '<SORT_PRIO xmlns="' + BASE_WFS_URL + '/default_db">' + sort_prio + '</SORT_PRIO>';
  395. request += '<OPIS_ZASOB xmlns="' + BASE_WFS_URL + '/default_db">' + cData(opis) + '</OPIS_ZASOB>';
  396. request += `
  397. </CRM_WSKAZNIK>
  398. </Insert>
  399. `;
  400. });
  401. });
  402. $.each(deletedId, function(key, value) {
  403. request += `
  404. <Insert xmlns="http://www.opengis.net/wfs">
  405. <CRM_PROCES xmlns="` + BASE_WFS_URL + `/default_db">
  406. `;
  407. request += '<ID xmlns="' + BASE_WFS_URL + '/default_db">' + value + '</ID>';
  408. request += '<PARENT_ID xmlns="' + BASE_WFS_URL + '/default_db">-1</PARENT_ID>';
  409. request += '<A_STATUS xmlns="' + BASE_WFS_URL + '/default_db">DELETED</A_STATUS>';
  410. request += `
  411. </CRM_PROCES>
  412. </Insert>
  413. `;
  414. });
  415. $.each(deletedRes, function(key, value) {
  416. request += `
  417. <Insert xmlns="http://www.opengis.net/wfs">
  418. <CRM_WSKAZNIK xmlns="` + BASE_WFS_URL + `/default_db">
  419. `;
  420. request += '<ID xmlns="' + BASE_WFS_URL + '/default_db">' + value + '</ID>';
  421. request += '<A_STATUS xmlns="' + BASE_WFS_URL + '/default_db">DELETED</A_STATUS>';
  422. request += `
  423. </CRM_WSKAZNIK>
  424. </Insert>
  425. `;
  426. });
  427. request += '</Transaction>';
  428. $.ajax({
  429. url: link,
  430. data: request,
  431. type: 'POST',
  432. contentType: "text/xml",
  433. dataType: "text",
  434. success: function(data) {
  435. if($(data).children("serviceException").text() == ""){
  436. deletedRes = [];
  437. deletedId = [];
  438. localStorage.removeItem("state" + mainProces_id);
  439. showPreview();
  440. $.notify("Zmiany zostały zapisane na serwerze.", "success");
  441. }
  442. else{
  443. $.notify("Błąd API. Zmiany zostały zapisane wyłącznie w pamięci Twojej przeglądarki. Skontaktuj się z administratorem.", "error");
  444. localStorage.setItem("state" + mainProces_id, JSON.stringify(state));
  445. localStorage.setItem("newStep" + mainProces_id, newSteps);
  446. localStorage.setItem("newRes" + mainProces_id, newRes);
  447. localStorage.setItem("deletedId" + mainProces_id, JSON.stringify(deletedId));
  448. localStorage.setItem("deletedRes" + mainProces_id, JSON.stringify(deletedRes));
  449. localStorage.setItem("date" + mainProces_id, moment().format("YYYY-MM-DD HH:mm:ss"));
  450. }
  451. $("#saveBtn").prop('disabled', false);
  452. },
  453. error: function(xhr, ajaxOptions, thrownError) {
  454. $.notify("Brak połączenia z bazą danych", "error");
  455. }
  456. });
  457. },
  458. error: function(xhr, ajaxOptions, thrownError) {
  459. $.notify("Brak połączenia z bazą danych", "error");
  460. }
  461. });
  462. });
  463. $(document).on('click', '.btnEdit', function() {
  464. var parentIndex = getIndexById($(this).parents(".drop").data("id"));
  465. var type;
  466. if ($(this).parents("li").closest(".professions").length > 0)
  467. type = "prof";
  468. else
  469. type = "res";
  470. var zasobIndex = getResById(parentIndex, $(this).parents("li").data("id"), type);
  471. var permsOpt = "";
  472. $.each(perms, function(key, value) {
  473. if (state[parentIndex][type][zasobIndex]["id_przypadek"] == value[0])
  474. permsOpt = permsOpt + "<option value=" + value[0] + " selected=selected>[" + value[2] + "] " + value[1] + "</option>";
  475. else
  476. permsOpt = permsOpt + "<option value=" + value[0] + ">[" + value[2] + "] " + value[1] + "</option>";
  477. });
  478. swal({
  479. showCancelButton: true,
  480. title: 'Uprawnienia',
  481. html: 'Uprawnienia<br><select class=form-control id="swal-input1">' + permsOpt + '</select>' +
  482. 'Komentarz<br><input class=form-control id="swal-input2" class="swal2-input" value="' + state[parentIndex][type][zasobIndex]["komentarz"] + '">',
  483. preConfirm: function() {
  484. return new Promise(function(resolve) {
  485. resolve([
  486. $('#swal-input1').val(),
  487. $('#swal-input2').val()
  488. ]);
  489. });
  490. }
  491. }).then(function(result) {
  492. state[parentIndex][type][zasobIndex]["id_przypadek"] = result[0];
  493. state[parentIndex][type][zasobIndex]["komentarz"] = result[1];
  494. state[parentIndex][type][zasobIndex]["changed"] = true;
  495. updateAll();
  496. }).catch(function(e) {})
  497. });
  498. //Buttony i ich zadania
  499. $(document).on('click', '.step', function() {
  500. newSteps--;
  501. var main = false;
  502. var temp = {};
  503. if ($(this).parents(".drop").data("id") === mainProces_id)
  504. main = true;
  505. $(this).parents(".drop").after("<div class='drop container-fluid' id='proc" + newSteps + "'></div>");
  506. temp["id"] = newSteps;
  507. temp["desc"] = "";
  508. temp["opis"] = "";
  509. var index = getIndexById($(this).parents(".drop").data("id"));
  510. temp["step"] = 0;
  511. temp["prof"] = new Array();
  512. temp["res"] = new Array();
  513. temp["C-desc"] = true;
  514. temp["C-opis"] = true;
  515. temp["stepDesc"] = "";
  516. if (!main) {
  517. temp["parent_id"] = state[index]["parent_id"];
  518. temp["depth"] = state[index]["depth"];
  519. } else {
  520. temp["parent_id"] = mainProces_id;
  521. temp["depth"] = 1;
  522. }
  523. state.splice(index + 1, 0, temp);
  524. stepsGenerator();
  525. updateAll();
  526. });
  527. $(document).on('keyup', '#sProcesy', function() {
  528. if ($(this).val() != lastSearch) {
  529. lastSearch = $(this).val();
  530. clearTimeout(sProcesy);
  531. sProcesy = setTimeout(function() {
  532. if (lastSearch == "")
  533. procesy();
  534. else
  535. searchProc();
  536. }, 300);
  537. }
  538. });
  539. $(document).on('keyup', '#sZasoby', function() {
  540. if ($(this).val() != lastSearch) {
  541. lastSearch = $(this).val();
  542. clearTimeout(sZasoby);
  543. sZasoby = setTimeout(function() {
  544. if (filtr === 0 && lastSearch == "")
  545. zasoby();
  546. else
  547. searchRes();
  548. }, 300);
  549. }
  550. });
  551. function arraymove(arr, fromIndex, toIndex) {
  552. //console.log("move " + fromIndex + " " + toIndex);
  553. var element = [];
  554. var element = arr[fromIndex];
  555. arr.splice(fromIndex, 1);
  556. arr.splice(toIndex, 0, element);
  557. }
  558. $(document).on('click', '.uArrowRes', function() {
  559. var parent = getIndexById(($(this).parents(".drop").data("id")));
  560. if ($(this).closest(".professions").length > 0)
  561. type = "prof";
  562. else
  563. type = "res";
  564. var id = getResById(parent, $(this).closest("li").data("id"), type);
  565. arraymove(state[parent][type], id, id - 1);
  566. updateAll();
  567. });
  568. $(document).on('click', '.dArrowRes', function() {
  569. var parent = getIndexById(($(this).parents(".drop").data("id")));
  570. if ($(this).closest(".professions").length > 0)
  571. type = "prof";
  572. else
  573. type = "res";
  574. var id = getResById(parent, $(this).closest("li").data("id"), type);
  575. arraymove(state[parent][type], id, id + 1);
  576. updateAll();
  577. });
  578. $(document).on('click', '.uArrow', function() {
  579. var id = $(this).parents(".drop").data("id");
  580. var index = getIndexById(id);
  581. arraymove(state, index, index - 1);
  582. updateAll();
  583. });
  584. $(document).on('click', '.dArrow', function() {
  585. var id = $(this).parents(".drop").data("id");
  586. var index = getIndexById(id);
  587. arraymove(state, index, index + 1);
  588. updateAll();
  589. });
  590. $(document).on('click', '.rArrow', function() {
  591. var id = $(this).parents(".drop").data("id");
  592. state[getIndexById(id)]["depth"]++;
  593. //var depthWidth = 20 * $(node).data("depth");
  594. // $(node).css("padding-left", depthWidth + "px");
  595. updateAll();
  596. });
  597. $(document).on('click', '.lArrow', function() {
  598. var id = $(this).parents(".drop").data("id");
  599. state[getIndexById(id)]["depth"]--;
  600. //var depthWidth = 20 * $(node).data("depth");
  601. // $(node).css("padding-left", depthWidth + "px");
  602. updateAll();
  603. });
  604. $(document).on('click', '#btnZasoby', function(e) {
  605. e.preventDefault();
  606. $(".lButton").removeClass("btn-primary");
  607. if (dialog == 0) {
  608. zasoby();
  609. $(this).addClass("btn-primary");
  610. $("#wrapper").removeClass("toggled");
  611. dialog = 1;
  612. } else if (dialog == 1) {
  613. $("#wrapper").addClass("toggled");
  614. dialog = 0;
  615. } else {
  616. $("#wrapper").addClass("toggled");
  617. $(this).addClass("btn-primary");
  618. setTimeout(function() {
  619. zasoby();
  620. $("#wrapper").removeClass("toggled");
  621. }, 500);
  622. dialog = 1;
  623. }
  624. });
  625. $(document).on('click', '#btnPhotos', function(e) {
  626. e.preventDefault();
  627. $(".lButton").removeClass("btn-primary");
  628. if (dialog == 0) {
  629. photos();
  630. $(this).addClass("btn-primary");
  631. $("#wrapper").removeClass("toggled");
  632. dialog = 3;
  633. } else if (dialog == 3) {
  634. $("#wrapper").addClass("toggled");
  635. dialog = 0;
  636. } else {
  637. $("#wrapper").addClass("toggled");
  638. $(this).addClass("btn-primary");
  639. setTimeout(function() {
  640. photos();
  641. $("#wrapper").removeClass("toggled");
  642. }, 500);
  643. dialog = 3;
  644. }
  645. });
  646. $(document).on('click', '#btnProcesy', function(e) {
  647. e.preventDefault();
  648. $(".lButton").removeClass("btn-primary");
  649. if (dialog == 0) {
  650. procesy();
  651. $("#wrapper").removeClass("toggled");
  652. $(this).addClass("btn-primary");
  653. dialog = 2;
  654. } else if (dialog == 2) {
  655. $("#wrapper").addClass("toggled");
  656. dialog = 0;
  657. } else {
  658. $("#wrapper").addClass("toggled");
  659. $(this).addClass("btn-primary");
  660. setTimeout(function() {
  661. procesy();
  662. $("#wrapper").removeClass("toggled");
  663. }, 500);
  664. dialog = 2;
  665. }
  666. });
  667. $(document).on('click', 'body', function() {
  668. if (selectedArea != false) {
  669. var content = $(selectedArea).val();
  670. var id = (selectedArea).parents(".drop").data("id");
  671. if ($(selectedArea).parent().hasClass("hdesc")) {
  672. state[getIndexById(id)]["desc"] = content;
  673. state[getIndexById(id)]["C-desc"] = true;
  674. }
  675. if ($(selectedArea).parent().hasClass("sdesc")) {
  676. state[getIndexById(id)]["opis"] = content;
  677. state[getIndexById(id)]["C-opis"] = true;
  678. }
  679. selectedArea = false;
  680. updateAll();
  681. }
  682. });
  683. $(document).on('click', '.hdesc', function() {
  684. if ($(this).find("textarea").is(selectedArea))
  685. return false;
  686. });
  687. $(document).on('click', '.sdesc', function() {
  688. if ($(this).find("textarea").is(selectedArea))
  689. return false;
  690. });
  691. $(document).on('dblclick', '.sdesc', function() {
  692. if (selectedArea)
  693. return;
  694. if ($(this).find("textarea").length == 0) {
  695. var content = $(this).html();
  696. $(this).empty();
  697. $(this).append("<textarea>" + content + "</textarea>");
  698. selectedArea = $(this).find("textarea");
  699. }
  700. });
  701. $(document).on('click', '.sDescAdd', function() {
  702. if (selectedArea)
  703. return;
  704. var action = $(this).parents(".drop").find(".sdesc");
  705. if ($(action).find("textarea").length == 0) {
  706. $(action).html("<textarea placeholder='Opis kroku'>" + $(action).text() + "</textarea>");
  707. selectedArea = $(action).find("textarea");
  708. return false;
  709. }
  710. });
  711. $(document).on('click', '.hDescAdd', function() {
  712. if (selectedArea)
  713. return;
  714. var action = $(this).parents(".drop").find(".hdesc");
  715. if ($(action).find("textarea").length == 0) {
  716. $(action).html("<textarea placeholder='Tytuł kroku'>" + $(action).text() + "</textarea>");
  717. selectedArea = $(action).find("textarea");
  718. return false;
  719. }
  720. });
  721. $(document).on('dblclick', '.hdesc', function() {
  722. if ($(this).find("textarea").length == 0) {
  723. var content = $(this).html();
  724. $(this).empty();
  725. $(this).append("<textarea>" + content + "</textarea>");
  726. selectedArea = $(this).find("textarea");
  727. }
  728. });
  729. $(document).on('click', '.del', function() {
  730. var id = $(this).parents(".drop").data("id");
  731. var index = getIndexById(id);
  732. swal({
  733. title: 'Usuwanie kroku',
  734. text: "Czy napewno chcesz usunąć ten krok?",
  735. type: 'warning',
  736. showCancelButton: true,
  737. confirmButtonColor: '#3085d6',
  738. cancelButtonColor: '#d33',
  739. cancelButtonText: "Anuluj",
  740. confirmButtonText: 'Tak, usuń ten krok'
  741. }).then(function() {
  742. state.splice(index, 1);
  743. deletedId.push(id);
  744. updateAll();
  745. //Parent_id = -1,
  746. }).catch(function(e) {})
  747. });
  748. $(document).on('click', '.delGoto', function() {
  749. //var parent = $(this).parents(".drop");
  750. var id = $(this).parents("li").data("id");
  751. var parent = getIndexById($(this).parents(".drop").data("id"));
  752. swal({
  753. title: 'Usuwanie bramki',
  754. text: "Czy napewno chcesz usunąć tę bramkę?",
  755. type: 'warning',
  756. showCancelButton: true,
  757. confirmButtonColor: '#3085d6',
  758. cancelButtonColor: '#d33',
  759. cancelButtonText: "Anuluj",
  760. confirmButtonText: 'Tak, usuń tę bramkę'
  761. }).then(function() {
  762. state[parent]["goto"] = {
  763. id: "",
  764. flag: ""
  765. };
  766. updateAll();
  767. //Parent_id = -1,
  768. }).catch(function(e) {})
  769. });
  770. $(document).on('click', '.delRes', function() {
  771. //var parent = $(this).parents(".drop");
  772. var id = $(this).parents("li").data("id");
  773. var parent = getIndexById($(this).parents(".drop").data("id"));
  774. var type;
  775. if ($(this).closest(".professions").length > 0)
  776. type = "prof";
  777. else
  778. type = "res";
  779. var index = getResById(parent, id, type);
  780. swal({
  781. title: 'Usuwanie wskaźnika',
  782. text: "Czy napewno chcesz usunąć ten wskaźnik?",
  783. type: 'warning',
  784. showCancelButton: true,
  785. confirmButtonColor: '#3085d6',
  786. cancelButtonColor: '#d33',
  787. cancelButtonText: "Anuluj",
  788. confirmButtonText: 'Tak, usuń ten wskaźnik'
  789. }).then(function() {
  790. deletedRes.push(id);
  791. state[parent][type].splice(index, 1);
  792. updateAll();
  793. //Parent_id = -1,
  794. }).catch(function(e) {})
  795. });
  796. $(document).on('click', '.fbutton', function(e) {
  797. e.preventDefault();
  798. $(".fbutton").removeClass("btn-success");
  799. if ($(this).data("type") == filtr) {
  800. filtr = 0;
  801. } else {
  802. filtr = $(this).data("type");
  803. $(this).addClass("btn-success");
  804. }
  805. if (filtr === 0)
  806. $("#xBtn").prop("disabled", true);
  807. else
  808. $("#xBtn").prop("disabled", false);
  809. if (filtr === 0) {
  810. zasoby();
  811. } else
  812. searchRes();
  813. });
  814. $(document).on('click', '.showMore', function() {
  815. var target = $(this).parent().find(".more");
  816. var id = $(this).data("id");
  817. if ($(target).parent().hasClass("resSelected")) {
  818. $(".more").empty();
  819. $(target).parent().removeClass("resSelected");
  820. $(target).parent().find(".gIco").addClass("glyphicon-chevron-down");
  821. $(target).parent().find(".gIco").removeClass("glyphicon-chevron-up");
  822. } else {
  823. $(".more").parent().removeClass("resSelected");
  824. $(".more").parent().find(".gIco").addClass("glyphicon-chevron-down");
  825. $(".more").parent().find(".gIco").removeClass("glyphicon-chevron-up");
  826. $(".more").empty();
  827. $(target).parent().addClass("resSelected");
  828. $(target).parent().find(".gIco").removeClass("glyphicon-chevron-down");
  829. $(target).parent().find(".gIco").addClass("glyphicon-chevron-up");
  830. var link = BASE_URL + "index.php?_route=UrlAction_ProcesEditor&_task=getResByParentAjax&parent_id=" + id;
  831. $.get(link, function(data) {
  832. $.each(data, function(i, e) {
  833. if (e["ID"] != 0) {
  834. var type = 0;
  835. $(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>");
  836. for (var i = 3; i > 0; i--) {
  837. if (e["p" + i + "_ID"] != null) {
  838. var temp = {};
  839. temp["ID"] = e["p" + i + "_ID"];
  840. temp["DESC"] = e["p" + i + "_DESC"];
  841. zasobTree[e["ID"]] = [];
  842. zasobTree[e["ID"]].push(temp);
  843. }
  844. }
  845. $('.drag').draggable({
  846. appendTo: 'body',
  847. helper: 'clone',
  848. stack: "div",
  849. distance: 0,
  850. cursor: "copy"
  851. });
  852. }
  853. });
  854. });
  855. }
  856. });
  857. function searchProc() {
  858. var id = lastSearch;
  859. var link;
  860. 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';
  861. $.get(link, function(data) {
  862. var side = $("#side");
  863. $(side).find("#ulproc").empty();
  864. $.each($(data).find("featureMember"), function() {
  865. if ($(this).find("ID").text() * 1 == 0) {
  866. $(side).find("#ulcon").append("<div><center>Brak wyników wyszukiwania</center></div>");
  867. return;
  868. }
  869. $(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>");
  870. $('.drag').draggable({
  871. appendTo: 'body',
  872. helper: 'clone',
  873. stack: "div",
  874. distance: 0,
  875. cursor: "copy"
  876. });
  877. });
  878. });
  879. }
  880. function searchRes() {
  881. var id = lastSearch;
  882. var link;
  883. link = BASE_URL + "index.php?_route=UrlAction_ProcesEditor&_task=getResAjax&word=" + id + "&filter=" + filtr;
  884. $.get(link, function(data) {
  885. var side = $("#side");
  886. $(side).find("#ulcon").empty();
  887. if (data.length == 0)
  888. $(side).find("#ulcon").append("<div><center>Brak wyników wyszukiwania</center></div>");
  889. $.each(data, function(i, e) {
  890. var tree = "";
  891. for (var i = 3; i > 0; i--) {
  892. if (e["p" + i + "_ID"] != null) {
  893. var temp = {};
  894. temp["ID"] = e["p" + i + "_ID"];
  895. temp["DESC"] = e["p" + i + "_DESC"];
  896. zasobTree[e["ID"]] = [];
  897. zasobTree[e["ID"]].push(temp);
  898. tree += e["p" + i + "_DESC"] + (i > 1 ? " <span class='glyphicon glyphicon-triangle-right'></span>" : "");
  899. }
  900. }
  901. var type = 0;
  902. if (e["TYPE"] == "DZIAL" || e["TYPE"] == "PODMIOT" || e["TYPE"] == "STANOWISKO")
  903. type = 1;
  904. if (filtr != 2 || e["TYPE"] != "TABELA")
  905. $(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>");
  906. else {
  907. $(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>");
  908. }
  909. });
  910. $('.drag').draggable({
  911. appendTo: 'body',
  912. helper: 'clone',
  913. stack: "div",
  914. distance: 0,
  915. cursor: "copy"
  916. });
  917. $(".drop").droppable({
  918. tolerance: 'pointer',
  919. accept: '.drag',
  920. hoverClass: "activeDrop",
  921. drop: function(event, ui) {
  922. if (ui.draggable.data("dropType") == 1)
  923. addProces(ui, this);
  924. else
  925. addResource(ui, this);
  926. }
  927. });
  928. });
  929. }
  930. $(document).on('click', '.liProc', function() {
  931. $(this).parents(".singleAdv").nextAll(".singleAdv").remove();
  932. $(this).parents(".singleAdv").find(".active").removeClass("active");
  933. $(this).find(".glyphicon").removeClass("glyphicon-triangle-right");
  934. $(this).find(".glyphicon").addClass("glyphicon-refresh");
  935. $(this).find(".glyphicon").addClass("anim-refresh");
  936. $(this).addClass("active");
  937. var parent = this;
  938. var parent_id = $(this).data("id");
  939. 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>';
  940. var result = "";
  941. var depth = $(this).parents(".singleAdv").data("depth") + 1;
  942. $("#procCon").css("width", depth * 290 + 290);
  943. $(this).parents(".singleAdv").after("<div class='singleAdv list-group' data-depth=" + depth + " id=depth" + depth + "></div>");
  944. var childs = true;
  945. $.get(link, function(data) {
  946. $(data).find("featureMember").each(function() {
  947. if ($(this).find("ID").text() == 0) {
  948. childs = false;
  949. return;
  950. }
  951. var type = 0;
  952. 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>";
  953. });
  954. if (!childs) {
  955. result += '<div class="panel panel-primary">';
  956. result += '<div class="panel-heading"><h3 class="panel-title">[' + $(parent).data('id') + '] ' + $(parent).data("desc") + '</h3></div>';
  957. result += '<div class="panel-body pbody">';
  958. result += '<b>Opis: </b>' + $(parent).data("opis");
  959. result += '</div>';
  960. result += '</div>'
  961. }
  962. $("#depth" + depth).html(result);
  963. $('.drag').draggable({
  964. appendTo: 'body',
  965. handle: '.handle',
  966. helper: 'clone',
  967. stack: "div",
  968. distance: 0,
  969. cursor: "copy"
  970. });
  971. $(parent).find(".glyphicon").addClass("glyphicon-triangle-right");
  972. $(parent).find(".glyphicon").removeClass("glyphicon-refresh");
  973. $(parent).find(".glyphicon").removeClass("anim-refresh");
  974. $("#ulproc").scrollLeft(depth * 290 + 290);
  975. $("#ulproc").scrollTop(0);
  976. });
  977. });
  978. function procesy() {
  979. var side = $("#side");
  980. $(side).empty();
  981. //$(side).append("<h3>Zarządzaj zasobami<h3>");
  982. $(side).append("<div class='form-group' ><input type='text' class=form-control id=sProcesy placeholder='Szukaj procesów'></div>");
  983. $(side).append("<div id=ulproc><div id=procCon></div></div>");
  984. $(side).find("#procCon").append("<div class='singleAdv list-group' data-depth=0 id=depth0></div>");
  985. $(side).find("#procCon").append("<div class=clearfix></div>");
  986. 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';
  987. var result = "";
  988. $.get(link, function(data) {
  989. $(data).find("featureMember").each(function() {
  990. var type = 0;
  991. 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() + " >";
  992. result += "<div class=textTable><span class=handle> # </span>";
  993. result += $(this).find("DESC").text()
  994. result += "</div><div class=detailsTable> [" + $(this).find("ID").text() + "]</div>";
  995. result += "<div class='glyphicon glyphicon-triangle-right' style=opacity:0.4;float:right;></div><div class=clearfix></div></div>";
  996. });
  997. $("#depth0").html(result);
  998. $('.drag').draggable({
  999. appendTo: 'body',
  1000. handle: '.handle',
  1001. helper: 'clone',
  1002. stack: "div",
  1003. distance: 0,
  1004. cursor: "copy"
  1005. });
  1006. });
  1007. }
  1008. $(document).on('click', '.liAdv', function() {
  1009. $(this).find(".glyphicon").removeClass("glyphicon-triangle-right");
  1010. $(this).find(".glyphicon").addClass("glyphicon-refresh");
  1011. $(this).parents(".singleAdv").nextAll(".singleAdv").remove();
  1012. $(this).parents(".singleAdv").find(".active").removeClass("active");
  1013. $(this).addClass("active");
  1014. var parent = this;
  1015. var parent_id = $(this).data("id");
  1016. 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';
  1017. var result = "";
  1018. var depth = $(this).parents(".singleAdv").data("depth") + 1;
  1019. $("#advCon").css("width", depth * 290 + 290);
  1020. $(this).parents(".singleAdv").after("<div class='singleAdv list-group' data-depth=" + depth + " id=depth" + depth + "></div>");
  1021. var childs = true;
  1022. $.get(link, function(data) {
  1023. $(data).find("featureMember").each(function() {
  1024. if ($(this).find("ID").text() == 0) {
  1025. childs = false;
  1026. return;
  1027. }
  1028. var type = 0;
  1029. if ($(this).find("TYPE").text() == "DZIAL" || $(this).find("TYPE").text() == "PODMIOT" || $(this).find("TYPE").text() == "STANOWISKO")
  1030. type = 1;
  1031. 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>";
  1032. result += "<div class='glyphicon glyphicon-triangle-right' style=opacity:0.4;float:right;></div>";
  1033. result += "<div class=clearfix></div><div class=detailsTable2>[" + $(this).find("ID").text() + "] " + $(this).find("TYPE").text() + "</div></div>";
  1034. });
  1035. if (!childs) {
  1036. result += '<div class="panel panel-primary">';
  1037. result += '<div class="panel-heading"><h3 class="panel-title">[' + $(parent).data('id') + '] ' + $(parent).data("desc") + '</h3></div>';
  1038. result += '<div class="panel-body pbody">';
  1039. result += '<b>Opis: </b>' + $(parent).data("opis");
  1040. result += '<br><b>Typ: </b>' + $(parent).data("typename");
  1041. result += '</div>';
  1042. result += '</div>'
  1043. }
  1044. $("#depth" + depth).html(result);
  1045. $('.drag').draggable({
  1046. appendTo: 'body',
  1047. handle: '.handle',
  1048. helper: 'clone',
  1049. stack: "div",
  1050. distance: 0,
  1051. cursor: "copy"
  1052. });
  1053. $(parent).find(".glyphicon").addClass("glyphicon-triangle-right");
  1054. $(parent).find(".glyphicon").removeClass("glyphicon-refresh");
  1055. $("#ulcon").scrollLeft(depth * 290 + 290);
  1056. $("#ulcon").scrollTop(0);
  1057. });
  1058. });
  1059. $(document).on('change', '#inp', function() {
  1060. if (this.files && this.files[0]) {
  1061. var link = BASE_URL + "wfs-data.php/default_db/?SERVICE=WFS&VERSION=1.0.0&SRSNAME=EPSG:3003";
  1062. var name = this.files[0].name;
  1063. var FR = new FileReader();
  1064. FR.onload = function(e) {
  1065. var contentBase64 = e.target.result;
  1066. var xml = `
  1067. <Transaction
  1068. xmlns="http://www.opengis.net/wfs"
  1069. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  1070. version="1.0.0"
  1071. service="WFS"
  1072. xmlns:p5_default_db="` + BASE_WFS_URL + `/default_db"
  1073. xmlns:gml="http://www.opengis.net/gml">
  1074. <Insert xmlns="http://www.opengis.net/wfs">
  1075. <CRM_IMAGE xmlns="` + BASE_WFS_URL + `/default_db">
  1076. <NAME xmlns="` + BASE_WFS_URL + `/default_db">`+name+`</NAME>
  1077. <IMAGE xmlns="` + BASE_WFS_URL + `/default_db">`+contentBase64+`</IMAGE>
  1078. <REMOTE_TABLE xmlns="` + BASE_WFS_URL + `/default_db">ADMIN_USERS</REMOTE_TABLE>
  1079. <REMOTE_ID xmlns="` + BASE_WFS_URL + `/default_db">`+USER_ID+`</REMOTE_ID>
  1080. </CRM_IMAGE>
  1081. </Insert>
  1082. </Transaction>`;
  1083. $.ajax({
  1084. url: link,
  1085. data: xml,
  1086. type: 'POST',
  1087. contentType: "text/xml",
  1088. dataType: "xml",
  1089. success: function(data) {
  1090. console.log(data);
  1091. if($(data).find("ServiceException").text() != ""){
  1092. $.notify($(data).find("ServiceException").text() ,"error");
  1093. } else {
  1094. $("#clipboard").append("<li class='list-group-item'><img src='"+contentBase64+"' / width=400></li>");
  1095. }
  1096. }
  1097. });
  1098. };
  1099. FR.readAsDataURL( this.files[0] );
  1100. }
  1101. });
  1102. function photos() {
  1103. var side = $("#side");
  1104. $(side).empty();
  1105. var form = `
  1106. <h4>Wrzuć pliki do swojego schowka</h4>
  1107. <input id="inp" type='file'>
  1108. <h4>Pliki w schowku</h4>`;
  1109. $(side).append(form);
  1110. var schowek = '<ul class="list-group" id=clipboard>';
  1111. schowek += '</ul>';
  1112. $(side).append(schowek);
  1113. 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:3003Filter=<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>';
  1114. $.get(link, function(data) {
  1115. $(data).find("featureMember").each(function() {
  1116. });
  1117. });
  1118. schowek += '<li class="list-group-item">';
  1119. schowek += 'Twoje zdjęcia w schowku';
  1120. schowek += '</li>';
  1121. }
  1122. function zasoby() {
  1123. var side = $("#side");
  1124. $(side).empty();
  1125. //$(side).append("<h3>Zarządzaj zasobami<h3>");
  1126. $(side).append("<div class='form-group' ><input type='text' class=form-control id=sZasoby placeholder='Szukaj zasobów'></div>");
  1127. $(side).append("<div class='btn-group' style=width:100% id=filtry></div>");
  1128. $("#filtry").append("<button type='button' data-type=1 class='fbutton btn btn-default input-block-level ' style=width:40%>Stanowiska</button>");
  1129. $("#filtry").append("<button type='button' data-type=2 class='fbutton btn btn-default input-block-level ' style=width:40%>Komórki</button>");
  1130. $("#filtry").append("<button type='button' data-type=0 class='fbutton btn btn-danger input-block-level' id=xBtn style=width:20% disabled>X</button>");
  1131. $(side).append("<div id=ulcon><div id=advCon></div></div>");
  1132. $(side).find("#advCon").append("<div class='singleAdv list-group' data-depth=0 id=depth0></div>");
  1133. $(side).find("#advCon").append("<div class=clearfix></div>");
  1134. 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';
  1135. var result = "";
  1136. $.get(link, function(data) {
  1137. $(data).find("featureMember").each(function() {
  1138. var type = 0;
  1139. if ($(this).find("TYPE").text() == "DZIAL" || $(this).find("TYPE").text() == "PODMIOT" || $(this).find("TYPE").text() == "STANOWISKO")
  1140. type = 1;
  1141. result += "<div class='drag list-group-item liAdv'";
  1142. 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() + "'"
  1143. result += "title='" + $(this).find("DESC").text() + "'>"
  1144. result += "<div class=textTable2>"
  1145. result += "<span class=handle> # </span>" + $(this).find("DESC").text() + "</div>"
  1146. result += "<div class='glyphicon glyphicon-triangle-right' style=opacity:0.4;float:right; style=float:left;></div>"
  1147. result += "<div class=clearfix></div>"
  1148. result += "<div class=detailsTable2>[" + $(this).find("ID").text() + "] " + $(this).find("TYPE").text() + "</div>"
  1149. result += "</div>";
  1150. });
  1151. $("#depth0").html(result);
  1152. $('.drag').draggable({
  1153. appendTo: 'body',
  1154. handle: '.handle',
  1155. helper: 'clone',
  1156. stack: "div",
  1157. distance: 0,
  1158. cursor: "copy"
  1159. });
  1160. });
  1161. //$(side).find("#ulcon").append("<div class='drag' data-id=1 data-type=1 >[STANOWISKO] Ulotkarz</div>");
  1162. //$(side).find("#ulcon").append("<div class='drag' data-id=2 data-type=1 >[STANOWISKO] Programista PHP</div>");
  1163. //$(side).find("#ulcon").append("<div class='drag' data-id=3 data-type=2 >[ZASÓB] Komputer</div>");
  1164. }
  1165. function addProces(ui, target) {
  1166. var id = $(target).data("id");
  1167. var gotoOpt = "";
  1168. $.each(gotoType, function(key, value) {
  1169. gotoOpt += "<option value=" + value[0] + ">" + value[1] + "</option>";
  1170. })
  1171. swal({
  1172. showCancelButton: true,
  1173. cancelButtonText: "Anuluj",
  1174. title: 'Typ łącza',
  1175. html: (typeof state[getIndexById(id)]["goto"] !== typeof undefined && state[getIndexById(id)]["goto"]["id"] != null && state[getIndexById(id)]["goto"]["id"] != 0 ? '<span class=class="alert alert-warning"><strong>Uwaga!</strong> Nowe łącze nadpisze już istniejące łącze.</span><br>' : "") + '<br><select class=form-control id="swal-input1">' + gotoOpt + '</select>',
  1176. preConfirm: function() {
  1177. return new Promise(function(resolve) {
  1178. resolve([
  1179. $('#swal-input1').val()
  1180. ]);
  1181. });
  1182. }
  1183. }).then(function(result) {
  1184. newRes--;
  1185. var temp = {};
  1186. temp["flag"] = result[0];
  1187. temp["id"] = ui.draggable.data("id");
  1188. state[getIndexById(id)]["goto"] = temp;
  1189. updateAll();
  1190. }).catch(function(e) {})
  1191. }
  1192. function addResource(ui, target) {
  1193. var permsOpt = "";
  1194. $.each(perms, function(key, value) {
  1195. permsOpt = permsOpt + "<option value=" + value[0] + ">[" + value[2] + "] " + value[1] + "</option>";
  1196. })
  1197. swal({
  1198. showCancelButton: true,
  1199. cancelButtonText: "Anuluj",
  1200. title: 'Uprawnienia',
  1201. html: 'Uprawnienia<br><select class=form-control id="swal-input1">' + permsOpt + '</select>' +
  1202. 'Komentarz<br><input class=form-control id="swal-input2" class="swal2-input">',
  1203. preConfirm: function() {
  1204. return new Promise(function(resolve) {
  1205. resolve([
  1206. $('#swal-input1').val(),
  1207. $('#swal-input2').val()
  1208. ]);
  1209. });
  1210. }
  1211. }).then(function(result) {
  1212. newRes--;
  1213. var temp = {};
  1214. temp["id_zasob"] = ui.draggable.data("id");
  1215. temp["id"] = newRes;
  1216. temp["id_przypadek"] = result[0];
  1217. temp["komentarz"] = result[1];
  1218. temp["changed"] = true;
  1219. temp["opis"] = ui.draggable.data("opis");
  1220. temp["desc"] = ui.draggable.data("desc");
  1221. temp["tree"] = zasobTree[temp["id_zasob"]];
  1222. var id = $(target).data("id");
  1223. if (ui.draggable.data("type") == 1) {
  1224. state[getIndexById(id)]["prof"].push(temp);
  1225. } else {
  1226. state[getIndexById(id)]["res"].push(temp);
  1227. }
  1228. updateAll();
  1229. }).catch(function(e) {})
  1230. }
  1231. //Najwazniejsza funkcja odpalana po kazdej zmianie. Sprawdza, czy wszystkie funkcje maja rodzica,
  1232. //jezeli nie to przesuwa w lewo obiekt
  1233. //Odpowiada tez za ukrywanie guzikow i wywowalanie funkcji generacji krokow
  1234. function updateAll() {
  1235. $.each(state, function(i, e) {
  1236. var pid = getParentNode(e["id"]);
  1237. if (pid != "NONE" && pid != false && pid != e["parent_id"]) {
  1238. e["parent_id"] = pid;
  1239. } else if (pid === false) {
  1240. e["depth"]--;
  1241. //var depthWidth = 20 * $(node).data("depth");
  1242. //$(node).css("padding-left", depthWidth + "px");
  1243. updateAll();
  1244. return;
  1245. }
  1246. if (checkParentNode(e["id"], "right") === false) {
  1247. $(this).find(".rArrow").hide();
  1248. } else {
  1249. $(this).find(".rArrow").show();
  1250. }
  1251. if (checkParentNode(e["id"], "left") === false) {
  1252. $(this).find(".lArrow").hide();
  1253. } else {
  1254. $(this).find(".lArrow").show();
  1255. }
  1256. if (i == 1)
  1257. $(this).find(".uArrow").hide();
  1258. else
  1259. $(this).find(".uArrow").show();
  1260. if (i == state.length - 1) {
  1261. $(this).find(".dArrow").hide();
  1262. } else {
  1263. $(this).find(".dArrow").show();
  1264. }
  1265. });
  1266. changes = true;
  1267. $("#clearBtn").show();
  1268. /*
  1269. localStorage.setItem("state" + mainProces_id, JSON.stringify(state));
  1270. localStorage.setItem("newStep" + mainProces_id, newSteps);
  1271. localStorage.setItem("newRes" + mainProces_id, newRes);
  1272. localStorage.setItem("deletedId" + mainProces_id, JSON.stringify(deletedId));
  1273. localStorage.setItem("deletedRes" + mainProces_id, JSON.stringify(deletedRes));
  1274. localStorage.setItem("date" + mainProces_id, moment().format("YYYY-MM-DD HH:mm:ss"));
  1275. */
  1276. render(state, $("#main"));
  1277. }
  1278. //Generuje kroki, sprawdza tez czy kolejnosc krokow w danym rodzicow zostala zmieniona
  1279. //Jezeli tak to mozna wyslac ajaxem zmiane kolejnosci dla sort_prio
  1280. function stepsGenerator() {
  1281. $.each(state, function(i, e) {
  1282. e["step"] = 0;
  1283. if (i == 0)
  1284. e["stepDesc"] = "";
  1285. else {
  1286. var iParent = getIndexById(e["parent_id"]);
  1287. state[iParent]["step"] += 1;
  1288. e["SORT_PRIO"] = state[iParent]["step"];
  1289. e["stepDesc"] = state[iParent]["stepDesc"] + state[iParent]["step"] + ". ";
  1290. }
  1291. });
  1292. }
  1293. //Na potrzeby guzikow dorobilem funkcje sprawdzajaca id rodzica po przesunieciu (przewidywanie).
  1294. //Jezeli nie znajdzie zwraca false, a wtedy blokuje sie odpowiednia strzalka
  1295. function checkParentNode(id, check) {
  1296. var x = getIndexById(id);
  1297. var y = x;
  1298. var result = false;
  1299. while (x > 0) {
  1300. x--;
  1301. if (check == "right")
  1302. if (state[x]["depth"] == state[y]["depth"]) {
  1303. result = state[x]["id"];
  1304. break;
  1305. }
  1306. if (check == "left")
  1307. if (state[x]["depth"] == state[y]["depth"] - 2) {
  1308. result = state[x]["id"];
  1309. break;
  1310. }
  1311. if (check == "right" && state[x]["depth"] < state[y]["depth"])
  1312. break;
  1313. }
  1314. return result;
  1315. }
  1316. //Zwraca id rodzica, jezeli nie ma zwraca false
  1317. function getParentNode(id) {
  1318. var x = getIndexById(id);
  1319. var y = x;
  1320. if (x == 0)
  1321. return "NONE";
  1322. var result = false;
  1323. while (x > 0) {
  1324. x--;
  1325. if (state[x]["depth"] == state[y]["depth"] - 1) {
  1326. result = state[x]["id"];
  1327. break;
  1328. }
  1329. if (state[x]["depth"] - state[y]["depth"] == -2)
  1330. break;
  1331. }
  1332. return result;
  1333. }
  1334. function getResById(index, id, type) {
  1335. var result = state[index][type].length - 1;
  1336. $.each(state[index][type], function(i, e) {
  1337. if (e["id"] == id) {
  1338. result = i;
  1339. return false;
  1340. }
  1341. });
  1342. return result;
  1343. }
  1344. function getIndexById(id) {
  1345. var result = state.length - 1;
  1346. $.each(state, function(i, e) {
  1347. if (e["id"] == id) {
  1348. result = i;
  1349. return false;
  1350. }
  1351. });
  1352. return result;
  1353. }
  1354. /*function logState() {
  1355. //console.log("########");
  1356. $.each(state, function(i, e) {
  1357. //console.log(i + ": " + e["id"]);
  1358. });
  1359. //console.log("########");
  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;