procesEditor.js 114 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718
  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("Podgląd: <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=" + e["ID"] + " data-type=" + type + " data-desc='" + e["DESC"] + "' data-opis='" + e["OPIS"] + "'>" + e["DESC"] + " [" + e["ID"] + "]</div>");
  1203. for (var i = 3; i > 0; i--) {
  1204. if (e["p" + i + "_ID"] != null) {
  1205. var temp = {};
  1206. temp["ID"] = e["p" + i + "_ID"];
  1207. temp["DESC"] = e["p" + i + "_DESC"];
  1208. zasobTree[e["ID"]] = [];
  1209. zasobTree[e["ID"]].push(temp);
  1210. }
  1211. }
  1212. $('.drag').draggable({
  1213. appendTo: 'body',
  1214. helper: 'clone',
  1215. stack: "div",
  1216. distance: 0,
  1217. cursor: "copy",
  1218. start: function(event, ui) {
  1219. $(this).data("startingScrollTop", $(this).parent().scrollTop());
  1220. },
  1221. drag: function(event, ui) {
  1222. var st = parseInt($(this).data("startingScrollTop"));
  1223. ui.position.top -= $(document).scrollTop() - st;
  1224. ui.helper.css('z-index', 1000);
  1225. }
  1226. });
  1227. }
  1228. });
  1229. });
  1230. }
  1231. });
  1232. function searchProc() {
  1233. var id = lastSearch;
  1234. var link;
  1235. 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';
  1236. $.get(link, function(data) {
  1237. var side = $("#side");
  1238. $(side).find("#ulproc").empty();
  1239. $.each($(data).find("featureMember"), function() {
  1240. if ($(this).find("ID").text() * 1 == 0) {
  1241. $(side).find("#ulcon").append("<div><center>Brak wyników wyszukiwania</center></div>");
  1242. return;
  1243. }
  1244. $(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>");
  1245. $('.drag').draggable({
  1246. appendTo: 'body',
  1247. helper: 'clone',
  1248. stack: "div",
  1249. distance: 0,
  1250. cursor: "copy",
  1251. start: function(event, ui) {
  1252. $(this).data("startingScrollTop", $(this).parent().scrollTop());
  1253. },
  1254. drag: function(event, ui) {
  1255. var st = parseInt($(this).data("startingScrollTop"));
  1256. ui.position.top -= $(document).scrollTop() - st;
  1257. ui.helper.css('z-index', 1000);
  1258. }
  1259. });
  1260. });
  1261. });
  1262. }
  1263. function searchRes() {
  1264. var id = lastSearch;
  1265. var link;
  1266. link = BASE_URL + "index.php?_route=UrlAction_ProcesEditor&_task=getResAjax&word=" + id + "&filter=" + filtr;
  1267. $.get(link, function(data) {
  1268. var side = $("#side");
  1269. $(side).find("#ulcon").empty();
  1270. if (data.length == 0)
  1271. $(side).find("#ulcon").append("<div><center>Brak wyników wyszukiwania</center></div>");
  1272. $.each(data, function(i, e) {
  1273. var tree = "";
  1274. for (var i = 3; i > 0; i--) {
  1275. if (e["p" + i + "_ID"] != null) {
  1276. var temp = {};
  1277. temp["ID"] = e["p" + i + "_ID"];
  1278. temp["DESC"] = e["p" + i + "_DESC"];
  1279. zasobTree[e["ID"]] = [];
  1280. zasobTree[e["ID"]].push(temp);
  1281. tree += e["p" + i + "_DESC"] + (i > 1 ? " <span class='glyphicon glyphicon-triangle-right'></span>" : "");
  1282. }
  1283. }
  1284. var type = 0;
  1285. if (e["TYPE"] == "DZIAL" || e["TYPE"] == "PODMIOT" || e["TYPE"] == "STANOWISKO")
  1286. type = 1;
  1287. if (filtr != 2 || e["TYPE"] != "TABELA")
  1288. $(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>");
  1289. else {
  1290. $(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>");
  1291. }
  1292. });
  1293. $('.drag').draggable({
  1294. appendTo: 'body',
  1295. helper: 'clone',
  1296. stack: "div",
  1297. distance: 0,
  1298. cursor: "copy",
  1299. start: function(event, ui) {
  1300. $(this).data("startingScrollTop", $(this).parent().scrollTop());
  1301. },
  1302. drag: function(event, ui) {
  1303. var st = parseInt($(this).data("startingScrollTop"));
  1304. ui.position.top -= $(document).scrollTop() - st;
  1305. ui.helper.css('z-index', 1000);
  1306. }
  1307. });
  1308. $(".drop").droppable({
  1309. tolerance: 'pointer',
  1310. accept: '.drag',
  1311. hoverClass: "activeDrop",
  1312. drop: function(event, ui) {
  1313. if (ui.draggable.data("dropType") == 1)
  1314. addProces(ui, this);
  1315. else
  1316. addResource(ui, this);
  1317. }
  1318. });
  1319. });
  1320. }
  1321. $(document).on('click', '.liProc', function() {
  1322. $(this).parents(".singleAdv").nextAll(".singleAdv").remove();
  1323. $(this).parents(".singleAdv").find(".active").removeClass("active");
  1324. $(this).find(".glyphicon").removeClass("glyphicon-triangle-right");
  1325. $(this).find(".glyphicon").addClass("glyphicon-refresh");
  1326. $(this).find(".glyphicon").addClass("anim-refresh");
  1327. $(this).addClass("active");
  1328. var parent = this;
  1329. var parent_id = $(this).data("id");
  1330. 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>';
  1331. var result = "";
  1332. var depth = $(this).parents(".singleAdv").data("depth") + 1;
  1333. $("#procCon").css("width", depth * 290 + 290);
  1334. $(this).parents(".singleAdv").after("<div class='singleAdv list-group' data-depth=" + depth + " id=depth" + depth + "></div>");
  1335. var childs = true;
  1336. $.get(link, function(data) {
  1337. $(data).find("featureMember").each(function() {
  1338. if ($(this).find("ID").text() == 0) {
  1339. childs = false;
  1340. return;
  1341. }
  1342. var type = 0;
  1343. 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>";
  1344. });
  1345. if (!childs) {
  1346. result += '<div class="panel panel-primary">';
  1347. result += '<div class="panel-heading"><h3 class="panel-title">[' + $(parent).data('id') + '] ' + $(parent).data("desc") + '</h3></div>';
  1348. result += '<div class="panel-body pbody">';
  1349. result += '<b>Opis: </b>' + $(parent).data("opis");
  1350. result += '</div>';
  1351. result += '</div>'
  1352. }
  1353. $("#depth" + depth).html(result);
  1354. $('.drag').draggable({
  1355. appendTo: 'body',
  1356. handle: '.handle',
  1357. helper: 'clone',
  1358. stack: "div",
  1359. distance: 0,
  1360. cursor: "copy",
  1361. start: function(event, ui) {
  1362. $(this).data("startingScrollTop", $(this).parent().scrollTop());
  1363. },
  1364. drag: function(event, ui) {
  1365. var st = parseInt($(this).data("startingScrollTop"));
  1366. ui.position.top -= $(document).scrollTop() - st;
  1367. ui.helper.css('z-index', 1000);
  1368. }
  1369. });
  1370. $(parent).find(".glyphicon").addClass("glyphicon-triangle-right");
  1371. $(parent).find(".glyphicon").removeClass("glyphicon-refresh");
  1372. $(parent).find(".glyphicon").removeClass("anim-refresh");
  1373. $("#ulproc").scrollLeft(depth * 290 + 290);
  1374. $("#ulproc").scrollTop(0);
  1375. });
  1376. });
  1377. function procesy() {
  1378. var side = $("#side");
  1379. $(side).empty();
  1380. //$(side).append("<h3>Zarządzaj zasobami<h3>");
  1381. $(side).append("<div class='form-group' ><input type='text' class=form-control id=sProcesy placeholder='Szukaj procesów'></div>");
  1382. $(side).append("<div id=ulproc><div id=procCon></div></div>");
  1383. $(side).find("#procCon").append("<div class='singleAdv list-group' data-depth=0 id=depth0></div>");
  1384. $(side).find("#procCon").append("<div class=clearfix></div>");
  1385. 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';
  1386. var result = "";
  1387. $.get(link, function(data) {
  1388. $(data).find("featureMember").each(function() {
  1389. var type = 0;
  1390. 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() + " >";
  1391. result += "<div class=textTable><span class=handle> # </span>";
  1392. result += $(this).find("DESC").text()
  1393. result += "</div><div class=detailsTable> [" + $(this).find("ID").text() + "]</div>";
  1394. result += "<div class='glyphicon glyphicon-triangle-right' style=opacity:0.4;float:right;></div><div class=clearfix></div></div>";
  1395. });
  1396. $("#depth0").html(result);
  1397. $('.drag').draggable({
  1398. appendTo: 'body',
  1399. handle: '.handle',
  1400. helper: 'clone',
  1401. stack: "div",
  1402. distance: 0,
  1403. cursor: "copy",
  1404. start: function(event, ui) {
  1405. $(this).data("startingScrollTop", $(this).parent().scrollTop());
  1406. },
  1407. drag: function(event, ui) {
  1408. var st = parseInt($(this).data("startingScrollTop"));
  1409. ui.position.top -= $(document).scrollTop() - st;
  1410. ui.helper.css('z-index', 1000);
  1411. }
  1412. });
  1413. });
  1414. }
  1415. $(document).on('click', '.liAdv', function() {
  1416. $(this).find(".glyphicon").removeClass("glyphicon-triangle-right");
  1417. $(this).find(".glyphicon").addClass("glyphicon-refresh");
  1418. $(this).parents(".singleAdv").nextAll(".singleAdv").remove();
  1419. $(this).parents(".singleAdv").find(".active").removeClass("active");
  1420. $(this).addClass("active");
  1421. var parent = this;
  1422. var parent_id = $(this).data("id");
  1423. 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';
  1424. var result = "";
  1425. var depth = $(this).parents(".singleAdv").data("depth") + 1;
  1426. $("#advCon").css("width", depth * 290 + 290);
  1427. $(this).parents(".singleAdv").after("<div class='singleAdv list-group' data-depth=" + depth + " id=depth" + depth + "></div>");
  1428. var childs = true;
  1429. $.get(link, function(data) {
  1430. $(data).find("featureMember").each(function() {
  1431. if ($(this).find("ID").text() == 0) {
  1432. childs = false;
  1433. return;
  1434. }
  1435. var type = 0;
  1436. if ($(this).find("TYPE").text() == "DZIAL" || $(this).find("TYPE").text() == "PODMIOT" || $(this).find("TYPE").text() == "STANOWISKO")
  1437. type = 1;
  1438. 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>";
  1439. result += "<div class='glyphicon glyphicon-triangle-right' style=opacity:0.4;float:right;></div>";
  1440. result += "<div class=clearfix></div><div class=detailsTable2>[" + $(this).find("ID").text() + "] " + $(this).find("TYPE").text() + "</div></div>";
  1441. });
  1442. if (!childs) {
  1443. result += '<div class="panel panel-primary">';
  1444. result += '<div class="panel-heading"><h3 class="panel-title">[' + $(parent).data('id') + '] ' + $(parent).data("desc") + '</h3></div>';
  1445. result += '<div class="panel-body pbody">';
  1446. result += '<b>Opis: </b>' + $(parent).data("opis");
  1447. result += '<br><b>Typ: </b>' + $(parent).data("typename");
  1448. result += '</div>';
  1449. result += '</div>'
  1450. }
  1451. $("#depth" + depth).html(result);
  1452. $('.drag').draggable({
  1453. appendTo: 'body',
  1454. handle: '.handle',
  1455. helper: 'clone',
  1456. stack: "div",
  1457. distance: 0,
  1458. cursor: "copy",
  1459. start: function(event, ui) {
  1460. $(this).data("startingScrollTop", $(this).parent().scrollTop());
  1461. },
  1462. drag: function(event, ui) {
  1463. var st = parseInt($(this).data("startingScrollTop"));
  1464. ui.position.top -= $(document).scrollTop() - st;
  1465. ui.helper.css('z-index', 1000);
  1466. }
  1467. });
  1468. $(parent).find(".glyphicon").addClass("glyphicon-triangle-right");
  1469. $(parent).find(".glyphicon").removeClass("glyphicon-refresh");
  1470. $("#ulcon").scrollLeft(depth * 290 + 290);
  1471. $("#ulcon").scrollTop(0);
  1472. });
  1473. });
  1474. function getImg(el) {
  1475. var name = el.files[0].name;
  1476. var size = el.files[0].size;
  1477. var type = el.files[0].type;
  1478. var link = BASE_URL + "wfs-data.php/default_db/?SERVICE=WFS&VERSION=1.0.0&SRSNAME=EPSG:3003";
  1479. var FR = new FileReader();
  1480. FR.onload = function(e) {
  1481. var content = e.target.result;
  1482. var image = new Image();
  1483. image.src = content;
  1484. image.onload = function() {
  1485. var width = el.width;
  1486. var height = el.height;
  1487. var xml =
  1488. `
  1489. <Transaction
  1490. xmlns="http://www.opengis.net/wfs"
  1491. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  1492. version="1.0.0"
  1493. service="WFS"
  1494. xmlns:p5_default_db="` + BASE_WFS_URL + `/default_db"
  1495. xmlns:gml="http://www.opengis.net/gml">
  1496. <Insert xmlns="http://www.opengis.net/wfs">
  1497. <CRM_IMAGE xmlns="` + BASE_WFS_URL + `/default_db">
  1498. <NAME xmlns="` + BASE_WFS_URL + `/default_db">` + name + `</NAME>
  1499. <IMAGE xmlns="` + BASE_WFS_URL + `/default_db">` + content + `</IMAGE>
  1500. <TYPE xmlns="` + BASE_WFS_URL + `/default_db">` + type + `</TYPE>
  1501. <SIZE xmlns="` + BASE_WFS_URL + `/default_db">` + size + `</SIZE>
  1502. <WIDTH xmlns="` + BASE_WFS_URL + `/default_db">` + width + `</WIDTH>
  1503. <HEIGHT xmlns="` + BASE_WFS_URL + `/default_db">` + height + `</HEIGHT>
  1504. <REMOTE_TABLE xmlns="` + BASE_WFS_URL + `/default_db">ADMIN_USERS</REMOTE_TABLE>
  1505. <REMOTE_ID xmlns="` + BASE_WFS_URL + `/default_db">` + USER_ID + `</REMOTE_ID>
  1506. </CRM_IMAGE>
  1507. </Insert>
  1508. </Transaction>`;
  1509. $.ajax({
  1510. url: link,
  1511. data: xml,
  1512. type: 'POST',
  1513. contentType: "text/xml",
  1514. dataType: "xml",
  1515. success: function(data) {
  1516. if ($(data).find("ServiceException").text() != "") {
  1517. $.notify($(data).find("ServiceException").text(), "error");
  1518. } else {
  1519. photos();
  1520. }
  1521. }
  1522. });
  1523. }
  1524. };
  1525. FR.readAsDataURL(el.files[0]);
  1526. }
  1527. function humanFileSize(bytes) {
  1528. var thresh = 1024;
  1529. if (Math.abs(bytes) < thresh) {
  1530. return bytes + ' B';
  1531. }
  1532. var units = ['kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']
  1533. var u = -1;
  1534. do {
  1535. bytes /= thresh;
  1536. ++u;
  1537. } while (Math.abs(bytes) >= thresh && u < units.length - 1);
  1538. return bytes.toFixed(1) + ' ' + units[u];
  1539. }
  1540. function uploadForm() {
  1541. var form = '<input id="fileupload" type="file" name="files[]" data-url="index.php?_route=UrlAction_procesEditor&_task=uploadVideo" multiple>' +
  1542. "<div id='upload_info'></div>" +
  1543. "<button style=width:100%; type='button' class='btn btn-default' id=upload_button>Umieść na serwerze</button>"
  1544. return form;
  1545. }
  1546. function photos() {
  1547. var side = $("#side");
  1548. $(side).empty();
  1549. $(side).append(uploadForm());
  1550. $('#upload_progress').css(
  1551. 'opacity',
  1552. 0
  1553. );
  1554. $('#fileupload').fileupload({
  1555. dataType: 'html',
  1556. add: function(e, data) {
  1557. $("#upload_button").off('click').on('click', function() {
  1558. data.submit();
  1559. });
  1560. var html = '<span class=upload_status></span>'
  1561. html += '<div class="progress" id=upload_progress>' +
  1562. '<div class="progress-bar" role="progressbar" aria-valuenow="0"' +
  1563. 'aria-valuemin="0" aria-valuemax="100" style="width:0%">' +
  1564. '<span>70%</span>' +
  1565. '</div>' +
  1566. '</div>'
  1567. $("#upload_info").html(html);
  1568. },
  1569. done: function(e, data) {
  1570. $('#upload_progress').css(
  1571. 'opacity',
  1572. 0
  1573. );
  1574. loadClipboard();
  1575. },
  1576. progressall: function(e, data) {
  1577. var progress = parseInt(data.loaded / data.total * 100, 10);
  1578. $('#upload_progress').find(".progress-bar").css(
  1579. 'width',
  1580. progress + '%'
  1581. );
  1582. var remaining = Math.ceil((data.total - data.loaded) * 8 / data.bitrate);
  1583. $('#upload_progress').find(".progress-bar").find("span").text(progress + '%');
  1584. var total = humanFileSize(data.total);
  1585. var bitrate = humanFileSize(data.bitrate / 10)
  1586. var loaded = humanFileSize(data.loaded);
  1587. $('#upload_info').find(".upload_status").text(loaded + "/" + total + " - pozostało " + remaining + " sekund [" + bitrate + "/s]");
  1588. }
  1589. });
  1590. var schowek = '<ul class="list-group" id=clipboard>';
  1591. schowek += '</ul>';
  1592. $(side).append(schowek);
  1593. loadClipboard();
  1594. }
  1595. function showVideo(data) {
  1596. var el = ""
  1597. return el;
  1598. }
  1599. function showMediaElement(data, type) {
  1600. var el = ""
  1601. if (!data || undefined === data['ID']) return '';
  1602. if ('video' === type && undefined === data['VIDEO_ID']) return '';
  1603. if ('img' === type && undefined === data['IMAGE']) return '';
  1604. if (type == "video") {
  1605. //el += "<div class=attVid><div class=remImg>X</div>"
  1606. el += "<div class=attVid><div class=imgTitle><i class='glyphicon glyphicon-option-vertical'></i>"
  1607. el += data["NAME"]
  1608. el += "</div>"
  1609. el += "<div class='p5VideoPlayer' id=p1 "
  1610. el += "data-start=0 data-end=560 "
  1611. el += "data-videoid=" + data["VIDEO_ID"] + ">"
  1612. el += "<div class=img>"
  1613. el += "<img src='" + "data:" + (data["THUMBNAIL"]["IMAGE"]) + "' / >"
  1614. el += "</div>"
  1615. el += "</div>"
  1616. el += "</div>"
  1617. } else if (type == "img") {
  1618. el += "<div class=attImg data-id=" + data["ID"] + ">"
  1619. el += "<div class=imgTitle>"
  1620. el += "<i class='glyphicon glyphicon-option-vertical'></i>"
  1621. el += data["NAME"] + "</div><div class='img'>"
  1622. el += "<img src='" + "data:" + data["IMAGE"] + "' / >"
  1623. el += "</div></div>"
  1624. }
  1625. return el;
  1626. }
  1627. function loadClipboard() {
  1628. $("#clipboard").empty();
  1629. 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>';
  1630. $.get(link, function(data) {
  1631. var list = "";
  1632. $(data).find("featureMember").each(function() {
  1633. if (typeof usedImg[$(this).find("ID").text()] == "undefined") {
  1634. var opts = {};
  1635. opts["ID"] = $(this).find("ID").text();
  1636. opts["IMAGE"] = base64_decode($(this).find("IMAGE").text());
  1637. opts["NAME"] = $(this).find("NAME").text();
  1638. list += showMediaElement(opts, "img");
  1639. }
  1640. });
  1641. $("#clipboard").append(list);
  1642. $('.attImg').draggable({
  1643. appendTo: 'body',
  1644. //revert: true,
  1645. zIndex: 100,
  1646. helper: "clone",
  1647. stack: "div",
  1648. distance: 0,
  1649. handle: '.imgTitle',
  1650. scroll: true,
  1651. start: function(event, ui) {
  1652. $(this).data("startingScrollTop", $(this).parent().scrollTop());
  1653. },
  1654. drag: function(event, ui) {
  1655. var st = parseInt($(this).data("startingScrollTop"));
  1656. ui.position.top -= $(document).scrollTop() - st;
  1657. ui.helper.css('z-index', 1000);
  1658. }
  1659. });
  1660. });
  1661. link = BASE_URL + "index.php?_route=UrlAction_ProcesEditor&_task=getVideosClipboardAjax"
  1662. $.get(link, function(data) {
  1663. var list = "";
  1664. $.each(data, function(i, e) {
  1665. list += showMediaElement(e, "video");
  1666. })
  1667. $("#clipboard").prepend(list);
  1668. $('.attVid').draggable({
  1669. appendTo: 'body',
  1670. //revert: true,
  1671. zIndex: 100,
  1672. helper: "clone",
  1673. stack: "div",
  1674. distance: 0,
  1675. handle: '.imgTitle',
  1676. scroll: true,
  1677. start: function(event, ui) {
  1678. $(this).data("startingScrollTop", $(this).parent().scrollTop());
  1679. },
  1680. drag: function(event, ui) {
  1681. var st = parseInt($(this).data("startingScrollTop"));
  1682. ui.position.top -= $(document).scrollTop() - st;
  1683. ui.helper.css('z-index', 1000);
  1684. }
  1685. });
  1686. });
  1687. }
  1688. function zasoby() {
  1689. var side = $("#side");
  1690. $(side).empty();
  1691. $(side).append("<div class='form-group' ><input type='text' class=form-control id=sZasoby placeholder='Szukaj zasobów'></div>");
  1692. $(side).append("<div class='btn-group' style=width:100% id=filtry></div>");
  1693. $("#filtry").append("<button type='button' data-type=1 class='fbutton btn btn-default input-block-level ' style=width:40%>Stanowiska</button>");
  1694. $("#filtry").append("<button type='button' data-type=2 class='fbutton btn btn-default input-block-level ' style=width:40%>Komórki</button>");
  1695. $("#filtry").append("<button type='button' data-type=0 class='fbutton btn btn-danger input-block-level' id=xBtn style=width:20% disabled>X</button>");
  1696. $(side).append("<div id=ulcon><div id=advCon></div></div>");
  1697. $(side).find("#advCon").append("<div class='singleAdv list-group' data-depth=0 id=depth0></div>");
  1698. $(side).find("#advCon").append("<div class=clearfix></div>");
  1699. 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';
  1700. var result = "";
  1701. $.get(link, function(data) {
  1702. $(data).find("featureMember").each(function() {
  1703. var type = 0;
  1704. if ($(this).find("TYPE").text() == "DZIAL" || $(this).find("TYPE").text() == "PODMIOT" || $(this).find("TYPE").text() == "STANOWISKO")
  1705. type = 1;
  1706. result += "<div class='drag list-group-item liAdv'";
  1707. 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() + "'"
  1708. result += "title='" + $(this).find("DESC").text() + "'>"
  1709. result += "<div class=textTable2>"
  1710. result += "<span class=handle> # </span>" + $(this).find("DESC").text() + "</div>"
  1711. result += "<div class='glyphicon glyphicon-triangle-right' style=opacity:0.4;float:right; style=float:left;></div>"
  1712. result += "<div class=clearfix></div>"
  1713. result += "<div class=detailsTable2>[" + $(this).find("ID").text() + "] " + $(this).find("TYPE").text() + "</div>"
  1714. result += "</div>";
  1715. });
  1716. $("#depth0").html(result);
  1717. $('.drag').draggable({
  1718. appendTo: 'body',
  1719. handle: '.handle',
  1720. helper: 'clone',
  1721. stack: "div",
  1722. distance: 0,
  1723. cursor: "copy",
  1724. scroll: true,
  1725. start: function(event, ui) {
  1726. $(this).data("startingScrollTop", $(this).parent().scrollTop());
  1727. },
  1728. drag: function(event, ui) {
  1729. var st = parseInt($(this).data("startingScrollTop"));
  1730. ui.position.top -= $(document).scrollTop() - st;
  1731. ui.helper.css('z-index', 1000);
  1732. }
  1733. });
  1734. });
  1735. //$(side).find("#ulcon").append("<div class='drag' data-id=1 data-type=1 >[STANOWISKO] Ulotkarz</div>");
  1736. //$(side).find("#ulcon").append("<div class='drag' data-id=2 data-type=1 >[STANOWISKO] Programista PHP</div>");
  1737. //$(side).find("#ulcon").append("<div class='drag' data-id=3 data-type=2 >[ZASÓB] Komputer</div>");
  1738. }
  1739. function removeImg(content, id) {
  1740. $.each(content, function(i, e) {
  1741. if (e["id"] == id) {
  1742. content.splice(i, 1);
  1743. return;
  1744. }
  1745. })
  1746. }
  1747. function dropVid(ui, target) {
  1748. var id = $(target).closest(".drop").data("id");
  1749. var proces = id;
  1750. var idBefore = $(ui.draggable).closest(".drop").data("id");
  1751. var procesBefore = idBefore;
  1752. var type = "CRM_PROCES";
  1753. var typeName = "proces";
  1754. var typeNameBefore = "proces";
  1755. if ($(target).closest(".professions").length) {
  1756. id = $(target).closest("li").data("id");
  1757. type = "CRM_WSKAZNIK";
  1758. typeName = "prof";
  1759. } else if ($(target).closest(".resources").length) {
  1760. id = $(target).closest("li").data("id");
  1761. typeNameBefore = "res";
  1762. type = "CRM_WSKAZNIK";
  1763. typeName = "res";
  1764. }
  1765. if ($(ui.draggable).closest(".professions").length) {
  1766. typeNameBefore = "prof";
  1767. idBefore = $(ui.draggable).closest("li").data("id");
  1768. } else if ($(ui.draggable).closest(".resources").length) {
  1769. typeNameBefore = "res";
  1770. idBefore = $(ui.draggable).closest("li").data("id");
  1771. }
  1772. var temp = {};
  1773. temp["THUMBNAIL"] = {};
  1774. temp["THUMBNAIL"]["IMAGE"] = $(ui.draggable).find("img").attr("src");
  1775. temp["NAME"] = $(ui.draggable).find(".imgTitle").text();
  1776. temp["VIDEO_ID"] = $(ui.draggable).find(".p5VideoPlayer").data("videoid");
  1777. usedImg[temp["id"]] = {
  1778. type: type,
  1779. targetID: id,
  1780. action: "ATTACH"
  1781. };
  1782. if (typeName != "proces" && typeof state[getIndexById(proces)][typeName][
  1783. [getResById(getIndexById(proces), $(target).closest("li").data("id"), typeName)]
  1784. ]["vid"] == "undefined") {
  1785. state[getIndexById(proces)][typeName][getResById(getIndexById(proces), $(target).closest("li").data("id"), typeName)]["vid"] = Array();
  1786. } else if (typeName == "proces" && typeof state[getIndexById(id)]["img"] == "undefined") {
  1787. state[getIndexById(proces)]["vid"] = Array();
  1788. }
  1789. if (typeof idBefore != "undefined")
  1790. if (typeNameBefore == "proces") {
  1791. removeImg(state[getIndexById(procesBefore)]["vid"], temp["id"]);
  1792. } else {
  1793. removeImg(state[getIndexById(procesBefore)][typeNameBefore][getResById(getIndexById(procesBefore), $(ui.draggable).closest("li").data("id"), typeNameBefore)]["img"], temp["id"]);
  1794. }
  1795. if (typeName == "proces")
  1796. state[getIndexById(id)]["vid"].push(temp);
  1797. else {
  1798. state[getIndexById(proces)][typeName][getResById(getIndexById(proces), $(target).closest("li").data("id"), typeName)]["img"].push(temp);
  1799. }
  1800. $(ui.draggable).remove();
  1801. console.log(state);
  1802. updateAll();
  1803. }
  1804. function dropImg(ui, target) {
  1805. var id = $(target).closest(".drop").data("id");
  1806. var proces = id;
  1807. var idBefore = $(ui.draggable).closest(".drop").data("id");
  1808. var procesBefore = idBefore;
  1809. var type = "CRM_PROCES";
  1810. var typeName = "proces";
  1811. var typeNameBefore = "proces";
  1812. if ($(target).closest(".professions").length) {
  1813. id = $(target).closest("li").data("id");
  1814. type = "CRM_WSKAZNIK";
  1815. typeName = "prof";
  1816. } else if ($(target).closest(".resources").length) {
  1817. id = $(target).closest("li").data("id");
  1818. typeNameBefore = "res";
  1819. type = "CRM_WSKAZNIK";
  1820. typeName = "res";
  1821. }
  1822. if ($(ui.draggable).closest(".professions").length) {
  1823. typeNameBefore = "prof";
  1824. idBefore = $(ui.draggable).closest("li").data("id");
  1825. } else if ($(ui.draggable).closest(".resources").length) {
  1826. typeNameBefore = "res";
  1827. idBefore = $(ui.draggable).closest("li").data("id");
  1828. }
  1829. var temp = {};
  1830. temp["src"] = $(ui.draggable).find("img").attr("src");
  1831. temp["title"] = $(ui.draggable).find(".imgTitle").text();
  1832. temp["id"] = $(ui.draggable).data("id");
  1833. usedImg[temp["id"]] = {
  1834. type: type,
  1835. targetID: id,
  1836. action: "ATTACH"
  1837. };
  1838. if (typeName != "proces" && typeof state[getIndexById(proces)][typeName][
  1839. [getResById(getIndexById(proces), $(target).closest("li").data("id"), typeName)]
  1840. ]["img"] == "undefined") {
  1841. state[getIndexById(proces)][typeName][getResById(getIndexById(proces), $(target).closest("li").data("id"), typeName)]["img"] = Array();
  1842. } else if (typeName == "proces" && typeof state[getIndexById(id)]["img"] == "undefined") {
  1843. state[getIndexById(proces)]["img"] = Array();
  1844. }
  1845. if (typeof idBefore != "undefined")
  1846. if (typeNameBefore == "proces") {
  1847. removeImg(state[getIndexById(procesBefore)]["img"], temp["id"]);
  1848. } else {
  1849. removeImg(state[getIndexById(procesBefore)][typeNameBefore][getResById(getIndexById(procesBefore), $(ui.draggable).closest("li").data("id"), typeNameBefore)]["img"], temp["id"]);
  1850. }
  1851. if (typeName == "proces")
  1852. state[getIndexById(id)]["img"].push(temp);
  1853. else {
  1854. state[getIndexById(proces)][typeName][getResById(getIndexById(proces), $(target).closest("li").data("id"), typeName)]["img"].push(temp);
  1855. }
  1856. $(ui.draggable).remove();
  1857. updateAll();
  1858. }
  1859. function addProces(ui, target) {
  1860. var id = $(target).data("id");
  1861. var gotoOpt = "";
  1862. $.each(gotoType, function(key, value) {
  1863. gotoOpt += "<option value=" + value[0] + ">" + value[1] + "</option>";
  1864. })
  1865. swal({
  1866. showCancelButton: true,
  1867. cancelButtonText: "Anuluj",
  1868. title: 'Typ łącza',
  1869. html: (
  1870. typeof state[getIndexById(id)]["goto"] !== typeof undefined && state[getIndexById(id)]["goto"]["id"] != null && state[getIndexById(id)]["goto"]["id"] != 0 ?
  1871. '<span class=class="alert alert-warning"><strong>Uwaga!</strong> Nowe łącze nadpisze już istniejące łącze.</span><br>' :
  1872. ""
  1873. ) + '<br><select class=form-control id="swal-input1">' + gotoOpt + '</select>',
  1874. preConfirm: function() {
  1875. return new Promise(function(resolve) {
  1876. resolve([
  1877. $('#swal-input1').val()
  1878. ]);
  1879. });
  1880. }
  1881. }).then(function(result) {
  1882. newRes--;
  1883. var temp = {};
  1884. temp["flag"] = result[0];
  1885. temp["id"] = ui.draggable.data("id");
  1886. state[getIndexById(id)]["goto"] = temp;
  1887. updateAll();
  1888. }).catch(function(e) {})
  1889. }
  1890. function addResource(ui, target) {
  1891. var permsOpt = "";
  1892. $.each(perms, function(key, value) {
  1893. permsOpt = permsOpt + "<option value=" + value[0] + ">[" + value[2] + "] " + value[1] + "</option>";
  1894. })
  1895. swal({
  1896. showCancelButton: true,
  1897. cancelButtonText: "Anuluj",
  1898. title: 'Uprawnienia',
  1899. html: 'Uprawnienia<br><select class=form-control id="swal-input1">' + permsOpt + '</select>' +
  1900. 'Komentarz<br><input class=form-control id="swal-input2" class="swal2-input">',
  1901. preConfirm: function() {
  1902. return new Promise(function(resolve) {
  1903. resolve([
  1904. $('#swal-input1').val(),
  1905. $('#swal-input2').val()
  1906. ]);
  1907. });
  1908. }
  1909. }).then(function(result) {
  1910. newRes--;
  1911. var temp = {};
  1912. temp["id_zasob"] = ui.draggable.data("id");
  1913. temp["id"] = newRes;
  1914. temp["id_przypadek"] = result[0];
  1915. temp["komentarz"] = result[1];
  1916. temp["changed"] = true;
  1917. temp["opis"] = ui.draggable.data("opis");
  1918. temp["desc"] = ui.draggable.data("desc");
  1919. temp["tree"] = zasobTree[temp["id_zasob"]];
  1920. var id = $(target).data("id");
  1921. if (ui.draggable.data("type") == 1) {
  1922. state[getIndexById(id)]["prof"].push(temp);
  1923. } else {
  1924. state[getIndexById(id)]["res"].push(temp);
  1925. }
  1926. updateAll();
  1927. }).catch(function(e) {})
  1928. }
  1929. //Najwazniejsza funkcja odpalana po kazdej zmianie. Sprawdza, czy wszystkie funkcje maja rodzica,
  1930. //jezeli nie to przesuwa w lewo obiekt
  1931. //Odpowiada tez za ukrywanie guzikow i wywowalanie funkcji generacji krokow
  1932. function updateAll() {
  1933. $.each(state, function(i, e) {
  1934. var pid = getParentNode(e["id"]);
  1935. if (pid != "NONE" && pid != false && pid != e["parent_id"]) {
  1936. e["parent_id"] = pid;
  1937. } else if (pid === false) {
  1938. e["depth"]--;
  1939. //var depthWidth = 20 * $(node).data("depth");
  1940. //$(node).css("padding-left", depthWidth + "px");
  1941. updateAll();
  1942. return;
  1943. }
  1944. });
  1945. changes = true;
  1946. $("#clearBtn").show();
  1947. /*
  1948. localStorage.setItem("state" + mainProces_id, JSON.stringify(state));
  1949. localStorage.setItem("newStep" + mainProces_id, newSteps);
  1950. localStorage.setItem("newRes" + mainProces_id, newRes);
  1951. localStorage.setItem("deletedId" + mainProces_id, JSON.stringify(deletedId));
  1952. localStorage.setItem("deletedRes" + mainProces_id, JSON.stringify(deletedRes));
  1953. localStorage.setItem("date" + mainProces_id, moment().format("YYYY-MM-DD HH:mm:ss"));
  1954. */
  1955. render(state, $("#main"));
  1956. }
  1957. //Generuje kroki, sprawdza tez czy kolejnosc krokow w danym rodzicow zostala zmieniona
  1958. //Jezeli tak to mozna wyslac ajaxem zmiane kolejnosci dla sort_prio
  1959. function stepsGenerator() {
  1960. $.each(state, function(i, e) {
  1961. e["step"] = 0;
  1962. if (i == 0)
  1963. e["stepDesc"] = "";
  1964. else {
  1965. var iParent = getIndexById(e["parent_id"]);
  1966. state[iParent]["step"] += 1;
  1967. e["SORT_PRIO"] = state[iParent]["step"];
  1968. e["stepDesc"] = state[iParent]["stepDesc"] + state[iParent]["step"] + ". ";
  1969. }
  1970. });
  1971. }
  1972. //Na potrzeby guzikow dorobilem funkcje sprawdzajaca id rodzica po przesunieciu (przewidywanie).
  1973. //Jezeli nie znajdzie zwraca false, a wtedy blokuje sie odpowiednia strzalka
  1974. function checkParentNode(id, check) {
  1975. var x = getIndexById(id);
  1976. var y = x;
  1977. var result = false;
  1978. while (x > 0) {
  1979. x--;
  1980. if (check == "right")
  1981. if (state[x]["depth"] == state[y]["depth"]) {
  1982. result = state[x]["id"];
  1983. break;
  1984. }
  1985. if (check == "left")
  1986. if (state[x]["depth"] == state[y]["depth"] - 2) {
  1987. result = state[x]["id"];
  1988. break;
  1989. }
  1990. if (check == "right" && state[x]["depth"] < state[y]["depth"])
  1991. break;
  1992. }
  1993. return result;
  1994. }
  1995. //Zwraca id rodzica, jezeli nie ma zwraca false
  1996. function getParentNode(id) {
  1997. var x = getIndexById(id);
  1998. var y = x;
  1999. if (x == 0)
  2000. return "NONE";
  2001. var result = false;
  2002. while (x > 0) {
  2003. x--;
  2004. if (state[x]["depth"] == state[y]["depth"] - 1) {
  2005. result = state[x]["id"];
  2006. break;
  2007. }
  2008. if (state[x]["depth"] - state[y]["depth"] == -2)
  2009. break;
  2010. }
  2011. return result;
  2012. }
  2013. function getResById(index, id, type) {
  2014. var result = state[index][type].length - 1;
  2015. $.each(state[index][type], function(i, e) {
  2016. if (e["id"] == id) {
  2017. result = i;
  2018. return false;
  2019. }
  2020. });
  2021. return result;
  2022. }
  2023. function getIndexById(id, arr, label) {
  2024. var arr = arr || state
  2025. var label = label || "id"
  2026. var result = arr.length - 1;
  2027. if (label == "ID")
  2028. result = -1;
  2029. $.each(arr, function(i, e) {
  2030. if (e[label] == id) {
  2031. result = i;
  2032. return false;
  2033. }
  2034. });
  2035. return result;
  2036. }
  2037. $(".remImg").on('click', function() {
  2038. var obj = $(this).closest(".attImg");
  2039. var id = $(this).closest(".drop").data("id");
  2040. var typeName = "proces";
  2041. if ($(obj).closest(".professions").length) {
  2042. typeName = "prof";
  2043. } else if ($(obj).closest(".resources").length) {
  2044. typeName = "res";
  2045. }
  2046. //if(typeof idBefore != "undefined")
  2047. if (typeName == "proces")
  2048. removeImg(state[getIndexById(id)]["img"], $(obj).data("id"));
  2049. else {
  2050. removeImg(state[getIndexById(id)][typeName][getResById(getIndexById(id), $(obj).closest("li").data("id"), typeName)]["img"], $(obj).data("id"));
  2051. }
  2052. $(ui.draggable).remove();
  2053. usedImg[$(obj).data("id")] = {
  2054. type: "",
  2055. targetID: -1,
  2056. action: "DELETED"
  2057. };
  2058. updateAll();
  2059. return false;
  2060. });
  2061. $(document).on('click', '.stateOff', function() {
  2062. $(this).closest(".mx").prev(".tree").show();
  2063. $(this).closest(".mx").remove();
  2064. });
  2065. $(document).on('click', '.tree', function() {
  2066. var type;
  2067. if ($(this).closest("ul").hasClass("resources")) {
  2068. type = "res";
  2069. } else {
  2070. type = "prof"
  2071. }
  2072. var id = getIndexById($(this).closest(".drop").data("id"));
  2073. var resId = getResById(id, $(this).closest(".liRes").data("id"), type);
  2074. $(this).hide();
  2075. showTree(state[id][type][resId]["tree"], $(this));
  2076. });
  2077. function showTree(arr, target) {
  2078. result = "";
  2079. $.each(arr, function(i, x) {
  2080. result += "<li style=padding-left:" + i * 16 + "px;><span class='glyphicon glyphicon-arrow-right'></span> " + x["DESC"] + "</li>";
  2081. });
  2082. $(target).after("<div class=mx><div class=stateOff><span class='glyphicon glyphicon-chevron-up'></span></div> <ul style=padding-left:0px;>" + result + "</ul></div>");
  2083. }
  2084. function render(arr, target) {
  2085. stepsGenerator();
  2086. var result = "";
  2087. $.each(arr, function(i, e) {
  2088. result += "<div class='drop container-fluid' data-id=" + e["id"] + " id='proc" + e["id"] + "'>";
  2089. result += "<div class='col-xs-1 options' style=text-align:right;padding-top:2px; id=opt" + e["id"] + ">";
  2090. if (i > 0) {
  2091. result += "<span class='glyphicon glyphicon-remove-sign ico del' title='Usuń krok' aria-hidden='true'></span>";
  2092. //Arrows
  2093. if (checkParentNode(e["id"], "right") !== false)
  2094. result += "<span class='glyphicon glyphicon-arrow-right ico rArrow' aria-hidden='true' title='Przesuń krok w prawo'></span>";
  2095. if (checkParentNode(e["id"], "left") !== false)
  2096. result += "<span class='glyphicon glyphicon-arrow-left ico lArrow' aria-hidden='true' title='Przesuń krok w lewo'></span>";
  2097. if (i != 1)
  2098. result += "<span class='glyphicon glyphicon-arrow-up ico uArrow' aria-hidden='true' title='Przesuń krok w górę'></span>";
  2099. if (i != state.length - 1)
  2100. result += "<span class='glyphicon glyphicon-arrow-down ico dArrow' aria-hidden='true' title='Przesuń krok w dół'></span>";
  2101. } else {}
  2102. result += "<span class='hDescAdd glyphicon glyphicon-edit ico' title='Edytuj tytuł'></span>";
  2103. result += "<div class='clearfix'></div>";
  2104. if (e["opis"] == "")
  2105. result += "<span class=sDescAdd>Dodaj opis</span>";
  2106. else
  2107. result += "<span class=sDescAdd>Edytuj opis</span>";
  2108. result += "</div>";
  2109. 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>";
  2110. // }
  2111. // if ($(this).find("OPIS").text() == "") {
  2112. // $("#proc" + $(this).find("ID").text()).find(".sdesc").after("<span class=sDescAdd>Dodaj opis</span>");
  2113. // }
  2114. result += "<div class='clearfix'></div><div class=imagesProc>";
  2115. if (typeof e["img"] !== "undefined") {
  2116. //console.log(e["img"])
  2117. $.each(e["img"], function(key, eImg) {
  2118. var img = showMediaElement({
  2119. "ID": eImg["id"],
  2120. "IMAGE": eImg["src"],
  2121. "NAME": eImg["title"]
  2122. }, "img")
  2123. result += img;
  2124. })
  2125. }
  2126. if (typeof e["vid"] !== "undefined") {
  2127. //console.log(e["img"])
  2128. $.each(e["vid"], function(key, eVid) {
  2129. var vid = showMediaElement(eVid, "video")
  2130. result += vid;
  2131. })
  2132. }
  2133. result += "<div class=clearfix></div></div><br>";
  2134. var anyProf = false;
  2135. $.each(e["prof"], function(i2, e2) {
  2136. if (!anyProf) {
  2137. 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;>";
  2138. anyProf = true;
  2139. }
  2140. 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>";
  2141. result += "<div class=col-sm-2 style=text-align:right;>";
  2142. if (i2 != 0)
  2143. result += "<span class='glyphicon glyphicon-arrow-up uArrowRes' title='Przesuń wskaźnik w górę' aria-hidden='true'></span>";
  2144. if (i2 != e["prof"].length - 1)
  2145. result += "<span class='glyphicon glyphicon-arrow-down dArrowRes' title='Przesuń wskaźnik w dół' aria-hidden='true'></span>";
  2146. 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>";
  2147. result += "</div>";
  2148. result += "<div class='col-sm-10 changable " + (e2["changed"] ? "changed" : "") + " '><b>" + e2["desc"] + "</b> " + e2["opis"] + " [" + e2["id_zasob"] + "] <br><span class=tree>";
  2149. if(typeof e2["tree"] !== "undefined" && e2["tree"].length > 0){ //TO DO DOWNLOAD TREE WHEN NOT EXISTS
  2150. result += "<span class=state><span class='glyphicon glyphicon-chevron-down'></span></span> ";
  2151. $.each(e2["tree"], function(i, x) {
  2152. result += x["DESC"] + (i < e2["tree"].length - 1 ? "<span class='glyphicon glyphicon-triangle-right'></span> " : "");
  2153. });
  2154. }
  2155. result += "</span></div>";
  2156. if (typeof e2["img"] !== "undefined") {
  2157. //console.log(e["img"])
  2158. $.each(e2["img"], function(key, eImg) {
  2159. var img = showMediaElement({
  2160. "ID": eImg["id"],
  2161. "IMAGE": eImg["src"],
  2162. "NAME": eImg["title"]
  2163. }, "img")
  2164. result += img;
  2165. })
  2166. }
  2167. result += "</div></li>";
  2168. });
  2169. if (anyProf) {
  2170. result += "</ul>";
  2171. }
  2172. var anyRes = false;
  2173. $.each(e["res"], function(i2, e2) {
  2174. if (!anyRes) {
  2175. 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;>";
  2176. anyRes = true;
  2177. }
  2178. 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>";
  2179. result += "<div class=col-sm-2 style=text-align:right;>";
  2180. if (i2 != 0)
  2181. result += "<span class='glyphicon glyphicon-arrow-up uArrowRes' title='Przesuń wskaźnik w górę' aria-hidden='true'></span>";
  2182. if (i2 != e["res"].length - 1)
  2183. result += "<span class='glyphicon glyphicon-arrow-down dArrowRes' title='Przesuń wskaźnik w dół' aria-hidden='true'></span>";
  2184. 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>";
  2185. result += "</div>";
  2186. result += "<div class='col-sm-10 changable " + (e2["changed"] ? "changed" : "") + " '><b>" + e2["desc"] + "</b> " + e2["opis"] + " [" + e2["id_zasob"] + "] <br><span class=tree>";
  2187. if(typeof e2["tree"] !== "undefined" && e2["tree"].length > 0){ //TO DO DOWNLOAD TREE WHEN NOT EXISTS
  2188. result += "<span class=state><span class='glyphicon glyphicon-chevron-down'></span></span> ";
  2189. $.each(e2["tree"], function(i, x) {
  2190. result += x["DESC"] + (i < e2["tree"].length - 1 ? "<span class='glyphicon glyphicon-triangle-right'></span> " : "");
  2191. });
  2192. }
  2193. result += "</span></div>";
  2194. if (typeof e2["img"] !== "undefined") {
  2195. //console.log(e["img"])
  2196. $.each(e2["img"], function(key, eImg) {
  2197. var img = showMediaElement({
  2198. "ID": eImg["id"],
  2199. "IMAGE": eImg["src"],
  2200. "NAME": eImg["title"]
  2201. }, "img")
  2202. result += img;
  2203. })
  2204. }
  2205. result += "</div></li>";
  2206. });
  2207. if (anyRes) {
  2208. result += "</ul>";
  2209. }
  2210. if (typeof e["goto"] !== typeof undefined && e["goto"]["id"] != null && e["goto"]["id"] != 0) {
  2211. var name;
  2212. switch (e["goto"]["flag"]) {
  2213. case "GOTO":
  2214. name = "Przejdź do procesu " + e["goto"]["id"] + ".";
  2215. break;
  2216. case "GOTO_AND_RETURN":
  2217. name = "Przejdź do procesu " + e["goto"]["id"] + ", a następnie wróć.";
  2218. break;
  2219. case "FORK":
  2220. name = "&mdash; FORK" + e["goto"]["id"];
  2221. break;
  2222. default:
  2223. name = e["goto"]["id"];
  2224. }
  2225. 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>";
  2226. }
  2227. result += "<br><span class=step>Dodaj nowy krok</span>";
  2228. result += "</div>"
  2229. result += "</div>";
  2230. });
  2231. $(target).html(result);
  2232. $('.drag').draggable({
  2233. appendTo: 'body',
  2234. helper: 'clone',
  2235. stack: "div",
  2236. distance: 0,
  2237. cursor: "copy",
  2238. scroll: true,
  2239. start: function(event, ui) {
  2240. $(this).data("startingScrollTop", $(this).parent().scrollTop());
  2241. },
  2242. drag: function(event, ui) {
  2243. var st = parseInt($(this).data("startingScrollTop"));
  2244. ui.position.top -= $(document).scrollTop() - st;
  2245. ui.helper.css('z-index', 1000);
  2246. }
  2247. });
  2248. $(".drop").droppable({
  2249. tolerance: 'pointer',
  2250. accept: '.drag',
  2251. zIndex: 0,
  2252. hoverClass: "activeDrop",
  2253. drop: function(event, ui) {
  2254. if (ui.draggable.data("droptype") == 1)
  2255. addProces(ui, this);
  2256. else
  2257. addResource(ui, this);
  2258. }
  2259. });
  2260. $(".sdesc").droppable({
  2261. tolerance: 'pointer',
  2262. accept: '.attImg, .attVid',
  2263. zIndex: 0,
  2264. hoverClass: "activeDrop",
  2265. drop: function(event, ui) {
  2266. if($(ui.draggable).hasClass("attVid"))
  2267. dropVid(ui, this);
  2268. else if($(ui.draggable).hasClass("attImg"))
  2269. dropImg(ui, this);
  2270. }
  2271. });
  2272. $(".liRes").droppable({
  2273. tolerance: 'pointer',
  2274. accept: '.attImg',
  2275. zIndex: 0,
  2276. hoverClass: "activeDrop",
  2277. drop: function(event, ui) {
  2278. dropImg(ui, this);
  2279. return false;
  2280. }
  2281. });
  2282. $('.attImg').draggable({
  2283. appendTo: 'body',
  2284. zIndex: 100,
  2285. helper: "clone",
  2286. stack: "div",
  2287. handle: '.imgTitle',
  2288. distance: 0,
  2289. scroll: true,
  2290. start: function(event, ui) {
  2291. $(this).data("startingScrollTop", $(this).parent().scrollTop());
  2292. },
  2293. drag: function(event, ui) {
  2294. var st = parseInt($(this).data("startingScrollTop"));
  2295. ui.position.top -= $(document).scrollTop() - st;
  2296. ui.helper.css('z-index', 1000);
  2297. }
  2298. });
  2299. }
  2300. function genTree(parent_id) {
  2301. 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';
  2302. $.ajax({
  2303. url: link,
  2304. success: function(data) {
  2305. var i = 0;
  2306. $.each($(data).find("featureMember"), function() {
  2307. var temp = {};
  2308. if ($(this).find("ID").text() == "0")
  2309. return;
  2310. var parentIndex = getIndexById(parent_id);
  2311. temp["id"] = $(this).find("ID").text();
  2312. temp["desc"] = $(this).find("DESC").text();
  2313. temp["opis"] = $(this).find("OPIS").text();
  2314. temp["parent_id"] = $(this).find("PARENT_ID").text();
  2315. temp["depth"] = state[parentIndex]["depth"] + 1;
  2316. temp["step"] = 0;
  2317. temp["prof"] = new Array();
  2318. temp["res"] = new Array();
  2319. temp["goto"] = {};
  2320. temp["goto"]["id"] = $(this).find("IF_TRUE_GOTO").text();
  2321. temp["goto"]["flag"] = $(this).find("IF_TRUE_GOTO_FLAG").text();
  2322. temp["stepDesc"] = "";
  2323. i++;
  2324. state.splice(parentIndex + i, 0, temp);
  2325. // 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>';
  2326. // $.get(linkImg, function(imgData) {
  2327. // var temp = Array();
  2328. // $.each($(imgData).find("featureMember"), function() {
  2329. // temp.push({
  2330. // "src": base64_decode($(this).find("IMAGE").text()),
  2331. // "title": $(this).find("NAME").text(),
  2332. // "id": $(this).find("ID").text(),
  2333. // });
  2334. // })
  2335. // state[getIndexById(temp["id"])]["img"] = temp;
  2336. // });
  2337. genTree($(this).find("ID").text());
  2338. });
  2339. }
  2340. });
  2341. }
  2342. function base64_decode(input) {
  2343. var _keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="
  2344. var output = "";
  2345. var chr1, chr2, chr3;
  2346. var enc1, enc2, enc3, enc4;
  2347. var i = 0;
  2348. input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
  2349. while (i < input.length) {
  2350. enc1 = _keyStr.indexOf(input.charAt(i++));
  2351. enc2 = _keyStr.indexOf(input.charAt(i++));
  2352. enc3 = _keyStr.indexOf(input.charAt(i++));
  2353. enc4 = _keyStr.indexOf(input.charAt(i++));
  2354. chr1 = (enc1 << 2) | (enc2 >> 4);
  2355. chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
  2356. chr3 = ((enc3 & 3) << 6) | enc4;
  2357. output = output + String.fromCharCode(chr1);
  2358. if (enc3 != 64) {
  2359. output = output + String.fromCharCode(chr2);
  2360. }
  2361. if (enc4 != 64) {
  2362. output = output + String.fromCharCode(chr3);
  2363. }
  2364. }
  2365. var string = "";
  2366. var i = 0;
  2367. var c = c1 = c2 = 0;
  2368. while (i < output.length) {
  2369. c = output.charCodeAt(i);
  2370. if (c < 128) {
  2371. string += String.fromCharCode(c);
  2372. i++;
  2373. } else if ((c > 191) && (c < 224)) {
  2374. c2 = output.charCodeAt(i + 1);
  2375. string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
  2376. i += 2;
  2377. } else {
  2378. c2 = output.charCodeAt(i + 1);
  2379. c3 = output.charCodeAt(i + 2);
  2380. string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
  2381. i += 3;
  2382. }
  2383. }
  2384. return string;
  2385. }
  2386. //Pierwszy render, tworzy potrzebna strukture
  2387. function showPreview() {
  2388. if (mainProces_id == -1)
  2389. newSteps = -1;
  2390. else
  2391. newSteps = 0;
  2392. changes = false;
  2393. $("#clearBtn").hide();
  2394. lastSearch = "";
  2395. filtr = 0;
  2396. selectedArea = false;
  2397. state = [];
  2398. newRes = 0;
  2399. deletedId = [];
  2400. deletedRes = [];
  2401. generatedId = [];
  2402. if (mainProces_id == -1) {
  2403. temp = {}
  2404. actSite = "preview";
  2405. loaded = false;
  2406. temp["id"] = -1;
  2407. temp["depth"] = 0;
  2408. temp["parent_id"] = 0;
  2409. temp["stepDesc"] = "";
  2410. temp["step"] = 0;
  2411. temp["prof"] = Array();
  2412. temp["res"] = Array();
  2413. temp["desc"] = "Tytuł procesu";
  2414. temp["opis"] = "Opis procesu";
  2415. temp["C-desc"] = true;
  2416. temp["C-opis"] = true;
  2417. temp["goto"] = {}
  2418. temp["goto"]["flag"] = "";
  2419. temp["goto"]["id"] = 0;
  2420. state[0] = temp;
  2421. loadResources();
  2422. } else if (localStorage.getItem("state" + mainProces_id) !== null) {
  2423. state = JSON.parse(localStorage.getItem("state" + mainProces_id));
  2424. newSteps = localStorage.getItem("newStep" + mainProces_id);
  2425. newRes = localStorage.getItem("newRes" + mainProces_id);
  2426. deletedId = JSON.parse(localStorage.getItem("deletedId" + mainProces_id));
  2427. deletedRes = JSON.parse(localStorage.getItem("deletedRes" + mainProces_id));
  2428. usedImg = JSON.parse(localStorage.getItem("usedImg" + mainProces_id));
  2429. $.notify("Wczytano niezapisany stan z " + localStorage.getItem("date" + mainProces_id), "info");
  2430. render(state, $("#main"));
  2431. loaded = true;
  2432. } else {
  2433. $("#main").html("<center>Synchronizowanie danych z serwerem.</center>");
  2434. var id = mainProces_id;
  2435. var link = BASE_URL + '/wfs-data.php/default_db/?SERVICE=WFS&VERSION=1.0.0&REQUEST=GetFeature&TYPENAME=p5_default_db:CRM_PROCES&SRSNAME=EPSG:3003&Filter=<ogc:Filter><ogc:Or><ogc:PropertyIsEqualTo><ogc:PropertyName>ID</ogc:PropertyName><ogc:Literal>' + id + '</ogc:Literal></ogc:PropertyIsEqualTo></ogc:Or></ogc:Filter>';
  2436. $.get(link, function(data) {
  2437. var temp = {};
  2438. loaded = false;
  2439. temp["id"] = mainProces_id;
  2440. temp["depth"] = 0;
  2441. temp["parent_id"] = $(data).find("featureMember").find("PARENT_ID").text();
  2442. temp["step"] = 0;
  2443. temp["goto"] = {};
  2444. temp["goto"]["id"] = $(data).find("featureMember").find("IF_TRUE_GOTO").text();
  2445. temp["goto"]["flag"] = $(data).find("featureMember").find("IF_TRUE_GOTO_FLAG").text();
  2446. temp["stepDesc"] = "";
  2447. temp["prof"] = Array();
  2448. temp["res"] = Array();
  2449. temp["desc"] = $(data).find("featureMember").find("DESC").text();
  2450. temp["opis"] = $(data).find("featureMember").find("OPIS").text()
  2451. state[0] = temp;
  2452. // 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>';
  2453. // $.get(linkImg, function(imgData) {
  2454. // var temp = Array();
  2455. // $.each($(imgData).find("featureMember"), function() {
  2456. // temp.push({
  2457. // "src": base64_decode($(this).find("IMAGE").text()),
  2458. // "title": $(this).find("NAME").text(),
  2459. // "id": $(this).find("ID").text(),
  2460. // });
  2461. // })
  2462. // state[0]["img"] = temp;
  2463. // });
  2464. genTree(mainProces_id);
  2465. });
  2466. actSite = "preview";
  2467. }
  2468. }
  2469. });
  2470. function unloadPage() {
  2471. if (changes)
  2472. return "";
  2473. }
  2474. window.onbeforeunload = unloadPage;