$(document).ready(function(){ var state = {}; var panels = true; var menuShow = false; var sTimeout = false; $("#SE-menu").hide(); $("#SE-menu-sub").hide(); function translate(objId){ var data = []; $.each(state[objId]["childs"], function(indexChilds, childs){ var temp = {}; var id = childs["ID"]; var style = ""; switch(state[id]["TYPE"]){ case "PROCES_INIT": style = 'style="background-color:#ffe5e5;color:#333"';break; case "PROCES": style = 'style="background-color:#ededed;color:#333"';break; case "PROCES_GROUP_1": style = 'style="background-color:#9999cc;color:#fff"';break; case "PROCES_GROUP_2": style = 'style="background-color:#d8d8b2;color:#fff"';break; default: style = 'style="background-color:#ededed;color:#333"';break; } temp["id"] = id; temp["text"] = ""+id+" "+state[id]["DESC"]; temp["parent"] = state[id]["PARENT_ID"]; data.push(temp); //console.log(data); $.merge(data, translate(id)); }); return data; } $(document).on('keyup', '#search', function(e) { if(sTimeout) { clearTimeout(sTimeout); } sTimeout = setTimeout(function () { var val = $('#search').val(); $('#tree').jstree(true).search(val, false); }, 250); }); function renderTree(){ // jQuery.jstree.defaults.core.themes.responsive = true; $('#view').empty(); $("#view").append("") $('#view').append("
"); $('#tree').jstree({ "core" : { "animation" : 0, "check_callback" : true, "themes" : { "stripes" : false, "dots": false }, 'data' : translate(0) }, "types" : { "root" : { "icon" : "/static/3.3.2/assets/images/tree_icon.png", "valid_children" : ["default"] }, "default" : { "valid_children" : ["default","file"] }, "file" : { "icon" : "glyphicon glyphicon-file", "valid_children" : [] } }, "plugins" : [ "contextmenu", "dnd", "search", "types" ], "search": { // search config "show_only_matches": true, }, "contextmenu":{ "items": function(node) { var tree = $("#tree").jstree(true); var id = node.id; return { "ProcesEditor": { "separator_before": false, "separator_after": false, "label": "Edytor procesów", "action": function (obj) { window.location = BASE_URL+'index.php?_route=UrlAction_procesEditor&id='+id; } }, "EditProces": { "separator_before": false, "separator_after": false, "label": "Edytuj proces", "action": function (obj) { window.location = BASE_URL+'index.php?_route=ViewTableAjax&typeName=p5_default_db:CRM_PROCES#EDIT/'+id; } }, "AddPytania": { "separator_before": false, "separator_after": true, "label": "Edytuj pytania", "action": function (obj) { window.location = BASE_URL+'procesy5.php?task=CRM_TESTY_ADD_PYTANIA&id_proces='+id; } }, "ProcesMap": { "separator_before": false, "separator_after": false, "label": "Mapa procesu", "action": function (obj) { window.location = BASE_URL+'index.php?FUNCTION_INIT=GRAPH_VIEW_PROCES&PROCES_INIT_SCAN=1&id_proces='+id; } }, "ListView": { "separator_before": false, "separator_after": false, "label": "Widok listy", "action": function (obj) { window.location = BASE_URL+'procesy5.php?task=PROCES_VIEW_LIST&HIDE_PANEL=0&show_big_img=1&group_stanowiska=1&id_proces='+id; } }, "AddResource": { "separator_before": true, "separator_after": false, "label": "Dodaj zasób", "action": function (obj) { window.location = BASE_URL+'index.php?MENU_INIT=PROCES_ADD_ZASOB&task=CRM_PROCES&procesID='+id; } }, "AddChild": { "separator_before": false, "separator_after": false, "label": "Dodaj dziecko", "action": function (obj) { window.location = BASE_URL+'index.php?_route=ViewTableAjax&typeName=p5_default_db:CRM_PROCES&ff_PARENT_ID='+id+'#CREATE'; } }, }; } } }); } function renderPanels(){ $("#view").empty(); var next = 0; var result = ""; var depth = 0; var previous = false; result += "
"; while(next !== false){ depth++; //console.log(next); result += "
    "; var details = false; //console.log("next: ", next); //console.log("prev: ", previous); if(previous !== false) //console.log("x", state[previous]["details"]); if(previous !== false && state[previous]["details"] == true){ //console.log("ok"); result += getDetails(state[next]); details = true; next = false; } if(!details ){ if(state[next]["childs"].length > 0){ $.each(state[next]["childs"], function(i, e){ if(state[next]["active"] == e["ID"]) result += getView(state[e["ID"]], true); else result += getView(state[e["ID"]], false); }); previous = next; next = state[next]["active"]; } else { result += getDetails(state[next]); next = false; } } result += "
"; } result += "
"; $("#ulproc").scrollTop(0); $("#view").html(result); $("#procCon").css("width", depth * 460); $("#ulproc").scrollLeft(depth * 460); $(".singleAdv").css("height", $( window ).height()-100 + "px"); //console.log(result); } function render(){ if(panels){ console.log("panels"); renderPanels(); }else{ console.log("drzewo"); renderTree(); } } function updateParent(id, parent, item){ var link = BASE_URL + 'wfs-data.php/default_db/?SERVICE=WFS&VERSION=1.0.0&SRSNAME=EPSG:3003&'; var req = ` `+id+` `+parent+` `; console.log(req); $.ajax({ url: link, data: req, type: 'POST', contentType: "text/xml", dataType: "text", success: function(data) { return true; }, error: function(xhr, ajaxOptions, thrownError) { $(item).sortable('cancel'); $.notify("Brak połączenia z bazą danych", "error"); } }); } function getDetails(e){ console.log("test", e); var result = ""; result += '
'; result += '

[' + e["ID"] + '] ' + e["DESC"] + '

'; result += '
'; result += 'Opis: ' + e["OPIS"]; result += '
'; result += '
'; return result; } function getView(data, active){ var result = ""; var childs = true; var type = 0; var style = ""; switch(data["TYPE"]){ case "PROCES_INIT": style = 'style="background-color:#ffe5e5;color:#333"';break; case "PROCES": style = 'style="background-color:#ededed;color:#333"';break; case "PROCES_GROUP_1": style = 'style="background-color:#9999cc;color:#fff"';break; case "PROCES_GROUP_2": style = 'style="background-color:#d8d8b2;color:#fff"';break; default: style = 'style="background-color:#ededed;color:#333"';break; } result += "
  • "; result += '
    ' result += "" + data["ID"] + " " result += data["DESC"] + "
    " result += "
    "; result += ""; result += '
  • '; if (!childs) { result += getDetails(parent); } return result; } $(document).on('click', '.details', function(e) { e.preventDefault(); $(this).parents(".singleAdv").nextAll(".singleAdv").remove(); $(this).parents(".singleAdv").find(".active").removeClass("active"); $(this).find(".gl").removeClass("glyphicon-triangle-right"); $(this).find(".gl").addClass("glyphicon-refresh"); $(this).find(".gl").addClass("anim-refresh"); $('.dropdown.open .dropdown-toggle').dropdown('toggle'); var parent = $(this).closest(".liProc"); var parent_id = $(parent).data("id"); var parentOfParent_id = $(this).closest(".singleAdv").data("parent"); state[parentOfParent_id]["active"] = parent_id; state[parentOfParent_id]["details"] = true; render(); initSortable(); }); $(document).on('click', '.dropdown-toggle', function(e) { e.stopPropagation(); }); $(document).on('click', '.dropdown', function(e) { e.stopPropagation(); }); $(document).on('click', '#toggleMenu' ,function(e){ e.preventDefault(); if(!menuShow){ $("#SE-menu").show(); $("#SE-menu-sub").show(); menuShow = true; }else{ menuShow = false; $("#SE-menu").hide(); $("#SE-menu-sub").hide(); } }); $(document).on('click', '#toggleView' ,function(e){ e.preventDefault(); if(!panels){ panels = true; render(); }else{ panels = false; render(); } }); $(document).on('click', '.liProc', function() { $(this).parents(".singleAdv").nextAll(".singleAdv").remove(); $(this).parents(".singleAdv").find(".active").removeClass("active"); $(this).find(".gl").removeClass("glyphicon-triangle-right"); $(this).find(".gl").addClass("glyphicon-refresh"); $(this).find(".gl").addClass("anim-refresh"); $(this).addClass("active"); var parent = this; var parent_id = $(this).data("id"); var parentOfParent_id = $(this).closest(".singleAdv").data("parent"); //console.log(link); var childs = true; state[parentOfParent_id]["active"] = parent_id; state[parentOfParent_id]["details"] = false; render(); initSortable(); }); function initSortable(){ $( ".singleAdvList" ).sortable({ items: "li", connectWith: ".singleAdvList", beforeStop: function(ev, ui) { if($(ui.item).data("id") == $(ui.placeholder).closest(".singleAdv").data("parent") || $(ui.item).hasClass("active")){ $(this).sortable('cancel'); $.notify("Nielogiczny ruch.", "error"); } }, stop: function(ev, ui) { updateParent($(ui.item).data("id"),$(ui.item).closest(".singleAdv").data("parent"), this); }, }).disableSelection(); } function start(){ var link = BASE_URL + 'index.php?_route=UrlAction_ProcesView&_task=getAllAjax'; var result = ""; var side = $("#view"); var tempF = {}; tempF["active"] = false; tempF["details"] = false; tempF["childs"] = []; state[0] = tempF; $.get(link, function(data) { //console.log("x"); //console.log(data); state = data; render(); }); } start(); });