procesEditor.js 114 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716
  1. //Request-URI Too Long
  2. $(document).ready(function() {
  3. function cData(text) {
  4. var nowy = "<![CDATA[";
  5. nowy += text;
  6. nowy += "]]>"
  7. return nowy;
  8. }
  9. var changes = false;
  10. $("#main").after('<div class="col-xs-1 col-xs-offset-7" id="buttons"></div>');
  11. $("#buttons").after("<button type=button id=saveBtn class='btn btn-primary text-center' style=margin-left:5px;>Opublikuj zmiany</button>");
  12. $("#buttons").after("<button type=button id=clearBtn style=display:none; class='btn btn-danger text-center' >Cofnij zmiany</button>");
  13. //$("#buttons").after("<button type=button id=expBtn class='btn btn-warning text-center' style=margin-right:5px;>Import/Export</button>");
  14. var deletedId = new Array();
  15. var generatedId = new Array();
  16. var deletedRes = new Array();
  17. var usedImg = {};
  18. var dialog = 0;
  19. $("#SE-menu").hide();
  20. $("#SE-menu-sub").hide();
  21. var menuShow = false
  22. var zasobTree = new Array();
  23. var perms = [
  24. [1, "Kto wykonuje", "X"],
  25. [2, "Tylko do odczytu", "R"],
  26. [3, "Odczyt, zapis, wykonanie", "R,W,X"],
  27. [4, "Odczyt, zapis, wykonanie, tworzenie", "R,W,X,C"],
  28. [5, "Odczyt i wykonanie", "R,X"],
  29. [6, "Tylko do odczytu", "R"],
  30. [7, "MAPA PROCESU - opis mapy procesu", ""],
  31. [9, "Tylko do tworzenia rekordu", "C"],
  32. [10, "Tylko tworzenie i czytanie rekordów bez edycji", "R,X,C"],
  33. [11, "Tylko edycja rekordu - ustalanie nowej wartosci", "W"],
  34. [12, "Tylko edycja i dodanie rekordu - ustalanie nowej wartosci", "W,C"],
  35. [13, "Nowy rekord i edycja z pominieciem A_ADM_COMPANY", "R,W,X,C,S"],
  36. [14, "Widok tylko swoich danych z rekordu", "W,O"],
  37. [15, "Edycja rekordów dla super admina", "R,W,C,S"],
  38. [16, "Widok i dodawanie rekordów tylko dla swojego ADM_COMPANY", "C,O"],
  39. [17, "Super widok wszystkich rekordow niezaleznie od uprawnien rekordu", "R,V"],
  40. [18, "Administracja Edycja i widok wszystkich rekordow z pominieciem A", "R,W,X,S,V"],
  41. [19, "Administracja Edycja Tworzenie i widok wszystkich rekordow z pom", "R,W,X,C,S,V"],
  42. [20, "Export", "R,X,E"],
  43. [21, "Widzenie tylko swoich rekordów", "O"]
  44. ];
  45. var gotoType = [
  46. ["GOTO", "Przejdź do procesu"],
  47. ["GOTO_AND_RETURN", "Przejdź do procesu i wróć"],
  48. ["FORK", "FORK"]
  49. ];
  50. var state = [];
  51. var loaded = true;
  52. var actSite = "none";
  53. var filtr = 0;
  54. var selectedArea = false;
  55. var sZasoby;
  56. var sProcesy;
  57. var lastSearch = "";
  58. var newSteps;
  59. var newRes = 0;
  60. showPreview();
  61. var XML_NAMESPACE = "default_db__x3A__";
  62. $(document).on('click', '#toggleMenu', function(e) {
  63. e.preventDefault();
  64. if (!menuShow) {
  65. $("#SE-menu").show();
  66. $("#SE-menu-sub").show();
  67. menuShow = true;
  68. } else {
  69. menuShow = false;
  70. $("#SE-menu").hide();
  71. $("#SE-menu-sub").hide();
  72. }
  73. });
  74. function showPath(parent, target = $(".path"), showEdit = true, renderTree = false) {
  75. var link = BASE_URL + "index.php?_route=UrlAction_ProcesEditor&_task=getPathAjax&id=" + parent;
  76. $.get(link, function(data) {
  77. var result = "";
  78. result += '<ol class="breadcrumb">';
  79. $.each(data, function(i, e) {
  80. result += '<li class="breadcrumb-item">' + e["DESC"] + " {" + e["ID"] + "}" + '</li>'
  81. })
  82. result += '<li '+(state[0]["parent_id"] <= 0 ? "style=color:red;" : "")+' class="breadcrumb-item">' + state[0]["desc"] + " {" + (state[0]["id"] < 0 ? "?" : state[0]["id"]) + "}"
  83. if (showEdit)
  84. result += '<i class="glyphicon glyphicon-edit ico editPath"></i>'
  85. result += '</li>'
  86. result += '</ol>';
  87. $(target).html(result);
  88. if (renderTree)
  89. renderProcesTree(data);
  90. });
  91. }
  92. function loadResources() {
  93. showPath(state[0]["parent_id"]);
  94. $("#main").html("<center>Pobieranie danych o zasobach.</center>");
  95. var sFiltr = "";
  96. sFiltr += `
  97. <GetFeature xmlns="http://www.opengis.net/wfs/2.0"
  98. xmlns:p5_default_db="` + BASE_WFS_URL + `/default_db"
  99. xmlns:ogc="http://www.opengis.net/ogc"
  100. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  101. service="WFS"
  102. version="2.0.2"
  103. xsi:schemaLocation="http://www.opengis.net/wfs/2.0 http://schemas.opengis.net/wfs/2.0/wfs.xsd">`;
  104. sFiltr += ' <ogc:Filter>';
  105. sFiltr += ' <ogc:And>';
  106. sFiltr += ' <ogc:Or>';
  107. $.each(state, function(idx, procesItem) {
  108. sFiltr += ' <ogc:PropertyIsEqualTo><ogc:PropertyName>ID_PROCES</ogc:PropertyName><ogc:Literal>' + procesItem["id"] + '</ogc:Literal></ogc:PropertyIsEqualTo>';
  109. });
  110. sFiltr += ' </ogc:Or>';
  111. sFiltr += ' <ogc:Not>';
  112. sFiltr += ' <ogc:PropertyIsEqualTo><ogc:PropertyName>A_STATUS</ogc:PropertyName><ogc:Literal>DELETED</ogc:Literal></ogc:PropertyIsEqualTo>';
  113. sFiltr += ' </ogc:Not>';
  114. sFiltr += ' </ogc:And>';
  115. sFiltr += ' </ogc:Filter>';
  116. sFiltr += '</GetFeature>';
  117. var link = BASE_URL + 'wfs-data.php/default_db/?SERVICE=WFS&VERSION=1.0.0&SRSNAME=EPSG:3003';
  118. link += '&REQUEST=GetFeature';
  119. link += '&TYPENAME=p5_default_db:CRM_WSKAZNIK';
  120. link += '&sortBy=SORT_PRIO+A,ID';
  121. var wskazniki = new Array();
  122. $.ajax({
  123. url: link,
  124. data: sFiltr,
  125. type: 'POST',
  126. contentType: "text/xml",
  127. dataType: "xml",
  128. success: function(data) {
  129. $.each($(data).find("featureMember"), function() {
  130. if ($(this).find("ID").text() == 0) return;
  131. var wsk = new Array();
  132. wsk["ID"] = $(this).find("ID").text();
  133. wsk["ID_ZASOB"] = $(this).find("ID_ZASOB").text();
  134. wsk["ID_PROCES"] = $(this).find("ID_PROCES").text();
  135. wsk["SORT_PRIO"] = $(this).find("SORT_PRIO").text();
  136. wsk["ID_PRZYPADEK"] = $(this).find("ID_PRZYPADEK").text();
  137. wsk["OPIS_ZASOB"] = $(this).find("OPIS_ZASOB").text();
  138. wskazniki.push(wsk);
  139. });
  140. var idsZasobyToFetch = [];
  141. $.each(wskazniki, function(index, wsk) {
  142. idsZasobyToFetch.push(wsk["ID_ZASOB"]);
  143. });
  144. if (idsZasobyToFetch.length > 0) {
  145. var zasobInfo = new Array();
  146. $.ajax({
  147. type: 'POST',
  148. url: BASE_URL + "index.php?_route=UrlAction_ProcesEditor&_task=getSingleResAjax",
  149. data: {
  150. data: idsZasobyToFetch
  151. },
  152. dataType: 'json'
  153. })
  154. .done(function(jsonZasobyTree) {
  155. $.each(jsonZasobyTree, function(idx, zasob) {
  156. zasobInfo[zasob["ID"]] = new Array();
  157. zasobInfo[zasob["ID"]]["DESC"] = zasob["DESC"];
  158. zasobInfo[zasob["ID"]]["OPIS"] = zasob["OPIS"];
  159. zasobInfo[zasob["ID"]]["TYPE"] = zasob["TYPE"];
  160. zasobInfo[zasob["ID"]]["TREE"] = [];
  161. for (var i = 3; i > 0; i--) {
  162. if (zasob["p" + i + "_ID"] != null) {
  163. var temp = {};
  164. temp["ID"] = zasob["p" + i + "_ID"];
  165. temp["DESC"] = zasob["p" + i + "_DESC"];
  166. zasobInfo[zasob["ID"]]["TREE"].push(temp);
  167. }
  168. }
  169. });
  170. $.each(wskazniki, function(index, wsk) {
  171. var type,
  172. idZasob = wsk["ID_ZASOB"];
  173. if (!zasobInfo[idZasob]) {
  174. $("#main").html("<center>Generowanie widoku.</center>");
  175. render(state, $("#main"));
  176. return;
  177. }
  178. if (zasobInfo[idZasob]["TYPE"] == "DZIAL" || zasobInfo[idZasob]["TYPE"] == "STANOWISKO" || zasobInfo[idZasob]["TYPE"] == "PODMIOT") {
  179. type = "prof";
  180. } else {
  181. type = "res";
  182. }
  183. var id = wsk["ID_PROCES"];
  184. var temp = {};
  185. temp["id_zasob"] = idZasob
  186. temp["id"] = wsk["ID"];
  187. temp["id_przypadek"] = wsk["ID_PRZYPADEK"];
  188. temp["komentarz"] = wsk["OPIS_ZASOB"];
  189. temp["desc"] = zasobInfo[idZasob]["DESC"];
  190. temp["opis"] = zasobInfo[idZasob]["OPIS"];
  191. temp["tree"] = zasobInfo[idZasob]["TREE"];
  192. //console.log(getIndexById(id));
  193. var newId = state[getIndexById(id)][type].push(temp) - 1;
  194. var linkImg = BASE_URL +
  195. 'wfs-data.php/default_db/?SERVICE=WFS&VERSION=1.0.0&REQUEST=GetFeature&TYPENAME=p5_default_db:CRM_IMAGE&SRSNAME=EPSG:3003&Filter=<ogc:Filter><ogc:And><ogc:PropertyIsEqualTo><ogc:PropertyName>REMOTE_ID</ogc:PropertyName><ogc:Literal>' + wsk["ID"] +
  196. '</ogc:Literal></ogc:PropertyIsEqualTo><ogc:PropertyIsEqualTo><ogc:PropertyName>REMOTE_TABLE</ogc:PropertyName><ogc:Literal>CRM_WSKAZNIK</ogc:Literal></ogc:PropertyIsEqualTo></ogc:And></ogc:Filter>';
  197. $.get(linkImg, function(imgData) {
  198. var temp = Array();
  199. $.each($(imgData).find("featureMember"), function() {
  200. temp.push({
  201. "src": base64_decode($(this).find("IMAGE").text()),
  202. "title": $(this).find("NAME").text(),
  203. "id": $(this).find("ID").text(),
  204. });
  205. })
  206. state[getIndexById(id)][type][newId]["img"] = temp;
  207. $("#main").html("<center>Generowanie widoku.</center>");
  208. render(state, $("#main"));
  209. });
  210. });
  211. })
  212. .fail(function(xhr) {
  213. if (xhr.responseJSON && xhr.responseJSON.msg && xhr.responseJSON.type) jQuery.notify(xhr.responseJSON.msg, xhr.responseJSON.type);
  214. else jQuery.notify("Wystąpił nieznany błąd", 'error');
  215. });
  216. } else {
  217. $("#main").html("<center>Generowanie widoku.</center>");
  218. render(state, $("#main"));
  219. }
  220. }
  221. });
  222. }
  223. $(document).ajaxStop(function() {
  224. if (loaded)
  225. return;
  226. loaded = true;
  227. //$(".drop").find("dl").hide();
  228. loadResources();
  229. });
  230. $(document).on('click', '#clearBtn', function() {
  231. swal({
  232. title: 'Cofnij zmiany',
  233. text: "Czy chcesz cofnąć wszystkie niezapisane zmiany?",
  234. type: 'warning',
  235. showCancelButton: true,
  236. confirmButtonColor: '#3085d6',
  237. cancelButtonColor: '#d33',
  238. cancelButtonText: "Anuluj",
  239. confirmButtonText: 'Cofnij zmiany'
  240. }).then(function() {
  241. localStorage.removeItem("state" + mainProces_id);
  242. $.notify("Niezapisane zmiany zostały wycofane.", "success");
  243. showPreview();
  244. //Parent_id = -1,
  245. }).catch(function(e) {})
  246. });
  247. //Saveaction
  248. var makeCRCTable = function() {
  249. var c;
  250. var crcTable = [];
  251. for (var n = 0; n < 256; n++) {
  252. c = n;
  253. for (var k = 0; k < 8; k++) {
  254. c = ((c & 1) ? (0xEDB88320 ^ (c >>> 1)) : (c >>> 1));
  255. }
  256. crcTable[n] = c;
  257. }
  258. return crcTable;
  259. }
  260. var crc32 = function(str) {
  261. var crcTable = window.crcTable || (window.crcTable = makeCRCTable());
  262. var crc = 0 ^ (-1);
  263. for (var i = 0; i < str.length; i++) {
  264. crc = (crc >>> 8) ^ crcTable[(crc ^ str.charCodeAt(i)) & 0xFF];
  265. }
  266. return (crc ^ (-1)) >>> 0;
  267. };
  268. function saveAs(uri, filename) {
  269. var link = document.createElement('a');
  270. if (typeof link.download === 'string') {
  271. link.href = uri;
  272. link.download = filename;
  273. document.body.appendChild(link);
  274. link.click();
  275. document.body.removeChild(link);
  276. } else {
  277. window.open(uri);
  278. }
  279. }
  280. //Source: https://gist.github.com/sente/1083506
  281. //License: The MIT License (MIT)
  282. function formatXml(xml) {
  283. var formatted = '';
  284. var reg = /(>)(<)(\/*)/g;
  285. xml = xml.replace(reg, '$1\r\n$2$3');
  286. var pad = 0;
  287. jQuery.each(xml.split('\r\n'), function(index, node) {
  288. var indent = 0;
  289. if (node.match(/.+<\/\w[^>]*>$/)) {
  290. indent = 0;
  291. } else if (node.match(/^<\/\w/)) {
  292. if (pad != 0) {
  293. pad -= 1;
  294. }
  295. } else if (node.match(/^<\w([^>]*[^\/])?>.*$/)) {
  296. indent = 1;
  297. } else {
  298. indent = 0;
  299. }
  300. var padding = '';
  301. for (var i = 0; i < pad; i++) {
  302. padding += ' ';
  303. }
  304. formatted += padding + node + '\r\n';
  305. pad += indent;
  306. });
  307. return formatted;
  308. }
  309. function createOpenTag(table, field) {
  310. var result = "";
  311. result += "<";
  312. result += XML_NAMESPACE + table + ":" + field;
  313. result += ">\n"
  314. return result;
  315. }
  316. function createCloseTag(table, field) {
  317. var result = "";
  318. result += "</";
  319. result += XML_NAMESPACE + table + ":" + field;
  320. result += ">\n"
  321. return result;
  322. }
  323. function createTag(table, field, content) {
  324. var result = "";
  325. if (content !== false && content !== true) {
  326. result += createOpenTag(table, field);
  327. result += content + "\n";
  328. result += createCloseTag(table, field);
  329. return result;
  330. }
  331. result += "<";
  332. if (content === false) result += "/";
  333. result += XML_NAMESPACE + table + ":" + field;
  334. result += ">\n"
  335. return result;
  336. }
  337. function createXmlWskaznik(index) {
  338. var arr = state[index];
  339. var xml = ""
  340. $.each(arr["res"].concat(arr["prof"]), function(i, e) {
  341. if (e["parent_id"] != arr["id"])
  342. return true;
  343. xml += createOpenTag("CRM_WSKAZNIK", "CRM_WSKAZNIK");
  344. xml += createTag("CRM_WSKAZNIK", "ID", e["id"])
  345. xml += createTag("CRM_WSKAZNIK", "OPIS_ZASOB", e["komentarz"])
  346. xml += createTag("CRM_WSKAZNIK", "ID_PRZYPADEK", e["komentarz"])
  347. xml += createOpenTag("CRM_LISTA_ZASOBOW", "CRM_LISTA_ZASOBOW");
  348. xml += createTag("CRM_LISTA_ZASOBOW", "ID_PRZYPADEK", e["id_przypadek"])
  349. xml += createCloseTag("CRM_LISTA_ZASOBOW", "CRM_LISTA_ZASOBOW");
  350. xml += createTag("CRM_WSKAZNIK", "ID", e["id"])
  351. xml += createCloseTag("CRM_WSKAZNIK", "CRM_WSKAZNIK");
  352. })
  353. return xml;
  354. }
  355. function createXmlProces(index) {
  356. var arr = state[index];
  357. var xml = ""
  358. xml += createTag("CRM_PROCES", "ID", arr["id"]);
  359. xml += createTag("CRM_PROCES", "DESC", arr["desc"]);
  360. xml += createTag("CRM_PROCES", "OPIS", arr["opis"]);
  361. xml += createTag("CRM_PROCES", "IF_TRUE_GOTO", arr["goto"]["id"]);
  362. xml += createTag("CRM_PROCES", "IF_TRUE_GOTO_FLAG", arr["goto"]["flag"]);
  363. xml += createTag("CRM_PROCES", "_CHANGED_DESC", (arr["C-desc"] ? "true" : "false"));
  364. xml += createTag("CRM_PROCES", "_CHANGES_OPIS", (arr["C-opis"] ? "true" : "false"));
  365. xml += createXmlWskaznik(index)
  366. $.each(state, function(i, e) {
  367. if (e["parent_id"] != arr["id"])
  368. return true;
  369. xml += createOpenTag("CRM_PROCES", "PROCES");
  370. xml += createXmlProces(i);
  371. xml += createCloseTag("CRM_PROCES", "PROCES");
  372. })
  373. return xml;
  374. }
  375. function saveToXml() {
  376. var xml = '<?xml version="1.0" encoding="utf-8"?>\n';
  377. /*
  378. xml + = 'schema namespace (default): default_db__x3A__CRM_PROCES = "default_db/CRM_PROCES"\n'
  379. + 'schema namespace: default_db__x3A__CRM_WSKAZNIK = "default_db/CRM_WSKAZNIK"\n'
  380. + 'schema namespace: default_db__x3A__CRM_IMAGE = "default_db/CRM_IMAGE"\n'
  381. */
  382. var proces_init = state[0];
  383. xml += createOpenTag("CRM_PROCES", "PROCES_INIT"); {
  384. xml += createXmlProces(0);
  385. }
  386. xml += createCloseTag("CRM_PROCES", "PROCES_INIT");
  387. console.log(formatXml(xml));
  388. saveAs('data:Application/octet-stream,' + encodeURIComponent(formatXml(xml)), 'export.xml')
  389. }
  390. function treeRecursive(data, id, parent, path) {
  391. if (id != 0) {
  392. var node = {
  393. 'id': id,
  394. type: "proces"
  395. };
  396. if (getIndexById(id, path, "ID") == -1)
  397. node["text"] = "<input type=checkbox class='checkParent' style=margin-right:5px; data-id='"+id+"' /> {" + id + "} " + data[id]["DESC"]
  398. else {
  399. node["text"] = "<input type=checkbox style=margin-right:5px;/><span style=color:#3498db;>{" + id + "} " + data[id]["DESC"] + "</span>"
  400. node["state"] = {}
  401. node["state"]["opened"] = true;
  402. if (path[path.length - 1]["ID"] == id) {
  403. node["text"] = "<input type=checkbox style=margin-right:5px; checked /><span style=color:#3498db;>{" + id + "} " + data[id]["DESC"] + "</span>"
  404. node["state"]["selected"] = true;
  405. node["state"]["opened"] = false;
  406. }
  407. }
  408. $("#pathList").jstree('create_node', parent, node, 'first', function() {
  409. $.each(data[id]["childs"], function(i, e) {
  410. treeRecursive(data, e["ID"], id, path);
  411. })
  412. });
  413. } else
  414. $.each(data[id]["childs"], function(i, e) {
  415. treeRecursive(data, e["ID"], "#", path);
  416. })
  417. }
  418. function customMenu(node) {
  419. var id = node.id
  420. //var target = $('#pathList').closest(".p5BModalContent");
  421. items = {
  422. "Move_parent": {
  423. "separator_before": false,
  424. "separator_after": false,
  425. "label": "Przepnij proces jako dziecko",
  426. "action": function(obj) {
  427. state[0]["parent_id"] = id;
  428. //pathModal(target);
  429. showPath(state[0]["parent_id"]);
  430. }
  431. },
  432. }
  433. return items;
  434. }
  435. $(document).on('click', ".checkParent", function(){
  436. state[0]["parent_id"] = $(this).data("id");
  437. var target = $(this).closest(".p5bModalModal")
  438. //pathModal(target);
  439. //showPath(state[0]["parent_id"]);
  440. showPath(state[0]["parent_id"], ".pathPreview", false, true);
  441. })
  442. function renderProcesTree(path) {
  443. var result = "";
  444. var link = BASE_URL + "index.php?_route=UrlAction_ProcesEditor&_task=getProcesListAjax";
  445. $.get(link, function(data) {
  446. $('#pathList').jstree("destroy").empty();
  447. //console.log(translate(0, data))
  448. $('#pathList').jstree(
  449. {
  450. 'core': {
  451. "check_callback": true,
  452. "themes": {
  453. "stripes": false,
  454. "dots": false
  455. },
  456. },
  457. "types": {
  458. "default": {
  459. "icon": "hide",
  460. },
  461. "proces": {
  462. "icon": "hide",
  463. },
  464. },
  465. "plugins": [
  466. "contextmenu", "search",
  467. "types"
  468. ],
  469. "contextmenu": {
  470. "items": customMenu
  471. }
  472. });
  473. treeRecursive(data, 0, "#", path)
  474. })
  475. }
  476. function pathModal(target) {
  477. $(target).html("Podgląd: <div style=display:none; class=pathPreview></div>Zaznacz proces nadrzędny: <div id=pathList>"
  478. + "</div>"
  479. + "<button type='button' class='btn btn-primary p5BModalButton' id='savePath'>Zachowaj</button>"
  480. + "<button type='button' class='btn btn-default p5BModalButton' id='previousPath'>Anuluj</button>"
  481. + "");
  482. $("#pathList").data("previous", state[0]["parent_id"])
  483. showPath(state[0]["parent_id"], ".pathPreview", false, true);
  484. }
  485. /* START p5BModal */
  486. function p5BModalDisplay(title, initFunction) {
  487. var back = "<div id='p5BModalBack' style=display:none;></div>"
  488. var modal = "<div class='p5BModalHeader'>" +
  489. "<span>" + title + "</span>" +
  490. "<div class='p5BModalDelete'>X</div>" +
  491. "</div>" +
  492. "<div class=p5BModalContent></div>"
  493. if ($("#p5BModalBack").length <= 0) {
  494. $("body").prepend(back);
  495. $("#p5BModalBack").fadeIn('fast');
  496. $('html, body').css({
  497. overflow: 'hidden',
  498. height: '100%'
  499. });
  500. }
  501. var p5BModal = $("<div>", {
  502. "class": "p5BModalModal"
  503. });
  504. $("#p5BModalBack").append(p5BModal);
  505. $(p5BModal).html(modal);
  506. $(p5BModal).draggable({
  507. containment: "body",
  508. handle: ".p5BModalHeader"
  509. });
  510. initFunction($(p5BModal).find(".p5BModalContent"))
  511. }
  512. $(document).on('click', '.editPath', function() {
  513. p5BModalDisplay("Przepinanie procesu", pathModal);
  514. });
  515. function hideModal(which) {
  516. $(which).remove();
  517. if ($(".p5BModalModal").length == 0) {
  518. $("#p5BModalBack").fadeOut('fast', function() {
  519. $("#p5BModalBack").remove();
  520. });
  521. $('html, body').css({
  522. overflow: 'auto',
  523. height: '100%'
  524. });
  525. }
  526. }
  527. $(document).on('click', '.p5BModalDelete, #previousPath,#p5BModalBack', function() {
  528. if($(this).closest(".p5BModalModal").find("#pathList").length > 0){
  529. state[0]["parent_id"] = $(this).closest(".p5BModalModal").find("#pathList").data("previous")
  530. }
  531. showPath(state[0]["parent_id"]);
  532. hideModal($(this).closest(".p5BModalModal"));
  533. return false;
  534. })
  535. $(document).on('click', '#savePath', function() {
  536. showPath(state[0]["parent_id"]);
  537. hideModal($(this).closest(".p5BModalModal"));
  538. return false;
  539. })
  540. $(document).on('click', '.p5BModalModal', function() {
  541. return false;
  542. })
  543. $(document).on('mousedown', '.p5BModalModal', function() {
  544. $(".p5BModalModal").css("z-index", 2001)
  545. $(this).css("z-index", 2002)
  546. })
  547. /* END p5BModal */
  548. $(document).on('click', '#expBtn', function() {
  549. var exp = {};
  550. exp["id"] = mainProces_id;
  551. exp["time"] = moment().format("YYYY-MM-DD HH:mm:ss");
  552. var temp = {};
  553. temp["state"] = state;
  554. temp["newSteps"] = newSteps;
  555. temp["newRes"] = newRes;
  556. temp["deletedId"] = deletedId;
  557. temp["deletedRes"] = deletedRes;
  558. exp["data"] = temp;
  559. var crc = {};
  560. crc["crc"] = crc32(JSON.stringify(exp));
  561. crc["content"] = exp;
  562. swal({
  563. title: 'Import/Export',
  564. text: 'Wybierz czynność:',
  565. type: 'warning',
  566. cancelButtonText: 'Import',
  567. confirmButtonText: 'Export',
  568. cancelButtonColor: '#d33',
  569. confirmButtonColor: '#3085d6',
  570. showCancelButton: true,
  571. }).then(function() {
  572. saveToXml();
  573. }, function(dismiss) {
  574. if (dismiss === 'cancel') {
  575. swal({
  576. title: 'Import',
  577. text: 'Wklej dane do zaimportowania:',
  578. inputPlaceholder: "Wklej tutaj dane, które otrzymałeś w trakcie eksportu.",
  579. input: 'textarea',
  580. }).then(function(imp) {
  581. var parsed = JSON.parse(imp);
  582. if (crc32(JSON.stringify(parsed["content"])) === parsed["crc"]) {
  583. parsed = parsed["content"];
  584. if (parsed["id"] === mainProces_id) {
  585. $.notify("Dane z " + parsed["time"] + " zaimportowane pozytywnie.", "success");
  586. parsed = parsed["data"];
  587. state = parsed["state"];
  588. newRes = parsed["newRes"];
  589. deletedId = parsed["deletedId"];
  590. deletedRes = parsed["deletedRes"];
  591. updateAll();
  592. } else {
  593. $.notify("Zły proces. Dane do eksportu dotyczą procesu " + parsed["id"] + ".", "error");
  594. }
  595. } else {
  596. $.notify("Suma kontrolna jest nieprawidłowa. Dane uległy uszkodzeniu.", "error");
  597. }
  598. })
  599. }
  600. })
  601. })
  602. function saveProces(){
  603. $("#saveBtn").prop('disabled', true);
  604. $.notify("Rozpoczęto zapisywanie. Nie zamykaj tego okna", "info");
  605. var genReq = `
  606. <Transaction
  607. xmlns="http://www.opengis.net/wfs"
  608. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  609. version="1.0.0"
  610. service="WFS"
  611. xmlns:p5_default_db="` + BASE_WFS_URL + `/default_db"
  612. xmlns:gml="http://www.opengis.net/gml">
  613. `;
  614. // xsi:schemaLocation="` + BASE_WFS_URL + `/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;"
  615. $.each(state, function(i, e) {
  616. if (e['id'] < 0) {
  617. genReq += `
  618. <Insert xmlns="http://www.opengis.net/wfs">
  619. <CRM_PROCES xmlns="` + BASE_WFS_URL + `/default_db">
  620. <PARENT_ID xmlns="` + BASE_WFS_URL + `/default_db">-1</PARENT_ID>
  621. </CRM_PROCES>
  622. </Insert>`;
  623. }
  624. });
  625. genReq += '</Transaction>';
  626. var link = BASE_URL + 'wfs-data.php/default_db/?SERVICE=WFS&VERSION=1.0.0&SRSNAME=EPSG:3003&';
  627. $.ajax({
  628. url: link,
  629. data: genReq,
  630. type: 'POST',
  631. contentType: "text/xml",
  632. dataType: "text",
  633. success: function(data) {
  634. $(data).find("[fid]").each(function(i, e) {
  635. var newId = $(e).attr("fid").substr($(e).attr("fid").indexOf('.') + 1);
  636. generatedId.push(newId);
  637. });
  638. var i = 0;
  639. var newIdTab = Array();
  640. $.each(state, function(z, e) {
  641. if (e["id"] < 0) {
  642. newIdTab[e["id"]] = generatedId[i];
  643. i++;
  644. }
  645. });
  646. var request = `
  647. <Transaction
  648. xmlns="http://www.opengis.net/wfs"
  649. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  650. version="1.0.0"
  651. service="WFS"
  652. xmlns:p5_default_db="` + BASE_WFS_URL + `/default_db"
  653. xmlns:gml="http://www.opengis.net/gml">
  654. `;
  655. $.each(state, function(i, e) {
  656. request += `
  657. <Insert xmlns="http://www.opengis.net/wfs">
  658. <CRM_PROCES xmlns="` + BASE_WFS_URL + `/default_db">
  659. `;
  660. if (e["id"] >= 0)
  661. request += '<ID xmlns="' + BASE_WFS_URL + '/default_db">' + e["id"] + '</ID>';
  662. else
  663. request += '<ID xmlns="' + BASE_WFS_URL + '/default_db">' + newIdTab[e["id"]] + '</ID>';
  664. if (i == 0)
  665. request += '<TYPE xmlns="' + BASE_WFS_URL + '/default_db">PROCES_INIT</TYPE>';
  666. else
  667. request += '<TYPE xmlns="' + BASE_WFS_URL + '/default_db">PROCES</TYPE>';
  668. if (e["parent_id"] >= 0)
  669. request += '<PARENT_ID xmlns="' + BASE_WFS_URL + '/default_db">' + e["parent_id"] + '</PARENT_ID>';
  670. else
  671. request += '<PARENT_ID xmlns="' + BASE_WFS_URL + '/default_db">' + newIdTab[e["parent_id"]] + '</PARENT_ID>';
  672. request += '<SORT_PRIO xmlns="' + BASE_WFS_URL + '/default_db">' + e["SORT_PRIO"] + '</SORT_PRIO>';
  673. if (typeof e["goto"] !== typeof undefined && e["goto"]["id"] !== null && e["goto"]["id"] !== 0 && e["goto"]["id"] !== "") {
  674. request += '<IF_TRUE_GOTO xmlns="' + BASE_WFS_URL + '/default_db">' + e["goto"]["id"] + '</IF_TRUE_GOTO>';
  675. request += '<IF_TRUE_GOTO_FLAG xmlns="' + BASE_WFS_URL + '/default_db">' + e["goto"]["flag"] + '</IF_TRUE_GOTO_FLAG>';
  676. } else {
  677. request += '<IF_TRUE_GOTO xmlns="' + BASE_WFS_URL + '/default_db">0</IF_TRUE_GOTO>';
  678. request += '<IF_TRUE_GOTO_FLAG xmlns="' + BASE_WFS_URL + '/default_db"></IF_TRUE_GOTO_FLAG>';
  679. }
  680. request += '<DESC xmlns="' + BASE_WFS_URL + '/default_db">' + cData(e["desc"]) + '</DESC>';
  681. request += '<OPIS xmlns="' + BASE_WFS_URL + '/default_db">' + cData(e["opis"]) + '</OPIS>';
  682. request += `
  683. </CRM_PROCES>
  684. </Insert>
  685. `;
  686. var id;
  687. if (e["id"] >= 0)
  688. id = e["id"];
  689. else
  690. id = newIdTab[e["id"]];
  691. var sort_prio = 0;
  692. $.each(e["prof"].concat(e["res"]), function(iR, eR) {
  693. sort_prio++;
  694. request += `
  695. <Insert xmlns="http://www.opengis.net/wfs">
  696. <CRM_WSKAZNIK xmlns="` + BASE_WFS_URL + `/default_db">
  697. `;
  698. if (eR["id"] >= 0) {
  699. request += '<ID xmlns="' + BASE_WFS_URL + '/default_db">' + eR["id"] + '</ID>';
  700. }
  701. request += '<ID_ZASOB xmlns="' + BASE_WFS_URL + '/default_db">' + eR["id_zasob"] + '</ID_ZASOB>';
  702. request += '<ID_PROCES xmlns="' + BASE_WFS_URL + '/default_db">' + id + '</ID_PROCES>';
  703. request += '<ID_PRZYPADEK xmlns="' + BASE_WFS_URL + '/default_db">' + eR["id_przypadek"] + '</ID_PRZYPADEK>';
  704. var opis = eR["komentarz"];
  705. opis = opis.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;').replace(/'/g, '&apos;');
  706. request += '<SORT_PRIO xmlns="' + BASE_WFS_URL + '/default_db">' + sort_prio + '</SORT_PRIO>';
  707. request += '<OPIS_ZASOB xmlns="' + BASE_WFS_URL + '/default_db">' + cData(opis) + '</OPIS_ZASOB>';
  708. request += `
  709. </CRM_WSKAZNIK>
  710. </Insert>
  711. `;
  712. });
  713. });
  714. $.each(deletedId, function(key, value) {
  715. if (value < 0)
  716. return true;
  717. request += `
  718. <Insert xmlns="http://www.opengis.net/wfs">
  719. <CRM_PROCES xmlns="` + BASE_WFS_URL + `/default_db">
  720. `;
  721. request += '<ID xmlns="' + BASE_WFS_URL + '/default_db">' + value + '</ID>';
  722. request += '<PARENT_ID xmlns="' + BASE_WFS_URL + '/default_db">-1</PARENT_ID>';
  723. request += '<A_STATUS xmlns="' + BASE_WFS_URL + '/default_db">DELETED</A_STATUS>';
  724. request += `
  725. </CRM_PROCES>
  726. </Insert>
  727. `;
  728. });
  729. $.each(deletedRes, function(key, value) {
  730. if (value < 0)
  731. return true;
  732. request += `
  733. <Insert xmlns="http://www.opengis.net/wfs">
  734. <CRM_WSKAZNIK xmlns="` + BASE_WFS_URL + `/default_db">
  735. `;
  736. request += '<ID xmlns="' + BASE_WFS_URL + '/default_db">' + value + '</ID>';
  737. request += '<A_STATUS xmlns="' + BASE_WFS_URL + '/default_db">DELETED</A_STATUS>';
  738. request += `
  739. </CRM_WSKAZNIK>
  740. </Insert>
  741. `;
  742. });
  743. $.each(usedImg, function(key, value) {
  744. if (key < 0)
  745. return true;
  746. request +=
  747. `
  748. <Insert xmlns="http://www.opengis.net/wfs">
  749. <CRM_IMAGE xmlns="` +
  750. BASE_WFS_URL + `/default_db">
  751. `;
  752. request += '<ID xmlns="' + BASE_WFS_URL + '/default_db">' + key + '</ID>';
  753. request += '<REMOTE_TABLE xmlns="' + BASE_WFS_URL + '/default_db">' + value["type"] + '</REMOTE_TABLE>';
  754. request += '<REMOTE_ID xmlns="' + BASE_WFS_URL + '/default_db">' + value["targetID"] + '</REMOTE_ID>';
  755. request += `
  756. </CRM_IMAGE>
  757. </Insert>
  758. `;
  759. });
  760. request += '</Transaction>';
  761. $.ajax({
  762. url: link,
  763. data: request,
  764. type: 'POST',
  765. contentType: "text/xml",
  766. dataType: "text",
  767. success: function(data) {
  768. if ($(data).children("serviceException").text() == "") {
  769. if (mainProces_id == -1)
  770. window.location.replace("index.php?_route=UrlAction_procesEditor&id=" + newIdTab[state[0]["id"]])
  771. deletedRes = [];
  772. deletedId = [];
  773. usedImg = {};
  774. localStorage.removeItem("state" + mainProces_id);
  775. showPreview();
  776. $.notify("Zmiany zostały zapisane na serwerze.", "success");
  777. } else {
  778. $.notify("Błąd API. Zmiany zostały zapisane wyłącznie w pamięci Twojej przeglądarki. Skontaktuj się z administratorem.", "error");
  779. localStorage.setItem("state" + mainProces_id, JSON.stringify(state));
  780. localStorage.setItem("newStep" + mainProces_id, newSteps);
  781. localStorage.setItem("newRes" + mainProces_id, newRes);
  782. localStorage.setItem("deletedId" + mainProces_id, JSON.stringify(deletedId));
  783. localStorage.setItem("usedImg" + mainProces_id, JSON.stringify(usedImg));
  784. localStorage.setItem("deletedRes" + mainProces_id, JSON.stringify(deletedRes));
  785. localStorage.setItem("date" + mainProces_id, moment().format("YYYY-MM-DD HH:mm:ss"));
  786. }
  787. $("#saveBtn").prop('disabled', false);
  788. },
  789. error: function(xhr, ajaxOptions, thrownError) {
  790. $.notify("Brak połączenia z bazą danych", "error");
  791. }
  792. });
  793. },
  794. error: function(xhr, ajaxOptions, thrownError) {
  795. $.notify("Brak połączenia z bazą danych", "error");
  796. }
  797. });
  798. }
  799. $(document).on('click', '#saveBtn', function() {
  800. if(state[0]["parent_id"] <= 0)
  801. swal({
  802. title: 'Brak procesu nadrzędnego',
  803. text: "proces_init nie został przypięty do żadnego nadrzędnego procesu.",
  804. type: 'error',
  805. showCancelButton: true,
  806. cancelButtonColor: '#3085d6',
  807. confirmButtonColor: '#d33',
  808. cancelButtonText: "Edytuj ścieżkę <i style=color:#00cc00;font-weight:bold;>[ZALECANE]</span>",
  809. confirmButtonText: 'Kontynuuj'
  810. }).then(function() {
  811. saveProces();
  812. }, function (dismiss) {
  813. p5BModalDisplay("Przepinanie procesu", pathModal);
  814. }
  815. ).catch(function(e) {})
  816. else
  817. saveProces();
  818. });
  819. $(document).on('click', '.btnEdit', function() {
  820. var parentIndex = getIndexById($(this).parents(".drop").data("id"));
  821. var type;
  822. if ($(this).parents("li").closest(".professions").length > 0)
  823. type = "prof";
  824. else
  825. type = "res";
  826. var zasobIndex = getResById(parentIndex, $(this).parents("li").data("id"), type);
  827. var permsOpt = "";
  828. $.each(perms, function(key, value) {
  829. if (state[parentIndex][type][zasobIndex]["id_przypadek"] == value[0])
  830. permsOpt = permsOpt + "<option value=" + value[0] + " selected=selected>[" + value[2] + "] " + value[1] + "</option>";
  831. else
  832. permsOpt = permsOpt + "<option value=" + value[0] + ">[" + value[2] + "] " + value[1] + "</option>";
  833. });
  834. swal({
  835. showCancelButton: true,
  836. title: 'Uprawnienia',
  837. html: 'Uprawnienia<br><select class=form-control id="swal-input1">' + permsOpt + '</select>' +
  838. 'Komentarz<br><input class=form-control id="swal-input2" class="swal2-input" value="' + state[parentIndex][type][zasobIndex]["komentarz"] + '">',
  839. preConfirm: function() {
  840. return new Promise(function(resolve) {
  841. resolve([
  842. $('#swal-input1').val(),
  843. $('#swal-input2').val()
  844. ]);
  845. });
  846. }
  847. }).then(function(result) {
  848. state[parentIndex][type][zasobIndex]["id_przypadek"] = result[0];
  849. state[parentIndex][type][zasobIndex]["komentarz"] = result[1];
  850. state[parentIndex][type][zasobIndex]["changed"] = true;
  851. updateAll();
  852. }).catch(function(e) {})
  853. });
  854. //Buttony i ich zadania
  855. $(document).on('click', '.step', function() {
  856. newSteps--;
  857. var main = false;
  858. var temp = {};
  859. if ($(this).parents(".drop").data("id") === mainProces_id)
  860. main = true;
  861. $(this).parents(".drop").after("<div class='drop container-fluid' id='proc" + newSteps + "'></div>");
  862. temp["id"] = newSteps;
  863. temp["desc"] = "";
  864. temp["opis"] = "";
  865. var index = getIndexById($(this).parents(".drop").data("id"));
  866. temp["step"] = 0;
  867. temp["prof"] = new Array();
  868. temp["res"] = new Array();
  869. temp["C-desc"] = true;
  870. temp["C-opis"] = true;
  871. temp["goto"] = {}
  872. temp["goto"]["flag"] = "";
  873. temp["goto"]["id"] = 0;
  874. temp["stepDesc"] = "";
  875. if (!main) {
  876. temp["parent_id"] = state[index]["parent_id"];
  877. temp["depth"] = state[index]["depth"];
  878. } else {
  879. temp["parent_id"] = mainProces_id;
  880. temp["depth"] = 1;
  881. }
  882. state.splice(index + 1, 0, temp);
  883. stepsGenerator();
  884. updateAll();
  885. });
  886. $(document).on('keyup', '#sProcesy', function() {
  887. if ($(this).val() != lastSearch) {
  888. lastSearch = $(this).val();
  889. clearTimeout(sProcesy);
  890. sProcesy = setTimeout(function() {
  891. if (lastSearch == "")
  892. procesy();
  893. else
  894. searchProc();
  895. }, 300);
  896. }
  897. });
  898. $(document).on('keyup', '#sZasoby', function() {
  899. if ($(this).val() != lastSearch) {
  900. lastSearch = $(this).val();
  901. clearTimeout(sZasoby);
  902. sZasoby = setTimeout(function() {
  903. if (filtr === 0 && lastSearch == "")
  904. zasoby();
  905. else
  906. searchRes();
  907. }, 300);
  908. }
  909. });
  910. function arraymove(arr, fromIndex, toIndex) {
  911. var element = [];
  912. var element = arr[fromIndex];
  913. arr.splice(fromIndex, 1);
  914. arr.splice(toIndex, 0, element);
  915. }
  916. $(document).on('click', '.uArrowRes', function() {
  917. var parent = getIndexById(($(this).parents(".drop").data("id")));
  918. if ($(this).closest(".professions").length > 0)
  919. type = "prof";
  920. else
  921. type = "res";
  922. var id = getResById(parent, $(this).closest("li").data("id"), type);
  923. arraymove(state[parent][type], id, id - 1);
  924. updateAll();
  925. });
  926. $(document).on('click', '.dArrowRes', function() {
  927. var parent = getIndexById(($(this).parents(".drop").data("id")));
  928. if ($(this).closest(".professions").length > 0)
  929. type = "prof";
  930. else
  931. type = "res";
  932. var id = getResById(parent, $(this).closest("li").data("id"), type);
  933. arraymove(state[parent][type], id, id + 1);
  934. updateAll();
  935. });
  936. $(document).on('click', '.uArrow', function() {
  937. var id = $(this).parents(".drop").data("id");
  938. var index = getIndexById(id);
  939. arraymove(state, index, index - 1);
  940. updateAll();
  941. });
  942. $(document).on('click', '.dArrow', function() {
  943. var id = $(this).parents(".drop").data("id");
  944. var index = getIndexById(id);
  945. arraymove(state, index, index + 1);
  946. updateAll();
  947. });
  948. $(document).on('click', '.rArrow', function() {
  949. var id = $(this).parents(".drop").data("id");
  950. state[getIndexById(id)]["depth"]++;
  951. //var depthWidth = 20 * $(node).data("depth");
  952. // $(node).css("padding-left", depthWidth + "px");
  953. updateAll();
  954. });
  955. $(document).on('click', '.lArrow', function() {
  956. var id = $(this).parents(".drop").data("id");
  957. state[getIndexById(id)]["depth"]--;
  958. //var depthWidth = 20 * $(node).data("depth");
  959. // $(node).css("padding-left", depthWidth + "px");
  960. updateAll();
  961. });
  962. $(document).on('click', '#btnZasoby', function(e) {
  963. e.preventDefault();
  964. $(".lButton").removeClass("btn-primary");
  965. if (dialog == 0) {
  966. zasoby();
  967. $(this).addClass("btn-primary");
  968. $("#wrapper").removeClass("toggled");
  969. dialog = 1;
  970. } else if (dialog == 1) {
  971. $("#wrapper").addClass("toggled");
  972. dialog = 0;
  973. } else {
  974. $("#wrapper").addClass("toggled");
  975. $(this).addClass("btn-primary");
  976. setTimeout(function() {
  977. zasoby();
  978. $("#wrapper").removeClass("toggled");
  979. }, 500);
  980. dialog = 1;
  981. }
  982. });
  983. $(document).on('click', '#btnPhotos', function(e) {
  984. e.preventDefault();
  985. $(".lButton").removeClass("btn-primary");
  986. if (dialog == 0) {
  987. photos();
  988. $(this).addClass("btn-primary");
  989. $("#wrapper").removeClass("toggled");
  990. dialog = 3;
  991. } else if (dialog == 3) {
  992. $("#wrapper").addClass("toggled");
  993. dialog = 0;
  994. } else {
  995. $("#wrapper").addClass("toggled");
  996. $(this).addClass("btn-primary");
  997. setTimeout(function() {
  998. photos();
  999. $("#wrapper").removeClass("toggled");
  1000. }, 500);
  1001. dialog = 3;
  1002. }
  1003. });
  1004. $(document).on('click', '#btnProcesy', function(e) {
  1005. e.preventDefault();
  1006. $(".lButton").removeClass("btn-primary");
  1007. if (dialog == 0) {
  1008. procesy();
  1009. $("#wrapper").removeClass("toggled");
  1010. $(this).addClass("btn-primary");
  1011. dialog = 2;
  1012. } else if (dialog == 2) {
  1013. $("#wrapper").addClass("toggled");
  1014. dialog = 0;
  1015. } else {
  1016. $("#wrapper").addClass("toggled");
  1017. $(this).addClass("btn-primary");
  1018. setTimeout(function() {
  1019. procesy();
  1020. $("#wrapper").removeClass("toggled");
  1021. }, 500);
  1022. dialog = 2;
  1023. }
  1024. });
  1025. $(document).on('click', 'body', function() {
  1026. if (selectedArea != false) {
  1027. var content = $(selectedArea).val();
  1028. var id = (selectedArea).parents(".drop").data("id");
  1029. if ($(selectedArea).parent().hasClass("hdesc")) {
  1030. if(getIndexById(id) == 0){
  1031. showPath(state[0]["parent_id"]);
  1032. }
  1033. state[getIndexById(id)]["desc"] = content;
  1034. state[getIndexById(id)]["C-desc"] = true;
  1035. }
  1036. if ($(selectedArea).parent().hasClass("sdesc")) {
  1037. state[getIndexById(id)]["opis"] = content;
  1038. state[getIndexById(id)]["C-opis"] = true;
  1039. }
  1040. selectedArea = false;
  1041. updateAll();
  1042. }
  1043. });
  1044. $(document).on('click', '.hdesc', function() {
  1045. if ($(this).find("textarea").is(selectedArea))
  1046. return false;
  1047. });
  1048. $(document).on('click', '.sdesc', function() {
  1049. if ($(this).find("textarea").is(selectedArea))
  1050. return false;
  1051. });
  1052. $(document).on('dblclick', '.sdesc', function() {
  1053. if (selectedArea)
  1054. return;
  1055. if ($(this).find("textarea").length == 0) {
  1056. var content = $(this).html();
  1057. $(this).empty();
  1058. $(this).append("<textarea>" + content + "</textarea>");
  1059. selectedArea = $(this).find("textarea");
  1060. }
  1061. });
  1062. $(document).on('click', '.sDescAdd', function() {
  1063. if (selectedArea)
  1064. return;
  1065. var action = $(this).parents(".drop").find(".sdesc");
  1066. if ($(action).find("textarea").length == 0) {
  1067. $(action).html("<textarea placeholder='Opis kroku'>" + $(action).text() + "</textarea>");
  1068. selectedArea = $(action).find("textarea");
  1069. return false;
  1070. }
  1071. });
  1072. $(document).on('click', '.hDescAdd', function() {
  1073. if (selectedArea)
  1074. return;
  1075. var action = $(this).parents(".drop").find(".hdesc");
  1076. if ($(action).find("textarea").length == 0) {
  1077. $(action).html("<textarea placeholder='Tytuł kroku'>" + $(action).text() + "</textarea>");
  1078. selectedArea = $(action).find("textarea");
  1079. return false;
  1080. }
  1081. });
  1082. $(document).on('dblclick', '.hdesc', function() {
  1083. if ($(this).find("textarea").length == 0) {
  1084. var content = $(this).html();
  1085. $(this).empty();
  1086. $(this).append("<textarea>" + content + "</textarea>");
  1087. selectedArea = $(this).find("textarea");
  1088. }
  1089. });
  1090. $(document).on('click', '.del', function() {
  1091. var id = $(this).parents(".drop").data("id");
  1092. var index = getIndexById(id);
  1093. swal({
  1094. title: 'Usuwanie kroku',
  1095. text: "Czy napewno chcesz usunąć ten krok?",
  1096. type: 'warning',
  1097. showCancelButton: true,
  1098. confirmButtonColor: '#3085d6',
  1099. cancelButtonColor: '#d33',
  1100. cancelButtonText: "Anuluj",
  1101. confirmButtonText: 'Tak, usuń ten krok'
  1102. }).then(function() {
  1103. state.splice(index, 1);
  1104. deletedId.push(id);
  1105. updateAll();
  1106. //Parent_id = -1,
  1107. }).catch(function(e) {})
  1108. });
  1109. $(document).on('click', '.delGoto', function() {
  1110. //var parent = $(this).parents(".drop");
  1111. var id = $(this).parents("li").data("id");
  1112. var parent = getIndexById($(this).parents(".drop").data("id"));
  1113. swal({
  1114. title: 'Usuwanie bramki',
  1115. text: "Czy napewno chcesz usunąć tę bramkę?",
  1116. type: 'warning',
  1117. showCancelButton: true,
  1118. confirmButtonColor: '#3085d6',
  1119. cancelButtonColor: '#d33',
  1120. cancelButtonText: "Anuluj",
  1121. confirmButtonText: 'Tak, usuń tę bramkę'
  1122. }).then(function() {
  1123. state[parent]["goto"] = {
  1124. id: "",
  1125. flag: ""
  1126. };
  1127. updateAll();
  1128. //Parent_id = -1,
  1129. }).catch(function(e) {})
  1130. });
  1131. $(document).on('click', '.delRes', function() {
  1132. //var parent = $(this).parents(".drop");
  1133. var id = $(this).parents("li").data("id");
  1134. var parent = getIndexById($(this).parents(".drop").data("id"));
  1135. var type;
  1136. if ($(this).closest(".professions").length > 0)
  1137. type = "prof";
  1138. else
  1139. type = "res";
  1140. var index = getResById(parent, id, type);
  1141. swal({
  1142. title: 'Usuwanie wskaźnika',
  1143. text: "Czy napewno chcesz usunąć ten wskaźnik?",
  1144. type: 'warning',
  1145. showCancelButton: true,
  1146. confirmButtonColor: '#3085d6',
  1147. cancelButtonColor: '#d33',
  1148. cancelButtonText: "Anuluj",
  1149. confirmButtonText: 'Tak, usuń ten wskaźnik'
  1150. }).then(function() {
  1151. deletedRes.push(id);
  1152. state[parent][type].splice(index, 1);
  1153. updateAll();
  1154. //Parent_id = -1,
  1155. }).catch(function(e) {})
  1156. });
  1157. $(document).on('click', '.fbutton', function(e) {
  1158. e.preventDefault();
  1159. $(".fbutton").removeClass("btn-success");
  1160. if ($(this).data("type") == filtr) {
  1161. filtr = 0;
  1162. } else {
  1163. filtr = $(this).data("type");
  1164. $(this).addClass("btn-success");
  1165. }
  1166. if (filtr === 0)
  1167. $("#xBtn").prop("disabled", true);
  1168. else
  1169. $("#xBtn").prop("disabled", false);
  1170. if (filtr === 0) {
  1171. zasoby();
  1172. } else
  1173. searchRes();
  1174. });
  1175. $(document).on('click', '.showMore', function() {
  1176. var target = $(this).parent().find(".more");
  1177. var id = $(this).data("id");
  1178. if ($(target).parent().hasClass("resSelected")) {
  1179. $(".more").empty();
  1180. $(target).parent().removeClass("resSelected");
  1181. $(target).parent().find(".gIco").addClass("glyphicon-chevron-down");
  1182. $(target).parent().find(".gIco").removeClass("glyphicon-chevron-up");
  1183. } else {
  1184. $(".more").parent().removeClass("resSelected");
  1185. $(".more").parent().find(".gIco").addClass("glyphicon-chevron-down");
  1186. $(".more").parent().find(".gIco").removeClass("glyphicon-chevron-up");
  1187. $(".more").empty();
  1188. $(target).parent().addClass("resSelected");
  1189. $(target).parent().find(".gIco").removeClass("glyphicon-chevron-down");
  1190. $(target).parent().find(".gIco").addClass("glyphicon-chevron-up");
  1191. var link = BASE_URL + "index.php?_route=UrlAction_ProcesEditor&_task=getResByParentAjax&parent_id=" + id;
  1192. $.get(link, function(data) {
  1193. $.each(data, function(i, e) {
  1194. if (e["ID"] != 0) {
  1195. var type = 0;
  1196. $(target).append("<div class='dragStyle drag dragStyle hov' data-id=" + e["ID"] + " data-type=" + type + " data-desc='" + e["DESC"] + "' data-opis='" + e["OPIS"] + "'>" + e["DESC"] + " [" + e["ID"] + "]</div>");
  1197. for (var i = 3; i > 0; i--) {
  1198. if (e["p" + i + "_ID"] != null) {
  1199. var temp = {};
  1200. temp["ID"] = e["p" + i + "_ID"];
  1201. temp["DESC"] = e["p" + i + "_DESC"];
  1202. zasobTree[e["ID"]] = [];
  1203. zasobTree[e["ID"]].push(temp);
  1204. }
  1205. }
  1206. $('.drag').draggable({
  1207. appendTo: 'body',
  1208. helper: 'clone',
  1209. stack: "div",
  1210. distance: 0,
  1211. cursor: "copy",
  1212. start: function(event, ui) {
  1213. $(this).data("startingScrollTop", $(this).parent().scrollTop());
  1214. },
  1215. drag: function(event, ui) {
  1216. var st = parseInt($(this).data("startingScrollTop"));
  1217. ui.position.top -= $(document).scrollTop() - st;
  1218. ui.helper.css('z-index', 1000);
  1219. }
  1220. });
  1221. }
  1222. });
  1223. });
  1224. }
  1225. });
  1226. function searchProc() {
  1227. var id = lastSearch;
  1228. var link;
  1229. 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';
  1230. $.get(link, function(data) {
  1231. var side = $("#side");
  1232. $(side).find("#ulproc").empty();
  1233. $.each($(data).find("featureMember"), function() {
  1234. if ($(this).find("ID").text() * 1 == 0) {
  1235. $(side).find("#ulcon").append("<div><center>Brak wyników wyszukiwania</center></div>");
  1236. return;
  1237. }
  1238. $(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>");
  1239. $('.drag').draggable({
  1240. appendTo: 'body',
  1241. helper: 'clone',
  1242. stack: "div",
  1243. distance: 0,
  1244. cursor: "copy",
  1245. start: function(event, ui) {
  1246. $(this).data("startingScrollTop", $(this).parent().scrollTop());
  1247. },
  1248. drag: function(event, ui) {
  1249. var st = parseInt($(this).data("startingScrollTop"));
  1250. ui.position.top -= $(document).scrollTop() - st;
  1251. ui.helper.css('z-index', 1000);
  1252. }
  1253. });
  1254. });
  1255. });
  1256. }
  1257. function searchRes() {
  1258. var id = lastSearch;
  1259. var link;
  1260. link = BASE_URL + "index.php?_route=UrlAction_ProcesEditor&_task=getResAjax&word=" + id + "&filter=" + filtr;
  1261. $.get(link, function(data) {
  1262. var side = $("#side");
  1263. $(side).find("#ulcon").empty();
  1264. if (data.length == 0)
  1265. $(side).find("#ulcon").append("<div><center>Brak wyników wyszukiwania</center></div>");
  1266. $.each(data, function(i, e) {
  1267. var tree = "";
  1268. for (var i = 3; i > 0; i--) {
  1269. if (e["p" + i + "_ID"] != null) {
  1270. var temp = {};
  1271. temp["ID"] = e["p" + i + "_ID"];
  1272. temp["DESC"] = e["p" + i + "_DESC"];
  1273. zasobTree[e["ID"]] = [];
  1274. zasobTree[e["ID"]].push(temp);
  1275. tree += e["p" + i + "_DESC"] + (i > 1 ? " <span class='glyphicon glyphicon-triangle-right'></span>" : "");
  1276. }
  1277. }
  1278. var type = 0;
  1279. if (e["TYPE"] == "DZIAL" || e["TYPE"] == "PODMIOT" || e["TYPE"] == "STANOWISKO")
  1280. type = 1;
  1281. if (filtr != 2 || e["TYPE"] != "TABELA")
  1282. $(side).find("#ulcon").append("<div class='drag dragStyle hov' data-id=" + e["ID"] + " data-type=" + type + " data-desc='" + e["DESC"] + "' data-opis='" + e["OPIS"] + "'><span class=treeInfo ><div>" + tree + "</div></span><br>" + e["DESC"] + " [" + e["ID"] + "]</div>");
  1283. else {
  1284. $(side).find("#ulcon").append("<div ><span class='drag dragStyle click' data-id=" + e["ID"] + " data-type=" + type + " data-desc='" + e["DESC"] + "' data-opis='" + e["OPIS"] + "'> # </span> <div style=width:80%;float:left; data-id=" + e["ID"] + " class=showMore><span class=tabelaName><span class=treeInfo ><div>" + tree + "</div></span><br>" + e["DESC"] + "</span> [" + e["ID"] + "]</div><span class='gIco glyphicon glyphicon-chevron-down' style:float:left;></span><div style=clear:both;></div><div class=more ></div></div>");
  1285. }
  1286. });
  1287. $('.drag').draggable({
  1288. appendTo: 'body',
  1289. helper: 'clone',
  1290. stack: "div",
  1291. distance: 0,
  1292. cursor: "copy",
  1293. start: function(event, ui) {
  1294. $(this).data("startingScrollTop", $(this).parent().scrollTop());
  1295. },
  1296. drag: function(event, ui) {
  1297. var st = parseInt($(this).data("startingScrollTop"));
  1298. ui.position.top -= $(document).scrollTop() - st;
  1299. ui.helper.css('z-index', 1000);
  1300. }
  1301. });
  1302. $(".drop").droppable({
  1303. tolerance: 'pointer',
  1304. accept: '.drag',
  1305. hoverClass: "activeDrop",
  1306. drop: function(event, ui) {
  1307. if (ui.draggable.data("dropType") == 1)
  1308. addProces(ui, this);
  1309. else
  1310. addResource(ui, this);
  1311. }
  1312. });
  1313. });
  1314. }
  1315. $(document).on('click', '.liProc', function() {
  1316. $(this).parents(".singleAdv").nextAll(".singleAdv").remove();
  1317. $(this).parents(".singleAdv").find(".active").removeClass("active");
  1318. $(this).find(".glyphicon").removeClass("glyphicon-triangle-right");
  1319. $(this).find(".glyphicon").addClass("glyphicon-refresh");
  1320. $(this).find(".glyphicon").addClass("anim-refresh");
  1321. $(this).addClass("active");
  1322. var parent = this;
  1323. var parent_id = $(this).data("id");
  1324. 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>';
  1325. var result = "";
  1326. var depth = $(this).parents(".singleAdv").data("depth") + 1;
  1327. $("#procCon").css("width", depth * 290 + 290);
  1328. $(this).parents(".singleAdv").after("<div class='singleAdv list-group' data-depth=" + depth + " id=depth" + depth + "></div>");
  1329. var childs = true;
  1330. $.get(link, function(data) {
  1331. $(data).find("featureMember").each(function() {
  1332. if ($(this).find("ID").text() == 0) {
  1333. childs = false;
  1334. return;
  1335. }
  1336. var type = 0;
  1337. 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>";
  1338. });
  1339. if (!childs) {
  1340. result += '<div class="panel panel-primary">';
  1341. result += '<div class="panel-heading"><h3 class="panel-title">[' + $(parent).data('id') + '] ' + $(parent).data("desc") + '</h3></div>';
  1342. result += '<div class="panel-body pbody">';
  1343. result += '<b>Opis: </b>' + $(parent).data("opis");
  1344. result += '</div>';
  1345. result += '</div>'
  1346. }
  1347. $("#depth" + depth).html(result);
  1348. $('.drag').draggable({
  1349. appendTo: 'body',
  1350. handle: '.handle',
  1351. helper: 'clone',
  1352. stack: "div",
  1353. distance: 0,
  1354. cursor: "copy",
  1355. start: function(event, ui) {
  1356. $(this).data("startingScrollTop", $(this).parent().scrollTop());
  1357. },
  1358. drag: function(event, ui) {
  1359. var st = parseInt($(this).data("startingScrollTop"));
  1360. ui.position.top -= $(document).scrollTop() - st;
  1361. ui.helper.css('z-index', 1000);
  1362. }
  1363. });
  1364. $(parent).find(".glyphicon").addClass("glyphicon-triangle-right");
  1365. $(parent).find(".glyphicon").removeClass("glyphicon-refresh");
  1366. $(parent).find(".glyphicon").removeClass("anim-refresh");
  1367. $("#ulproc").scrollLeft(depth * 290 + 290);
  1368. $("#ulproc").scrollTop(0);
  1369. });
  1370. });
  1371. function procesy() {
  1372. var side = $("#side");
  1373. $(side).empty();
  1374. //$(side).append("<h3>Zarządzaj zasobami<h3>");
  1375. $(side).append("<div class='form-group' ><input type='text' class=form-control id=sProcesy placeholder='Szukaj procesów'></div>");
  1376. $(side).append("<div id=ulproc><div id=procCon></div></div>");
  1377. $(side).find("#procCon").append("<div class='singleAdv list-group' data-depth=0 id=depth0></div>");
  1378. $(side).find("#procCon").append("<div class=clearfix></div>");
  1379. 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';
  1380. var result = "";
  1381. $.get(link, function(data) {
  1382. $(data).find("featureMember").each(function() {
  1383. var type = 0;
  1384. 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() + " >";
  1385. result += "<div class=textTable><span class=handle> # </span>";
  1386. result += $(this).find("DESC").text()
  1387. result += "</div><div class=detailsTable> [" + $(this).find("ID").text() + "]</div>";
  1388. result += "<div class='glyphicon glyphicon-triangle-right' style=opacity:0.4;float:right;></div><div class=clearfix></div></div>";
  1389. });
  1390. $("#depth0").html(result);
  1391. $('.drag').draggable({
  1392. appendTo: 'body',
  1393. handle: '.handle',
  1394. helper: 'clone',
  1395. stack: "div",
  1396. distance: 0,
  1397. cursor: "copy",
  1398. start: function(event, ui) {
  1399. $(this).data("startingScrollTop", $(this).parent().scrollTop());
  1400. },
  1401. drag: function(event, ui) {
  1402. var st = parseInt($(this).data("startingScrollTop"));
  1403. ui.position.top -= $(document).scrollTop() - st;
  1404. ui.helper.css('z-index', 1000);
  1405. }
  1406. });
  1407. });
  1408. }
  1409. $(document).on('click', '.liAdv', function() {
  1410. $(this).find(".glyphicon").removeClass("glyphicon-triangle-right");
  1411. $(this).find(".glyphicon").addClass("glyphicon-refresh");
  1412. $(this).parents(".singleAdv").nextAll(".singleAdv").remove();
  1413. $(this).parents(".singleAdv").find(".active").removeClass("active");
  1414. $(this).addClass("active");
  1415. var parent = this;
  1416. var parent_id = $(this).data("id");
  1417. 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';
  1418. var result = "";
  1419. var depth = $(this).parents(".singleAdv").data("depth") + 1;
  1420. $("#advCon").css("width", depth * 290 + 290);
  1421. $(this).parents(".singleAdv").after("<div class='singleAdv list-group' data-depth=" + depth + " id=depth" + depth + "></div>");
  1422. var childs = true;
  1423. $.get(link, function(data) {
  1424. $(data).find("featureMember").each(function() {
  1425. if ($(this).find("ID").text() == 0) {
  1426. childs = false;
  1427. return;
  1428. }
  1429. var type = 0;
  1430. if ($(this).find("TYPE").text() == "DZIAL" || $(this).find("TYPE").text() == "PODMIOT" || $(this).find("TYPE").text() == "STANOWISKO")
  1431. type = 1;
  1432. 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>";
  1433. result += "<div class='glyphicon glyphicon-triangle-right' style=opacity:0.4;float:right;></div>";
  1434. result += "<div class=clearfix></div><div class=detailsTable2>[" + $(this).find("ID").text() + "] " + $(this).find("TYPE").text() + "</div></div>";
  1435. });
  1436. if (!childs) {
  1437. result += '<div class="panel panel-primary">';
  1438. result += '<div class="panel-heading"><h3 class="panel-title">[' + $(parent).data('id') + '] ' + $(parent).data("desc") + '</h3></div>';
  1439. result += '<div class="panel-body pbody">';
  1440. result += '<b>Opis: </b>' + $(parent).data("opis");
  1441. result += '<br><b>Typ: </b>' + $(parent).data("typename");
  1442. result += '</div>';
  1443. result += '</div>'
  1444. }
  1445. $("#depth" + depth).html(result);
  1446. $('.drag').draggable({
  1447. appendTo: 'body',
  1448. handle: '.handle',
  1449. helper: 'clone',
  1450. stack: "div",
  1451. distance: 0,
  1452. cursor: "copy",
  1453. start: function(event, ui) {
  1454. $(this).data("startingScrollTop", $(this).parent().scrollTop());
  1455. },
  1456. drag: function(event, ui) {
  1457. var st = parseInt($(this).data("startingScrollTop"));
  1458. ui.position.top -= $(document).scrollTop() - st;
  1459. ui.helper.css('z-index', 1000);
  1460. }
  1461. });
  1462. $(parent).find(".glyphicon").addClass("glyphicon-triangle-right");
  1463. $(parent).find(".glyphicon").removeClass("glyphicon-refresh");
  1464. $("#ulcon").scrollLeft(depth * 290 + 290);
  1465. $("#ulcon").scrollTop(0);
  1466. });
  1467. });
  1468. function getImg(el) {
  1469. var name = el.files[0].name;
  1470. var size = el.files[0].size;
  1471. var type = el.files[0].type;
  1472. var link = BASE_URL + "wfs-data.php/default_db/?SERVICE=WFS&VERSION=1.0.0&SRSNAME=EPSG:3003";
  1473. var FR = new FileReader();
  1474. FR.onload = function(e) {
  1475. var content = e.target.result;
  1476. var image = new Image();
  1477. image.src = content;
  1478. image.onload = function() {
  1479. var width = el.width;
  1480. var height = el.height;
  1481. var xml =
  1482. `
  1483. <Transaction
  1484. xmlns="http://www.opengis.net/wfs"
  1485. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  1486. version="1.0.0"
  1487. service="WFS"
  1488. xmlns:p5_default_db="` + BASE_WFS_URL + `/default_db"
  1489. xmlns:gml="http://www.opengis.net/gml">
  1490. <Insert xmlns="http://www.opengis.net/wfs">
  1491. <CRM_IMAGE xmlns="` + BASE_WFS_URL + `/default_db">
  1492. <NAME xmlns="` + BASE_WFS_URL + `/default_db">` + name + `</NAME>
  1493. <IMAGE xmlns="` + BASE_WFS_URL + `/default_db">` + content + `</IMAGE>
  1494. <TYPE xmlns="` + BASE_WFS_URL + `/default_db">` + type + `</TYPE>
  1495. <SIZE xmlns="` + BASE_WFS_URL + `/default_db">` + size + `</SIZE>
  1496. <WIDTH xmlns="` + BASE_WFS_URL + `/default_db">` + width + `</WIDTH>
  1497. <HEIGHT xmlns="` + BASE_WFS_URL + `/default_db">` + height + `</HEIGHT>
  1498. <REMOTE_TABLE xmlns="` + BASE_WFS_URL + `/default_db">ADMIN_USERS</REMOTE_TABLE>
  1499. <REMOTE_ID xmlns="` + BASE_WFS_URL + `/default_db">` + USER_ID + `</REMOTE_ID>
  1500. </CRM_IMAGE>
  1501. </Insert>
  1502. </Transaction>`;
  1503. $.ajax({
  1504. url: link,
  1505. data: xml,
  1506. type: 'POST',
  1507. contentType: "text/xml",
  1508. dataType: "xml",
  1509. success: function(data) {
  1510. if ($(data).find("ServiceException").text() != "") {
  1511. $.notify($(data).find("ServiceException").text(), "error");
  1512. } else {
  1513. photos();
  1514. }
  1515. }
  1516. });
  1517. }
  1518. };
  1519. FR.readAsDataURL(el.files[0]);
  1520. }
  1521. function humanFileSize(bytes) {
  1522. var thresh = 1024;
  1523. if (Math.abs(bytes) < thresh) {
  1524. return bytes + ' B';
  1525. }
  1526. var units = ['kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']
  1527. var u = -1;
  1528. do {
  1529. bytes /= thresh;
  1530. ++u;
  1531. } while (Math.abs(bytes) >= thresh && u < units.length - 1);
  1532. return bytes.toFixed(1) + ' ' + units[u];
  1533. }
  1534. function uploadForm() {
  1535. var form = '<input id="fileupload" type="file" name="files[]" data-url="index.php?_route=UrlAction_procesEditor&_task=uploadVideo" multiple>' +
  1536. "<div id='upload_info'></div>" +
  1537. "<button style=width:100%; type='button' class='btn btn-default' id=upload_button>Umieść na serwerze</button>"
  1538. return form;
  1539. }
  1540. function photos() {
  1541. var side = $("#side");
  1542. $(side).empty();
  1543. $(side).append(uploadForm());
  1544. $('#upload_progress').css(
  1545. 'opacity',
  1546. 0
  1547. );
  1548. $('#fileupload').fileupload({
  1549. dataType: 'html',
  1550. add: function(e, data) {
  1551. $("#upload_button").off('click').on('click', function() {
  1552. data.submit();
  1553. });
  1554. var html = '<span class=upload_status></span>'
  1555. html += '<div class="progress" id=upload_progress>' +
  1556. '<div class="progress-bar" role="progressbar" aria-valuenow="0"' +
  1557. 'aria-valuemin="0" aria-valuemax="100" style="width:0%">' +
  1558. '<span>70%</span>' +
  1559. '</div>' +
  1560. '</div>'
  1561. $("#upload_info").html(html);
  1562. },
  1563. done: function(e, data) {
  1564. $('#upload_progress').css(
  1565. 'opacity',
  1566. 0
  1567. );
  1568. loadClipboard();
  1569. },
  1570. progressall: function(e, data) {
  1571. var progress = parseInt(data.loaded / data.total * 100, 10);
  1572. $('#upload_progress').find(".progress-bar").css(
  1573. 'width',
  1574. progress + '%'
  1575. );
  1576. var remaining = Math.ceil((data.total - data.loaded) * 8 / data.bitrate);
  1577. $('#upload_progress').find(".progress-bar").find("span").text(progress + '%');
  1578. var total = humanFileSize(data.total);
  1579. var bitrate = humanFileSize(data.bitrate / 10)
  1580. var loaded = humanFileSize(data.loaded);
  1581. $('#upload_info').find(".upload_status").text(loaded + "/" + total + " - pozostało " + remaining + " sekund [" + bitrate + "/s]");
  1582. }
  1583. });
  1584. var schowek = '<ul class="list-group" id=clipboard>';
  1585. schowek += '</ul>';
  1586. $(side).append(schowek);
  1587. loadClipboard();
  1588. }
  1589. function showVideo(data) {
  1590. var el = ""
  1591. return el;
  1592. }
  1593. function showMediaElement(data, type) {
  1594. var el = ""
  1595. if (type == "video") {
  1596. //el += "<div class=attVid><div class=remImg>X</div>"
  1597. el += "<div class=attVid><div class=imgTitle><i class='glyphicon glyphicon-option-vertical'></i>"
  1598. el += data["NAME"]
  1599. el += "</div>"
  1600. el += "<div class='p5VideoPlayer' id=p1 "
  1601. el += "data-start=0 data-end=560 "
  1602. el += "data-videoid=" + data["VIDEO_ID"] + ">"
  1603. el += "<div class=img>"
  1604. el += "<img src='" + "data:" + (data["THUMBNAIL"]["IMAGE"]) + "' / >"
  1605. el += "</div>"
  1606. el += "</div>"
  1607. el += "</div>"
  1608. } else if (type == "img") {
  1609. el += "<div class=attImg data-id=" + data["ID"] + ">"
  1610. el += "<div class=imgTitle>"
  1611. el += "<i class='glyphicon glyphicon-option-vertical'></i>"
  1612. el += data["NAME"] + "</div><div class='img'>"
  1613. el += "<img src='" + "data:" + data["IMAGE"] + "' / >"
  1614. el += "</div></div>"
  1615. }
  1616. return el;
  1617. }
  1618. function loadClipboard() {
  1619. $("#clipboard").empty();
  1620. var link = BASE_URL + 'wfs-data.php/default_db/?SERVICE=WFS&VERSION=1.0.0&REQUEST=GetFeature&TYPENAME=p5_default_db:CRM_IMAGE&SRSNAME=EPSG:3003&Filter=<ogc:Filter><ogc:And><ogc:PropertyIsEqualTo><ogc:PropertyName>REMOTE_ID</ogc:PropertyName><ogc:Literal>' + USER_ID + '</ogc:Literal></ogc:PropertyIsEqualTo><ogc:PropertyIsEqualTo><ogc:PropertyName>REMOTE_TABLE</ogc:PropertyName><ogc:Literal>ADMIN_USERS</ogc:Literal></ogc:PropertyIsEqualTo></ogc:And></ogc:Filter>';
  1621. $.get(link, function(data) {
  1622. var list = "";
  1623. $(data).find("featureMember").each(function() {
  1624. if (typeof usedImg[$(this).find("ID").text()] == "undefined") {
  1625. var opts = {};
  1626. opts["ID"] = $(this).find("ID").text();
  1627. opts["IMAGE"] = base64_decode($(this).find("IMAGE").text());
  1628. opts["NAME"] = $(this).find("NAME").text();
  1629. list += showMediaElement(opts, "img");
  1630. }
  1631. });
  1632. $("#clipboard").append(list);
  1633. $('.attImg').draggable({
  1634. appendTo: 'body',
  1635. //revert: true,
  1636. zIndex: 100,
  1637. helper: "clone",
  1638. stack: "div",
  1639. distance: 0,
  1640. handle: '.imgTitle',
  1641. scroll: true,
  1642. start: function(event, ui) {
  1643. $(this).data("startingScrollTop", $(this).parent().scrollTop());
  1644. },
  1645. drag: function(event, ui) {
  1646. var st = parseInt($(this).data("startingScrollTop"));
  1647. ui.position.top -= $(document).scrollTop() - st;
  1648. ui.helper.css('z-index', 1000);
  1649. }
  1650. });
  1651. });
  1652. link = BASE_URL + "index.php?_route=UrlAction_ProcesEditor&_task=getVideosClipboardAjax"
  1653. $.get(link, function(data) {
  1654. var list = "";
  1655. $.each(data, function(i, e) {
  1656. list += showMediaElement(e, "video");
  1657. })
  1658. $("#clipboard").prepend(list);
  1659. $('.attVid').draggable({
  1660. appendTo: 'body',
  1661. //revert: true,
  1662. zIndex: 100,
  1663. helper: "clone",
  1664. stack: "div",
  1665. distance: 0,
  1666. handle: '.imgTitle',
  1667. scroll: true,
  1668. start: function(event, ui) {
  1669. $(this).data("startingScrollTop", $(this).parent().scrollTop());
  1670. },
  1671. drag: function(event, ui) {
  1672. var st = parseInt($(this).data("startingScrollTop"));
  1673. ui.position.top -= $(document).scrollTop() - st;
  1674. ui.helper.css('z-index', 1000);
  1675. }
  1676. });
  1677. });
  1678. }
  1679. function zasoby() {
  1680. var side = $("#side");
  1681. $(side).empty();
  1682. $(side).append("<div class='form-group' ><input type='text' class=form-control id=sZasoby placeholder='Szukaj zasobów'></div>");
  1683. $(side).append("<div class='btn-group' style=width:100% id=filtry></div>");
  1684. $("#filtry").append("<button type='button' data-type=1 class='fbutton btn btn-default input-block-level ' style=width:40%>Stanowiska</button>");
  1685. $("#filtry").append("<button type='button' data-type=2 class='fbutton btn btn-default input-block-level ' style=width:40%>Komórki</button>");
  1686. $("#filtry").append("<button type='button' data-type=0 class='fbutton btn btn-danger input-block-level' id=xBtn style=width:20% disabled>X</button>");
  1687. $(side).append("<div id=ulcon><div id=advCon></div></div>");
  1688. $(side).find("#advCon").append("<div class='singleAdv list-group' data-depth=0 id=depth0></div>");
  1689. $(side).find("#advCon").append("<div class=clearfix></div>");
  1690. 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';
  1691. var result = "";
  1692. $.get(link, function(data) {
  1693. $(data).find("featureMember").each(function() {
  1694. var type = 0;
  1695. if ($(this).find("TYPE").text() == "DZIAL" || $(this).find("TYPE").text() == "PODMIOT" || $(this).find("TYPE").text() == "STANOWISKO")
  1696. type = 1;
  1697. result += "<div class='drag list-group-item liAdv'";
  1698. result += "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() + "'"
  1699. result += "title='" + $(this).find("DESC").text() + "'>"
  1700. result += "<div class=textTable2>"
  1701. result += "<span class=handle> # </span>" + $(this).find("DESC").text() + "</div>"
  1702. result += "<div class='glyphicon glyphicon-triangle-right' style=opacity:0.4;float:right; style=float:left;></div>"
  1703. result += "<div class=clearfix></div>"
  1704. result += "<div class=detailsTable2>[" + $(this).find("ID").text() + "] " + $(this).find("TYPE").text() + "</div>"
  1705. result += "</div>";
  1706. });
  1707. $("#depth0").html(result);
  1708. $('.drag').draggable({
  1709. appendTo: 'body',
  1710. handle: '.handle',
  1711. helper: 'clone',
  1712. stack: "div",
  1713. distance: 0,
  1714. cursor: "copy",
  1715. scroll: true,
  1716. start: function(event, ui) {
  1717. $(this).data("startingScrollTop", $(this).parent().scrollTop());
  1718. },
  1719. drag: function(event, ui) {
  1720. var st = parseInt($(this).data("startingScrollTop"));
  1721. ui.position.top -= $(document).scrollTop() - st;
  1722. ui.helper.css('z-index', 1000);
  1723. }
  1724. });
  1725. });
  1726. //$(side).find("#ulcon").append("<div class='drag' data-id=1 data-type=1 >[STANOWISKO] Ulotkarz</div>");
  1727. //$(side).find("#ulcon").append("<div class='drag' data-id=2 data-type=1 >[STANOWISKO] Programista PHP</div>");
  1728. //$(side).find("#ulcon").append("<div class='drag' data-id=3 data-type=2 >[ZASÓB] Komputer</div>");
  1729. }
  1730. function removeImg(content, id) {
  1731. $.each(content, function(i, e) {
  1732. if (e["id"] == id) {
  1733. content.splice(i, 1);
  1734. return;
  1735. }
  1736. })
  1737. }
  1738. function dropVid(ui, target) {
  1739. var id = $(target).closest(".drop").data("id");
  1740. var proces = id;
  1741. var idBefore = $(ui.draggable).closest(".drop").data("id");
  1742. var procesBefore = idBefore;
  1743. var type = "CRM_PROCES";
  1744. var typeName = "proces";
  1745. var typeNameBefore = "proces";
  1746. if ($(target).closest(".professions").length) {
  1747. id = $(target).closest("li").data("id");
  1748. type = "CRM_WSKAZNIK";
  1749. typeName = "prof";
  1750. } else if ($(target).closest(".resources").length) {
  1751. id = $(target).closest("li").data("id");
  1752. typeNameBefore = "res";
  1753. type = "CRM_WSKAZNIK";
  1754. typeName = "res";
  1755. }
  1756. if ($(ui.draggable).closest(".professions").length) {
  1757. typeNameBefore = "prof";
  1758. idBefore = $(ui.draggable).closest("li").data("id");
  1759. } else if ($(ui.draggable).closest(".resources").length) {
  1760. typeNameBefore = "res";
  1761. idBefore = $(ui.draggable).closest("li").data("id");
  1762. }
  1763. var temp = {};
  1764. temp["THUMBNAIL"] = {};
  1765. temp["THUMBNAIL"]["IMAGE"] = $(ui.draggable).find("img").attr("src");
  1766. temp["NAME"] = $(ui.draggable).find(".imgTitle").text();
  1767. temp["VIDEO_ID"] = $(ui.draggable).find(".p5VideoPlayer").data("videoid");
  1768. usedImg[temp["id"]] = {
  1769. type: type,
  1770. targetID: id,
  1771. action: "ATTACH"
  1772. };
  1773. if (typeName != "proces" && typeof state[getIndexById(proces)][typeName][
  1774. [getResById(getIndexById(proces), $(target).closest("li").data("id"), typeName)]
  1775. ]["vid"] == "undefined") {
  1776. state[getIndexById(proces)][typeName][getResById(getIndexById(proces), $(target).closest("li").data("id"), typeName)]["vid"] = Array();
  1777. } else if (typeName == "proces" && typeof state[getIndexById(id)]["img"] == "undefined") {
  1778. state[getIndexById(proces)]["vid"] = Array();
  1779. }
  1780. if (typeof idBefore != "undefined")
  1781. if (typeNameBefore == "proces") {
  1782. removeImg(state[getIndexById(procesBefore)]["vid"], temp["id"]);
  1783. } else {
  1784. removeImg(state[getIndexById(procesBefore)][typeNameBefore][getResById(getIndexById(procesBefore), $(ui.draggable).closest("li").data("id"), typeNameBefore)]["img"], temp["id"]);
  1785. }
  1786. if (typeName == "proces")
  1787. state[getIndexById(id)]["vid"].push(temp);
  1788. else {
  1789. state[getIndexById(proces)][typeName][getResById(getIndexById(proces), $(target).closest("li").data("id"), typeName)]["img"].push(temp);
  1790. }
  1791. $(ui.draggable).remove();
  1792. console.log(state);
  1793. updateAll();
  1794. }
  1795. function dropImg(ui, target) {
  1796. var id = $(target).closest(".drop").data("id");
  1797. var proces = id;
  1798. var idBefore = $(ui.draggable).closest(".drop").data("id");
  1799. var procesBefore = idBefore;
  1800. var type = "CRM_PROCES";
  1801. var typeName = "proces";
  1802. var typeNameBefore = "proces";
  1803. if ($(target).closest(".professions").length) {
  1804. id = $(target).closest("li").data("id");
  1805. type = "CRM_WSKAZNIK";
  1806. typeName = "prof";
  1807. } else if ($(target).closest(".resources").length) {
  1808. id = $(target).closest("li").data("id");
  1809. typeNameBefore = "res";
  1810. type = "CRM_WSKAZNIK";
  1811. typeName = "res";
  1812. }
  1813. if ($(ui.draggable).closest(".professions").length) {
  1814. typeNameBefore = "prof";
  1815. idBefore = $(ui.draggable).closest("li").data("id");
  1816. } else if ($(ui.draggable).closest(".resources").length) {
  1817. typeNameBefore = "res";
  1818. idBefore = $(ui.draggable).closest("li").data("id");
  1819. }
  1820. var temp = {};
  1821. temp["src"] = $(ui.draggable).find("img").attr("src");
  1822. temp["title"] = $(ui.draggable).find(".imgTitle").text();
  1823. temp["id"] = $(ui.draggable).data("id");
  1824. usedImg[temp["id"]] = {
  1825. type: type,
  1826. targetID: id,
  1827. action: "ATTACH"
  1828. };
  1829. if (typeName != "proces" && typeof state[getIndexById(proces)][typeName][
  1830. [getResById(getIndexById(proces), $(target).closest("li").data("id"), typeName)]
  1831. ]["img"] == "undefined") {
  1832. state[getIndexById(proces)][typeName][getResById(getIndexById(proces), $(target).closest("li").data("id"), typeName)]["img"] = Array();
  1833. } else if (typeName == "proces" && typeof state[getIndexById(id)]["img"] == "undefined") {
  1834. state[getIndexById(proces)]["img"] = Array();
  1835. }
  1836. if (typeof idBefore != "undefined")
  1837. if (typeNameBefore == "proces") {
  1838. removeImg(state[getIndexById(procesBefore)]["img"], temp["id"]);
  1839. } else {
  1840. removeImg(state[getIndexById(procesBefore)][typeNameBefore][getResById(getIndexById(procesBefore), $(ui.draggable).closest("li").data("id"), typeNameBefore)]["img"], temp["id"]);
  1841. }
  1842. if (typeName == "proces")
  1843. state[getIndexById(id)]["img"].push(temp);
  1844. else {
  1845. state[getIndexById(proces)][typeName][getResById(getIndexById(proces), $(target).closest("li").data("id"), typeName)]["img"].push(temp);
  1846. }
  1847. $(ui.draggable).remove();
  1848. updateAll();
  1849. }
  1850. function addProces(ui, target) {
  1851. var id = $(target).data("id");
  1852. var gotoOpt = "";
  1853. $.each(gotoType, function(key, value) {
  1854. gotoOpt += "<option value=" + value[0] + ">" + value[1] + "</option>";
  1855. })
  1856. swal({
  1857. showCancelButton: true,
  1858. cancelButtonText: "Anuluj",
  1859. title: 'Typ łącza',
  1860. html: (
  1861. typeof state[getIndexById(id)]["goto"] !== typeof undefined && state[getIndexById(id)]["goto"]["id"] != null && state[getIndexById(id)]["goto"]["id"] != 0 ?
  1862. '<span class=class="alert alert-warning"><strong>Uwaga!</strong> Nowe łącze nadpisze już istniejące łącze.</span><br>' :
  1863. ""
  1864. ) + '<br><select class=form-control id="swal-input1">' + gotoOpt + '</select>',
  1865. preConfirm: function() {
  1866. return new Promise(function(resolve) {
  1867. resolve([
  1868. $('#swal-input1').val()
  1869. ]);
  1870. });
  1871. }
  1872. }).then(function(result) {
  1873. newRes--;
  1874. var temp = {};
  1875. temp["flag"] = result[0];
  1876. temp["id"] = ui.draggable.data("id");
  1877. state[getIndexById(id)]["goto"] = temp;
  1878. updateAll();
  1879. }).catch(function(e) {})
  1880. }
  1881. function addResource(ui, target) {
  1882. var permsOpt = "";
  1883. $.each(perms, function(key, value) {
  1884. permsOpt = permsOpt + "<option value=" + value[0] + ">[" + value[2] + "] " + value[1] + "</option>";
  1885. })
  1886. swal({
  1887. showCancelButton: true,
  1888. cancelButtonText: "Anuluj",
  1889. title: 'Uprawnienia',
  1890. html: 'Uprawnienia<br><select class=form-control id="swal-input1">' + permsOpt + '</select>' +
  1891. 'Komentarz<br><input class=form-control id="swal-input2" class="swal2-input">',
  1892. preConfirm: function() {
  1893. return new Promise(function(resolve) {
  1894. resolve([
  1895. $('#swal-input1').val(),
  1896. $('#swal-input2').val()
  1897. ]);
  1898. });
  1899. }
  1900. }).then(function(result) {
  1901. newRes--;
  1902. var temp = {};
  1903. temp["id_zasob"] = ui.draggable.data("id");
  1904. temp["id"] = newRes;
  1905. temp["id_przypadek"] = result[0];
  1906. temp["komentarz"] = result[1];
  1907. temp["changed"] = true;
  1908. temp["opis"] = ui.draggable.data("opis");
  1909. temp["desc"] = ui.draggable.data("desc");
  1910. temp["tree"] = zasobTree[temp["id_zasob"]];
  1911. var id = $(target).data("id");
  1912. if (ui.draggable.data("type") == 1) {
  1913. state[getIndexById(id)]["prof"].push(temp);
  1914. } else {
  1915. state[getIndexById(id)]["res"].push(temp);
  1916. }
  1917. updateAll();
  1918. }).catch(function(e) {})
  1919. }
  1920. //Najwazniejsza funkcja odpalana po kazdej zmianie. Sprawdza, czy wszystkie funkcje maja rodzica,
  1921. //jezeli nie to przesuwa w lewo obiekt
  1922. //Odpowiada tez za ukrywanie guzikow i wywowalanie funkcji generacji krokow
  1923. function updateAll() {
  1924. $.each(state, function(i, e) {
  1925. var pid = getParentNode(e["id"]);
  1926. if (pid != "NONE" && pid != false && pid != e["parent_id"]) {
  1927. e["parent_id"] = pid;
  1928. } else if (pid === false) {
  1929. e["depth"]--;
  1930. //var depthWidth = 20 * $(node).data("depth");
  1931. //$(node).css("padding-left", depthWidth + "px");
  1932. updateAll();
  1933. return;
  1934. }
  1935. });
  1936. changes = true;
  1937. $("#clearBtn").show();
  1938. /*
  1939. localStorage.setItem("state" + mainProces_id, JSON.stringify(state));
  1940. localStorage.setItem("newStep" + mainProces_id, newSteps);
  1941. localStorage.setItem("newRes" + mainProces_id, newRes);
  1942. localStorage.setItem("deletedId" + mainProces_id, JSON.stringify(deletedId));
  1943. localStorage.setItem("deletedRes" + mainProces_id, JSON.stringify(deletedRes));
  1944. localStorage.setItem("date" + mainProces_id, moment().format("YYYY-MM-DD HH:mm:ss"));
  1945. */
  1946. render(state, $("#main"));
  1947. }
  1948. //Generuje kroki, sprawdza tez czy kolejnosc krokow w danym rodzicow zostala zmieniona
  1949. //Jezeli tak to mozna wyslac ajaxem zmiane kolejnosci dla sort_prio
  1950. function stepsGenerator() {
  1951. $.each(state, function(i, e) {
  1952. e["step"] = 0;
  1953. if (i == 0)
  1954. e["stepDesc"] = "";
  1955. else {
  1956. var iParent = getIndexById(e["parent_id"]);
  1957. state[iParent]["step"] += 1;
  1958. e["SORT_PRIO"] = state[iParent]["step"];
  1959. e["stepDesc"] = state[iParent]["stepDesc"] + state[iParent]["step"] + ". ";
  1960. }
  1961. });
  1962. }
  1963. //Na potrzeby guzikow dorobilem funkcje sprawdzajaca id rodzica po przesunieciu (przewidywanie).
  1964. //Jezeli nie znajdzie zwraca false, a wtedy blokuje sie odpowiednia strzalka
  1965. function checkParentNode(id, check) {
  1966. var x = getIndexById(id);
  1967. var y = x;
  1968. var result = false;
  1969. while (x > 0) {
  1970. x--;
  1971. if (check == "right")
  1972. if (state[x]["depth"] == state[y]["depth"]) {
  1973. result = state[x]["id"];
  1974. break;
  1975. }
  1976. if (check == "left")
  1977. if (state[x]["depth"] == state[y]["depth"] - 2) {
  1978. result = state[x]["id"];
  1979. break;
  1980. }
  1981. if (check == "right" && state[x]["depth"] < state[y]["depth"])
  1982. break;
  1983. }
  1984. return result;
  1985. }
  1986. //Zwraca id rodzica, jezeli nie ma zwraca false
  1987. function getParentNode(id) {
  1988. var x = getIndexById(id);
  1989. var y = x;
  1990. if (x == 0)
  1991. return "NONE";
  1992. var result = false;
  1993. while (x > 0) {
  1994. x--;
  1995. if (state[x]["depth"] == state[y]["depth"] - 1) {
  1996. result = state[x]["id"];
  1997. break;
  1998. }
  1999. if (state[x]["depth"] - state[y]["depth"] == -2)
  2000. break;
  2001. }
  2002. return result;
  2003. }
  2004. function getResById(index, id, type) {
  2005. var result = state[index][type].length - 1;
  2006. $.each(state[index][type], function(i, e) {
  2007. if (e["id"] == id) {
  2008. result = i;
  2009. return false;
  2010. }
  2011. });
  2012. return result;
  2013. }
  2014. function getIndexById(id, arr = state, label = "id") {
  2015. var result = arr.length - 1;
  2016. if (label == "ID")
  2017. result = -1;
  2018. $.each(arr, function(i, e) {
  2019. if (e[label] == id) {
  2020. result = i;
  2021. return false;
  2022. }
  2023. });
  2024. return result;
  2025. }
  2026. $(".remImg").on('click', function() {
  2027. var obj = $(this).closest(".attImg");
  2028. var id = $(this).closest(".drop").data("id");
  2029. var typeName = "proces";
  2030. if ($(obj).closest(".professions").length) {
  2031. typeName = "prof";
  2032. } else if ($(obj).closest(".resources").length) {
  2033. typeName = "res";
  2034. }
  2035. //if(typeof idBefore != "undefined")
  2036. if (typeName == "proces")
  2037. removeImg(state[getIndexById(id)]["img"], $(obj).data("id"));
  2038. else {
  2039. removeImg(state[getIndexById(id)][typeName][getResById(getIndexById(id), $(obj).closest("li").data("id"), typeName)]["img"], $(obj).data("id"));
  2040. }
  2041. $(ui.draggable).remove();
  2042. usedImg[$(obj).data("id")] = {
  2043. type: "",
  2044. targetID: -1,
  2045. action: "DELETED"
  2046. };
  2047. updateAll();
  2048. return false;
  2049. });
  2050. $(document).on('click', '.stateOff', function() {
  2051. $(this).closest(".mx").prev(".tree").show();
  2052. $(this).closest(".mx").remove();
  2053. });
  2054. $(document).on('click', '.tree', function() {
  2055. var type;
  2056. if ($(this).closest("ul").hasClass("resources")) {
  2057. type = "res";
  2058. } else {
  2059. type = "prof"
  2060. }
  2061. var id = getIndexById($(this).closest(".drop").data("id"));
  2062. var resId = getResById(id, $(this).closest(".liRes").data("id"), type);
  2063. $(this).hide();
  2064. showTree(state[id][type][resId]["tree"], $(this));
  2065. });
  2066. function showTree(arr, target) {
  2067. result = "";
  2068. $.each(arr, function(i, x) {
  2069. result += "<li style=padding-left:" + i * 16 + "px;><span class='glyphicon glyphicon-arrow-right'></span> " + x["DESC"] + "</li>";
  2070. });
  2071. $(target).after("<div class=mx><div class=stateOff><span class='glyphicon glyphicon-chevron-up'></span></div> <ul style=padding-left:0px;>" + result + "</ul></div>");
  2072. }
  2073. function render(arr, target) {
  2074. stepsGenerator();
  2075. var result = "";
  2076. $.each(arr, function(i, e) {
  2077. result += "<div class='drop container-fluid' data-id=" + e["id"] + " id='proc" + e["id"] + "'>";
  2078. result += "<div class='col-xs-1 options' style=text-align:right;padding-top:2px; id=opt" + e["id"] + ">";
  2079. if (i > 0) {
  2080. result += "<span class='glyphicon glyphicon-remove-sign ico del' title='Usuń krok' aria-hidden='true'></span>";
  2081. //Arrows
  2082. if (checkParentNode(e["id"], "right") !== false)
  2083. result += "<span class='glyphicon glyphicon-arrow-right ico rArrow' aria-hidden='true' title='Przesuń krok w prawo'></span>";
  2084. if (checkParentNode(e["id"], "left") !== false)
  2085. result += "<span class='glyphicon glyphicon-arrow-left ico lArrow' aria-hidden='true' title='Przesuń krok w lewo'></span>";
  2086. if (i != 1)
  2087. result += "<span class='glyphicon glyphicon-arrow-up ico uArrow' aria-hidden='true' title='Przesuń krok w górę'></span>";
  2088. if (i != state.length - 1)
  2089. result += "<span class='glyphicon glyphicon-arrow-down ico dArrow' aria-hidden='true' title='Przesuń krok w dół'></span>";
  2090. } else {}
  2091. result += "<span class='hDescAdd glyphicon glyphicon-edit ico' title='Edytuj tytuł'></span>";
  2092. result += "<div class='clearfix'></div>";
  2093. if (e["opis"] == "")
  2094. result += "<span class=sDescAdd>Dodaj opis</span>";
  2095. else
  2096. result += "<span class=sDescAdd>Edytuj opis</span>";
  2097. result += "</div>";
  2098. result += "<div class='col-xs-11 desc' id='desc" + e["id"] + "' ><h4 class='changable " + (e["C-desc"] ? "changed" : "") + "'><span class='stepDesc'>" + e["stepDesc"] + "</span><span class=hdesc>" + e["desc"] + "</span> <span class=ids>{" + (e["id"] >= 0 ? e["id"] : "?") + "}</span></h4><span class='sdesc changable " + (e["C-opis"] ? "changed" : "") + "'>" + e["opis"] + "</span>";
  2099. // }
  2100. // if ($(this).find("OPIS").text() == "") {
  2101. // $("#proc" + $(this).find("ID").text()).find(".sdesc").after("<span class=sDescAdd>Dodaj opis</span>");
  2102. // }
  2103. result += "<div class='clearfix'></div><div class=imagesProc>";
  2104. if (typeof e["img"] !== "undefined") {
  2105. //console.log(e["img"])
  2106. $.each(e["img"], function(key, eImg) {
  2107. var img = showMediaElement({
  2108. "ID": eImg["id"],
  2109. "IMAGE": eImg["src"],
  2110. "NAME": eImg["title"]
  2111. }, "img")
  2112. result += img;
  2113. })
  2114. }
  2115. if (typeof e["vid"] !== "undefined") {
  2116. //console.log(e["img"])
  2117. $.each(e["vid"], function(key, eVid) {
  2118. var vid = showMediaElement(eVid, "video")
  2119. result += vid;
  2120. })
  2121. }
  2122. result += "<div class=clearfix></div></div><br>";
  2123. var anyProf = false;
  2124. $.each(e["prof"], function(i2, e2) {
  2125. if (!anyProf) {
  2126. 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;>";
  2127. anyProf = true;
  2128. }
  2129. result += "<li style=padding-top:5px;padding-bottom:5px; class='liRes' data-zasob=" + e2["id_zasob"] + " data-id=" + e2["id"] + " data-przypadek=" + e2["id_przypadek"] + " data-komentarz='" + e2["komentarz"] + "'><div class=row>";
  2130. result += "<div class=col-sm-2 style=text-align:right;>";
  2131. if (i2 != 0)
  2132. result += "<span class='glyphicon glyphicon-arrow-up uArrowRes' title='Przesuń wskaźnik w górę' aria-hidden='true'></span>";
  2133. if (i2 != e["prof"].length - 1)
  2134. result += "<span class='glyphicon glyphicon-arrow-down dArrowRes' title='Przesuń wskaźnik w dół' aria-hidden='true'></span>";
  2135. 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>";
  2136. result += "</div>";
  2137. result += "<div class='col-sm-10 changable " + (e2["changed"] ? "changed" : "") + " '><b>" + e2["desc"] + "</b> " + e2["opis"] + " [" + e2["id_zasob"] + "] <br><span class=tree>";
  2138. if(typeof e2["tree"] !== "undefined" && e2["tree"].length > 0){ //TO DO DOWNLOAD TREE WHEN NOT EXISTS
  2139. result += "<span class=state><span class='glyphicon glyphicon-chevron-down'></span></span> ";
  2140. $.each(e2["tree"], function(i, x) {
  2141. result += x["DESC"] + (i < e2["tree"].length - 1 ? "<span class='glyphicon glyphicon-triangle-right'></span> " : "");
  2142. });
  2143. }
  2144. result += "</span></div>";
  2145. if (typeof e2["img"] !== "undefined") {
  2146. //console.log(e["img"])
  2147. $.each(e2["img"], function(key, eImg) {
  2148. var img = showMediaElement({
  2149. "ID": eImg["id"],
  2150. "IMAGE": eImg["src"],
  2151. "NAME": eImg["title"]
  2152. }, "img")
  2153. result += img;
  2154. })
  2155. }
  2156. result += "</div></li>";
  2157. });
  2158. if (anyProf) {
  2159. result += "</ul>";
  2160. }
  2161. var anyRes = false;
  2162. $.each(e["res"], function(i2, e2) {
  2163. if (!anyRes) {
  2164. 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;>";
  2165. anyRes = true;
  2166. }
  2167. result += "<li style=padding-top:5px;padding-bottom:5px; class='liRes' data-zasob=" + e2["id_zasob"] + " data-id=" + e2["id"] + " data-przypadek=" + e2["id_przypadek"] + " data-komentarz='" + e2["komentarz"] + "'><div class=row>";
  2168. result += "<div class=col-sm-2 style=text-align:right;>";
  2169. if (i2 != 0)
  2170. result += "<span class='glyphicon glyphicon-arrow-up uArrowRes' title='Przesuń wskaźnik w górę' aria-hidden='true'></span>";
  2171. if (i2 != e["res"].length - 1)
  2172. result += "<span class='glyphicon glyphicon-arrow-down dArrowRes' title='Przesuń wskaźnik w dół' aria-hidden='true'></span>";
  2173. 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>";
  2174. result += "</div>";
  2175. result += "<div class='col-sm-10 changable " + (e2["changed"] ? "changed" : "") + " '><b>" + e2["desc"] + "</b> " + e2["opis"] + " [" + e2["id_zasob"] + "] <br><span class=tree>";
  2176. if(typeof e2["tree"] !== "undefined" && e2["tree"].length > 0){ //TO DO DOWNLOAD TREE WHEN NOT EXISTS
  2177. result += "<span class=state><span class='glyphicon glyphicon-chevron-down'></span></span> ";
  2178. $.each(e2["tree"], function(i, x) {
  2179. result += x["DESC"] + (i < e2["tree"].length - 1 ? "<span class='glyphicon glyphicon-triangle-right'></span> " : "");
  2180. });
  2181. }
  2182. result += "</span></div>";
  2183. if (typeof e2["img"] !== "undefined") {
  2184. //console.log(e["img"])
  2185. $.each(e2["img"], function(key, eImg) {
  2186. var img = showMediaElement({
  2187. "ID": eImg["id"],
  2188. "IMAGE": eImg["src"],
  2189. "NAME": eImg["title"]
  2190. }, "img")
  2191. result += img;
  2192. })
  2193. }
  2194. result += "</div></li>";
  2195. });
  2196. if (anyRes) {
  2197. result += "</ul>";
  2198. }
  2199. if (typeof e["goto"] !== typeof undefined && e["goto"]["id"] != null && e["goto"]["id"] != 0) {
  2200. var name;
  2201. switch (e["goto"]["flag"]) {
  2202. case "GOTO":
  2203. name = "Przejdź do procesu " + e["goto"]["id"] + ".";
  2204. break;
  2205. case "GOTO_AND_RETURN":
  2206. name = "Przejdź do procesu " + e["goto"]["id"] + ", a następnie wróć.";
  2207. break;
  2208. case "FORK":
  2209. name = "&mdash; FORK" + e["goto"]["id"];
  2210. break;
  2211. default:
  2212. name = e["goto"]["id"];
  2213. }
  2214. 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>";
  2215. }
  2216. result += "<br><span class=step>Dodaj nowy krok</span>";
  2217. result += "</div>"
  2218. result += "</div>";
  2219. });
  2220. $(target).html(result);
  2221. $('.drag').draggable({
  2222. appendTo: 'body',
  2223. helper: 'clone',
  2224. stack: "div",
  2225. distance: 0,
  2226. cursor: "copy",
  2227. scroll: true,
  2228. start: function(event, ui) {
  2229. $(this).data("startingScrollTop", $(this).parent().scrollTop());
  2230. },
  2231. drag: function(event, ui) {
  2232. var st = parseInt($(this).data("startingScrollTop"));
  2233. ui.position.top -= $(document).scrollTop() - st;
  2234. ui.helper.css('z-index', 1000);
  2235. }
  2236. });
  2237. $(".drop").droppable({
  2238. tolerance: 'pointer',
  2239. accept: '.drag',
  2240. zIndex: 0,
  2241. hoverClass: "activeDrop",
  2242. drop: function(event, ui) {
  2243. if (ui.draggable.data("droptype") == 1)
  2244. addProces(ui, this);
  2245. else
  2246. addResource(ui, this);
  2247. }
  2248. });
  2249. $(".sdesc").droppable({
  2250. tolerance: 'pointer',
  2251. accept: '.attImg, .attVid',
  2252. zIndex: 0,
  2253. hoverClass: "activeDrop",
  2254. drop: function(event, ui) {
  2255. if($(ui.draggable).hasClass("attVid"))
  2256. dropVid(ui, this);
  2257. else if($(ui.draggable).hasClass("attImg"))
  2258. dropImg(ui, this);
  2259. }
  2260. });
  2261. $(".liRes").droppable({
  2262. tolerance: 'pointer',
  2263. accept: '.attImg',
  2264. zIndex: 0,
  2265. hoverClass: "activeDrop",
  2266. drop: function(event, ui) {
  2267. dropImg(ui, this);
  2268. return false;
  2269. }
  2270. });
  2271. $('.attImg').draggable({
  2272. appendTo: 'body',
  2273. zIndex: 100,
  2274. helper: "clone",
  2275. stack: "div",
  2276. handle: '.imgTitle',
  2277. distance: 0,
  2278. scroll: true,
  2279. start: function(event, ui) {
  2280. $(this).data("startingScrollTop", $(this).parent().scrollTop());
  2281. },
  2282. drag: function(event, ui) {
  2283. var st = parseInt($(this).data("startingScrollTop"));
  2284. ui.position.top -= $(document).scrollTop() - st;
  2285. ui.helper.css('z-index', 1000);
  2286. }
  2287. });
  2288. }
  2289. function genTree(parent_id) {
  2290. 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';
  2291. $.ajax({
  2292. url: link,
  2293. success: function(data) {
  2294. var i = 0;
  2295. $.each($(data).find("featureMember"), function() {
  2296. var linkImg = BASE_URL + 'wfs-data.php/default_db/?SERVICE=WFS&VERSION=1.0.0&REQUEST=GetFeature&TYPENAME=p5_default_db:CRM_IMAGE&SRSNAME=EPSG:3003&Filter=<ogc:Filter><ogc:And><ogc:PropertyIsEqualTo><ogc:PropertyName>REMOTE_ID</ogc:PropertyName><ogc:Literal>' + $(this).find("ID").text() + '</ogc:Literal></ogc:PropertyIsEqualTo><ogc:PropertyIsEqualTo><ogc:PropertyName>REMOTE_TABLE</ogc:PropertyName><ogc:Literal>CRM_PROCES</ogc:Literal></ogc:PropertyIsEqualTo></ogc:And></ogc:Filter>';
  2297. $.get(linkImg, function(imgData) {
  2298. });
  2299. var temp = {};
  2300. if ($(this).find("ID").text() == "0")
  2301. return;
  2302. var parentIndex = getIndexById(parent_id);
  2303. temp["id"] = $(this).find("ID").text();
  2304. temp["desc"] = $(this).find("DESC").text();
  2305. temp["opis"] = $(this).find("OPIS").text();
  2306. temp["parent_id"] = $(this).find("PARENT_ID").text();
  2307. temp["depth"] = state[parentIndex]["depth"] + 1;
  2308. temp["step"] = 0;
  2309. temp["prof"] = new Array();
  2310. temp["res"] = new Array();
  2311. temp["goto"] = {};
  2312. temp["goto"]["id"] = $(this).find("IF_TRUE_GOTO").text();
  2313. temp["goto"]["flag"] = $(this).find("IF_TRUE_GOTO_FLAG").text();
  2314. temp["stepDesc"] = "";
  2315. i++;
  2316. state.splice(parentIndex + i, 0, temp);
  2317. var linkImg = BASE_URL + 'wfs-data.php/default_db/?SERVICE=WFS&VERSION=1.0.0&REQUEST=GetFeature&TYPENAME=p5_default_db:CRM_IMAGE&SRSNAME=EPSG:3003&Filter=<ogc:Filter><ogc:And><ogc:PropertyIsEqualTo><ogc:PropertyName>REMOTE_ID</ogc:PropertyName><ogc:Literal>' + temp["id"] + '</ogc:Literal></ogc:PropertyIsEqualTo><ogc:PropertyIsEqualTo><ogc:PropertyName>REMOTE_TABLE</ogc:PropertyName><ogc:Literal>CRM_PROCES</ogc:Literal></ogc:PropertyIsEqualTo></ogc:And></ogc:Filter>';
  2318. $.get(linkImg, function(imgData) {
  2319. var temp = Array();
  2320. $.each($(imgData).find("featureMember"), function() {
  2321. temp.push({
  2322. "src": base64_decode($(this).find("IMAGE").text()),
  2323. "title": $(this).find("NAME").text(),
  2324. "id": $(this).find("ID").text(),
  2325. });
  2326. })
  2327. state[getIndexById(temp["id"])]["img"] = temp;
  2328. });
  2329. genTree($(this).find("ID").text());
  2330. });
  2331. }
  2332. });
  2333. }
  2334. function base64_decode(input) {
  2335. var _keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="
  2336. var output = "";
  2337. var chr1, chr2, chr3;
  2338. var enc1, enc2, enc3, enc4;
  2339. var i = 0;
  2340. input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
  2341. while (i < input.length) {
  2342. enc1 = _keyStr.indexOf(input.charAt(i++));
  2343. enc2 = _keyStr.indexOf(input.charAt(i++));
  2344. enc3 = _keyStr.indexOf(input.charAt(i++));
  2345. enc4 = _keyStr.indexOf(input.charAt(i++));
  2346. chr1 = (enc1 << 2) | (enc2 >> 4);
  2347. chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
  2348. chr3 = ((enc3 & 3) << 6) | enc4;
  2349. output = output + String.fromCharCode(chr1);
  2350. if (enc3 != 64) {
  2351. output = output + String.fromCharCode(chr2);
  2352. }
  2353. if (enc4 != 64) {
  2354. output = output + String.fromCharCode(chr3);
  2355. }
  2356. }
  2357. var string = "";
  2358. var i = 0;
  2359. var c = c1 = c2 = 0;
  2360. while (i < output.length) {
  2361. c = output.charCodeAt(i);
  2362. if (c < 128) {
  2363. string += String.fromCharCode(c);
  2364. i++;
  2365. } else if ((c > 191) && (c < 224)) {
  2366. c2 = output.charCodeAt(i + 1);
  2367. string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
  2368. i += 2;
  2369. } else {
  2370. c2 = output.charCodeAt(i + 1);
  2371. c3 = output.charCodeAt(i + 2);
  2372. string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
  2373. i += 3;
  2374. }
  2375. }
  2376. return string;
  2377. }
  2378. //Pierwszy render, tworzy potrzebna strukture
  2379. function showPreview() {
  2380. if (mainProces_id == -1)
  2381. newSteps = -1;
  2382. else
  2383. newSteps = 0;
  2384. changes = false;
  2385. $("#clearBtn").hide();
  2386. lastSearch = "";
  2387. filtr = 0;
  2388. selectedArea = false;
  2389. state = [];
  2390. newRes = 0;
  2391. deletedId = [];
  2392. deletedRes = [];
  2393. generatedId = [];
  2394. if (mainProces_id == -1) {
  2395. temp = {}
  2396. actSite = "preview";
  2397. loaded = false;
  2398. temp["id"] = -1;
  2399. temp["depth"] = 0;
  2400. temp["parent_id"] = 0;
  2401. temp["stepDesc"] = "";
  2402. temp["step"] = 0;
  2403. temp["prof"] = Array();
  2404. temp["res"] = Array();
  2405. temp["desc"] = "Tytuł procesu";
  2406. temp["opis"] = "Opis procesu";
  2407. temp["C-desc"] = true;
  2408. temp["C-opis"] = true;
  2409. temp["goto"] = {}
  2410. temp["goto"]["flag"] = "";
  2411. temp["goto"]["id"] = 0;
  2412. state[0] = temp;
  2413. loadResources();
  2414. } else if (localStorage.getItem("state" + mainProces_id) !== null) {
  2415. state = JSON.parse(localStorage.getItem("state" + mainProces_id));
  2416. newSteps = localStorage.getItem("newStep" + mainProces_id);
  2417. newRes = localStorage.getItem("newRes" + mainProces_id);
  2418. deletedId = JSON.parse(localStorage.getItem("deletedId" + mainProces_id));
  2419. deletedRes = JSON.parse(localStorage.getItem("deletedRes" + mainProces_id));
  2420. usedImg = JSON.parse(localStorage.getItem("usedImg" + mainProces_id));
  2421. $.notify("Wczytano niezapisany stan z " + localStorage.getItem("date" + mainProces_id), "info");
  2422. render(state, $("#main"));
  2423. loaded = true;
  2424. } else {
  2425. $("#main").html("<center>Synchronizowanie danych z serwerem.</center>");
  2426. var id = mainProces_id;
  2427. 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>';
  2428. $.get(link, function(data) {
  2429. var temp = {};
  2430. loaded = false;
  2431. temp["id"] = mainProces_id;
  2432. temp["depth"] = 0;
  2433. temp["parent_id"] = $(data).find("featureMember").find("PARENT_ID").text();
  2434. temp["step"] = 0;
  2435. temp["goto"] = {};
  2436. temp["goto"]["id"] = $(data).find("featureMember").find("IF_TRUE_GOTO").text();
  2437. temp["goto"]["flag"] = $(data).find("featureMember").find("IF_TRUE_GOTO_FLAG").text();
  2438. temp["stepDesc"] = "";
  2439. temp["prof"] = Array();
  2440. temp["res"] = Array();
  2441. temp["desc"] = $(data).find("featureMember").find("DESC").text();
  2442. temp["opis"] = $(data).find("featureMember").find("OPIS").text()
  2443. state[0] = temp;
  2444. var linkImg = BASE_URL + 'wfs-data.php/default_db/?SERVICE=WFS&VERSION=1.0.0&REQUEST=GetFeature&TYPENAME=p5_default_db:CRM_IMAGE&SRSNAME=EPSG:3003&Filter=<ogc:Filter><ogc:And><ogc:PropertyIsEqualTo><ogc:PropertyName>REMOTE_ID</ogc:PropertyName><ogc:Literal>' + mainProces_id + '</ogc:Literal></ogc:PropertyIsEqualTo><ogc:PropertyIsEqualTo><ogc:PropertyName>REMOTE_TABLE</ogc:PropertyName><ogc:Literal>CRM_PROCES</ogc:Literal></ogc:PropertyIsEqualTo></ogc:And></ogc:Filter>';
  2445. $.get(linkImg, function(imgData) {
  2446. var temp = Array();
  2447. $.each($(imgData).find("featureMember"), function() {
  2448. temp.push({
  2449. "src": base64_decode($(this).find("IMAGE").text()),
  2450. "title": $(this).find("NAME").text(),
  2451. "id": $(this).find("ID").text(),
  2452. });
  2453. })
  2454. state[0]["img"] = temp;
  2455. });
  2456. genTree(mainProces_id);
  2457. });
  2458. actSite = "preview";
  2459. }
  2460. }
  2461. });
  2462. function unloadPage() {
  2463. if (changes)
  2464. return "";
  2465. }
  2466. window.onbeforeunload = unloadPage;