procesEditor.js 71 KB

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