Commit 16f13b68 by Estók Dániel

setty: code cleanup

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