", {
"class": "p5BModalModal"
});
$("#p5BModalBack").append(p5BModal);
$(p5BModal).html(modal);
$(p5BModal).draggable({
containment: "body",
handle: ".p5BModalHeader"
});
if (args)
initFunction($(p5BModal).find(".p5BModalContent"), args)
else
initFunction($(p5BModal).find(".p5BModalContent"))
}
$(document).on('click', '.editPath', function() {
p5BModalDisplay("Przepinanie procesu", pathModal);
});
function hideModal(which) {
$(which).remove();
if ($(".p5BModalModal").length == 0) {
$("#p5BModalBack").fadeOut('fast', function() {
$("#p5BModalBack").remove();
});
// $('html, body').css({
// overflow: 'auto',
// height: '100%'
// });
}
}
$(document).on('click', '#savePath', function() {
showPath(state[0]["PARENT_ID"]);
hideModal($(this).closest(".p5BModalModal"));
return false;
})
$(document).on('mousedown', '.p5BModalModal', function() {
$(".p5BModalModal").css("z-index", 2001)
$(this).css("z-index", 2002)
})
/* END p5BModal */
$(document).on('click', '#expBtn', function() {
var exp = {};
exp["ID"] = mainProces_id;
exp["time"] = moment().format("YYYY-MM-DD HH:mm:ss");
var temp = {};
temp["state"] = state;
temp["newSteps"] = newSteps;
temp["newRes"] = newRes;
temp["deletedId"] = deletedId;
temp["deletedRes"] = deletedRes;
exp["data"] = temp;
var crc = {};
crc["crc"] = crc32(JSON.stringify(exp));
crc["content"] = exp;
swal({
title: 'Import/Export',
text: 'Wybierz czynność:',
type: 'warning',
cancelButtonText: 'Import',
confirmButtonText: 'Export',
cancelButtonColor: '#d33',
confirmButtonColor: '#3085d6',
showCancelButton: true,
}).then(function() {
saveToXml();
}, function(dismiss) {
if (dismiss === 'cancel') {
swal({
title: 'Import',
text: 'Wklej dane do zaimportowania:',
inputPlaceholder: "Wklej tutaj dane, które otrzymałeś w trakcie eksportu.",
input: 'textarea',
}).then(function(imp) {
loadFromXml(imp);
})
}
}).catch(function(e) {
console.log('Error', e)
})
})
function saveProces() {
$("#saveBtn").prop('disabled', true);
$.notify("Rozpoczęto zapisywanie. Nie zamykaj tego okna", "info");
var genReq = `
`;
// xsi:schemaLocation="` + BASE_WFS_URL + `/default_db/CRM_PROCES ` + BASE_URL + `dev-pl/se-feature-api/wfs.php/xml/wfs/default_db/CRM_PROCES/?SERVICE=WFS&VERSION=1.0.0&REQUEST=DescribeFeatureType&TYPENAME=p5_default_db:CRM_PROCES&SRSNAME=EPSG:4326&"
$.each(state, function(i, e) {
if (e['ID'] < 0) {
genReq += `
-1`;
}
});
genReq += '';
var link = BASE_URL + 'wfs-data.php/default_db/?SERVICE=WFS&VERSION=1.0.0&SRSNAME=EPSG:3003&';
$.ajax({
url: link,
data: genReq,
type: 'POST',
contentType: "text/xml",
dataType: "text",
success: function(data) {
$(data).find("[fid]").each(function(i, e) {
var newId = $(e).attr("fid").substr($(e).attr("fid").indexOf('.') + 1);
generatedId.push(newId);
});
var i = 0;
var newIdTab = Array();
$.each(state, function(z, e) {
if (e["ID"] < 0) {
newIdTab[e["ID"]] = generatedId[i];
i++;
}
});
var request = `
`;
$.each(state, function(i, e) {
request += `
`;
if (e["ID"] >= 0)
request += '' + e["ID"] + '';
else
request += '' + newIdTab[e["ID"]] + '';
if (i == 0)
request += 'PROCES_INIT';
else
request += 'PROCES';
if (e["PARENT_ID"] >= 0)
request += '' + e["PARENT_ID"] + '';
else
request += '' + newIdTab[e["PARENT_ID"]] + '';
request += '' + e["SORT_PRIO"] + '';
if (e["IF_TRUE_GOTO"] != false) {
request += '' + e["IF_TRUE_GOTO"] + '';
request += '' + e["IF_TRUE_GOTO_FLAG"] + '';
} else {
request += '0';
request += '';
}
request += '' + cData(e["DESC"]) + '';
request += '' + cData(e["OPIS"]) + '';
request += `
`;
var id;
if (e["ID"] >= 0)
id = e["ID"];
else
id = newIdTab[e["ID"]];
var sort_prio = 0;
$.each(e["_prof"].concat(e["_res"]), function(iR, eR) {
sort_prio++;
request += `
`;
if (eR["ID"] >= 0) {
request += '' + eR["ID"] + '';
}
request += '' + eR["ID_ZASOB"] + '';
request += '' + id + '';
request += '' + eR["ID_PRZYPADEK"] + '';
var opis = eR["OPIS_ZASOB"];
opis = opis.replace(/&/g, '&').replace(//g, '>').replace(/"/g, '"').replace(/'/g, ''');
request += '' + sort_prio + '';
request += '' + cData(opis) + '';
request += `
`;
});
});
$.each(deletedId, function(key, value) {
if (value < 0)
return true;
request += `
`;
request += '' + value + '';
request += '-1';
request += 'DELETED';
request += `
`;
});
$.each(deletedRes, function(key, value) {
if (value < 0)
return true;
request += `
`;
request += '' + value + '';
request += 'DELETED';
request += `
`;
});
$.each(usedImg, function(key, value) {
//console.log("usedImg()")
//console.log(key, value)
if (key < 0)
return true;
if(value.action == "ATTACH"){
request +=
`
`;
request += '' + key + '';
request += '' + value["type"] + '';
request += '' + (value["targetID"] >= 0 ? value["targetID"] : newIdTab[value["targetID"]]) + '';
request += `
`;
}else if(value.action == "DELETED"){
request += ''
request += ''
request += ''
request += ''
request += ''
}
});
request += '';
//console.log(request);
$.ajax({
url: link,
data: request,
type: 'POST',
contentType: "text/xml",
dataType: "text",
success: function(data) {
if ($(data).children("serviceException").text() == "") {
if (mainProces_id == -1)
window.location.replace("index.php?_route=UrlAction_procesEditor&id=" + newIdTab[state[0]["ID"]])
deletedRes = [];
deletedId = [];
usedImg = {};
localStorage.removeItem("state" + mainProces_id);
showPreview();
$.notify("Zmiany zostały zapisane na serwerze.", "success");
} else {
$.notify("Błąd API. Zmiany zostały zapisane wyłącznie w pamięci Twojej przeglądarki. Skontaktuj się z administratorem.", "error");
localStorage.setItem("state" + mainProces_id, JSON.stringify(state));
localStorage.setItem("newStep" + mainProces_id, newSteps);
localStorage.setItem("newRes" + mainProces_id, newRes);
localStorage.setItem("deletedId" + mainProces_id, JSON.stringify(deletedId));
localStorage.setItem("usedImg" + mainProces_id, JSON.stringify(usedImg));
localStorage.setItem("deletedRes" + mainProces_id, JSON.stringify(deletedRes));
localStorage.setItem("date" + mainProces_id, moment().format("YYYY-MM-DD HH:mm:ss"));
}
$("#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', '#saveBtn', function() {
if (state[0]["PARENT_ID"] <= 0)
swal({
title: 'Brak procesu nadrzędnego',
text: "proces_init nie został przypięty do żadnego nadrzędnego procesu.",
type: 'error',
showCancelButton: true,
cancelButtonColor: '#3085d6',
confirmButtonColor: '#d33',
cancelButtonText: "Edytuj ścieżkę [ZALECANE]",
confirmButtonText: 'Kontynuuj'
}).then(function() {
saveProces();
}, function(dismiss) {
p5BModalDisplay("Przepinanie procesu", pathModal);
}
).catch(function(e) {})
else
saveProces();
});
$(document).on('click', '.btnEdit', function() {
var parentIndex = getIndexById($(this).parents(".drop").data("id"));
var type;
if ($(this).parents("li").closest(".professions").length > 0)
type = "_prof";
else
type = "_res";
var zasobIndex = getResById(parentIndex, $(this).parents("li").data("id"), type);
var permsOpt = "";
$.each(perms, function(key, value) {
if (state[parentIndex][type][zasobIndex]["ID_PRZYPADEK"] == value[0])
permsOpt = permsOpt + "";
else
permsOpt = permsOpt + "";
});
swal({
showCancelButton: true,
title: 'Uprawnienia',
html: 'Uprawnienia ' +
'Komentarz ',
preConfirm: function() {
return new Promise(function(resolve) {
resolve([
$('#swal-input1').val(),
$('#swal-input2').val()
]);
});
}
}).then(function(result) {
state[parentIndex][type][zasobIndex]["ID_PRZYPADEK"] = result[0];
state[parentIndex][type][zasobIndex]["OPIS_ZASOB"] = result[1];
state[parentIndex][type][zasobIndex]["changed"] = true;
updateAll();
}).catch(function(e) {})
});
//Buttony i ich zadania
$(document).on('click', '.step', function() {
newSteps--;
var main = false;
var temp = {};
if ($(this).parents(".drop").data("id") === mainProces_id)
main = true;
$(this).parents(".drop").after("");
temp["ID"] = newSteps;
temp["DESC"] = "";
temp["OPIS"] = "";
var index = getIndexById($(this).parents(".drop").data("id"));
temp["_step"] = 0;
temp["_prof"] = new Array();
temp["_res"] = new Array();
temp["_C-desc"] = true;
temp["_C-opis"] = true;
temp["IF_TRUE_GOTO_FLAG"] = "";
temp["IF_TRUE_GOTO"] = 0;
temp["_stepDesc"] = "";
if (!main) {
temp["PARENT_ID"] = state[index]["PARENT_ID"];
temp["_depth"] = state[index]["_depth"];
} else {
temp["PARENT_ID"] = mainProces_id;
temp["_depth"] = 1;
}
state.splice(index + 1, 0, temp);
stepsGenerator();
updateAll();
});
$(document).on('keyup', '#sProcesy', function() {
if ($(this).val() != lastSearch) {
lastSearch = $(this).val();
clearTimeout(sProcesy);
sProcesy = setTimeout(function() {
if (lastSearch == "")
procesy();
else
searchProc();
}, 300);
}
});
$(document).on('keyup', '#sZasoby', function() {
if ($(this).val() != lastSearch) {
lastSearch = $(this).val();
clearTimeout(sZasoby);
sZasoby = setTimeout(function() {
if (filtr === 0 && lastSearch == "")
zasoby();
else
searchRes();
}, 300);
}
});
function arraymove(arr, fromIndex, toIndex) {
var element = [];
var element = arr[fromIndex];
arr.splice(fromIndex, 1);
arr.splice(toIndex, 0, element);
}
$(document).on('click', '.uArrowRes', function() {
var parent = getIndexById(($(this).parents(".drop").data("id")));
if ($(this).closest(".professions").length > 0)
type = "_prof";
else
type = "_res";
var id = getResById(parent, $(this).closest("li").data("id"), type);
arraymove(state[parent][type], id, id - 1);
updateAll();
});
$(document).on('click', '.dArrowRes', function() {
var parent = getIndexById(($(this).parents(".drop").data("id")));
if ($(this).closest(".professions").length > 0)
type = "_prof";
else
type = "_res";
var id = getResById(parent, $(this).closest("li").data("id"), type);
arraymove(state[parent][type], id, id + 1);
updateAll();
});
$(document).on('click', '.uArrow', function() {
var id = $(this).parents(".drop").data("id");
var index = getIndexById(id);
arraymove(state, index, index - 1);
updateAll();
});
$(document).on('click', '.dArrow', function() {
var id = $(this).parents(".drop").data("id");
var index = getIndexById(id);
arraymove(state, index, index + 1);
updateAll();
});
$(document).on('click', '.rArrow', function() {
var id = $(this).parents(".drop").data("id");
state[getIndexById(id)]["_depth"]++;
//var depthWidth = 20 * $(node).data("_depth");
// $(node).css("padding-left", depthWidth + "px");
updateAll();
});
$(document).on('click', '.lArrow', function() {
var id = $(this).parents(".drop").data("id");
state[getIndexById(id)]["_depth"]--;
//var depthWidth = 20 * $(node).data("_depth");
// $(node).css("padding-left", depthWidth + "px");
updateAll();
});
$(document).on('click', '#btnZasoby', function(e) {
e.preventDefault();
$(".lButton").removeClass("btn-primary");
if (dialog == 0) {
zasoby();
$(this).addClass("btn-primary");
$("#wrapper").removeClass("toggled");
dialog = 1;
} else if (dialog == 1) {
$("#wrapper").addClass("toggled");
dialog = 0;
} else {
$("#wrapper").addClass("toggled");
$(this).addClass("btn-primary");
setTimeout(function() {
zasoby();
$("#wrapper").removeClass("toggled");
}, 500);
dialog = 1;
}
});
$(document).on('click', '#btnPhotos', function(e) {
e.preventDefault();
$(".lButton").removeClass("btn-primary");
if (dialog == 0) {
photos();
$(this).addClass("btn-primary");
$("#wrapper").removeClass("toggled");
dialog = 3;
} else if (dialog == 3) {
$("#wrapper").addClass("toggled");
dialog = 0;
} else {
$("#wrapper").addClass("toggled");
$(this).addClass("btn-primary");
setTimeout(function() {
photos();
$("#wrapper").removeClass("toggled");
}, 500);
dialog = 3;
}
});
$(document).on('click', '#btnProcesy', function(e) {
e.preventDefault();
$(".lButton").removeClass("btn-primary");
if (dialog == 0) {
procesy();
$("#wrapper").removeClass("toggled");
$(this).addClass("btn-primary");
dialog = 2;
} else if (dialog == 2) {
$("#wrapper").addClass("toggled");
dialog = 0;
} else {
$("#wrapper").addClass("toggled");
$(this).addClass("btn-primary");
setTimeout(function() {
procesy();
$("#wrapper").removeClass("toggled");
}, 500);
dialog = 2;
}
});
$(document).on('click', 'body', function() {
if (selectedArea != false) {
var content = $(selectedArea).val();
var id = (selectedArea).parents(".drop").data("id");
if ($(selectedArea).parent().hasClass("hdesc")) {
if (getIndexById(id) == 0) {
showPath(state[0]["PARENT_ID"]);
}
state[getIndexById(id)]["DESC"] = content;
state[getIndexById(id)]["_C-desc"] = true;
}
if ($(selectedArea).parent().hasClass("sdesc")) {
state[getIndexById(id)]["OPIS"] = content;
state[getIndexById(id)]["_C-opis"] = true;
}
selectedArea = false;
updateAll();
}
});
$(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) {
$(action).html("");
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) {
$(action).html("");
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 id = $(this).parents(".drop").data("id");
var index = getIndexById(id);
swal({
title: 'Usuwanie kroku',
text: "Czy napewno chcesz usunąć ten krok?",
type: 'warning',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
cancelButtonText: "Anuluj",
confirmButtonText: 'Tak, usuń ten krok'
}).then(function() {
state.splice(index, 1);
deletedId.push(id);
updateAll();
//Parent_id = -1,
}).catch(function(e) {})
});
$(document).on('click', '.delGoto', function() {
//var parent = $(this).parents(".drop");
var id = $(this).parents("li").data("id");
var parent = getIndexById($(this).parents(".drop").data("id"));
swal({
title: 'Usuwanie bramki',
text: "Czy napewno chcesz usunąć tę bramkę?",
type: 'warning',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
cancelButtonText: "Anuluj",
confirmButtonText: 'Tak, usuń tę bramkę'
}).then(function() {
state[parent]["IF_TRUE_GOTO_FLAG"] = ""
state[parent]["IF_TRUE_GOTO"] = ""
updateAll();
//Parent_id = -1,
}).catch(function(e) {})
});
$(document).on('click', '.delRes', function() {
//var parent = $(this).parents(".drop");
var id = $(this).parents("li").data("id");
var parent = getIndexById($(this).parents(".drop").data("id"));
var type;
if ($(this).closest(".professions").length > 0)
type = "_prof";
else
type = "_res";
var index = getResById(parent, id, type);
swal({
title: 'Usuwanie wskaźnika',
text: "Czy napewno chcesz usunąć ten wskaźnik?",
type: 'warning',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
cancelButtonText: "Anuluj",
confirmButtonText: 'Tak, usuń ten wskaźnik'
}).then(function() {
deletedRes.push(id);
state[parent][type].splice(index, 1);
updateAll();
//Parent_id = -1,
}).catch(function(e) {})
});
$(document).on('click', '.fbutton', function(e) {
e.preventDefault();
$(".fbutton").removeClass("btn-success");
if ($(this).data("type") == filtr) {
filtr = 0;
} else {
filtr = $(this).data("type");
$(this).addClass("btn-success");
}
if (filtr === 0)
$("#xBtn").prop("disabled", true);
else
$("#xBtn").prop("disabled", false);
if (filtr === 0) {
zasoby();
} else
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 + "index.php?_route=UrlAction_ProcesEditor&_task=getResByParentAjax&parent_id=" + id;
$.get(link, function(data) {
$.each(data, function(i, e) {
if (e["ID"] != 0) {
var type = 0;
$(target).append("
" +
e["DESC"] +
" [" +
e["ID"] + "]
");
for (var i = 3; i > 0; i--) {
if (e["p" + i + "_ID"] != null) {
var temp = {};
temp["ID"] = e["p" + i + "_ID"];
temp["DESC"] = e["p" + i + "_DESC"];
zasobTree[e["ID"]] = [];
zasobTree[e["ID"]].push(temp);
}
}
updateDropZones();
}
});
});
}
});
function searchProc() {
var id = lastSearch;
var link;
//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=&';
p5WFS_GetFeature('p5_default_db:CRM_PROCES', {
'Filter': 'ID*' + id + '*DESC*' + id + '*',
'sortBy': 'SORT_PRIO+A,ID',
'maxFeatures': 100,
}).then(function(features) {
var side = $("#side");
$(side).find("#ulproc").empty();
$.each(features, function(i, xml) {
if (xml["ID"] * 1 == 0) {
$(side).find("#ulcon").append("
Brak wyników wyszukiwania
");
return;
}
$(side).find("#ulproc").append("
" +
xml["DESC"] +
" [" +
xml["ID"] +
"]
");
updateDropZones();
});
}).catch(function(e) {
console.log('Error', e)
})
}
function searchRes() {
var id = lastSearch;
var link;
link = BASE_URL + "index.php?_route=UrlAction_ProcesEditor&_task=getResAjax&word=" + id + "&filter=" + filtr;
$.get(link, function(data) {
var side = $("#side");
$(side).find("#ulcon").empty();
if (data.length == 0)
$(side).find("#ulcon").append("
Brak wyników wyszukiwania
");
$.each(data, function(i, e) {
var tree = "";
for (var i = 3; i > 0; i--) {
if (e["p" + i + "_ID"] != null) {
var temp = {};
temp["ID"] = e["p" + i + "_ID"];
temp["DESC"] = e["p" + i + "_DESC"];
zasobTree[e["ID"]] = [];
zasobTree[e["ID"]].push(temp);
tree += e["p" + i + "_DESC"] + (i > 1 ? " " : "");
}
}
var type = 0;
if (e["TYPE"] == "DZIAL" || e["TYPE"] == "PODMIOT" || e["TYPE"] == "STANOWISKO")
type = 1;
if (filtr != 2 || e["TYPE"] != "TABELA")
$(side).find("#ulcon").append("
" + tree + "
" + e["DESC"] + " [" + e["ID"] + "]
");
else {
$(side).find("#ulcon").append("
#
" + tree + "
" + e["DESC"] + " [" + e["ID"] + "]
");
}
});
updateDropZones();
});
}
$(document).on('click', '.liProc', function() {
$(this).parents(".singleAdv").nextAll(".singleAdv").remove();
$(this).parents(".singleAdv").find(".active").removeClass("active");
$(this).find(".glyphicon").removeClass("glyphicon-triangle-right");
$(this).find(".glyphicon").addClass("glyphicon-refresh");
$(this).find(".glyphicon").addClass("anim-refresh");
$(this).addClass("active");
var parent = this;
var parent_id = $(this).data("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=PARENT_ID' + parent_id + '';
var result = "";
var depth = $(this).parents(".singleAdv").data("_depth") + 1;
$("#procCon").css("width", depth * 290 + 290);
$(this).parents(".singleAdv").after("");
var childs = true;
p5WFS_GetFeature('p5_default_db:CRM_PROCES', {
'Filter': 'PARENT_ID' + parent_id + '',
'sortBy': 'SORT_PRIO+A,ID',
}).then(function(features) {
$.each(features, function(i, xml) {
if (xml["ID"] == 0) {
childs = false;
return;
}
var type = 0;
result += "
"
$(wind).html(el)
p5VideoPlayer_init($(wind).find(".p5VideoPlayer").find(".img"))
}
function dropVid(ui, target) {
elementVid = ui.draggable
targetVid = target
p5BModalDisplay("Edytor video", videoEditor, {
"ui": ui,
"target": target
})
}
function getDomLocalization(e) {
//console.log("getDomLocalization(e)")
var obj = {}
obj.type = null;
obj.typeName = null;
if ($(e).closest(".drop").length != 0) {
obj.idProces = $(e).closest(".drop").data("id");
obj.type = "CRM_PROCES";
obj.procesObj = state[getIndexById(obj.idProces)];
}
if ($(e).closest(".professions").length) {
obj.id = $(e).closest("li").data("id");
obj.type = "CRM_WSKAZNIK";
obj.typeName = "_prof";
obj.wskObj = obj.procesObj[obj.typeName][getIndexById(obj.id, obj.procesObj[obj.typeName])]
} else if ($(e).closest(".resources").length) {
obj.id = $(e).closest("li").data("id");
obj.type = "CRM_WSKAZNIK";
obj.typeName = "_res";
obj.wskObj = obj.procesObj[obj.typeName][getIndexById(obj.id, obj.procesObj[obj.typeName])]
}
//console.log(obj)
return obj;
}
function dropImg(ui, target) {
var targetInfo = getDomLocalization(target)
var objInfo = getDomLocalization(ui.draggable)
//console.log("dropImg()")
//console.log(targetInfo)
//console.log(objInfo)
var temp = {};
temp["src"] = $(ui.draggable).find("img").attr("src");
temp["title"] = $(ui.draggable).find(".imgTitle").text();
temp["ID"] = $(ui.draggable).data("id");
var id;
if (targetInfo.type == "CRM_PROCES") {
if (!targetInfo.procesObj._IMG) targetInfo.procesObj._IMG = [];
targetInfo.procesObj._IMG.push(temp);
id = targetInfo.idProces;
} else if (targetInfo.type == "CRM_WSKAZNIK") {
if (!targetInfo.wskObj._IMG) targetInfo.wskObj._IMG = [];
targetInfo.wskObj._IMG.push(temp);
id = targetInfo.id;
}
usedImg[temp["ID"]] = {
type: targetInfo.type,
targetID: id,
action: "ATTACH"
};
$(ui.draggable).remove();
updateAll();
}
function addProces(ui, target) {
var id = $(target).data("id");
var gotoOpt = "";
$.each(gotoType, function(key, value) {
gotoOpt += "";
})
swal({
showCancelButton: true,
cancelButtonText: "Anuluj",
title: 'Typ łącza',
html: (
state[getIndexById(id)]["IF_TRUE_GOTO"] != false ?
'Uwaga! Nowe łącze nadpisze już istniejące łącze. ' :
""
) + ' ',
preConfirm: function() {
return new Promise(function(resolve) {
resolve([
$('#swal-input1').val()
]);
});
}
}).then(function(result) {
newRes--;
state[getIndexById(id)]["IF_TRUE_GOTO"] = ui.draggable.data("id");
state[getIndexById(id)]["IF_TRUE_GOTO_FLAG"] = result[0];
updateAll();
}).catch(function(e) {})
}
function addResource(ui, target) {
var permsOpt = "";
$.each(perms, function(key, value) {
permsOpt = permsOpt + "";
})
swal({
showCancelButton: true,
cancelButtonText: "Anuluj",
title: 'Uprawnienia',
html: 'Uprawnienia ' +
'Komentarz ',
preConfirm: function() {
return new Promise(function(resolve) {
resolve([
$('#swal-input1').val(),
$('#swal-input2').val()
]);
});
}
}).then(function(result) {
newRes--;
var temp = {};
temp["ID_ZASOB"] = ui.draggable.data("id");
temp["ID"] = newRes;
temp["ID_PRZYPADEK"] = result[0];
temp["OPIS_ZASOB"] = result[1];
temp["changed"] = true;
temp["OPIS"] = ui.draggable.data("opis");
temp["DESC"] = ui.draggable.data("desc");
temp["_TREE"] = zasobTree[temp["ID_ZASOB"]];
var id = $(target).data("id");
if (ui.draggable.data("type") == 1) {
state[getIndexById(id)]["_prof"].push(temp);
} else {
state[getIndexById(id)]["_res"].push(temp);
}
updateAll();
}).catch(function(e) {})
}
//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() {
$.each(state, function(i, e) {
var pid = getParentNode(e["ID"]);
if (pid != "NONE" && pid != false && pid != e["PARENT_ID"]) {
e["PARENT_ID"] = pid;
} else if (pid === false) {
e["_depth"]--;
updateAll();
return;
}
});
changes = true;
$("#clearBtn").show();
/*
localStorage.setItem("state" + mainProces_id, JSON.stringify(state));
localStorage.setItem("newStep" + mainProces_id, newSteps);
localStorage.setItem("newRes" + mainProces_id, newRes);
localStorage.setItem("deletedId" + mainProces_id, JSON.stringify(deletedId));
localStorage.setItem("deletedRes" + mainProces_id, JSON.stringify(deletedRes));
localStorage.setItem("date" + mainProces_id, moment().format("YYYY-MM-DD HH:mm:ss"));
*/
render(state, $("#main"));
}
//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() {
$.each(state, function(i, e) {
e["_step"] = 0;
if (i == 0)
e["_stepDesc"] = "";
else {
var iParent = getIndexById(e["PARENT_ID"]);
state[iParent]["_step"] += 1;
e["SORT_PRIO"] = state[iParent]["_step"];
e["_stepDesc"] = state[iParent]["_stepDesc"] + state[iParent]["_step"] + ". ";
}
});
}
//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 = getIndexById(id);
var y = x;
var result = false;
while (x > 0) {
x--;
if (check == "right")
if (state[x]["_depth"] == state[y]["_depth"]) {
result = state[x]["ID"];
break;
}
if (check == "left")
if (state[x]["_depth"] == state[y]["_depth"] - 2) {
result = state[x]["ID"];
break;
}
if (check == "right" && state[x]["_depth"] < state[y]["_depth"])
break;
}
return result;
}
//Zwraca id rodzica, jezeli nie ma zwraca false
function getParentNode(id) {
var x = getIndexById(id);
var y = x;
if (x == 0)
return "NONE";
var result = false;
while (x > 0) {
x--;
if (state[x]["_depth"] == state[y]["_depth"] - 1) {
result = state[x]["ID"];
break;
}
if (state[x]["_depth"] - state[y]["_depth"] == -2)
break;
}
return result;
}
function getResById(index, id, type) {
var result = state[index][type].length - 1;
$.each(state[index][type], function(i, e) {
if (e["ID"] == id) {
result = i;
return false;
}
});
return result;
}
function getIndexById(id, arr, label) {
var arr = arr || state
var label = label || "ID"
var result = arr.length - 1;
if (label == "ID")
result = -1;
$.each(arr, function(i, e) {
if (e[label] == id) {
result = i;
return false;
}
});
return result;
}
$(document).on('click', ".remImg", function() {
//console.log(1);
obj = getDomLocalization($(this));
id = $(this).closest(".attImg").data('id');
if (obj.type == "CRM_PROCES") {
var index = getIndexById(id, obj.procesObj._IMG, "ID")
obj.procesObj._IMG.splice(index, 1);
} else if (obj.type == "CRM_WSKAZNIK") {
var index = getIndexById(id, obj.wskObj._IMG, "ID")
obj.wskObj._IMG.splice(index, 1);
}
usedImg[id] = {
type: "",
targetID: -1,
action: "DELETED"
};
updateAll();
return false;
});
$(document).on('click', '.stateOff', function() {
$(this).closest(".mx").prev(".tree").show();
$(this).closest(".mx").remove();
});
$(document).on('click', '.tree', function() {
var type;
if ($(this).closest("ul").hasClass("resources")) {
type = "_res";
} else {
type = "_prof"
}
var id = getIndexById($(this).closest(".drop").data("id"));
var resId = getResById(id, $(this).closest(".liRes").data("id"), type);
$(this).hide();
showTree(state[id][type][resId]["_TREE"], $(this));
});
function showTree(arr, target) {
result = "";
$.each(arr, function(i, x) {
result += "
" + x["DESC"] + "
";
});
$(target).after("
" + result + "
");
}
function render(arr, target) {
//console.log("STATE")
//console.log(arr)
//console.log("USEDIMG")
//console.log(usedImg)
stepsGenerator();
var result = "";
$.each(arr, function(i, e) {
result += "
";
result += "
";
if (i > 0) {
result += "";
//Arrows
if (checkParentNode(e["ID"], "right") !== false)
result += "";
if (checkParentNode(e["ID"], "left") !== false)
result += "";
if (i != 1)
result += "";
if (i != state.length - 1)
result += "";
} else {}
result += "";
result += "";
if (e["OPIS"] == "")
result += "Dodaj opis";
else
result += "Edytuj opis";
result += "
";
if (typeof e["_IMG"] !== "undefined") {
//console.log(e["_IMG"])
$.each(e["_IMG"], function(key, eImg) {
var img = showMediaElement({
"ID": eImg["ID"],
"IMAGE": eImg["src"],
"NAME": eImg["title"],
}, "_IMG", {
classes: "no-draggable"
})
result += img;
})
}
if (typeof e["vid"] !== "undefined") {
//console.log(e["_IMG"])
$.each(e["vid"], function(key, eVid) {
var vid = showMediaElement(eVid, "video", {
"start": eVid["START"],
"end": eVid["END"],
classes: "no-draggable"
})
result += vid;
})
}
result += "
";
var anyProf = false;
$.each(e["_prof"], function(i2, e2) {
if (!anyProf) {
result += "
Stanowiska
";
anyProf = true;
}
result += "
";
result += "
";
if (i2 != 0)
result += "";
if (i2 != e["_prof"].length - 1)
result += "";
result += "";
result += "
";
result += "
" + e2["DESC"] + " " + e2["OPIS"] + " [" + e2["ID_ZASOB"] + "] ";
if (typeof e2["_TREE"] !== "undefined" && e2["_TREE"].length > 0) { //TO DO DOWNLOAD TREE WHEN NOT EXISTS
result += " ";
$.each(e2["_TREE"], function(i, x) {
result += x["DESC"] + (i < e2["_TREE"].length - 1 ? " " : "");
});
}
result += "";
result += "
";
if (typeof e2["_IMG"] !== "undefined") {
//console.log(e["_IMG"])
$.each(e2["_IMG"], function(key, eImg) {
var img = showMediaElement({
"ID": eImg["ID"],
"IMAGE": eImg["src"],
"NAME": eImg["title"]
}, "_IMG", {
classes: "no-draggable"
})
result += img;
})
}
result += "
";
result += "
";
});
if (anyProf) {
result += "
";
}
var anyRes = false;
$.each(e["_res"], function(i2, e2) {
if (!anyRes) {
result += "
Użyte zasoby
";
anyRes = true;
}
result += "
";
result += "
";
if (i2 != 0)
result += "";
if (i2 != e["_res"].length - 1)
result += "";
result += "";
result += "
";
result += "
" + e2["DESC"] + " " + e2["OPIS"] + " [" + e2["ID_ZASOB"] + "] ";
if (typeof e2["_TREE"] !== "undefined" && e2["_TREE"].length > 0) { //TO DO DOWNLOAD TREE WHEN NOT EXISTS
result += " ";
$.each(e2["_TREE"], function(i, x) {
result += x["DESC"] + (i < e2["_TREE"].length - 1 ? " " : "");
});
}
result += "";
result += "
";
if (typeof e2["_IMG"] !== "undefined") {
$.each(e2["_IMG"], function(key, eImg) {
var img = showMediaElement({
"ID": eImg["ID"],
"IMAGE": eImg["src"],
"NAME": eImg["title"]
}, "_IMG", {
classes: "no-draggable"
})
result += img;
})
}
result += "
";
result += "
";
});
if (anyRes) {
result += "
";
}
if (e["IF_TRUE_GOTO"] != false) {
var name;
switch (e["IF_TRUE_GOTO_FLAG"]) {
case "GOTO":
name = "Przejdź do procesu " + e["IF_TRUE_GOTO"] + ".";
break;
case "GOTO_AND_RETURN":
name = "Przejdź do procesu " + e["IF_TRUE_GOTO"] + ", a następnie wróć.";
break;
case "FORK":
name = "— FORK" + e["IF_TRUE_GOTO"];
break;
default:
name = e["IF_TRUE_GOTO"];
}
result += "— " + name + " ";
}
result += " Dodaj nowy krok";
result += "