$(document).ready(function() { var procesy = {}; var res = {}; var state = []; var panels = true; var menuShow = false; var sTimeout = false; $("#SE-menu").hide(); $("#SE-menu-sub").hide(); function translate(objId, arr) { var data = []; $.each(arr[objId]["childs"], function(indexChilds, childs) { var temp = {}; var id = childs["ID"]; var style = ""; switch (arr[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; if (TYPE == "childs") { temp["type"] = "proces"; } else { if (arr[id]["TYPE"] == "STANOWISKO" || arr[id]["TYPE"] == "DZIAL" || arr[id]["TYPE"] == "PODMIOT") { temp["type"] = "stanowiska"; } else { temp["type"] = "zasoby"; } } temp["text"] = "" + id + " " + arr[id]["DESC"]; temp["parent"] = arr[id]["PARENT_ID"]; data.push(temp); //console.log(data); $.merge(data, translate(id, arr)); }); 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 customMenu(node) { var tree = $("#tree").jstree(true); var id = node.id; var items = {}; if (node.type === "proces") { items = { "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'; } }, "ShowWsk": { "separator_before": true, "separator_after": false, "label": "Pokaż powiązane zasoby", "action": function(obj) { node = { id:"res"+id, text:"Zasoby"}; $('#tree').jstree('create_node', id, node, 'first'); var node = { id:"prof"+id,text:"Stanowiska"}; $('#tree').jstree('create_node', id, node, 'first'); var link = BASE_URL + "index.php?_route=UrlAction_ProcesView&_task=getDetailsAjax&id=" + id; $.get(link, function(data){ var isProf = false; var isRes = false; $.each(data["wsk"], function(i, e){ //console.log(e); var idX = e["ID_ZASOB"]; var node = { id:"wsk"+e["ID"],text: "["+e["ID_ZASOB"]+"] " + res[idX]["DESC"]}; if(res[idX]["TYPE"] == "STANOWISKO" || res[idX]["TYPE"] == "DZIAL" || res[idX]["TYPE"] == "PODMIOT"){ node["type"] = "stanowiska"; isProf = true; $('#tree').jstree('create_node', "prof"+id, node, 'first'); }else{ node["type"] = "zasoby"; isRes = false; $('#tree').jstree('create_node', "res"+id, node, 'first'); } }); if(!isProf) $("#tree").jstree('rename_node', "prof"+id , "Stanowiska [BRAK]" ); if(!isRes) $("#tree").jstree('rename_node', "res"+id , "Zasoby [BRAK]" ); $("#tree").jstree("open_node", id); $("#tree").jstree("open_node", "res"+id); $("#tree").jstree("open_node", "prof"+id); }) } }, }; } if (node.type === "zasoby" || node.type === "stanowiska") { items = { "Edit": { "separator_before": false, "separator_after": true, "label": "Edytuj zasób", "action": function(obj) { var zId = id.replace("wsk", ""); window.location = BASE_URL + 'index.php?_route=ViewTableAjax&typeName=p5_default_db:CRM_LISTA_ZASOBOW#EDIT/' + zId; } }, }; } return items; } 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': (TYPE == "childs" ? translate(0, procesy) : translate(0, res)) }, "types": { "default": { "icon": "glyphicon glyphicon-folder-open", }, "proces": { "icon": "glyphicon glyphicon-file", }, "stanowiska": { "icon": "glyphicon glyphicon glyphicon-user", }, "zasoby": { "icon": "glyphicon glyphicon glyphicon-hdd", }, }, "plugins": [ "contextmenu", "search", "types" ], "search": { // search config "show_only_matches": true, }, "contextmenu": { "items": customMenu } }); } function renderPanels() { $("#view").html("