procesEditor.js 70 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734
  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 wyknanie", "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).parent().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).empty();
  593. $(action).append("<textarea placeholder='Opis kroku'></textarea>");
  594. $(this).remove();
  595. selectedArea = $(action).find("textarea");
  596. return false;
  597. }
  598. });
  599. $(document).on('click', '.hDescAdd', function() {
  600. if (selectedArea)
  601. return;
  602. var action = $(this).parents(".drop").find(".hdesc");
  603. if ($(action).find("textarea").length == 0) {
  604. //alert($(action).text());
  605. $(action).empty();
  606. $(action).append("<textarea placeholder='Tytuł kroku'></textarea>");
  607. $(this).remove();
  608. selectedArea = $(action).find("textarea");
  609. return false;
  610. }
  611. });
  612. $(document).on('dblclick', '.hdesc', function() {
  613. if ($(this).find("textarea").length == 0) {
  614. var content = $(this).html();
  615. $(this).empty();
  616. $(this).append("<textarea>" + content + "</textarea>");
  617. selectedArea = $(this).find("textarea");
  618. }
  619. });
  620. $(document).on('click', '.del', function() {
  621. var id = $(this).parents(".drop").data("id");
  622. var index = getIndexById(id);
  623. swal({
  624. title: 'Usuwanie kroku',
  625. text: "Czy napewno chcesz usunąć ten krok?",
  626. type: 'warning',
  627. showCancelButton: true,
  628. confirmButtonColor: '#3085d6',
  629. cancelButtonColor: '#d33',
  630. cancelButtonText: "Anuluj",
  631. confirmButtonText: 'Tak, usuń ten krok'
  632. }).then(function() {
  633. state.splice(index, 1);
  634. deletedId.push(id);
  635. updateAll();
  636. //Parent_id = -1,
  637. }).catch(function(e) {})
  638. });
  639. $(document).on('click', '.delGoto', function() {
  640. //var parent = $(this).parents(".drop");
  641. var id = $(this).parents("li").data("id");
  642. var parent = getIndexById($(this).parents(".drop").data("id"));
  643. swal({
  644. title: 'Usuwanie bramki',
  645. text: "Czy napewno chcesz usunąć tę bramkę?",
  646. type: 'warning',
  647. showCancelButton: true,
  648. confirmButtonColor: '#3085d6',
  649. cancelButtonColor: '#d33',
  650. cancelButtonText: "Anuluj",
  651. confirmButtonText: 'Tak, usuń tę bramkę'
  652. }).then(function() {
  653. state[parent]["goto"] = {
  654. id: "",
  655. flag: ""
  656. };
  657. updateAll();
  658. //Parent_id = -1,
  659. }).catch(function(e) {})
  660. });
  661. $(document).on('click', '.delRes', function() {
  662. //var parent = $(this).parents(".drop");
  663. var id = $(this).parents("li").data("id");
  664. var parent = getIndexById($(this).parents(".drop").data("id"));
  665. var type;
  666. if ($(this).closest(".professions").length > 0)
  667. type = "prof";
  668. else
  669. type = "res";
  670. var index = getResById(parent, id, type);
  671. swal({
  672. title: 'Usuwanie wskaźnika',
  673. text: "Czy napewno chcesz usunąć ten wskaźnik?",
  674. type: 'warning',
  675. showCancelButton: true,
  676. confirmButtonColor: '#3085d6',
  677. cancelButtonColor: '#d33',
  678. cancelButtonText: "Anuluj",
  679. confirmButtonText: 'Tak, usuń ten wskaźnik'
  680. }).then(function() {
  681. deletedRes.push(id);
  682. state[parent][type].splice(index, 1);
  683. updateAll();
  684. //Parent_id = -1,
  685. }).catch(function(e) {})
  686. });
  687. //
  688. $(document).on('click', '.fbutton', function(e) {
  689. e.preventDefault();
  690. $(".fbutton").removeClass("btn-success");
  691. if ($(this).data("type") == filtr) {
  692. filtr = 0;
  693. //console.log("Odznaczono");
  694. } else {
  695. filtr = $(this).data("type");
  696. $(this).addClass("btn-success");
  697. }
  698. if (filtr === 0)
  699. $("#xBtn").prop("disabled", true);
  700. else
  701. $("#xBtn").prop("disabled", false);
  702. if (filtr === 0) {
  703. zasoby();
  704. } else
  705. searchRes();
  706. });
  707. $(document).on('click', '.showMore', function() {
  708. var target = $(this).parent().find(".more");
  709. var id = $(this).data("id");
  710. if ($(target).parent().hasClass("resSelected")) {
  711. $(".more").empty();
  712. $(target).parent().removeClass("resSelected");
  713. $(target).parent().find(".gIco").addClass("glyphicon-chevron-down");
  714. $(target).parent().find(".gIco").removeClass("glyphicon-chevron-up");
  715. } else {
  716. $(".more").parent().removeClass("resSelected");
  717. $(".more").parent().find(".gIco").addClass("glyphicon-chevron-down");
  718. $(".more").parent().find(".gIco").removeClass("glyphicon-chevron-up");
  719. $(".more").empty();
  720. $(target).parent().addClass("resSelected");
  721. $(target).parent().find(".gIco").removeClass("glyphicon-chevron-down");
  722. $(target).parent().find(".gIco").addClass("glyphicon-chevron-up");
  723. 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';
  724. //console.log(link);
  725. $.get(link, function(data) {
  726. $.each($(data).find("featureMember"), function() {
  727. if ($(this).find("ID").text() != 0) {
  728. var type = 0;
  729. $(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>");
  730. $('.drag').draggable({
  731. appendTo: 'body',
  732. helper: 'clone',
  733. stack: "div",
  734. distance: 0,
  735. cursor: "copy"
  736. });
  737. }
  738. });
  739. });
  740. }
  741. });
  742. function searchProc() {
  743. var id = lastSearch;
  744. var link;
  745. //console.log("Szukam");
  746. 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';
  747. $.get(link, function(data) {
  748. var side = $("#side");
  749. //console.log(data);
  750. $(side).find("#ulproc").empty();
  751. $.each($(data).find("featureMember"), function() {
  752. if ($(this).find("ID").text() * 1 == 0) {
  753. $(side).find("#ulcon").append("<div><center>Brak wyników wyszukiwania</center></div>");
  754. return;
  755. }
  756. $(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>");
  757. $('.drag').draggable({
  758. appendTo: 'body',
  759. helper: 'clone',
  760. stack: "div",
  761. distance: 0,
  762. cursor: "copy"
  763. });
  764. });
  765. });
  766. }
  767. function searchRes() {
  768. var id = lastSearch;
  769. var link;
  770. //console.log("Szukam");
  771. switch (filtr) {
  772. case 0:
  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: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';
  774. break;
  775. case 1:
  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>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';
  777. break;
  778. case 2:
  779. 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';
  780. //console.log(link);
  781. break;
  782. default:
  783. link = "";
  784. }
  785. $.get(link, function(data) {
  786. var side = $("#side");
  787. //console.log(data);
  788. $(side).find("#ulcon").empty();
  789. $.each($(data).find("featureMember"), function() {
  790. if ($(this).find("ID").text() * 1 == 0) {
  791. $(side).find("#ulcon").append("<div><center>Brak wyników wyszukiwania</center></div>");
  792. return;
  793. }
  794. var type = 0;
  795. if ($(this).find("TYPE").text() == "DZIAL" || $(this).find("TYPE").text() == "PODMIOT" || $(this).find("TYPE").text() == "STANOWISKO")
  796. type = 1;
  797. if (filtr != 2 || $(this).find("TYPE").text() != "TABELA")
  798. $(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>");
  799. else {
  800. $(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>");
  801. }
  802. });
  803. $('.drag').draggable({
  804. appendTo: 'body',
  805. helper: 'clone',
  806. stack: "div",
  807. distance: 0,
  808. cursor: "copy"
  809. });
  810. $(".drop").droppable({
  811. tolerance: 'pointer',
  812. accept: '.drag',
  813. hoverClass: "activeDrop",
  814. drop: function(event, ui) {
  815. if (ui.draggable.data("dropType") == 1)
  816. addProces(ui, this);
  817. else
  818. addResource(ui, this);
  819. }
  820. });
  821. });
  822. }
  823. $(document).on('click', '.liProc', function() {
  824. $(this).parents(".singleAdv").nextAll(".singleAdv").remove();
  825. $(this).parents(".singleAdv").find(".active").removeClass("active");
  826. $(this).find(".glyphicon").removeClass("glyphicon-triangle-right");
  827. $(this).find(".glyphicon").addClass("glyphicon-refresh");
  828. $(this).find(".glyphicon").addClass("anim-refresh");
  829. $(this).addClass("active");
  830. var parent = this;
  831. var parent_id = $(this).data("id");
  832. 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>';
  833. var result = "";
  834. var depth = $(this).parents(".singleAdv").data("depth") + 1;
  835. $("#procCon").css("width", depth * 290 + 290);
  836. $(this).parents(".singleAdv").after("<div class='singleAdv list-group' data-depth=" + depth + " id=depth" + depth + "></div>");
  837. //console.log(link);
  838. var childs = true;
  839. $.get(link, function(data) {
  840. $(data).find("featureMember").each(function() {
  841. if ($(this).find("ID").text() == 0) {
  842. childs = false;
  843. return;
  844. }
  845. var type = 0;
  846. 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>";
  847. });
  848. if (!childs) {
  849. result += '<div class="panel panel-primary">';
  850. result += '<div class="panel-heading"><h3 class="panel-title">[' + $(parent).data('id') + '] ' + $(parent).data("desc") + '</h3></div>';
  851. result += '<div class="panel-body pbody">';
  852. result += '<b>Opis: </b>' + $(parent).data("opis");
  853. result += '</div>';
  854. result += '</div>'
  855. }
  856. $("#depth" + depth).html(result);
  857. $('.drag').draggable({
  858. appendTo: 'body',
  859. handle: '.handle',
  860. helper: 'clone',
  861. stack: "div",
  862. distance: 0,
  863. cursor: "copy"
  864. });
  865. $(parent).find(".glyphicon").addClass("glyphicon-triangle-right");
  866. $(parent).find(".glyphicon").removeClass("glyphicon-refresh");
  867. $(parent).find(".glyphicon").removeClass("anim-refresh");
  868. $("#ulproc").scrollLeft(depth * 290 + 290);
  869. $("#ulproc").scrollTop(0);
  870. });
  871. });
  872. function procesy() {
  873. var side = $("#side");
  874. $(side).empty();
  875. $("#sidebar-wrapper").css("width", "600px");
  876. $("#wrapper").css("padding-left", "600px");
  877. //$(side).append("<h3>Zarządzaj zasobami<h3>");
  878. $(side).append("<div class='form-group' ><input type='text' class=form-control id=sProcesy placeholder='Szukaj procesów'></div>");
  879. $(side).append("<div id=ulproc><div id=procCon></div></div>");
  880. $(side).find("#procCon").append("<div class='singleAdv list-group' data-depth=0 id=depth0></div>");
  881. $(side).find("#procCon").append("<div class=clearfix></div>");
  882. 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';
  883. var result = "";
  884. $.get(link, function(data) {
  885. //console.log(data);
  886. $(data).find("featureMember").each(function() {
  887. var type = 0;
  888. 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>";
  889. });
  890. $("#depth0").html(result);
  891. $('.drag').draggable({
  892. appendTo: 'body',
  893. handle: '.handle',
  894. helper: 'clone',
  895. stack: "div",
  896. distance: 0,
  897. cursor: "copy"
  898. });
  899. });
  900. }
  901. $(document).on('click', '.liAdv', function() {
  902. $(this).find(".glyphicon").removeClass("glyphicon-triangle-right");
  903. $(this).find(".glyphicon").addClass("glyphicon-refresh");
  904. $(this).parents(".singleAdv").nextAll(".singleAdv").remove();
  905. $(this).parents(".singleAdv").find(".active").removeClass("active");
  906. $(this).addClass("active");
  907. var parent = this;
  908. var parent_id = $(this).data("id");
  909. 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';
  910. var result = "";
  911. var depth = $(this).parents(".singleAdv").data("depth") + 1;
  912. $("#advCon").css("width", depth * 290 + 290);
  913. $(this).parents(".singleAdv").after("<div class='singleAdv list-group' data-depth=" + depth + " id=depth" + depth + "></div>");
  914. //console.log(link);
  915. var childs = true;
  916. $.get(link, function(data) {
  917. $(data).find("featureMember").each(function() {
  918. if ($(this).find("ID").text() == 0) {
  919. childs = false;
  920. return;
  921. }
  922. var type = 0;
  923. if ($(this).find("TYPE").text() == "DZIAL" || $(this).find("TYPE").text() == "PODMIOT" || $(this).find("TYPE").text() == "STANOWISKO")
  924. type = 1;
  925. 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>";
  926. });
  927. if (!childs) {
  928. result += '<div class="panel panel-primary">';
  929. result += '<div class="panel-heading"><h3 class="panel-title">[' + $(parent).data('id') + '] ' + $(parent).data("desc") + '</h3></div>';
  930. result += '<div class="panel-body pbody">';
  931. result += '<b>Opis: </b>' + $(parent).data("opis");
  932. result += '<br><b>Typ: </b>' + $(parent).data("typename");
  933. result += '</div>';
  934. result += '</div>'
  935. }
  936. $("#depth" + depth).html(result);
  937. $('.drag').draggable({
  938. appendTo: 'body',
  939. handle: '.handle',
  940. helper: 'clone',
  941. stack: "div",
  942. distance: 0,
  943. cursor: "copy"
  944. });
  945. $(parent).find(".glyphicon").addClass("glyphicon-triangle-right");
  946. $(parent).find(".glyphicon").removeClass("glyphicon-refresh");
  947. $("#ulcon").scrollLeft(depth * 290 + 290);
  948. $("#ulcon").scrollTop(0);
  949. });
  950. });
  951. function zasoby() {
  952. var side = $("#side");
  953. $(side).empty();
  954. $("#sidebar-wrapper").css("width", "600px");
  955. $("#wrapper").css("padding-left", "600px");
  956. //$(side).append("<h3>Zarządzaj zasobami<h3>");
  957. $(side).append("<div class='form-group' ><input type='text' class=form-control id=sZasoby placeholder='Szukaj zasobów'></div>");
  958. $(side).append("<div class='btn-group' style=width:100% id=filtry></div>");
  959. $("#filtry").append("<button type='button' data-type=1 class='fbutton btn btn-default input-block-level ' style=width:40%>Stanowiska</button>");
  960. $("#filtry").append("<button type='button' data-type=2 class='fbutton btn btn-default input-block-level ' style=width:40%>Komórki</button>");
  961. $("#filtry").append("<button type='button' data-type=0 class='fbutton btn btn-danger input-block-level' id=xBtn style=width:20% disabled>X</button>");
  962. $(side).append("<div id=ulcon><div id=advCon></div></div>");
  963. $(side).find("#advCon").append("<div class='singleAdv list-group' data-depth=0 id=depth0></div>");
  964. $(side).find("#advCon").append("<div class=clearfix></div>");
  965. 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';
  966. var result = "";
  967. $.get(link, function(data) {
  968. //console.log(data);
  969. $(data).find("featureMember").each(function() {
  970. var type = 0;
  971. if ($(this).find("TYPE").text() == "DZIAL" || $(this).find("TYPE").text() == "PODMIOT" || $(this).find("TYPE").text() == "STANOWISKO")
  972. type = 1;
  973. 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>";
  974. });
  975. $("#depth0").html(result);
  976. $('.drag').draggable({
  977. appendTo: 'body',
  978. handle: '.handle',
  979. helper: 'clone',
  980. stack: "div",
  981. distance: 0,
  982. cursor: "copy"
  983. });
  984. });
  985. //$(side).find("#ulcon").append("<div class='drag' data-id=1 data-type=1 >[STANOWISKO] Ulotkarz</div>");
  986. //$(side).find("#ulcon").append("<div class='drag' data-id=2 data-type=1 >[STANOWISKO] Programista PHP</div>");
  987. //$(side).find("#ulcon").append("<div class='drag' data-id=3 data-type=2 >[ZASÓB] Komputer</div>");
  988. }
  989. function addProces(ui, target) {
  990. var id = $(target).data("id");
  991. var gotoOpt = "";
  992. $.each(gotoType, function(key, value) {
  993. gotoOpt += "<option value=" + value[0] + ">" + value[1] + "</option>";
  994. })
  995. swal({
  996. showCancelButton: true,
  997. cancelButtonText: "Anuluj",
  998. title: 'Typ łącza',
  999. 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>',
  1000. preConfirm: function() {
  1001. return new Promise(function(resolve) {
  1002. resolve([
  1003. $('#swal-input1').val()
  1004. ]);
  1005. });
  1006. }
  1007. }).then(function(result) {
  1008. //console.log("Dodaj zasob " + ui.draggable.data("id") + " do " + $(target).data("id") + " i uprawnienia id " + result[0] + " komentarz: " + result[1]); //
  1009. newRes--;
  1010. var temp = {};
  1011. temp["flag"] = result[0];
  1012. temp["id"] = ui.draggable.data("id");
  1013. //console.log(temp);
  1014. //console.log(state[getIndexById(id)]);
  1015. state[getIndexById(id)]["goto"] = temp;
  1016. updateAll();
  1017. }).catch(function(e) {})
  1018. }
  1019. function addResource(ui, target) {
  1020. var permsOpt = "";
  1021. $.each(perms, function(key, value) {
  1022. permsOpt = permsOpt + "<option value=" + value[0] + ">[" + value[2] + "] " + value[1] + "</option>";
  1023. })
  1024. swal({
  1025. showCancelButton: true,
  1026. cancelButtonText: "Anuluj",
  1027. title: 'Uprawnienia',
  1028. html: 'Uprawnienia<br><select class=form-control id="swal-input1">' + permsOpt + '</select>' +
  1029. 'Komentarz<br><input class=form-control id="swal-input2" class="swal2-input">',
  1030. preConfirm: function() {
  1031. return new Promise(function(resolve) {
  1032. resolve([
  1033. $('#swal-input1').val(),
  1034. $('#swal-input2').val()
  1035. ]);
  1036. });
  1037. }
  1038. }).then(function(result) {
  1039. //console.log("Dodaj zasob " + ui.draggable.data("id") + " do " + $(target).data("id") + " i uprawnienia id " + result[0] + " komentarz: " + result[1]); //
  1040. newRes--;
  1041. var temp = {};
  1042. temp["id_zasob"] = ui.draggable.data("id");
  1043. temp["id"] = newRes;
  1044. temp["id_przypadek"] = result[0];
  1045. temp["komentarz"] = result[1];
  1046. temp["changed"] = true;
  1047. temp["opis"] = ui.draggable.data("opis");
  1048. temp["desc"] = ui.draggable.data("desc");
  1049. var id = $(target).data("id");
  1050. if (ui.draggable.data("type") == 1) {
  1051. state[getIndexById(id)]["prof"].push(temp);
  1052. } else {
  1053. state[getIndexById(id)]["res"].push(temp);
  1054. }
  1055. updateAll();
  1056. }).catch(function(e) {})
  1057. }
  1058. //Najwazniejsza funkcja odpalana po kazdej zmianie. Sprawdza, czy wszystkie funkcje maja rodzica,
  1059. //jezeli nie to przesuwa w lewo obiekt
  1060. //Odpowiada tez za ukrywanie guzikow i wywowalanie funkcji generacji krokow
  1061. function updateAll() {
  1062. $.each(state, function(i, e) {
  1063. var pid = getParentNode(e["id"]);
  1064. if (pid != "NONE" && pid != false && pid != e["parent_id"]) {
  1065. e["parent_id"] = pid;
  1066. //console.log("Ustawiono nowe parent_id na " + e["parent_id"] + " dla " + e["id"]); //
  1067. } else if (pid === false) {
  1068. e["depth"]--;
  1069. //var depthWidth = 20 * $(node).data("depth");
  1070. //$(node).css("padding-left", depthWidth + "px");
  1071. updateAll();
  1072. return;
  1073. }
  1074. if (checkParentNode(e["id"], "right") === false) {
  1075. $(this).find(".rArrow").hide();
  1076. } else {
  1077. $(this).find(".rArrow").show();
  1078. }
  1079. if (checkParentNode(e["id"], "left") === false) {
  1080. $(this).find(".lArrow").hide();
  1081. } else {
  1082. $(this).find(".lArrow").show();
  1083. }
  1084. if (i == 1)
  1085. $(this).find(".uArrow").hide();
  1086. else
  1087. $(this).find(".uArrow").show();
  1088. if (i == state.length - 1) {
  1089. $(this).find(".dArrow").hide();
  1090. } else {
  1091. $(this).find(".dArrow").show();
  1092. }
  1093. });
  1094. //console.log(JSON.stringify(state));
  1095. changes = true;
  1096. $("#clearBtn").show();
  1097. localStorage.setItem("state" + mainProces_id, JSON.stringify(state));
  1098. localStorage.setItem("newStep" + mainProces_id, newSteps);
  1099. localStorage.setItem("newRes" + mainProces_id, newRes);
  1100. localStorage.setItem("deletedId" + mainProces_id, JSON.stringify(deletedId));
  1101. localStorage.setItem("deletedRes" + mainProces_id, JSON.stringify(deletedRes));
  1102. localStorage.setItem("date" + mainProces_id, moment().format("YYYY-MM-DD HH:mm:ss"));
  1103. render(state, $("#main"));
  1104. }
  1105. //Generuje kroki, sprawdza tez czy kolejnosc krokow w danym rodzicow zostala zmieniona
  1106. //Jezeli tak to mozna wyslac ajaxem zmiane kolejnosci dla sort_prio
  1107. function stepsGenerator() {
  1108. $.each(state, function(i, e) {
  1109. e["step"] = 0;
  1110. if (i == 0)
  1111. e["stepDesc"] = "";
  1112. else {
  1113. var iParent = getIndexById(e["parent_id"]);
  1114. //console.log("Generowanie step dla "+e["id"]);
  1115. //console.log("iParent "+iParent);
  1116. state[iParent]["step"] += 1;
  1117. //console.log(state[iParent]["step"]);
  1118. e["SORT_PRIO"] = state[iParent]["step"];
  1119. e["stepDesc"] = state[iParent]["stepDesc"] + state[iParent]["step"] + ". ";
  1120. }
  1121. });
  1122. }
  1123. //Na potrzeby guzikow dorobilem funkcje sprawdzajaca id rodzica po przesunieciu (przewidywanie).
  1124. //Jezeli nie znajdzie zwraca false, a wtedy blokuje sie odpowiednia strzalka
  1125. function checkParentNode(id, check) {
  1126. var x = getIndexById(id);
  1127. var y = x;
  1128. //console.log(tab);
  1129. var result = false;
  1130. while (x > 0) {
  1131. x--;
  1132. if (check == "right")
  1133. if (state[x]["depth"] == state[y]["depth"]) {
  1134. result = state[x]["id"];
  1135. break;
  1136. }
  1137. if (check == "left")
  1138. if (state[x]["depth"] == state[y]["depth"] - 2) {
  1139. result = state[x]["id"];
  1140. break;
  1141. }
  1142. if (check == "right" && state[x]["depth"] < state[y]["depth"])
  1143. break;
  1144. }
  1145. return result;
  1146. }
  1147. //Zwraca id rodzica, jezeli nie ma zwraca false
  1148. function getParentNode(id) {
  1149. var x = getIndexById(id);
  1150. var y = x;
  1151. if (x == 0)
  1152. return "NONE";
  1153. var result = false;
  1154. while (x > 0) {
  1155. x--;
  1156. if (state[x]["depth"] == state[y]["depth"] - 1) {
  1157. result = state[x]["id"];
  1158. break;
  1159. }
  1160. if (state[x]["depth"] - state[y]["depth"] == -2)
  1161. break;
  1162. }
  1163. return result;
  1164. }
  1165. function getResById(index, id, type) {
  1166. var result = state[index][type].length - 1;
  1167. $.each(state[index][type], function(i, e) {
  1168. //console.log(e["id"]);
  1169. //console.log(id);
  1170. if (e["id"] == id) {
  1171. //console.log("Zwraca "+i);
  1172. result = i;
  1173. return false;
  1174. }
  1175. });
  1176. return result;
  1177. }
  1178. function getIndexById(id) {
  1179. //console.log("Szuka"+id);
  1180. var result = state.length - 1;
  1181. $.each(state, function(i, e) {
  1182. //console.log(e["id"]);
  1183. //console.log(id);
  1184. if (e["id"] == id) {
  1185. //console.log("Zwraca "+i);
  1186. result = i;
  1187. return false;
  1188. }
  1189. });
  1190. return result;
  1191. }
  1192. /*function logState() {
  1193. //console.log("########");
  1194. $.each(state, function(i, e) {
  1195. //console.log(i + ": " + e["id"]);
  1196. });
  1197. //console.log("########");
  1198. }*/
  1199. function render(arr, target) {
  1200. stepsGenerator();
  1201. var result = "";
  1202. console.log(arr);
  1203. $.each(arr, function(i, e) {
  1204. result += "<div class='drop container-fluid' data-id=" + e["id"] + " id='proc" + e["id"] + "'>";
  1205. result += "<div class='col-xs-1 options' id=opt" + e["id"] + ">";
  1206. if (i > 0) {
  1207. result += "<span class='glyphicon glyphicon-remove-sign ico del' title='Usuń krok' aria-hidden='true'></span>";
  1208. //Arrows
  1209. if (checkParentNode(e["id"], "right") !== false)
  1210. result += "<span class='glyphicon glyphicon-arrow-right ico rArrow' aria-hidden='true' title='Przesuń krok w prawo'></span>";
  1211. if (checkParentNode(e["id"], "left") !== false)
  1212. result += "<span class='glyphicon glyphicon-arrow-left ico lArrow' aria-hidden='true' title='Przesuń krok w lewo'></span>";
  1213. if (i != 1)
  1214. result += "<span class='glyphicon glyphicon-arrow-up ico uArrow' aria-hidden='true' title='Przesuń krok w górę'></span>";
  1215. if (i != state.length - 1)
  1216. result += "<span class='glyphicon glyphicon-arrow-down ico dArrow' aria-hidden='true' title='Przesuń krok w dół'></span>";
  1217. } else {
  1218. }
  1219. result += "<div class='clearfix'></div>";
  1220. result += "</div>";
  1221. 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>";
  1222. // }
  1223. // if ($(this).find("OPIS").text() == "") {
  1224. // $("#proc" + $(this).find("ID").text()).find(".sdesc").after("<span class=sDescAdd>Dodaj opis</span>");
  1225. // }
  1226. result += "<div class='clearfix'></div>";
  1227. var anyProf = false;
  1228. $.each(e["prof"], function(i2, e2) {
  1229. if (!anyProf) {
  1230. result += "<dl class='dl-horizontal'><dt>Stanowiska</dt><dd><ul class=professions>";
  1231. anyProf = true;
  1232. }
  1233. result += "<li class='" + (e2["changed"] ? "changed" : "") + "' data-zasob=" + e2["id_zasob"] + " data-id=" + e2["id"] + " data-przypadek=" + e2["id_przypadek"] + " data-komentarz='" + e2["komentarz"] + "'><b>" + e2["desc"] + "</b> " + e2["opis"] + " [" + e2["id_zasob"] + "] <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>";
  1234. if (i2 != 0)
  1235. result += "<span class='glyphicon glyphicon-arrow-up uArrowRes' title='Przesuń wskaźnik w górę' aria-hidden='true'></span>";
  1236. if (i2 != e["prof"].length - 1)
  1237. result += "<span class='glyphicon glyphicon-arrow-down dArrowRes' title='Przesuń wskaźnik w dół' aria-hidden='true'></span>";
  1238. result += "</li>";
  1239. });
  1240. if (anyProf) {
  1241. result += "</ul></dd></dl>";
  1242. }
  1243. var anyRes = false;
  1244. $.each(e["res"], function(i2, e2) {
  1245. if (!anyRes) {
  1246. result += "<dl class='dl-horizontal'><dt>Użyte zasoby</dt><dd><ul class=resources>";
  1247. anyRes = true;
  1248. }
  1249. result += "<li class='" + (e2["changed"] ? "changed" : "") + "' data-zasob=" + e2["id_zasob"] + " data-id=" + e2["id"] + " data-przypadek=" + e2["id_przypadek"] + " data-komentarz='" + e2["komentarz"] + "'><b>" + e2["desc"] + "</b> " + e2["opis"] + " [" + e2["id_zasob"] + "] <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>";
  1250. if (i2 != 0)
  1251. result += "<span class='glyphicon glyphicon-arrow-up uArrowRes' title='Przesuń wskaźnik w górę' aria-hidden='true'></span>";
  1252. if (i2 != e["prof"].length - 1)
  1253. result += "<span class='glyphicon glyphicon-arrow-down dArrowRes' title='Przesuń wskaźnik w dół' aria-hidden='true'></span>";
  1254. result += "</li>";
  1255. });
  1256. if (anyRes) {
  1257. result += "</ul></dd></dl>";
  1258. }
  1259. if (typeof e["goto"] !== typeof undefined && e["goto"]["id"] != null && e["goto"]["id"] != 0) {
  1260. var name;
  1261. switch (e["goto"]["flag"]) {
  1262. case "GOTO":
  1263. name = "Jeżeli TAK to należy przejść do procesu " + e["goto"]["id"] + ".";
  1264. break;
  1265. case "GOTO_AND_RETURN":
  1266. name = "Jeżeli TAK to należy przejść do procesu " + e["goto"]["id"] + ", a następnie wrócić.";
  1267. break;
  1268. case "FORK":
  1269. name = "FORK" + e["goto"]["id"];
  1270. break;
  1271. default:
  1272. name = e["goto"]["id"];
  1273. }
  1274. result += "<span class=goto>" + name + "</span> <span class='glyphicon glyphicon-remove-sign delGoto' title='Usuń GOTO' style=font-size:12px; aria-hidden='true' ></span><br><br>";
  1275. }
  1276. if (e["desc"] == "")
  1277. result += "<span class=hDescAdd>Dodaj tytuł</span><br>";
  1278. if (e["opis"] == "")
  1279. result += "<span class=sDescAdd>Dodaj opis</span>";
  1280. result += "<br><span class=step>Dodaj nowy krok</span>";
  1281. result += "</div>"
  1282. result += "</div>";
  1283. });
  1284. //console.log(result);
  1285. $(target).html(result);
  1286. $('.drag').draggable({
  1287. appendTo: 'body',
  1288. helper: 'clone',
  1289. stack: "div",
  1290. distance: 0,
  1291. cursor: "copy"
  1292. });
  1293. $(".drop").droppable({
  1294. tolerance: 'pointer',
  1295. accept: '.drag',
  1296. zIndex: 0,
  1297. hoverClass: "activeDrop",
  1298. drop: function(event, ui) {
  1299. if (ui.draggable.data("droptype") == 1)
  1300. addProces(ui, this);
  1301. else
  1302. addResource(ui, this);
  1303. }
  1304. });
  1305. }
  1306. function genTree(parent_id) {
  1307. //logState();
  1308. 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';
  1309. //console.log(link);
  1310. $.ajax({
  1311. url: link,
  1312. success: function(data) {
  1313. //console.log(data);
  1314. var i = 0;
  1315. $.each($(data).find("featureMember"), function() {
  1316. var temp = {};
  1317. if ($(this).find("ID").text() == "0")
  1318. return;
  1319. var parentIndex = getIndexById(parent_id);
  1320. temp["id"] = $(this).find("ID").text();
  1321. temp["desc"] = $(this).find("DESC").text();
  1322. temp["opis"] = $(this).find("OPIS").text();
  1323. temp["parent_id"] = $(this).find("PARENT_ID").text();
  1324. temp["depth"] = state[parentIndex]["depth"] + 1;
  1325. temp["step"] = 0;
  1326. temp["changes"] = {};
  1327. temp["prof"] = new Array();
  1328. temp["res"] = new Array();
  1329. temp["goto"] = {};
  1330. temp["goto"]["id"] = $(this).find("IF_TRUE_GOTO").text();
  1331. temp["goto"]["flag"] = $(this).find("IF_TRUE_GOTO_FLAG").text();
  1332. temp["stepDesc"] = "";
  1333. i++;
  1334. state.splice(parentIndex + i, 0, temp);
  1335. genTree($(this).find("ID").text());
  1336. });
  1337. }
  1338. });
  1339. }
  1340. //Pierwszy render, tworzy potrzebna strukture
  1341. function showPreview() {
  1342. changes = false;
  1343. $("#clearBtn").hide();
  1344. lastSearch = "";
  1345. filtr = 0;
  1346. selectedArea = false;
  1347. state = [];
  1348. if (false && localStorage.getItem("state" + mainProces_id) !== null) {
  1349. state = JSON.parse(localStorage.getItem("state" + mainProces_id));
  1350. newSteps = localStorage.getItem("newStep" + mainProces_id);
  1351. newRes = localStorage.getItem("newRes" + mainProces_id);
  1352. deletedId = JSON.parse(localStorage.getItem("deletedId" + mainProces_id));
  1353. deletedRes = JSON.parse(localStorage.getItem("deletedRes" + mainProces_id));
  1354. //console.log("z");
  1355. //console.log(localStorage.getItem("state" + mainProces_id));
  1356. $.notify("Wczytano niezapisany stan z " + localStorage.getItem("date" + mainProces_id), "info");
  1357. //console.log(state);
  1358. render(state, $("#main"));
  1359. loaded = true;
  1360. } else {
  1361. $("#main").html("<center>Synchronizowanie danych z serwerem.</center>");
  1362. newSteps = 0;
  1363. newRes = 0;
  1364. deletedId = [];
  1365. deletedRes = [];
  1366. var id = mainProces_id;
  1367. 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>';
  1368. //console.log(link);
  1369. $.get(link, function(data) {
  1370. var temp = {};
  1371. loaded = false;
  1372. temp["id"] = mainProces_id;
  1373. temp["depth"] = 0;
  1374. temp["parent_id"] = false;
  1375. temp["step"] = 0;
  1376. temp["goto"] = {};
  1377. temp["goto"]["id"] = $(data).find("featureMember").find("IF_TRUE_GOTO").text();
  1378. temp["goto"]["flag"] = $(data).find("featureMember").find("IF_TRUE_GOTO_FLAG").text();
  1379. temp["changes"] = {};
  1380. temp["stepDesc"] = "";
  1381. temp["prof"] = new Array();
  1382. temp["res"] = new Array();
  1383. temp["desc"] = $(data).find("featureMember").find("DESC").text();
  1384. temp["opis"] = $(data).find("featureMember").find("OPIS").text()
  1385. tab.push(mainProces_id);
  1386. state[0] = temp;
  1387. genTree(mainProces_id);
  1388. });
  1389. actSite = "preview";
  1390. }
  1391. }
  1392. });
  1393. function unloadPage() {
  1394. if (changes)
  1395. return "";
  1396. }
  1397. window.onbeforeunload = unloadPage;