Commit 16f13b68 by Estók Dániel

setty: code cleanup

parent c500500c
jsPlumb.ready(function() {
jsPlumb.ready(function(){
/**
* Global variables.
*/
......@@ -54,7 +54,7 @@ jsPlumb.ready(function() {
if(status == "saved"){
$("#unsavedDiv").remove();
}
}
};
/**
......@@ -74,9 +74,9 @@ jsPlumb.ready(function() {
+ '<button id="addEndpoint" class="btn btn-success">+</button></div>'
+ '<div class="col-xs-6 text-center">'
+ '<button id="removeEndpoint" class="btn btn-danger">-</button></div></div>';
$("#informationContainer").empty().append(div);
$("#informationContainer").empty().append(div);
$("#infoInput").val(info).keyup(function(){
setServiceStatus("unsaved");
newParams = $("#infoInput").val();
......@@ -92,13 +92,13 @@ jsPlumb.ready(function() {
$("#removeEndpoint").click(function(){
removeEndoint(element);
});
}
};
/**
* Function for updating connection array whether an event was fired.
*/
updateConnections = function(connection, remove) {
updateConnections = function(connection, remove){
setServiceStatus("unsaved");
if (!remove)
elementConnections.push(connection);
......@@ -119,7 +119,7 @@ jsPlumb.ready(function() {
/**
* Function for checking and ignoring duplicate connections.
*/
checkDuplicateConnection = function(connection) {
checkDuplicateConnection = function(connection){
for (var i = 0; i < elementConnections.length; i++) {
if ((elementConnections[i].targetId == connection.targetId && elementConnections[i].sourceId == connection.sourceId) ||
(elementConnections[i].targetId == connection.sourceId && elementConnections[i].sourceId == connection.targetId)) {
......@@ -134,7 +134,7 @@ jsPlumb.ready(function() {
/**
* Function for checking element compatibility.
*/
checkCompatibility = function(sourceId, targetId) {
checkCompatibility = function(sourceId, targetId){
validTargets = $("#" + sourceId).attr("type").split(',');
if (jQuery.inArray(targetId.split('_')[1], validTargets) == -1) {
......@@ -148,7 +148,7 @@ jsPlumb.ready(function() {
/**
* Function for checking source and target equality.
*/
checkSourceTargetEquality = function(connection) {
checkSourceTargetEquality = function(connection){
if (connection.targetId == connection.sourceId) {
addMessage("Source element is the same as target element.", "danger");
return false;
......@@ -160,7 +160,7 @@ jsPlumb.ready(function() {
/**
* Function for determining anchor positions for an element.
*/
getAnchorCoordinate = function(rate) {
getAnchorCoordinate = function(rate){
x = Math.cos(2.0 * Math.PI * rate) / 2;
y = Math.sin(2.0 * Math.PI * rate) / 2;
dx = 0;
......@@ -190,53 +190,53 @@ jsPlumb.ready(function() {
return [y + 0.5, -x + 0.5, dy, -dx];
};
/**
* Check whether an anchor is connected.
*/
isConnected = function(anchorId){
returnValue = false;
$.each(elementConnections, function(index) {
if(elementConnections[index].endpoints[0].getUuid()==anchorId ||
elementConnections[index].endpoints[1].getUuid()==anchorId){
returnValue = true;
return;
}
});
return returnValue;
}
/**
* Get connection parameters and other connected anchor concerning an anchor coming from parameters.
*/
getConnectionparamAndAnchor = function(anchorId){
parameters = "";
otherAnchor = "";
$.each(elementConnections, function(index) {
if(elementConnections[index].endpoints[0].getUuid()==anchorId)
{
parameters = elementConnections[index];
otherAnchor = elementConnections[index].endpoints[1].getUuid();
return;
}
if(elementConnections[index].endpoints[1].getUuid()==anchorId)
{
parameters = elementConnections[index].parameters;
otherAnchor = elementConnections[index].endpoints[0].getUuid();
return;
}
});
return [parameters, otherAnchor];
}
/**
* Check whether an anchor is connected.
*/
isConnected = function(anchorId){
returnValue = false;
$.each(elementConnections, function(index) {
if(elementConnections[index].endpoints[0].getUuid()==anchorId ||
elementConnections[index].endpoints[1].getUuid()==anchorId){
returnValue = true;
return;
}
});
return returnValue;
};
/**
* Get connection parameters and other connected anchor concerning an anchor coming from parameters.
*/
getConnectionparamAndAnchor = function(anchorId){
parameters = "";
otherAnchor = "";
$.each(elementConnections, function(index) {
if(elementConnections[index].endpoints[0].getUuid()==anchorId)
{
parameters = elementConnections[index];
otherAnchor = elementConnections[index].endpoints[1].getUuid();
return;
}
if(elementConnections[index].endpoints[1].getUuid()==anchorId)
{
parameters = elementConnections[index].parameters;
otherAnchor = elementConnections[index].endpoints[0].getUuid();
return;
}
});
return [parameters, otherAnchor];
};
/**
* Function to add new element to service.
*/
addEndpoint = function(element) {
anchors = element.attr("anchors");
addEndpoint = function(element){
anchors = element.attr("anchors");
if(anchors==8) return;
......@@ -250,59 +250,59 @@ jsPlumb.ready(function() {
for (i = 0; i < anchors; i++) jsPlumbInstance.getEndpoint(i + "_" + element.attr("id")).setAnchor(getAnchorCoordinate(i / (anchors)));
element.attr("anchors", anchors);
element.attr("anchors", anchors);
jsPlumbInstance.repaintEverything();
}
};
/**
* Function for removing an endpoint of an element.
/**
* Function for removing an endpoint of an element.
*/
removeEndoint = function(element){
anchors = element.attr("anchors");
if(anchors==4) return;
i = anchors-1;
anchors--;
while(isConnected(i + "_" + element.attr("id")) && i>=0){
i--;
}
if(i==-1){
addMessage("All the anchors are connected so that removing any is forbidden.", "danger");
return;
}
else if(i==anchors){
jsPlumbInstance.deleteEndpoint(jsPlumbInstance.getEndpoint(anchors + "_" + element.attr("id")));
}
else{
newId = i + "_" + element.attr("id");
oldId = anchors + "_" + element.attr("id");
data = getConnectionparamAndAnchor(oldId);
jsPlumbInstance.deleteEndpoint(jsPlumbInstance.getEndpoint(oldId));
connectionObject = jsPlumbInstance.connect({
uuids: [newId, data[1]]
});
connectionObject.parameters = data[0];
}
for (i=0;i<anchors;i++) jsPlumbInstance.getEndpoint(i + "_" + element.attr("id")).setAnchor(getAnchorCoordinate(i / (anchors)));
element.attr("anchors", anchors);
removeEndoint = function(element){
anchors = element.attr("anchors");
if(anchors==4) return;
i = anchors-1;
anchors--;
while(isConnected(i + "_" + element.attr("id")) && i>=0){
i--;
}
if(i==-1){
addMessage("All the anchors are connected so that removing any is forbidden.", "danger");
return;
}
else if(i==anchors){
jsPlumbInstance.deleteEndpoint(jsPlumbInstance.getEndpoint(anchors + "_" + element.attr("id")));
}
else{
newId = i + "_" + element.attr("id");
oldId = anchors + "_" + element.attr("id");
data = getConnectionparamAndAnchor(oldId);
jsPlumbInstance.deleteEndpoint(jsPlumbInstance.getEndpoint(oldId));
connectionObject = jsPlumbInstance.connect({
uuids: [newId, data[1]]
});
connectionObject.parameters = data[0];
}
for (i=0;i<anchors;i++) jsPlumbInstance.getEndpoint(i + "_" + element.attr("id")).setAnchor(getAnchorCoordinate(i / (anchors)));
element.attr("anchors", anchors);
jsPlumbInstance.repaintEverything();
}
};
/**
* Function for managing instantiation of new elements based on their templates.
*/
addElement = function(templateId, newId, newPositionY, endpoints, parameters, newPositionX) {
addElement = function(templateId, newId, newPositionY, endpoints, parameters, newPositionX){
newInstance = $('#' + templateId)
.clone()
.prop("id", newId)
......@@ -324,8 +324,8 @@ jsPlumb.ready(function() {
containment: $("#dropContainer")
});
newInstance.mousedown(function(e) {
if(e.button == 0){
newInstance.mousedown(function(e){
if(e.button === 0){
element = $(this);
addInfo(element.attr("alt"), element.attr("parameters"), "element", element);
return false;
......@@ -339,8 +339,8 @@ jsPlumb.ready(function() {
return true;
});
setServiceStatus("unsaved");
setServiceStatus("unsaved");
jsPlumbInstance.repaintEverything();
};
......@@ -348,26 +348,26 @@ jsPlumb.ready(function() {
/**
* Handling events on workspace.
*/
jsPlumbInstance.bind("connection", function(info) {
jsPlumbInstance.bind("connection", function(info){
updateConnections(info.connection);
info.connection.parameters = "";
});
jsPlumbInstance.bind("beforeDrop", function(info) {
jsPlumbInstance.bind("beforeDrop", function(info){
return checkDuplicateConnection(info.connection) &&
checkSourceTargetEquality(info.connection) &&
checkCompatibility(info.connection.sourceId, info.connection.targetId);
});
jsPlumbInstance.bind("connectionDetached", function(info) {
jsPlumbInstance.bind("connectionDetached", function(info){
updateConnections(info.connection, true);
});
jsPlumbInstance.bind("connectionMoved", function(info) {
jsPlumbInstance.bind("connectionMoved", function(info){
updateConnections(info.connection, true);
});
jsPlumbInstance.bind("contextmenu", function(info) {
jsPlumbInstance.bind("contextmenu", function(info){
jsPlumbInstance.detach(info);
$("#informationContainer").empty();
});
jsPlumbInstance.bind("click", function(info) {
jsPlumbInstance.bind("click", function(info){
addInfo($("#"+info.sourceId.split('_')[1]).attr("alt") + ' - '
+ $("#"+info.targetId.split('_')[1]).attr("alt"),
info.parameters,
......@@ -382,7 +382,7 @@ jsPlumb.ready(function() {
/**
* Handling click event on elements.
*/
$(".elementTemplate").click(function() {
$(".elementTemplate").click(function(){
addElement($(this).prop("id"),
(++elementIndex) + "_" + $(this).prop("id"),
$(this).position().top,
......@@ -402,13 +402,13 @@ jsPlumb.ready(function() {
/**
* Handling click event on clear button.
*/
$("#clearService").click(function(e) {
$("#clearService").click(function(e){
jsPlumbInstance.detachEveryConnection()
.deleteEveryEndpoint();
$(".element").remove();
setServiceStatus("unsaved");
jsPlumbInstance.repaintEverything();
setServiceStatus("unsaved");
jsPlumbInstance.repaintEverything();
elementIndex = 0;
});
......@@ -424,12 +424,12 @@ jsPlumb.ready(function() {
/**
* Handling click event on save button.
*/
$("#saveService").click(function() {
$("#saveService").click(function(){
serviceName = $("#serviceName").text();
connectionSet = [];
instanceSet = [];
$.each(elementConnections, function(index) {
$.each(elementConnections, function(index){
connectionSet.push({
"sourceId": elementConnections[index].sourceId,
"sourceEndpoint": elementConnections[index].endpoints[0].getUuid(),
......@@ -439,7 +439,7 @@ jsPlumb.ready(function() {
});
});
$.each($(".element"), function(index) {
$.each($(".element"), function(index){
instanceSet.push({
"displayId": $(this).prop("id"),
"posX": Math.floor($(this).position().left),
......@@ -470,8 +470,8 @@ jsPlumb.ready(function() {
/**
* Handling window resize event for preventing elements against overflow.
*/
$(window).resize(function() {
$(".element").each(function() {
$(window).resize(function(){
$(".element").each(function(){
if ($(this).position().left + $(this).width() > $("#dropContainer").position().left + $("#dropContainer").width()) {
$(this).css("left", $("#dropContainer").position().left + $("#dropContainer").width() - $(this).width() + 4);
}
......@@ -483,12 +483,12 @@ jsPlumb.ready(function() {
/**
* Handling click events on scroll buttons.
*/
$("#dragContainerScrollUp").click(function() {
$("#dragContainerScrollUp").click(function(){
if (dragContainerScroll > 0) dragContainerScroll -= 1;
$("#dragContainer").scrollTop(dragContainerScroll * $("#elementTemplatePanel").height());
});
$("#dragContainerScrollDown").click(function() {
$("#dragContainerScrollDown").click(function(){
if (dragContainerScroll < $(".elementTemplate").length - 3) dragContainerScroll += 1;
$("#dragContainer").scrollTop(dragContainerScroll * $("#elementTemplatePanel").height());
});
......@@ -497,8 +497,8 @@ jsPlumb.ready(function() {
/**
* Handling search feature.
*/
$("#searchElementTemplate").keyup(function() {
$(".elementTemplate").each(function() {
$("#searchElementTemplate").keyup(function(){
$(".elementTemplate").each(function(){
$(this).parent().parent().hide();
if ($(this).attr("alt").toLowerCase()
.indexOf($("#searchElementTemplateInput")
......@@ -512,11 +512,11 @@ jsPlumb.ready(function() {
/**
* Handling page load event.
*/
$(document).ready(function() {
$(document).ready(function(){
$.post("", {
event: "loadService"
}, function(resultValue) {
if(resultValue=="") return;
}, function(resultValue) {
if(resultValue === "") return;
result = jQuery.parseJSON(resultValue);
$("#serviceName").text(result.serviceName);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment