procesView.js 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785
  1. $(document).ready(function() {
  2. var procesy = {};
  3. var res = {};
  4. var state = [];
  5. var panels = true;
  6. var menuShow = false;
  7. var sTimeout = false;
  8. $("#SE-menu").hide();
  9. $("#SE-menu-sub").hide();
  10. function translate(objId, arr) {
  11. var data = [];
  12. $.each(arr[objId]["childs"], function(indexChilds, childs) {
  13. var temp = {};
  14. var id = childs["ID"];
  15. var style = "";
  16. switch (arr[id]["TYPE"]) {
  17. case "PROCES_INIT":
  18. style = 'style="background-color:#ffe5e5;color:#333"';
  19. break;
  20. case "PROCES":
  21. style = 'style="background-color:#ededed;color:#333"';
  22. break;
  23. case "PROCES_GROUP_1":
  24. style = 'style="background-color:#9999cc;color:#fff"';
  25. break;
  26. case "PROCES_GROUP_2":
  27. style = 'style="background-color:#d8d8b2;color:#fff"';
  28. break;
  29. default:
  30. style = 'style="background-color:#ededed;color:#333"';
  31. break;
  32. }
  33. temp["id"] = id;
  34. if (TYPE == "childs") {
  35. temp["type"] = "proces";
  36. } else {
  37. if (arr[id]["TYPE"] == "STANOWISKO" || arr[id]["TYPE"] == "DZIAL" || arr[id]["TYPE"] == "PODMIOT") {
  38. temp["type"] = "stanowiska";
  39. } else {
  40. temp["type"] = "zasoby";
  41. }
  42. }
  43. temp["text"] = "<span class=detailsTable2 " + style + " >" + id + "</span> " + arr[id]["DESC"];
  44. temp["parent"] = arr[id]["PARENT_ID"];
  45. data.push(temp);
  46. //console.log(data);
  47. $.merge(data, translate(id, arr));
  48. });
  49. return data;
  50. }
  51. $(document).on('keyup', '#search', function(e) {
  52. if (sTimeout) {
  53. clearTimeout(sTimeout);
  54. }
  55. sTimeout = setTimeout(function() {
  56. var val = $('#search').val();
  57. $('#tree').jstree(true).search(val, false);
  58. }, 250);
  59. });
  60. function customMenu(node) {
  61. var tree = $("#tree").jstree(true);
  62. var id = node.id;
  63. var items = {};
  64. if (node.type === "proces") {
  65. items = {
  66. "ProcesEditor": {
  67. "separator_before": false,
  68. "separator_after": false,
  69. "label": "Edytor procesów",
  70. "action": function(obj) {
  71. window.location = BASE_URL + 'index.php?_route=UrlAction_procesEditor&id=' + id;
  72. }
  73. },
  74. "EditProces": {
  75. "separator_before": false,
  76. "separator_after": false,
  77. "label": "Edytuj proces",
  78. "action": function(obj) {
  79. window.location = BASE_URL + 'index.php?_route=ViewTableAjax&typeName=p5_default_db:CRM_PROCES#EDIT/' + id;
  80. }
  81. },
  82. "AddPytania": {
  83. "separator_before": false,
  84. "separator_after": true,
  85. "label": "Edytuj pytania",
  86. "action": function(obj) {
  87. window.location = BASE_URL + 'procesy5.php?task=CRM_TESTY_ADD_PYTANIA&id_proces=' + id;
  88. }
  89. },
  90. "ProcesMap": {
  91. "separator_before": false,
  92. "separator_after": false,
  93. "label": "Mapa procesu",
  94. "action": function(obj) {
  95. window.location = BASE_URL + 'index.php?FUNCTION_INIT=GRAPH_VIEW_PROCES&PROCES_INIT_SCAN=1&id_proces=' + id;
  96. }
  97. },
  98. "ListView": {
  99. "separator_before": false,
  100. "separator_after": false,
  101. "label": "Widok listy",
  102. "action": function(obj) {
  103. window.location = BASE_URL + 'procesy5.php?task=PROCES_VIEW_LIST&HIDE_PANEL=0&show_big_img=1&group_stanowiska=1&id_proces=' + id;
  104. }
  105. },
  106. "AddResource": {
  107. "separator_before": true,
  108. "separator_after": false,
  109. "label": "Dodaj zasób",
  110. "action": function(obj) {
  111. window.location = BASE_URL + 'index.php?MENU_INIT=PROCES_ADD_ZASOB&task=CRM_PROCES&procesID=' + id;
  112. }
  113. },
  114. "AddChild": {
  115. "separator_before": false,
  116. "separator_after": false,
  117. "label": "Dodaj dziecko",
  118. "action": function(obj) {
  119. window.location = BASE_URL + 'index.php?_route=ViewTableAjax&typeName=p5_default_db:CRM_PROCES&ff_PARENT_ID=' + id + '#CREATE';
  120. }
  121. },
  122. "ShowWsk": {
  123. "separator_before": true,
  124. "separator_after": false,
  125. "label": "Pokaż powiązane zasoby",
  126. "action": function(obj) {
  127. node = { id:"res"+id, text:"Zasoby"};
  128. $('#tree').jstree('create_node', id, node, 'first');
  129. var node = { id:"prof"+id,text:"Stanowiska"};
  130. $('#tree').jstree('create_node', id, node, 'first');
  131. var link = BASE_URL + "index.php?_route=UrlAction_ProcesView&_task=getDetailsAjax&id=" + id;
  132. $.get(link, function(data){
  133. var isProf = false;
  134. var isRes = false;
  135. $.each(data["wsk"], function(i, e){
  136. //console.log(e);
  137. var idX = e["ID_ZASOB"];
  138. var node = { id:"wsk"+e["ID"],text: "["+e["ID_ZASOB"]+"] " + res[idX]["DESC"]};
  139. if(res[idX]["TYPE"] == "STANOWISKO" || res[idX]["TYPE"] == "DZIAL" || res[idX]["TYPE"] == "PODMIOT"){
  140. node["type"] = "stanowiska";
  141. isProf = true;
  142. $('#tree').jstree('create_node', "prof"+id, node, 'first');
  143. }else{
  144. node["type"] = "zasoby";
  145. isRes = false;
  146. $('#tree').jstree('create_node', "res"+id, node, 'first');
  147. }
  148. });
  149. if(!isProf)
  150. $("#tree").jstree('rename_node', "prof"+id , "Stanowiska <b style=color:red>[BRAK]</b>" );
  151. if(!isRes)
  152. $("#tree").jstree('rename_node', "res"+id , "Zasoby <b style=color:red>[BRAK]</b>" );
  153. $("#tree").jstree("open_node", id);
  154. $("#tree").jstree("open_node", "res"+id);
  155. $("#tree").jstree("open_node", "prof"+id);
  156. })
  157. }
  158. },
  159. };
  160. }
  161. if (node.type === "zasoby" || node.type === "stanowiska") {
  162. items = {
  163. "Edit": {
  164. "separator_before": false,
  165. "separator_after": true,
  166. "label": "Edytuj zasób",
  167. "action": function(obj) {
  168. var zId = id.replace("wsk", "");
  169. window.location = BASE_URL + 'index.php?_route=ViewTableAjax&typeName=p5_default_db:CRM_LISTA_ZASOBOW#EDIT/' + zId;
  170. }
  171. },
  172. };
  173. }
  174. return items;
  175. }
  176. function renderTree() {
  177. // jQuery.jstree.defaults.core.themes.responsive = true;
  178. $('#view').empty();
  179. $("#view").append("<input id=search type=next class=form-control>")
  180. $('#view').append("<div id=tree></div>");
  181. $('#tree').jstree({
  182. "core": {
  183. "animation": 0,
  184. "check_callback": true,
  185. "themes": {
  186. "stripes": false,
  187. "dots": false
  188. },
  189. 'data': (TYPE == "childs" ? translate(0, procesy) : translate(0, res))
  190. },
  191. "types": {
  192. "default": {
  193. "icon": "glyphicon glyphicon-folder-open",
  194. },
  195. "proces": {
  196. "icon": "glyphicon glyphicon-file",
  197. },
  198. "stanowiska": {
  199. "icon": "glyphicon glyphicon glyphicon-user",
  200. },
  201. "zasoby": {
  202. "icon": "glyphicon glyphicon glyphicon-hdd",
  203. },
  204. },
  205. "plugins": [
  206. "contextmenu", "search",
  207. "types"
  208. ],
  209. "search": {
  210. // search config
  211. "show_only_matches": true,
  212. },
  213. "contextmenu": {
  214. "items": customMenu
  215. }
  216. });
  217. }
  218. function renderPanels() {
  219. $("#view").html("<div id=ulproc><div id=procCon><div class=clearfix></div></div></div>");
  220. //console.log(procesy);
  221. if (localStorage.getItem(TYPE) !== null) {
  222. var arr = JSON.parse( localStorage.getItem(TYPE) );
  223. $.each(arr, function(i, e){
  224. createPanel(e["ID"], i, e["TYPE"]);
  225. });
  226. } else {
  227. createPanel(START_ID, 0, TYPE);
  228. }
  229. }
  230. function createPanel(id, depth, type) {
  231. state.splice(depth);
  232. var temp = {};
  233. temp["ID"] = id;
  234. var inherit = $("#depth" + (depth - 1)).data("type");
  235. if ("connect" == inherit) {
  236. inherit = "childs";
  237. }
  238. if ("aliasChilds" == inherit) {
  239. inherit = "res";
  240. }
  241. if ("gotoChilds" == inherit) {
  242. inherit = "childs";
  243. }
  244. if (type == "inherit") {
  245. type = inherit;
  246. }
  247. if (type == "childs" && procesy[id]["childs"].length == 0) {
  248. type = "details";
  249. }
  250. if (type == "alias") {
  251. type = "detailsRes";
  252. }
  253. if (type == "res" && res[id]["childs"].length == 0) {
  254. type = "detailsRes";
  255. }
  256. temp["TYPE"] = type;
  257. temp["FOCUS"] = 0;
  258. state[depth] = temp;
  259. if(depth > 0)
  260. state[depth-1]["FOCUS"] = id;
  261. renderPanel(depth);
  262. }
  263. function renderPanel(depth) {
  264. var type = state[depth]["TYPE"];
  265. var id = state[depth]["ID"];
  266. var link = BASE_URL + "index.php?_route=UrlAction_ProcesView&_task=getDetailsAjax&id=" + id;
  267. if ("connect" == type) {
  268. link = BASE_URL + "index.php?_route=UrlAction_ProcesView&_task=getConnectedProcAjax&id=" + id;
  269. }
  270. $("#depth" + (depth - 1)).nextAll(".singleAdv").remove();
  271. var target = $('<div class="singleAdv" data-depth="' + depth + '" id="depth' + depth + '" data-parent="' + id + '" data-type="' + type + '"></div>');
  272. target.appendTo("#procCon");
  273. $("#procCon").css("width", depth * 460 + 460);
  274. $("#ulproc").scrollLeft(depth * 460 + 460);
  275. $.get(link, function(exp) {
  276. var result = "";
  277. result += "<li ";
  278. if (id != 0) {
  279. if ("childs" == type || "goto" == type || "details" == type) {
  280. result += "data-opis='" + procesy[id]["OPIS"] + "' data-desc='" + procesy[id]["DESC"] + "' data-id=" + id + " ";
  281. } else {
  282. result += "data-opis='" + res[id]["OPIS"] + "' data-desc='" + res[id]["DESC"] + "' data-id=" + id + " ";
  283. }
  284. }
  285. if ("childs" == type) {
  286. result += "class='list-group-item disabled-item normalChilds'>" + (id == 0 ? "Procesy" : "{" + id + "} Procesy podrzędne");
  287. }
  288. if ("details" == type) {
  289. result += "class='list-group-item disabled-item normalChilds '>{" + id + "} Szczegóły";
  290. }
  291. if ("res" == type || "alias" == type) {
  292. result += "class='list-group-item disabled-item normalChilds'>" + (id == 0 ? "Zasoby" : "[" + id + "] Zasoby podrzędne");
  293. }
  294. if ("detailsRes" == type) {
  295. result += "class='list-group-item disabled-item normalChilds'>[" + id + "] Szczegóły";
  296. }
  297. if ("goto" == type) {
  298. result += "class='list-group-item disabled-item normalChilds'>{" + id + "} Procesy podrzędne";
  299. }
  300. if ("connect" == type) {
  301. result += "class='list-group-item disabled-item normalChilds'>[" + id + "] Procesy powiązane";
  302. }
  303. if(id != 0 && "connect" != type){
  304. result += "<div style=float:right;><div class='dropdown '>";
  305. if ("goto" == type || "details" == type || "childs" == type) {
  306. result += "<span class='glyph glyphicon glyphicon glyphicon-menu-hamburger dropdown-toggle' data-toggle='dropdown' aria-haspopup='true' aria-expanded='true' id='dropdownMenuP" + procesy[id]["ID"] + "'></span>";
  307. result += '<ul class="dropdown-menu dropdown-menu-right" style=z-index:100 aria-labelledby="dropdownMenuP' + procesy[id]["ID"] + '">';
  308. }
  309. if ("res" == type || "alias" == type || "connect" == type || "detailsRes" == type) {
  310. result += "<span class='glyph glyphicon glyphicon glyphicon-menu-hamburger dropdown-toggle' data-toggle='dropdown' aria-haspopup='true' aria-expanded='true' id='dropdownMenuR" + res[id]["ID"] + "'></span>";
  311. result += '<ul class="dropdown-menu dropdown-menu-right" style=z-index:100 aria-labelledby="dropdownMenuR' + res[id]["ID"] + '">';
  312. }
  313. if("detailsRes" != type && "details" != type)
  314. result += '<li><a href="" class=details>Szczegóły</a></li>';
  315. if ("goto" == type || "details" == type || "childs" == type) {
  316. data = procesy[id];
  317. result += '<li><a href="' + BASE_URL + 'index.php?_route=UrlAction_procesEditor&id=' + data["ID"] + '">Edytor procesu</a></li>';
  318. result += '<li><a href="' + BASE_URL + 'index.php?_route=ViewTableAjax&typeName=p5_default_db:CRM_PROCES#EDIT/' + data["ID"] + '">Edytuj proces</a></li>';
  319. result += '<li><a href="' + BASE_URL + 'index.php?MENU_INIT=PROCES_ADD_ZASOB&task=CRM_PROCES&procesID=' + data["ID"] + '">Dodaj zasób</a></li>';
  320. result += '<li><a href="' + BASE_URL + 'procesy5.php?task=CRM_TESTY_ADD_PYTANIA&id_proces=' + data["ID"] + '">Edytuj Pytania</a></li>';
  321. result += '<li><a href="' + BASE_URL + 'index.php?FUNCTION_INIT=GRAPH_VIEW_PROCES&PROCES_INIT_SCAN=1&id_proces=' + data["ID"] + '">Mapa procesu</a></li>';
  322. result += '<li><a href="' + BASE_URL + 'procesy5.php?task=PROCES_VIEW_LIST&HIDE_PANEL=0&show_big_img=1&group_stanowiska=1&id_proces=' + data["ID"] + '">Widok listy</a></li>';
  323. result += '<li><a href="' + BASE_URL + 'index.php?_route=ViewTableAjax&typeName=p5_default_db:CRM_PROCES&ff_PARENT_ID=' + data["ID"] + '#CREATE">Dodaj dziecko</a></li>';
  324. }
  325. if ("res" == type || "alias" == type || "connect" == type || "detailsRes" == type) {
  326. data = res[id];
  327. result += '<li><a href="' + BASE_URL + 'index.php?_route=ViewTableAjax&typeName=p5_default_db:CRM_LISTA_ZASOBOW#EDIT/' + data["ID"] + '">Edytuj zasób</a></li>';
  328. result += '<li><a href="" class=connect>Procesy powiązane</a></li>';
  329. }
  330. result += '</ul>';
  331. result += "</div><div>";
  332. }
  333. result += "</li>";
  334. result += "<ul class='singleAdvList list-group' style=margin-bottom:0px;>";
  335. if (("details" == type && "res" != $("#depth" + (depth - 1)).data("type"))) {
  336. result += getDetails(procesy[id], exp, "proces");
  337. }
  338. if (("details" == type && "res" == $("#depth" + (depth - 1)).data("type")) || "detailsRes" == type) {
  339. result += getDetails(res[id], exp, "res");
  340. }
  341. if ("childs" == type || "gotoChilds" == type) {
  342. if (procesy[id]["childs"].length > 0) {
  343. $.each(procesy[id]["childs"], function(i, e) {
  344. result += getView(procesy[e["ID"]], false, "proces", depth);
  345. });
  346. } else {
  347. result += getDetails(procesy[id], exp, "proces");
  348. }
  349. }
  350. if ("goto" == type) {
  351. result += getDetails(procesy[id], exp);
  352. }
  353. if ("connect" == type) {
  354. if (exp["wsk"].length > 0) {
  355. $.each(exp["wsk"], function(i, e) {
  356. result += getView(procesy[e["ID_PROCES"]], false, "childs", depth);
  357. });
  358. } else {
  359. result += "<li class='list-group-item disabled-item list-group-item-danger'>Brak procesów powiązanych.</li>";
  360. }
  361. }
  362. if ("res" == type || "aliasChilds" == type) {
  363. if (res[id]["childs"].length > 0) {
  364. $.each(res[id]["childs"], function(i, e) {
  365. result += getView(res[e["ID"]], false, "res", depth);
  366. });
  367. } else {
  368. result += getDetails(res[id], exp);
  369. }
  370. }
  371. if ("alias" == type) {
  372. result += getDetails(res[id], exp);
  373. }
  374. result += "</ul></div>";
  375. $("#ulproc").scrollTop(0);
  376. target.html(result);
  377. $(".singleAdvList").css("height", $(window).height() - 200 + "px");
  378. });
  379. localStorage.setItem( TYPE, JSON.stringify(state) );
  380. }
  381. function render() {
  382. if (panels) {
  383. renderPanels();
  384. } else {
  385. renderTree();
  386. }
  387. }
  388. function updateParent(id, parent, item) {
  389. var link = BASE_URL + 'wfs-data.php/default_db/?SERVICE=WFS&VERSION=1.0.0&SRSNAME=EPSG:3003&';
  390. var req = `
  391. <Transaction
  392. xmlns="http://www.opengis.net/wfs"
  393. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  394. version="1.0.0"
  395. service="WFS"
  396. xmlns:p5_default_db="` + BASE_URL + `wfs/default_db/CRM_PROCES"
  397. xsi:schemaLocation="` + BASE_URL + `wfs/default_db/CRM_PROCES ` + BASE_URL + `dev-pl/se-feature-api/wfs.php/xml/wfs/default_db/CRM_PROCES/?SERVICE=WFS&amp;VERSION=1.0.0&amp;REQUEST=DescribeFeatureType&amp;TYPENAME=p5_default_db:CRM_PROCES&amp;SRSNAME=EPSG:4326&amp;"
  398. xmlns:gml="http://www.opengis.net/gml">
  399. <Insert xmlns="http://www.opengis.net/wfs">
  400. <CRM_PROCES xmlns="` + BASE_URL + `wfs/default_db/CRM_PROCES">
  401. <ID xmlns="` + BASE_URL + `wfs/default_db/CRM_PROCES">` + id + `</ID>
  402. <PARENT_ID xmlns="` + BASE_URL + `wfs/default_db/CRM_PROCES">` + parent + `</PARENT_ID>
  403. </CRM_PROCES>
  404. </Insert>
  405. </Transaction>`;
  406. //console.log(req);
  407. $.ajax({
  408. url: link,
  409. data: req,
  410. type: 'POST',
  411. contentType: "text/xml",
  412. dataType: "text",
  413. success: function(data) {
  414. return true;
  415. },
  416. error: function(xhr, ajaxOptions, thrownError) {
  417. $(item).sortable('cancel');
  418. $.notify("Brak połączenia z bazą danych", "error");
  419. }
  420. });
  421. }
  422. $(document).on("click", ".toggleRoute", function(){
  423. var obj = $(this).closest(".singleAdv");
  424. var id = $(obj).data("parent");
  425. var type = $(obj).data("type");
  426. if ($(this).data("state") == 0) {
  427. $(this).data("state", 1);
  428. $(this).text("UKRYJ ŚCIEŻKĘ");
  429. $(this).parent().find(".route").html("<ul style=list-style:none;padding-left:0px;>"+showTree(id, type, 0)+"</ul>");
  430. var depth = 0;
  431. $(this).parent().find(".route").find("li").each(function(){
  432. $(this).css("padding-left", depth);
  433. depth += 16;
  434. });
  435. $(this).parent().find(".route").show();
  436. } else {
  437. $(this).data("state", 0);
  438. $(this).text("POKAŻ ŚCIEŻKĘ");
  439. $(this).parent().find(".route").hide();
  440. $(this).parent().find(".route").html("");
  441. }
  442. });
  443. function showTree(id, type, count) {
  444. if (id == "#" || count >= 100) return "";
  445. if (type == "detailsRes" || type == "alias") {
  446. if (typeof res[id]["DESC"] != "undefined") {
  447. return showTree(res[id]["PARENT_ID"], "detailsRes", count+1)+"<li style=padding-left:0px;><span class='glyphicon glyphicon-arrow-right'></span> " + res[id]["DESC"] + "</li>";
  448. } else {
  449. return "";
  450. }
  451. } else {
  452. if (typeof procesy[id]["DESC"] != "undefined") {
  453. return showTree(procesy[id]["PARENT_ID"], "detailsProc", count+1)+"<li style=padding-left:0px;><span class='glyphicon glyphicon-arrow-right'></span> " + procesy[id]["DESC"] + "</li>";
  454. } else {
  455. return "";
  456. }
  457. }
  458. }
  459. function getDetails(e, data, type) {
  460. var result = "";
  461. if (type == "proces") {
  462. result += '<div class="panel panel-info" style=margin-bottom:0px;>';
  463. } else {
  464. result += '<div class="panel panel-success" style=margin-bottom:0px;>';
  465. }
  466. result += '<div class="panel-heading"><h3 class="panel-title">' + e["DESC"] + '</h3></div>';
  467. result += '<div class="panel-body pbody">';
  468. result += e["OPIS"];
  469. result += '<div class=toggleRoute data-state=0>POKAŻ ŚCIEŻKĘ</div>';
  470. result += '<div class=route></div>';
  471. result += '</div>';
  472. result += '</div>';
  473. if (data["wsk"].length > 0 && type == "proces") {
  474. result += "<li class='list-group-item disabled-item list-group-item-success'>Zasoby powiązane</li>";
  475. result += "<ul class='singleAdvList list-group' list-group' style=margin-bottom:0px;>";
  476. $.each(data["wsk"], function(i, e) {
  477. id = e["ID_ZASOB"];
  478. if (typeof res[id] !== "undefined") {
  479. result += "<li class='list-group-item liProc wsk'";
  480. result += "data-opis='" + res[id]["OPIS"] + "' data-desc='" + res[id]["DESC"] + "' data-id=" + res[id]["ID"] + " >";
  481. result += '<div class="textTable">';
  482. result += "<span class=detailsTable>" + res[id]["ID"] + "</span> ";
  483. result += res[id]["DESC"];
  484. result += "</div>"
  485. result += "<div style=float:right;><span class='glyph glyphicon gl glyphicon-triangle-right'></span>";
  486. result += "<div class='dropdown '>";
  487. result += "<span class='glyph glyphicon glyphicon glyphicon-menu-hamburger dropdown-toggle' data-toggle='dropdown' aria-haspopup='true' aria-expanded='true' id='dropdownMenu" + res[id]["ID"] + "'></span>";
  488. result += '<ul class="dropdown-menu dropdown-menu-right" style=z-index:100 aria-labelledby="dropdownMenu' + res[id]["ID"] + '">';
  489. result += '<li><a href="" class=details>Szczegóły</a></li>';
  490. result += '</ul>';
  491. result += "</div>";
  492. result += '</div><div class=clearfix></div></li>';
  493. }
  494. });
  495. result += "</ul>";
  496. }
  497. return result;
  498. }
  499. $(document).on("click", ".goto", function() {
  500. $(this).parents(".singleAdv").find(".active").removeClass("active");
  501. $(this).parents(".singleAdv").find(".list-group-item-info").removeClass("list-group-item-info");
  502. $(this).addClass("list-group-item-info");
  503. var parent_id = $(this).data("id");
  504. var id = procesy[parent_id]["ID"];
  505. var depth = $(this).closest(".singleAdv").data("depth") + 1;
  506. createPanel(id, depth, "goto");
  507. return false;
  508. });
  509. $(document).on("click", ".alias", function() {
  510. $(this).parents(".singleAdv").find(".active").removeClass("active");
  511. $(this).parents(".singleAdv").find(".list-group-item-info").removeClass("list-group-item-info");
  512. $(this).addClass("list-group-item-info");
  513. var parent_id = $(this).data("id");
  514. var id = res[parent_id]["ID"];
  515. var depth = $(this).closest(".singleAdv").data("depth") + 1;
  516. createPanel(id, depth, "alias");
  517. return false;
  518. });
  519. function getView(data, active, type, depth) {
  520. var result = "";
  521. var style = "";
  522. switch (data["TYPE"]) {
  523. case "PROCES_INIT":
  524. style = 'style="background-color:#ffe5e5;color:#333"';
  525. break;
  526. case "PROCES":
  527. style = 'style="background-color:#ededed;color:#333"';
  528. break;
  529. case "PROCES_GROUP_1":
  530. style = 'style="background-color:#9999cc;color:#fff"';
  531. break;
  532. case "PROCES_GROUP_2":
  533. style = 'style="background-color:#d8d8b2;color:#fff"';
  534. break;
  535. default:
  536. style = 'style="background-color:#ededed;color:#333"';
  537. break;
  538. }
  539. result += "<li class='list-group-item liProc " + (state[depth]["FOCUS"] == data["ID"] ? "active" : "") + "'; ";
  540. result += "data-opis='" + data["OPIS"] + "' data-desc='" + data["DESC"] + "' data-id=" + data["ID"] + " >";
  541. result += '<div class="textTable">'
  542. result += "<span class=detailsTable " + style + ">" + data["ID"] + "</span> "
  543. result += data["DESC"];
  544. result += "</div>"
  545. result += "<div style=float:right;><span class='glyph glyphicon gl glyphicon-triangle-right'></span>";
  546. result += "<div class='dropdown '>";
  547. result += "<span class='glyph glyphicon glyphicon glyphicon-menu-hamburger dropdown-toggle' data-toggle='dropdown' aria-haspopup='true' aria-expanded='true' id='dropdownMenu" + data["ID"] + "'></span>";
  548. result += '<ul class="dropdown-menu dropdown-menu-right" style=z-index:100 aria-labelledby="dropdownMenu' + data["ID"] + '">';
  549. if ("proces" == type) {
  550. result += '<li><a href="' + BASE_URL + 'index.php?_route=UrlAction_procesEditor&id=' + data["ID"] + '">Edytor procesu</a></li>';
  551. result += '<li><a href="' + BASE_URL + 'index.php?_route=ViewTableAjax&typeName=p5_default_db:CRM_PROCES#EDIT/' + data["ID"] + '">Edytuj proces</a></li>';
  552. result += '<li><a href="' + BASE_URL + 'index.php?MENU_INIT=PROCES_ADD_ZASOB&task=CRM_PROCES&procesID=' + data["ID"] + '">Dodaj zasób</a></li>';
  553. result += '<li><a href="' + BASE_URL + 'procesy5.php?task=CRM_TESTY_ADD_PYTANIA&id_proces=' + data["ID"] + '">Edytuj Pytania</a></li>';
  554. result += '<li><a href="' + BASE_URL + 'index.php?FUNCTION_INIT=GRAPH_VIEW_PROCES&PROCES_INIT_SCAN=1&id_proces=' + data["ID"] + '">Mapa procesu</a></li>';
  555. result += '<li><a href="' + BASE_URL + 'procesy5.php?task=PROCES_VIEW_LIST&HIDE_PANEL=0&show_big_img=1&group_stanowiska=1&id_proces=' + data["ID"] + '">Widok listy</a></li>';
  556. result += '<li><a href="' + BASE_URL + 'index.php?_route=ViewTableAjax&typeName=p5_default_db:CRM_PROCES&ff_PARENT_ID=' + data["ID"] + '#CREATE">Dodaj dziecko</a></li>';
  557. }
  558. if ("res" == type) {
  559. result += '<li><a href="' + BASE_URL + 'index.php?_route=ViewTableAjax&typeName=p5_default_db:CRM_LISTA_ZASOBOW#EDIT/' + data["ID"] + '">Edytuj zasób</a></li>';
  560. result += '<li><a href="" class=connect>Procesy powiązane</a></li>';
  561. }
  562. //result += '<li><a href="'+BASE_URL+''+$(this).find("ID").text()+'">Widok listy</a></li>';
  563. result += '<li><a href="" class=details>Szczegóły</a></li>';
  564. result += '</ul>';
  565. result += "</div>";
  566. result += '</div><div class=clearfix></div></li>';
  567. if (data["IF_TRUE_GOTO"] != 0 && type == "proces") {
  568. var goto = data["IF_TRUE_GOTO_FLAG"];
  569. var id = data["IF_TRUE_GOTO"];
  570. data = procesy[id];
  571. result += "<li class='list-group-item goto " + (state[depth]["FOCUS"] == data["ID"] ? "list-group-item-info" : "") + "'; ";
  572. result += "data-opis='" + data["OPIS"] + "' data-desc='" + data["DESC"] + "' data-id=" + data["ID"] + " style=border-top-style:none;>";
  573. result += "";
  574. result += '<div class="textTable">'
  575. result += "<span class=gotoInfo><span class='glyphicon glyphicon-arrow-right'></span> " + goto + " </span><span class=gotoWay>" + data["ID"] + "</span>";
  576. result += "</div>"
  577. result += "<div style=float:right;><span class='glyph glyphicon gl glyphicon-triangle-right'></span>";
  578. result += "<div class='dropdown '>";
  579. result += "<span class='glyph glyphicon glyphicon glyphicon-menu-hamburger dropdown-toggle' data-toggle='dropdown' aria-haspopup='true' aria-expanded='true' id='dropdownMenu" + data["ID"] + "'></span>";
  580. result += '<ul class="dropdown-menu dropdown-menu-right" style=z-index:100 aria-labelledby="dropdownMenu' + data["ID"] + '">';
  581. result += '<li><a href="' + BASE_URL + 'index.php?_route=UrlAction_procesEditor&id=' + data["ID"] + '">Edytor procesu</a></li>';
  582. result += '<li><a href="' + BASE_URL + 'index.php?_route=ViewTableAjax&typeName=p5_default_db:CRM_PROCES#EDIT/' + data["ID"] + '">Edytuj proces</a></li>';
  583. result += '<li><a href="' + BASE_URL + 'index.php?MENU_INIT=PROCES_ADD_ZASOB&task=CRM_PROCES&procesID=' + data["ID"] + '">Dodaj zasób</a></li>';
  584. result += '<li><a href="' + BASE_URL + 'procesy5.php?task=CRM_TESTY_ADD_PYTANIA&id_proces=' + data["ID"] + '">Edytuj Pytania</a></li>';
  585. result += '<li><a href="' + BASE_URL + 'index.php?FUNCTION_INIT=GRAPH_VIEW_PROCES&PROCES_INIT_SCAN=1&id_proces=' + data["ID"] + '">Mapa procesu</a></li>';
  586. result += '<li><a href="' + BASE_URL + 'procesy5.php?task=PROCES_VIEW_LIST&HIDE_PANEL=0&show_big_img=1&group_stanowiska=1&id_proces=' + data["ID"] + '">Widok listy</a></li>';
  587. result += '<li><a href="' + BASE_URL + 'index.php?_route=ViewTableAjax&typeName=p5_default_db:CRM_PROCES&ff_PARENT_ID=' + data["ID"] + '#CREATE">Dodaj dziecko</a></li>';
  588. //result += '<li><a href="'+BASE_URL+''+$(this).find("ID").text()+'">Widok listy</a></li>';
  589. result += '<li><a href="" class=details>Szczegóły</a></li>';
  590. result += '</ul>';
  591. result += "</div>";
  592. result += '</div><div class=clearfix></div></blockqoute></li>';
  593. }
  594. if (data["ALIAS_ID"] != 0 && type == "res") {
  595. var id = data["ALIAS_ID"];
  596. if (id in res) {
  597. data = res[id];
  598. result += "<li class='list-group-item alias " + (state[depth]["FOCUS"] == data["ID"] ? "list-group-item-info" : "") + "'; ";
  599. result += "data-opis='" + data["OPIS"] + "' data-desc='" + data["DESC"] + "' data-id=" + data["ID"] + " style=border-top-style:none;>";
  600. result += "";
  601. result += '<div class="textTable">'
  602. result += "<span class=gotoInfo><span class='glyphicon glyphicon-arrow-right'></span> ALIAS </span><span class=gotoWay>" + data["ID"] + "</span>";
  603. result += "</div>"
  604. result += "<div style=float:right;><span class='glyph glyphicon gl glyphicon-triangle-right'></span>";
  605. result += "<div class='dropdown '>";
  606. result += "<span class='glyph glyphicon glyphicon glyphicon-menu-hamburger dropdown-toggle' data-toggle='dropdown' aria-haspopup='true' aria-expanded='true' id='dropdownMenu" + data["ID"] + "'></span>";
  607. result += '<ul class="dropdown-menu dropdown-menu-right" style=z-index:100 aria-labelledby="dropdownMenu' + data["ID"] + '">';
  608. result += '<li><a href="' + BASE_URL + 'index.php?_route=ViewTableAjax&typeName=p5_default_db:CRM_LISTA_ZASOBOW#EDIT/' + data["ID"] + '">Edytuj zasób</a></li>';
  609. result += '<li><a href="" class=connect>Procesy powiązane</a></li>';
  610. result += '<li><a href="" class=details>Szczegóły</a></li>';
  611. result += '</ul>';
  612. result += "</div>";
  613. result += '</div><div class=clearfix></div></blockqoute></li>';
  614. } else {
  615. console.log('BUG ALIAS_ID['+data['ALIAS_ID']+'] in ['+data['ID']+'] not in res', data, res);
  616. }
  617. }
  618. return result;
  619. }
  620. $(document).on('click', '.connect', function(e) {
  621. e.preventDefault();
  622. $(this).parents(".singleAdv").nextAll(".singleAdv").remove();
  623. $(this).parents(".singleAdv").find(".active").removeClass("active");
  624. $(this).parents(".singleAdv").find(".list-group-item-info").removeClass("list-group-item-info");
  625. $(this).parents(".liProc").addClass("active");
  626. $('.dropdown.open .dropdown-toggle').dropdown('toggle');
  627. var parent_id = $(this).closest(".list-group-item").data("id");
  628. var parentOfParent_id = $(this).closest(".singleAdv").data("parent");
  629. var depth = $(this).closest(".singleAdv").data("depth") + 1;
  630. createPanel(parent_id, depth, "connect");
  631. });
  632. $(document).on('click', '.details', function(e) {
  633. e.preventDefault();
  634. $(this).parents(".singleAdv").nextAll(".singleAdv").remove();
  635. $(this).parents(".singleAdv").find(".active").removeClass("active");
  636. $(this).parents(".singleAdv").find(".list-group-item-info").removeClass("list-group-item-info");
  637. $(this).parents(".liProc").addClass("active");
  638. $('.dropdown.open .dropdown-toggle').dropdown('toggle');
  639. var parent_id = $(this).closest(".list-group-item").data("id");
  640. var parentOfParent_id = $(this).closest(".singleAdv").data("parent");
  641. var depth = $(this).closest(".singleAdv").data("depth") + 1;
  642. if ($(this).closest(".list-group-item").hasClass("wsk") || $(this).closest(".singleAdv").data("type") == "res" || $(this).closest(".list-group-item").hasClass("alias")) {
  643. createPanel(parent_id, depth, "detailsRes");
  644. } else {
  645. createPanel(parent_id, depth, "details");
  646. }
  647. initSortable();
  648. });
  649. $(document).on('click', '.dropdown-toggle', function(e) {
  650. e.stopPropagation();
  651. });
  652. $(document).on('click', '.dropdown', function(e) {
  653. e.stopPropagation();
  654. });
  655. $(document).on('click', '#toggleMenu', function(e) {
  656. e.preventDefault();
  657. if (!menuShow) {
  658. $("#SE-menu").show();
  659. $("#SE-menu-sub").show();
  660. menuShow = true;
  661. } else {
  662. menuShow = false;
  663. $("#SE-menu").hide();
  664. $("#SE-menu-sub").hide();
  665. }
  666. });
  667. $(document).on('click', '#toggleView', function(e) {
  668. e.preventDefault();
  669. if (!panels) {
  670. panels = true;
  671. render();
  672. } else {
  673. panels = false;
  674. render();
  675. }
  676. });
  677. $(document).on('click', '.liProc', function() {
  678. $(this).parents(".singleAdv").find(".active").removeClass("active");
  679. $(this).parents(".singleAdv").find(".list-group-item-info").removeClass("list-group-item-info");
  680. $(this).addClass("active");
  681. var parent_id = $(this).data("id");
  682. var parentOfParent_id = $(this).closest(".singleAdv").data("parent");
  683. var depth = $(this).closest(".singleAdv").data("depth") + 1;
  684. if ($(this).hasClass("wsk")) {
  685. createPanel(parent_id, depth, "res");
  686. } else {
  687. createPanel(parent_id, depth, "inherit");
  688. }
  689. initSortable();
  690. });
  691. function initSortable() {
  692. // $( ".singleAdvList" ).sortable({
  693. // items: "li",
  694. // connectWith: ".singleAdvList",
  695. // cancel: ".disabled-item",
  696. // beforeStop: function(ev, ui) {
  697. // if($(ui.item).data("id") == $(ui.placeholder).closest(".singleAdv").data("parent") || $(ui.item).hasClass("active")){
  698. // $(this).sortable('cancel');
  699. // $.notify("Nielogiczny ruch.", "error");
  700. // }
  701. //
  702. // },
  703. // stop: function(ev, ui) {
  704. // updateParent($(ui.item).data("id"),$(ui.item).closest(".singleAdv").data("parent"), this);
  705. // },
  706. // }).disableSelection();
  707. }
  708. function start() {
  709. var link = BASE_URL + 'index.php?_route=UrlAction_ProcesView&_task=getAllAjax';
  710. $.get(link, function(data) {
  711. procesy = {}
  712. for (idx in data) {// FIX childs by SORT_PRIO
  713. var d = data[idx]
  714. if ('childs' in d) {
  715. var dataChilds = d['childs'].map(function (child) {
  716. var idChild = child['ID'];
  717. var sortPrio = (idChild in data) ? parseInt(data[idChild]['SORT_PRIO']) : 0;
  718. return {SORT_PRIO: sortPrio, ID: idChild};
  719. });
  720. var sortedChilds = dataChilds.sort(function(a, b) {
  721. if (a['SORT_PRIO'] == b['SORT_PRIO']) {
  722. return a['ID'] - b['ID'];
  723. }
  724. else {
  725. return a['SORT_PRIO'] - b['SORT_PRIO'];
  726. }
  727. });
  728. d['childs'] = sortedChilds;
  729. }
  730. procesy[idx] = d;
  731. }
  732. if (TYPE == "childs") render();
  733. });
  734. link = BASE_URL + 'index.php?_route=UrlAction_ProcesView&_task=getAllResAjax';
  735. $.get(link, function(data) {
  736. res = data;
  737. if (TYPE == "res") render();
  738. });
  739. }
  740. start();
  741. });