metamaps--metamaps/app/assets/javascripts/Jit/select-edit-delete-nodes-and-edges.js

231 lines
6 KiB
JavaScript
Raw Normal View History

function editEdge(edge, e) {
if (authorizeToEdit(edge)) {
//reset so we don't interfere with other edges
$('#edit_synapse').remove();
deselectEdge(edge); //so the label is missing while editing
var perm = document.createElement('div');
perm.className = 'permission canEdit';
var edit_div = document.createElement('div');
edit_div.setAttribute('id', 'edit_synapse');
perm.appendChild(edit_div);
$('.main .wrapper').append(perm);
$('#edit_synapse').attr('class', 'best_in_place best_in_place_desc');
$('#edit_synapse').attr('data-object', 'synapse');
$('#edit_synapse').attr('data-attribute', 'desc');
$('#edit_synapse').attr('data-type', 'input');
//TODO how to get blank data-nil
$('#edit_synapse').attr('data-nil', ' ');
$('#edit_synapse').attr('data-url', '/synapses/' + edge.getData("id"));
$('#edit_synapse').html(edge.getData("desc"));
$('#edit_synapse').css('position', 'absolute');
$('#edit_synapse').css('left', e.clientX);
$('#edit_synapse').css('top', e.clientY);
$('#edit_synapse').bind("ajax:success", function() {
var desc = $(this).html();
edge.setData("desc", desc);
selectEdge(edge);
Mconsole.plot();
$('#edit_synapse').remove();
});
$('#edit_synapse').focusout(function() {
//in case they cancel
$('#edit_synapse').hide();
});
//css stuff above moves it, this activates it
$('#edit_synapse').click();
$('#edit_synapse form').submit(function() {
//hide it once form submits.
//If you don't do this, and data is unchanged, it'll show up on canvas
$('#edit_synapse').hide();
});
$('#edit_synapse input').focus();
$('#edit_synapse').show();
}
else if ((! authorizeToEdit(edge)) && userid) {
alert("You don't have the permissions to edit this synapse.");
}
}
function deselectAllEdges() {
for (var i = 0; i < MetamapsModel.selectedEdges.length; i += 1) {
var edge = MetamapsModel.selectedEdges[i];
deselectEdge(edge);
}
}
// this is for hiding one topic from your canvas
function removeEdge(edge) {
var id = edge.getData("id");
$.ajax({
type: "DELETE",
url: "/synapses/" + id,
success: function(){
hideEdge(edge);
},
});
}
function hideEdge(edge) {
var from = edge.nodeFrom.id;
var to = edge.nodeTo.id;
edge.setData('alpha', 0, 'end');
Mconsole.fx.animate({
modes: ['edge-property:alpha'],
duration: 1000
});
Mconsole.graph.removeAdjacence(from, to);
Mconsole.plot();
}
function hideSelectedEdges() {
for (var i = 0; i < MetamapsModel.selectedEdges.length; i += 1) {
var edge = MetamapsModel.selectedEdges[i];
hideEdge(edge);
}
MetamapsModel.selectedEdges = new Array();
}
function removeSelectedEdges() {
for (var i = 0; i < MetamapsModel.selectedEdges.length; i += 1) {
if (mapid != null) {
var edge = MetamapsModel.selectedEdges[i];
var id = edge.getData("id");
//delete mapping of id mapid
$.ajax({
type: "POST",
url: "/synapses/" + mapid + "/" + id + "/removefrommap",
});
}
hideEdge(edge);
}
MetamapsModel.selectedEdges = new Array();
}
function deleteSelectedEdges() {
for (var i = 0; i < MetamapsModel.selectedEdges.length; i += 1) {
var edge = MetamapsModel.selectedEdges[i];
var id = edge.getData("id");
$.ajax({
type: "DELETE",
url: "/synapses/" + id,
});
hideEdge(edge);
}
MetamapsModel.selectedEdges = new Array();
}
function selectEdge(edge) {
var showDesc = edge.getData("showDesc");
if (! showDesc) {
edge.setData('showDesc', true, 'current');
edge.setDataset('end', {
lineWidth: 4,
2013-01-24 04:40:06 +00:00
color: '#FFFFFF',
alpha: 1
});
Mconsole.fx.animate({
2013-01-24 04:40:06 +00:00
modes: ['edge-property:lineWidth:color:alpha'],
duration: 100
});
}
MetamapsModel.selectedEdges.push(edge);
}
function deselectEdge(edge) {
var showDesc = edge.getData("showDesc");
if (showDesc) {
edge.setData('showDesc', false, 'current');
edge.setDataset('end', {
lineWidth: 2,
2013-01-24 04:40:06 +00:00
color: '#222222',
alpha: 0.4
});
if (MetamapsModel.edgeHoveringOver == edge) {
edge.setDataset('end', {
lineWidth: 4,
2013-01-24 04:40:06 +00:00
color: '#222222',
alpha: 1
});
}
Mconsole.fx.animate({
2013-01-24 04:40:06 +00:00
modes: ['edge-property:lineWidth:color:alpha'],
duration: 100
});
}
//remove the edge
MetamapsModel.selectedEdges.splice(
MetamapsModel.selectedEdges.indexOf(edge), 1);
}
2013-01-25 05:47:32 +00:00
// this is for hiding one topic from your canvas
function hideNode(nodeid) {
var node = Mconsole.graph.getNode(nodeid);
if (nodeid == Mconsole.root && gType == "centered") {
alert("You can't hide this topic, it is the root of your graph.");
return;
}
node.setData('alpha', 0, 'end');
node.eachAdjacency(function(adj) {
adj.setData('alpha', 0, 'end');
});
Mconsole.fx.animate({
modes: ['node-property:alpha',
'edge-property:alpha'],
duration: 1000
});
Mconsole.graph.removeNode(nodeid);
Mconsole.labels.disposeLabel(nodeid);
}
function hideSelectedNodes() {
Mconsole.graph.eachNode( function (n) {
2013-01-25 05:47:32 +00:00
if (n.data.$onCanvas == true) {
hideNode(n.id);
}
});
}
2013-01-25 05:47:32 +00:00
function removeNode(nodeid) {
if (mapperm) {
$.ajax({
type: "POST",
url: "/topics/" + mapid + "/" + nodeid + "/removefrommap",
});
}
}
function removeSelectedNodes() {
2013-01-25 05:47:32 +00:00
if (mapperm) {
Mconsole.graph.eachNode( function (n) {
if (n.data.$onCanvas == true) {
removeNode(n.id);
}
2013-01-25 05:47:32 +00:00
});
}
}
2013-01-25 05:47:32 +00:00
function deleteNode(nodeid) {
if (nodeid == Mconsole.root && gType == "centered") {
alert("You can't delete this topic, it is the root of your graph.");
return;
}
$.ajax({
type: "DELETE",
url: "/topics/" + nodeid,
});
}
function deleteSelectedNodes() {
Mconsole.graph.eachNode( function (n) {
2013-01-25 05:47:32 +00:00
if (n.data.$onCanvas == true) {
deleteNode(n.id);
}
});
}