$(document).ready(function() {
$("#main").after("Zapisz zmiany ");
var deletedId = new Array();
var generatedId = new Array();
var deletedRes = new Array();
var perms = [
[1, "Kto wykonuje", "X"],
[2, "Tylko do odczytu", "R"],
[3, "Odczyt, zapis, wykonanie", "R,W,X"],
[4, "Odczyt, zapis, wykonanie, tworzenie", "R,W,X,C"],
[5, "Odczyt i wyknanie", "R,X"],
[6, "Tylko do odczytu", "R"],
[7, "MAPA PROCESU - opis mapy procesu", ""],
[9, "Tylko do tworzenia rekordu", "C"],
[10, "Tylko tworzenie i czytanie rekordów bez edycji", "R,X,C"],
[11, "Tylko edycja rekordu - ustalanie nowej wartosci", "W"],
[12, "Tylko edycja i dodanie rekordu - ustalanie nowej wartosci", "W,C"],
[13, "Nowy rekord i edycja z pominieciem A_ADM_COMPANY", "R,W,X,C,S"],
[14, "Widok tylko swoich danych z rekordu", "W,O"],
[15, "Edycja rekordów dla super admina", "R,W,C,S"],
[16, "Widok i dodawanie rekordów tylko dla swojego ADM_COMPANY", "C,O"],
[17, "Super widok wszystkich rekordow niezaleznie od uprawnien rekordu", "R,V"],
[18, "Administracja Edycja i widok wszystkich rekordow z pominieciem A", "R,W,X,S,V"],
[19, "Administracja Edycja Tworzenie i widok wszystkich rekordow z pom", "R,W,X,C,S,V"],
[20, "Export", "R,X,E"],
[21, "Widzenie tylko swoich rekordów", "O"]
];
var loaded = false;
var tab = new Array(); //tablica kolejnosci
//var mainProces_id = 1; //id procesu glownego. Potem bedzie przypisywane z linku
var actSite = "none";
showPreview();
var filtr = 0;
var selectedArea = false;
var sZasoby;
var lastSearch = "";
var newSteps = 0;
var newRes = 0;
$("#main").hide();
$("#saveBtn").hide();
function loadResources() {
var res = new Array();
var sFiltr = "";
var link = BASE_URL + 'wfs-data.php/default_db/?SERVICE=WFS&VERSION=1.0.0&REQUEST=GetFeature&TYPENAME=p5_default_db:CRM_WSKAZNIK&SRSNAME=EPSG:3003&sortBy=SORT_PRIO+A';
//console.log("link "+link);
sFiltr += `
`;
$("#main").children().each(function(index) {
var id = $(this).data("id");
sFiltr += 'ID_PROCES ' + id + ' ';
});
sFiltr += ' A_STATUS DELETED ';
//console.log("x "+sFiltr);
$.ajax({
url: link,
data: sFiltr,
type: 'POST',
contentType: "text/xml",
dataType: "xml",
success: function(data) {
//console.log(data);
$.each($(data).find("featureMember"), function() {
var result = new Array();
result["ID"] = $(this).find("ID").text();
result["ID_ZASOB"] = $(this).find("ID_ZASOB").text();
result["ID_PROCES"] = $(this).find("ID_PROCES").text();
result["SORT_PRIO"] = $(this).find("SORT_PRIO").text();
result["ID_PRZYPADEK"] = $(this).find("ID_PRZYPADEK").text();
result["OPIS_ZASOB"] = $(this).find("OPIS_ZASOB").text();
res.push(result);
});
//console.log(res);
var sFiltr2 = "";
var link2 = 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';
sFiltr2 += `
`;
$.each(res, function(index, value) {
var id = res[index]["ID_ZASOB"];
sFiltr2 += `
ID
` + id + `
`;
});
sFiltr2 += `
`;
//console.log(sFiltr2);
//console.log(link2);
var zasobInfo = new Array();
$.ajax({
url: link2,
data: sFiltr2,
type: 'POST',
contentType: "text/xml",
dataType: "xml",
success: function(data2) {
//console.log("data");
//console.log(data2);
$.each($(data2).find("featureMember"), function() {
//console.log();
zasobInfo[$(this).find("ID").text()] = new Array();
zasobInfo[$(this).find("ID").text()]["DESC"] = $(this).find("DESC").text();
zasobInfo[$(this).find("ID").text()]["OPIS"] = $(this).find("OPIS").text();
zasobInfo[$(this).find("ID").text()]["TYPE"] = $(this).find("TYPE").text();
});
//console.log(res);
$.each(res, function(index, value) {
var type;
if (zasobInfo[res[index]["ID_ZASOB"]]["TYPE"] == "DZIAL" || zasobInfo[res[index]["ID_ZASOB"]]["TYPE"] == "STANOWISKO" || zasobInfo[res[index]["ID_ZASOB"]]["TYPE"] == "PODMIOT") {
type = $("#proc" + res[index]["ID_PROCES"]).find(".professions");
} else {
type = $("#proc" + res[index]["ID_PROCES"]).find(".resources");
}
$(type).append("
" + zasobInfo[res[index]["ID_ZASOB"]]["DESC"] + " " + zasobInfo[res[index]["ID_ZASOB"]]["OPIS"] + " [" + res[index]["ID_ZASOB"] + "] ");
$(type).parents("dl").show();
updateArrows(type);
});
}
});
}
});
}
$(document).ajaxStop(function() {
if (loaded)
return;
//alert("OK");
loaded = true;
$(".drop").find("dl").hide();
loadResources();
$("#main").show();
$("#saveBtn").show();
});
//Saveaction
$(document).on('click', '#saveBtn', function() {
$("#saveBtn").prop('disabled', true);
//console.log("Saving has been started");
var genReq = `
`;
$("#main").children().each(function() {
if ($(this).data("id") < 0) {
genReq += `
-1
`;
}
});
genReq += ' ';
//console.log("genReq: " + genReq)
var link = BASE_URL + 'wfs-data.php/default_db/?SERVICE=WFS&VERSION=1.0.0&SRSNAME=EPSG:3003&';
//console.log(link);
$.ajax({
url: link,
data: genReq,
type: 'POST',
contentType: "text/xml",
dataType: "text",
success: function(data) {
//console.log("x: " + data);
$(data).find("[fid]").each(function(i, e) {
var newId = $(e).attr("fid").substr($(e).attr("fid").indexOf('.') + 1);
generatedId.push(newId);
});
//console.log(generatedId[0]);
var i = 0;
var newIdTab = Array();
//console.log(generatedId);
$("#main").children().each(function() {
if ($(this).data("id") < 0) {
newIdTab[$(this).data("id")] = generatedId[i];
i++;
}
});
//console.log(newIdTab);
var request = `
`;
$("#main").children().each(function() {
request += `
`;
if ($(this).data("id") >= 0)
request += '' + $(this).data("id") + ' ';
else
request += '' + newIdTab[$(this).data("id")] + ' ';
if ($(this).data("parent_id") != false) {
if ($(this).data("parent_id") >= 0)
request += '' + $(this).data("parent_id") + ' ';
else
request += '' + newIdTab[$(this).data("parent_id")] + ' ';
request += '' + $(this).data("SORT_PRIO") + ' ';
}
request += '' + $(this).find(".hdesc").text() + ' ';
request += '' + $(this).find(".sdesc").text() + ' ';
request += `
`;
var id;
if ($(this).data("id") >= 0)
id = $(this).data("id");
else
id = newIdTab[$(this).data("id")];
var sort_prio = 0;
$(this).find(".professions,.resources").find("li").each(function() {
sort_prio++;
request += `
`;
if ($(this).data("id") >= 0) {
request += '' + $(this).data("id") + ' ';
}
request += '' + $(this).data("zasob") + ' ';
request += '' + id + ' ';
request += '' + $(this).data("przypadek") + ' ';
var opis = $(this).data("komentarz");
opis = opis.replace(/&/g, '&').replace(//g, '>').replace(/"/g, '"').replace(/'/g, ''');
request += '' + sort_prio + ' ';
request += '' + opis + ' ';
request += `
`;
});
});
$.each(deletedId, function(key, value) {
request += `
`;
request += '' + value + ' ';
request += '-1 ';
request += 'DELETED ';
request += `
`;
});
$.each(deletedRes, function(key, value) {
request += `
`;
request += '' + value + ' ';
request += 'DELETED ';
request += `
`;
});
request += ' ';
//console.log(request); console.log(link);
$.ajax({
url: link,
data: request,
type: 'POST',
contentType: "text/xml",
dataType: "text",
success: function(data) {
//console.log(data);
deletedRes = [];
deletedId = [];
showPreview();
$("#saveBtn").prop('disabled', false);
},
error: function(xhr, ajaxOptions, thrownError) {
$.notify("Brak połączenia z bazą danych", "error");
}
});
},
error: function(xhr, ajaxOptions, thrownError) {
$.notify("Brak połączenia z bazą danych", "error");
}
});
});
$(document).on('click', '.btnEdit', function() {
var zasob = $(this).parents("li");
var permsOpt = "";
$.each(perms, function(key, value) {
if ($(zasob).data("przypadek") == value[0])
permsOpt = permsOpt + "[" + value[2] + "] " + value[1] + " ";
else
permsOpt = permsOpt + "[" + value[2] + "] " + value[1] + " ";
})
swal({
showCancelButton: true,
title: 'Uprawnienia',
html: 'Uprawnienia' + permsOpt + ' ' +
'Komentarz ',
preConfirm: function() {
return new Promise(function(resolve) {
resolve([
$('#swal-input1').val(),
$('#swal-input2').val()
]);
});
}
}).then(function(result) {
$(zasob).data("przypadek", result[0]);
$(zasob).data("komentarz", result[1]);
}).catch(function(e) {})
});
//Buttony i ich zadania
$(document).on('click', '.step', function() {
newSteps--;
var main = false;
if ($(this).parents(".drop").data("id") === mainProces_id)
main = true;
$(this).parents(".drop").after("
");
$("#proc" + newSteps).data("id", newSteps);
$("#proc" + newSteps).append("
");
$("#opt" + newSteps).append(" ");
//Arrows
$("#opt" + newSteps).append(" ");
$("#opt" + newSteps).append(" ");
$("#opt" + newSteps).append(" ");
$("#opt" + newSteps).append(" ");
//
$("#opt" + newSteps).append("
");
$("#proc" + newSteps).append("
Nowy krok {?} Opis nowego kroku ");
$("#proc" + newSteps).append("
");
$("#desc" + newSteps).append("Stanowiska ");
$("#desc" + newSteps).append("Użyte zasoby ");
if (!main)
$("#proc" + newSteps).data("parent_id", $(this).parents(".drop").data("parent_id"));
else
$("#proc" + newSteps).data("parent_id", mainProces_id);
$("#desc" + newSteps).append("Dodaj nowy krok ");
tab.push(newSteps);
var parent_id = $("#proc" + newSteps).data("parent_id");
//console.log(parent_id);
$("#proc" + newSteps).data("depth", $("#proc" + parent_id).data("depth") + 1);
//var depthWidth = 20 * $("#proc" + this.id).data("depth");
//$("#proc" + this.id).css("padding-left", depthWidth + "px");
$("#proc" + newSteps).find("dl").hide();
updateX();
updateAll();
});
$(document).on('keyup', '#sZasoby', function() {
if ($(this).val() != lastSearch) {
lastSearch = $(this).val();
clearTimeout(sZasoby);
sZasoby = setTimeout(function() {
searchRes();
}, 300);
}
});
function updateArrows(node){
$(node).find("li").each(function(){
if($(this).prev().length == 0){
$(this).find(".uArrowRes").hide();
}else {
$(this).find(".uArrowRes").show();
}
if($(this).next().length == 0){
$(this).find(".dArrowRes").hide();
}else{
$(this).find(".dArrowRes").show();
}
});
}
$(document).on('click', '.uArrowRes', function() {
var node = $(this).parents("li");
node.insertBefore(node.prev());
updateArrows(node.parents("ul"));
});
$(document).on('click', '.dArrowRes', function() {
var node = $(this).parents("li");
node.insertAfter(node.next());
updateArrows(node.parents("ul"));
});
$(document).on('click', '.uArrow', function() {
var node = $(this).parent().parent();
node.insertBefore(node.prev());
updateX();
updateAll();
});
$(document).on('click', '.dArrow', function() {
var node = $(this).parent().parent();
node.insertAfter(node.next());
updateX();
updateAll();
});
$(document).on('click', '.rArrow', function() {
var node = $(this).parent().parent();
$(node).data("depth", $(node).data("depth") + 1);
//var depthWidth = 20 * $(node).data("depth");
// $(node).css("padding-left", depthWidth + "px");
updateAll();
});
$(document).on('click', '.lArrow', function() {
var node = $(this).parent().parent();
$(node).data("depth", $(node).data("depth") - 1);
//var depthWidth = 20 * $(node).data("depth");
//$(node).css("padding-left", depthWidth + "px");
updateAll();
});
$(document).on('click', '#btnZasoby', function(e) {
e.preventDefault();
zasoby();
$("#wrapper").toggleClass("toggled");
});
$(document).on('click', 'body', function() {
if (selectedArea != false) {
var content = $(selectedArea).val();
var type;
if ($(selectedArea).parent().hasClass("hdesc")) {
type = "DESC";
$(selectedArea).parents("h4").addClass("changed");
}
if ($(selectedArea).parent().hasClass("sdesc")) {
$(selectedArea).parents(".sdesc").addClass("changed");
type = "OPIS";
}
var id = (selectedArea).parents(".drop").data("id");
var post = ' ' + content + ' ';
//console.log("Nowy "+type+" dla id "+id+" to "+content);
if (content == "" && type == "OPIS") {
$(selectedArea).parent().after("Dodaj opis ");
}
if (content == "" && type == "DESC") {
$(selectedArea).parent().after("Dodaj opis ");
}
$(selectedArea).parent().html(content);
selectedArea = false;
}
});
$(document).on('click', '.hdesc', function() {
if ($(this).find("textarea").is(selectedArea))
return false;
});
$(document).on('click', '.sdesc', function() {
if ($(this).find("textarea").is(selectedArea))
return false;
});
$(document).on('dblclick', '.sdesc', function() {
if (selectedArea)
return;
if ($(this).find("textarea").length == 0) {
var content = $(this).html();
$(this).empty();
$(this).append("");
selectedArea = $(this).find("textarea");
}
});
$(document).on('click', '.sDescAdd', function() {
if (selectedArea)
return;
var action = $(this).parents(".drop").find(".sdesc");
if ($(action).find("textarea").length == 0) {
//alert($(action).text());
$(action).empty();
$(action).append("");
$(this).remove();
selectedArea = $(action).find("textarea");
return false;
}
});
$(document).on('click', '.hDescAdd', function() {
if (selectedArea)
return;
var action = $(this).parents(".drop").find(".hdesc");
if ($(action).find("textarea").length == 0) {
//alert($(action).text());
$(action).empty();
$(action).append("");
$(this).remove();
selectedArea = $(action).find("textarea");
return false;
}
});
$(document).on('dblclick', '.hdesc', function() {
if ($(this).find("textarea").length == 0) {
var content = $(this).html();
$(this).empty();
$(this).append("");
selectedArea = $(this).find("textarea");
}
});
$(document).on('click', '.del', function() {
var node = $(this).parent().parent();
swal({
title: 'Usuwanie kroku',
text: "Czy napewno chcesz usunąć ten krok?",
type: 'warning',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: 'Tak, usuń ten krok'
}).then(function() {
deletedId.push($(node).data("id"));
node.remove();
updateX();
updateAll();
//Parent_id = -1,
})
});
$(document).on('click', '.delRes', function() {
//var parent = $(this).parents(".drop");
var child = $(this).parents("li");
var li =
swal({
title: 'Usuwanie wskaźnika',
text: "Czy napewno chcesz usunąć ten wskaźnik?",
type: 'warning',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: 'Tak, usuń ten wskaźnik'
}).then(function() {
deletedRes.push($(child).data("id"));
child.remove();
updateX();
updateAll();
//Parent_id = -1,
})
});
//
$(document).on('click', '.fbutton', function(e) {
e.preventDefault();
$(".fbutton").removeClass("btn-success");
if ($(this).data("type") == filtr) {
filtr = 0;
//console.log("Odznaczono");
} else {
filtr = $(this).data("type");
$(this).addClass("btn-success");
}
if (filtr === 0)
$("#xBtn").prop("disabled", true);
else
$("#xBtn").prop("disabled", false);
searchRes();
});
$(document).on('click', '.showMore', function() {
var target = $(this).parent().find(".more");
var id = $(this).data("id");
if ($(target).parent().hasClass("resSelected")) {
$(".more").empty();
$(target).parent().removeClass("resSelected");
$(target).parent().find(".gIco").addClass("glyphicon-chevron-down");
$(target).parent().find(".gIco").removeClass("glyphicon-chevron-up");
} else {
$(".more").parent().removeClass("resSelected");
$(".more").parent().find(".gIco").addClass("glyphicon-chevron-down");
$(".more").parent().find(".gIco").removeClass("glyphicon-chevron-up");
$(".more").empty();
$(target).parent().addClass("resSelected");
$(target).parent().find(".gIco").removeClass("glyphicon-chevron-down");
$(target).parent().find(".gIco").addClass("glyphicon-chevron-up");
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=PARENT_ID ' + id + ' TYPE KOMORKA &sortBy=SORT_PRIO+A';
//console.log(link);
$.get(link, function(data) {
$.each($(data).find("featureMember"), function() {
if ($(this).find("ID").text() != 0) {
var type = 0;
$(target).append("" + $(this).find("DESC").text() + " [" + $(this).find("ID").text() + "]
");
$('.drag').draggable({
appendTo: 'body',
helper: 'clone',
stack: "div",
distance: 0,
cursor: "copy"
});
$(".drop").droppable({
tolerance: 'pointer',
accept: '.drag',
drop: function(event, ui) {
addResource(ui, this);
}
});
}
});
});
}
});
function searchRes() {
var id = lastSearch;
var link;
//console.log("Szukam");
switch (filtr) {
case 0:
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=ID *' + id + '* DESC *' + id + '* &maxFeatures=100';
break;
case 1:
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=ID *' + id + '* DESC *' + id + '* TYPE STANOWISKO TYPE PODMIOT TYPE DZIAL &maxFeatures=100';
break;
case 2:
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=ID *' + id + '* DESC *' + id + '* TYPE KOMORKA TYPE TABELA &maxFeatures=100&sortBy=TYPE+A';
//console.log(link);
break;
default:
link = "";
}
$.get(link, function(data) {
var side = $("#side");
//console.log(data);
$(side).find("#ulcon").empty();
$.each($(data).find("featureMember"), function() {
if ($(this).find("ID").text() * 1 == 0) {
$(side).find("#ulcon").append("
Brak wyników wyszukiwania ");
return;
}
var type = 0;
if ($(this).find("TYPE").text() == "DZIAL" || $(this).find("TYPE").text() == "PODMIOT" || $(this).find("TYPE").text() == "STANOWISKO")
type = 1;
if (filtr != 2 || $(this).find("TYPE").text() != "TABELA")
$(side).find("#ulcon").append("" + $(this).find("DESC").text() + " [" + $(this).find("ID").text() + "]
");
else {
$(side).find("#ulcon").append("# " + $(this).find("DESC").text() + " [" + $(this).find("ID").text() + "]
");
}
});
$('.drag').draggable({
appendTo: 'body',
helper: 'clone',
stack: "div",
distance: 0,
cursor: "copy"
});
$(".drop").droppable({
tolerance: 'pointer',
accept: '.drag',
drop: function(event, ui) {
addResource(ui, this);
}
});
});
}
function zasoby() {
var side = $("#side");
$(side).empty();
$(side).append("Zarządzaj zasobami");
$(side).append("
");
$(side).append("
");
$("#filtry").append("Stanowiska ");
$("#filtry").append("Komórki ");
$("#filtry").append("X ");
$(side).append("
");
//$(side).find("#ulcon").append("[STANOWISKO] Ulotkarz
");
//$(side).find("#ulcon").append("[STANOWISKO] Programista PHP
");
//$(side).find("#ulcon").append("[ZASÓB] Komputer
");
$('.drag').draggable({
appendTo: 'body',
helper: 'clone',
stack: "div",
distance: 0,
cursor: "copy"
});
$(".drop").droppable({
tolerance: 'pointer',
accept: '.drag',
drop: function(event, ui) {
addResource(ui, this);
}
});
}
function addResource(ui, target) {
var permsOpt = "";
$.each(perms, function(key, value) {
permsOpt = permsOpt + "[" + value[2] + "] " + value[1] + " ";
})
swal({
showCancelButton: true,
title: 'Uprawnienia',
html: 'Uprawnienia' + permsOpt + ' ' +
'Komentarz ',
preConfirm: function() {
return new Promise(function(resolve) {
resolve([
$('#swal-input1').val(),
$('#swal-input2').val()
]);
});
}
}).then(function(result) {
//console.log("Dodaj zasob " + ui.draggable.data("id") + " do " + $(target).data("id") + " i uprawnienia id " + result[0] + " komentarz: " + result[1]); //
newRes--;
if (ui.draggable.data("type") == 1) {
$(target).find(".professions").append("" + ui.draggable.data("opis") + " ");
$(target).find(".professions").parents("dl").show();
updateArrows($(target).find(".professions"));
} else {
$(target).find(".resources").append("" + ui.draggable.data("opis") + " ");
$(target).find(".resources").parents("dl").show();
updateArrows($(target).find(".resources"));
}
}).catch(function(e) {})
}
//Po uzyciu uArrow lub dArrow tworzy nowa kolejnosc
function updateX() {
tab = [];
$.each($("#main").children(), function(index) {
tab.push($(this).data("id") * 1);
});
//console.log(tab);
}
//Najwazniejsza funkcja odpalana po kazdej zmianie. Sprawdza, czy wszystkie funkcje maja rodzica,
//jezeli nie to przesuwa w lewo obiekt
//Odpowiada tez za ukrywanie guzikow i wywowalanie funkcji generacji krokow
function updateAll() {
$("#main").children().each(function(index) {
if (getParentNode($(this).data("id")) != "NONE" && getParentNode($(this).data("id")) != false && getParentNode($(this).data("id")) != $(this).data("parent_id")) {
$(this).data("parent_id", getParentNode($(this).data("id")));
console.log("Ustawiono nowe parent_id na " + $(this).data("parent_id") + " dla " + $(this).data("id")); //
} else if (getParentNode($(this).data("id")) === false) {
var node = this;
$(node).data("depth", $(node).data("depth") - 1);
//var depthWidth = 20 * $(node).data("depth");
//$(node).css("padding-left", depthWidth + "px");
updateAll();
return;
}
if (checkParentNode($(this).data("id"), "right") === false) {
$(this).find(".rArrow").hide();
} else {
$(this).find(".rArrow").show();
}
if (checkParentNode($(this).data("id"), "left") === false) {
$(this).find(".lArrow").hide();
} else {
$(this).find(".lArrow").show();
}
if (tab[1] == $(this).data("id"))
$(this).find(".uArrow").hide();
else
$(this).find(".uArrow").show();
if ($(this).next().length == 0) {
$(this).find(".dArrow").hide();
} else {
$(this).find(".dArrow").show();
}
});
stepsGenerator();
}
//Generuje kroki, sprawdza tez czy kolejnosc krokow w danym rodzicow zostala zmieniona
//Jezeli tak to mozna wyslac ajaxem zmiane kolejnosci dla sort_prio
function stepsGenerator() {
$("#main").children().each(function(index) {
$(this).data("step", 0);
if ($(this).data("id") == mainProces_id) {
$(this).data("stepDesc", "");
} else {
$("#proc" + $(this).data("parent_id")).data("step", $("#proc" + $(this).data("parent_id")).data("step") + 1);
$(this).data("SORT_PRIO", $("#proc" + $(this).data("parent_id")).data("step"));
$(this).data("stepDesc", $("#proc" + $(this).data("parent_id")).data("stepDesc") + $("#proc" + $(this).data("parent_id")).data("step") + ". ");
//console.log($(this).data("stepDesc"));
$(this).find(".stepDesc").text($(this).data("stepDesc"));
}
});
}
//Prosta funkcja sprawdzajaca pozycje danego obiektu
function getX(id) {
//alert("id "+id)
var result;
$.each(tab, function(index, value) {
if (value == id)
result = index;
});
return result;
}
//Na potrzeby guzikow dorobilem funkcje sprawdzajaca id rodzica po przesunieciu (przewidywanie).
//Jezeli nie znajdzie zwraca false, a wtedy blokuje sie odpowiednia strzalka
function checkParentNode(id, check) {
var x = getX(id);
//console.log(tab);
var result = false;
while (x > 0) {
x--;
if (check == "right")
if ($("#proc" + tab[x]).data("depth") == $("#proc" + id).data("depth")) {
result = tab[x];
break;
}
if (check == "left")
if ($("#proc" + tab[x]).data("depth") == $("#proc" + id).data("depth") - 2) {
result = tab[x];
break;
}
if (check == "right" && $("#proc" + tab[x]).data("depth") < $("#proc" + id).data("depth"))
break;
}
return result;
}
//Zwraca id rodzica, jezeli nie ma zwraca false
function getParentNode(id) {
var x = getX(id);
if (mainProces_id == id)
return "NONE";
var result = false;
while (x > 0) {
x--;
var depth = $("#proc" + tab[x]).data("depth") - $("#proc" + id).data("depth");
if ($("#proc" + tab[x]).data("depth") == $("#proc" + id).data("depth") - 1) {
result = tab[x];
break;
}
if ($("#proc" + tab[x]).data("depth") - $("#proc" + id).data("depth") == -2)
break;
}
return result;
}
function genTree(parent_id, last) {
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=PARENT_ID ' + parent_id + ' &sortBy=SORT_PRIO+A';
//console.log(link);
$.ajax({
url: link,
success: function(data) {
//console.log(data);
$.each($(data).find("featureMember"), function() {
if ($(this).find("ID").text() == "0")
return;
$(last).after("
");
$("#proc" + $(this).find("ID").text()).data("id", $(this).find("ID").text() * 1);
$("#proc" + $(this).find("ID").text()).append("
");
$("#opt" + $(this).find("ID").text()).append(" ");
//Arrows
$("#opt" + $(this).find("ID").text()).append(" ");
$("#opt" + $(this).find("ID").text()).append(" ");
$("#opt" + $(this).find("ID").text()).append(" ");
$("#opt" + $(this).find("ID").text()).append(" ");
//
$("#opt" + $(this).find("ID").text()).append("
");
$("#proc" + $(this).find("ID").text()).append("
" + $(this).find("DESC").text() + " {" + $(this).find("ID").text() + "} " + $(this).find("OPIS").text() + " ");
if ($(this).find("DESC").text() == "") {
$("#proc" + $(this).find("ID").text()).find(".hdesc").after("Dodaj tytuł ");
}
if ($(this).find("OPIS").text() == "") {
$("#proc" + $(this).find("ID").text()).find(".sdesc").after("Dodaj opis ");
}
$("#proc" + $(this).find("ID").text()).append("
");
$("#desc" + $(this).find("ID").text()).append("Stanowiska ");
$("#desc" + $(this).find("ID").text()).append("Użyte zasoby ");
$("#proc" + $(this).find("ID").text()).data("parent_id", $(this).find("PARENT_ID").text());
$("#desc" + $(this).find("ID").text()).append("Dodaj nowy krok ");
//tab.push($(this).find("ID").text()*1);
var parent_id = $("#proc" + $(this).find("ID").text()).data("parent_id");
$("#proc" + $(this).find("ID").text()).data("depth", $("#proc" + $(this).find("PARENT_ID").text()).data("depth") + 1);
last = $("#proc" + $(this).find("ID").text());
genTree($(this).find("ID").text(), last);
//var depthWidth = 20 * $("#proc" + this.id).data("depth");
//$("#proc" + this.id).css("padding-left", depthWidth + "px");
//alert("add");
updateX();
updateAll();
});
}
});
}
//Pierwszy render, tworzy potrzebna strukture
function showPreview() {
filtr = 0;
selectedArea = false;
lastSearch = "";
newSteps = 0;
newRes = 0;
tab = [];
deletedId = [];
$("#main").empty();
$("#main").hide();
var id = mainProces_id;
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=ID ' + id + ' ';
//console.log(link);
$.get(link, function(data) {
loaded = false;
//console.log(data);
$("#main").append("
");
$("#proc" + mainProces_id).data("id", mainProces_id);
$("#proc" + mainProces_id).data("depth", 0);
$("#proc" + mainProces_id).data("parent_id", false);
$("#proc" + mainProces_id).append("
");
$("#proc" + mainProces_id).append("
" + $(data).find("featureMember").find("DESC").text() + " {" + mainProces_id + "} " + $(data).find("featureMember").find("OPIS").text() + " ");
if ($(data).find("featureMember").find("DESC").text() == "") {
$("#proc" + mainProces_id).find(".hdesc").after("Dodaj Tytuł ");
}
if ($(data).find("featureMember").find("OPIS").text() == "") {
$("#proc" + mainProces_id).find(".sdesc").after("Dodaj opis ");
}
$("#proc" + mainProces_id).append("
");
$("#desc" + mainProces_id).append("Stanowiska ");
$("#desc" + mainProces_id).append("Użyte zasoby ");
$("#desc" + mainProces_id).append("Dodaj nowy krok ");
tab.push(mainProces_id);
genTree(mainProces_id, $("#proc" + mainProces_id));
});
actSite = "preview";
}
});