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