procesEditor.js 114 KB

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