procesEditor.js 70 KB

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