procesView.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413
  1. $(document).ready(function(){
  2. var state = {};
  3. var panels = true;
  4. var menuShow = false;
  5. var sTimeout = false;
  6. $("#SE-menu").hide();
  7. $("#SE-menu-sub").hide();
  8. function translate(objId){
  9. var data = [];
  10. $.each(state[objId]["childs"], function(indexChilds, childs){
  11. var temp = {};
  12. var id = childs["ID"];
  13. var style = "";
  14. switch(state[id]["TYPE"]){
  15. case "PROCES_INIT": style = 'style="background-color:#ffe5e5;color:#333"';break;
  16. case "PROCES": style = 'style="background-color:#ededed;color:#333"';break;
  17. case "PROCES_GROUP_1": style = 'style="background-color:#9999cc;color:#fff"';break;
  18. case "PROCES_GROUP_2": style = 'style="background-color:#d8d8b2;color:#fff"';break;
  19. default: style = 'style="background-color:#ededed;color:#333"';break;
  20. }
  21. temp["id"] = id;
  22. temp["text"] = "<span class=detailsTable2 "+style+" >"+id+"</span> "+state[id]["DESC"];
  23. temp["parent"] = state[id]["PARENT_ID"];
  24. data.push(temp);
  25. //console.log(data);
  26. $.merge(data, translate(id));
  27. });
  28. return data;
  29. }
  30. $(document).on('keyup', '#search', function(e) {
  31. if(sTimeout) { clearTimeout(sTimeout); }
  32. sTimeout = setTimeout(function () {
  33. var val = $('#search').val();
  34. $('#tree').jstree(true).search(val, false);
  35. }, 250);
  36. });
  37. function renderTree(){
  38. // jQuery.jstree.defaults.core.themes.responsive = true;
  39. $('#view').empty();
  40. $("#view").append("<input id=search type=next class=form-control>")
  41. $('#view').append("<div id=tree></div>");
  42. $('#tree').jstree({
  43. "core" : {
  44. "animation" : 0,
  45. "check_callback" : true,
  46. "themes" : { "stripes" : false, "dots": false },
  47. 'data' : translate(0)
  48. },
  49. "types" : {
  50. "root" : {
  51. "icon" : "/static/3.3.2/assets/images/tree_icon.png",
  52. "valid_children" : ["default"]
  53. },
  54. "default" : {
  55. "valid_children" : ["default","file"]
  56. },
  57. "file" : {
  58. "icon" : "glyphicon glyphicon-file",
  59. "valid_children" : []
  60. }
  61. },
  62. "plugins" : [
  63. "contextmenu", "dnd", "search",
  64. "types"
  65. ],
  66. "search": {
  67. // search config
  68. "show_only_matches": true,
  69. },
  70. "contextmenu":{
  71. "items": function(node) {
  72. var tree = $("#tree").jstree(true);
  73. var id = node.id;
  74. return {
  75. "ProcesEditor": {
  76. "separator_before": false,
  77. "separator_after": false,
  78. "label": "Edytor procesów",
  79. "action": function (obj) {
  80. window.location = BASE_URL+'index.php?_route=UrlAction_procesEditor&id='+id;
  81. }
  82. },
  83. "EditProces": {
  84. "separator_before": false,
  85. "separator_after": false,
  86. "label": "Edytuj proces",
  87. "action": function (obj) {
  88. window.location = BASE_URL+'index.php?_route=ViewTableAjax&typeName=p5_default_db:CRM_PROCES#EDIT/'+id;
  89. }
  90. },
  91. "AddPytania": {
  92. "separator_before": false,
  93. "separator_after": true,
  94. "label": "Edytuj pytania",
  95. "action": function (obj) {
  96. window.location = BASE_URL+'procesy5.php?task=CRM_TESTY_ADD_PYTANIA&id_proces='+id;
  97. }
  98. },
  99. "ProcesMap": {
  100. "separator_before": false,
  101. "separator_after": false,
  102. "label": "Mapa procesu",
  103. "action": function (obj) {
  104. window.location = BASE_URL+'index.php?FUNCTION_INIT=GRAPH_VIEW_PROCES&PROCES_INIT_SCAN=1&id_proces='+id;
  105. }
  106. },
  107. "ListView": {
  108. "separator_before": false,
  109. "separator_after": false,
  110. "label": "Widok listy",
  111. "action": function (obj) {
  112. window.location = BASE_URL+'procesy5.php?task=PROCES_VIEW_LIST&HIDE_PANEL=0&show_big_img=1&group_stanowiska=1&id_proces='+id;
  113. }
  114. },
  115. "AddResource": {
  116. "separator_before": true,
  117. "separator_after": false,
  118. "label": "Dodaj zasób",
  119. "action": function (obj) {
  120. window.location = BASE_URL+'index.php?MENU_INIT=PROCES_ADD_ZASOB&task=CRM_PROCES&procesID='+id;
  121. }
  122. },
  123. "AddChild": {
  124. "separator_before": false,
  125. "separator_after": false,
  126. "label": "Dodaj dziecko",
  127. "action": function (obj) {
  128. window.location = BASE_URL+'index.php?_route=ViewTableAjax&typeName=p5_default_db:CRM_PROCES&ff_PARENT_ID='+id+'#CREATE';
  129. }
  130. },
  131. };
  132. }
  133. }
  134. });
  135. }
  136. function renderPanels(){
  137. $("#view").empty();
  138. var next = 0;
  139. var result = "";
  140. var depth = 0;
  141. var previous = false;
  142. result += "<div id=ulproc><div id=procCon>";
  143. while(next !== false){
  144. depth++;
  145. //console.log(next);
  146. result += "<div class=singleAdv data-depth=0 id=depth0 data-parent="+next+" ><ul class='singleAdvList list-group' list-group' style=margin-bottom:0px;>";
  147. var details = false;
  148. //console.log("next: ", next);
  149. //console.log("prev: ", previous);
  150. if(previous !== false)
  151. //console.log("x", state[previous]["details"]);
  152. if(previous !== false && state[previous]["details"] == true){
  153. //console.log("ok");
  154. result += getDetails(state[next]);
  155. details = true;
  156. next = false;
  157. }
  158. if(!details ){
  159. if(state[next]["childs"].length > 0){
  160. $.each(state[next]["childs"], function(i, e){
  161. if(state[next]["active"] == e["ID"])
  162. result += getView(state[e["ID"]], true);
  163. else
  164. result += getView(state[e["ID"]], false);
  165. });
  166. previous = next;
  167. next = state[next]["active"];
  168. } else {
  169. result += getDetails(state[next]);
  170. next = false;
  171. }
  172. }
  173. result += "</ul></div>";
  174. }
  175. result += "<div class=clearfix></div></div></div>";
  176. $("#ulproc").scrollTop(0);
  177. $("#view").html(result);
  178. $("#procCon").css("width", depth * 460);
  179. $("#ulproc").scrollLeft(depth * 460);
  180. $(".singleAdv").css("height", $( window ).height()-100 + "px");
  181. //console.log(result);
  182. }
  183. function render(){
  184. if(panels){
  185. console.log("panels");
  186. renderPanels();
  187. }else{
  188. console.log("drzewo");
  189. renderTree();
  190. }
  191. }
  192. function updateParent(id, parent, item){
  193. var link = BASE_URL + 'wfs-data.php/default_db/?SERVICE=WFS&VERSION=1.0.0&SRSNAME=EPSG:3003&';
  194. var req = `
  195. <Transaction
  196. xmlns="http://www.opengis.net/wfs"
  197. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  198. version="1.0.0"
  199. service="WFS"
  200. xmlns:p5_default_db="` + BASE_URL + `wfs/default_db/CRM_PROCES"
  201. 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;"
  202. xmlns:gml="http://www.opengis.net/gml">
  203. <Insert xmlns="http://www.opengis.net/wfs">
  204. <CRM_PROCES xmlns="` + BASE_URL + `wfs/default_db/CRM_PROCES">
  205. <ID xmlns="` + BASE_URL + `wfs/default_db/CRM_PROCES">`+id+`</ID>
  206. <PARENT_ID xmlns="` + BASE_URL + `wfs/default_db/CRM_PROCES">`+parent+`</PARENT_ID>
  207. </CRM_PROCES>
  208. </Insert>
  209. </Transaction>`;
  210. console.log(req);
  211. $.ajax({
  212. url: link,
  213. data: req,
  214. type: 'POST',
  215. contentType: "text/xml",
  216. dataType: "text",
  217. success: function(data) {
  218. return true;
  219. },
  220. error: function(xhr, ajaxOptions, thrownError) {
  221. $(item).sortable('cancel');
  222. $.notify("Brak połączenia z bazą danych", "error");
  223. }
  224. });
  225. }
  226. function getDetails(e){
  227. console.log("test", e);
  228. var result = "";
  229. result += '<div class="panel panel-primary">';
  230. result += '<div class="panel-heading"><h3 class="panel-title">[' + e["ID"] + '] ' + e["DESC"] + '</h3></div>';
  231. result += '<div class="panel-body pbody">';
  232. result += '<b>Opis: </b>' + e["OPIS"];
  233. result += '</div>';
  234. result += '</div>';
  235. return result;
  236. }
  237. function getView(data, active){
  238. var result = "";
  239. var childs = true;
  240. var type = 0;
  241. var style = "";
  242. switch(data["TYPE"]){
  243. case "PROCES_INIT": style = 'style="background-color:#ffe5e5;color:#333"';break;
  244. case "PROCES": style = 'style="background-color:#ededed;color:#333"';break;
  245. case "PROCES_GROUP_1": style = 'style="background-color:#9999cc;color:#fff"';break;
  246. case "PROCES_GROUP_2": style = 'style="background-color:#d8d8b2;color:#fff"';break;
  247. default: style = 'style="background-color:#ededed;color:#333"';break;
  248. }
  249. result += "<li class='list-group-item liProc "+(active ? "active" : "")+"'; ";
  250. result += "data-opis='" + data["OPIS"] + "' data-desc='" + data["DESC"] + "' data-id=" + data["ID"] + " >";
  251. result += '<div class="textTable">'
  252. result += "<span class=detailsTable "+style+">" + data["ID"] + "</span> "
  253. result += data["DESC"] + "</div>"
  254. result += "<div style=float:right;><span class='glyph glyphicon gl glyphicon-triangle-right'></span>";
  255. result += "<div class='dropdown '>";
  256. 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>";
  257. result += '<ul class="dropdown-menu dropdown-menu-right" style=z-index:100 aria-labelledby="dropdownMenu'+data["ID"]+'">';
  258. result += '<li><a href="'+BASE_URL+'index.php?_route=UrlAction_procesEditor&id='+data["ID"]+'">Edytor procesu</a></li>';
  259. result += '<li><a href="'+BASE_URL+'index.php?_route=ViewTableAjax&typeName=p5_default_db:CRM_PROCES#EDIT/'+data["ID"]+'">Edytuj proces</a></li>';
  260. result += '<li><a href="'+BASE_URL+'index.php?MENU_INIT=PROCES_ADD_ZASOB&task=CRM_PROCES&procesID='+data["ID"]+'">Dodaj zasób</a></li>';
  261. result += '<li><a href="'+BASE_URL+'procesy5.php?task=CRM_TESTY_ADD_PYTANIA&id_proces='+data["ID"]+'">Edytuj Pytania</a></li>';
  262. 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>';
  263. 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>';
  264. 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>';
  265. //result += '<li><a href="'+BASE_URL+''+$(this).find("ID").text()+'">Widok listy</a></li>';
  266. result += '<li><a href="" class=details>Szczegóły</a></li>';
  267. result += '</ul>';
  268. result += "</div>";
  269. result += '</div><div class=clearfix></div></li>';
  270. if (!childs) {
  271. result += getDetails(parent);
  272. }
  273. return result;
  274. }
  275. $(document).on('click', '.details', function(e) {
  276. e.preventDefault();
  277. $(this).parents(".singleAdv").nextAll(".singleAdv").remove();
  278. $(this).parents(".singleAdv").find(".active").removeClass("active");
  279. $(this).find(".gl").removeClass("glyphicon-triangle-right");
  280. $(this).find(".gl").addClass("glyphicon-refresh");
  281. $(this).find(".gl").addClass("anim-refresh");
  282. $('.dropdown.open .dropdown-toggle').dropdown('toggle');
  283. var parent = $(this).closest(".liProc");
  284. var parent_id = $(parent).data("id");
  285. var parentOfParent_id = $(this).closest(".singleAdv").data("parent");
  286. state[parentOfParent_id]["active"] = parent_id;
  287. state[parentOfParent_id]["details"] = true;
  288. render();
  289. initSortable();
  290. });
  291. $(document).on('click', '.dropdown-toggle', function(e) {
  292. e.stopPropagation();
  293. });
  294. $(document).on('click', '.dropdown', function(e) {
  295. e.stopPropagation();
  296. });
  297. $(document).on('click', '#toggleMenu' ,function(e){
  298. e.preventDefault();
  299. if(!menuShow){
  300. $("#SE-menu").show();
  301. $("#SE-menu-sub").show();
  302. menuShow = true;
  303. }else{
  304. menuShow = false;
  305. $("#SE-menu").hide();
  306. $("#SE-menu-sub").hide();
  307. }
  308. });
  309. $(document).on('click', '#toggleView' ,function(e){
  310. e.preventDefault();
  311. if(!panels){
  312. panels = true;
  313. render();
  314. }else{
  315. panels = false;
  316. render();
  317. }
  318. });
  319. $(document).on('click', '.liProc', function() {
  320. $(this).parents(".singleAdv").nextAll(".singleAdv").remove();
  321. $(this).parents(".singleAdv").find(".active").removeClass("active");
  322. $(this).find(".gl").removeClass("glyphicon-triangle-right");
  323. $(this).find(".gl").addClass("glyphicon-refresh");
  324. $(this).find(".gl").addClass("anim-refresh");
  325. $(this).addClass("active");
  326. var parent = this;
  327. var parent_id = $(this).data("id");
  328. var parentOfParent_id = $(this).closest(".singleAdv").data("parent");
  329. //console.log(link);
  330. var childs = true;
  331. state[parentOfParent_id]["active"] = parent_id;
  332. state[parentOfParent_id]["details"] = false;
  333. render();
  334. initSortable();
  335. });
  336. function initSortable(){
  337. $( ".singleAdvList" ).sortable({
  338. items: "li",
  339. connectWith: ".singleAdvList",
  340. beforeStop: function(ev, ui) {
  341. if($(ui.item).data("id") == $(ui.placeholder).closest(".singleAdv").data("parent") || $(ui.item).hasClass("active")){
  342. $(this).sortable('cancel');
  343. $.notify("Nielogiczny ruch.", "error");
  344. }
  345. },
  346. stop: function(ev, ui) {
  347. updateParent($(ui.item).data("id"),$(ui.item).closest(".singleAdv").data("parent"), this);
  348. },
  349. }).disableSelection();
  350. }
  351. function start(){
  352. var link = BASE_URL + 'index.php?_route=UrlAction_ProcesView&_task=getAllAjax';
  353. var result = "";
  354. var side = $("#view");
  355. var tempF = {};
  356. tempF["active"] = false;
  357. tempF["details"] = false;
  358. tempF["childs"] = [];
  359. state[0] = tempF;
  360. $.get(link, function(data) {
  361. //console.log("x");
  362. //console.log(data);
  363. state = data;
  364. render();
  365. });
  366. }
  367. start();
  368. });