procesEditor.js 115 KB

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