procesEditor.js 70 KB

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