2013-01-11 03:01:24 +00:00
|
|
|
/*
|
|
|
|
* @file
|
|
|
|
* There is a lot of code that goes into creating the "label" of a node
|
|
|
|
* This includes editable cards with all node details, and some controls
|
|
|
|
* onCreateLabelHandler is the main function of this file, and the file
|
|
|
|
* also contains a bunch of helper functions
|
|
|
|
*
|
|
|
|
* html and littleHTML are potentially confusing variables
|
|
|
|
* html is the contents of the card shown when you click on a node's label.
|
|
|
|
* littleHTML creates little controls for removing/hiding nodes from the canvas
|
|
|
|
*
|
|
|
|
* This function features PHP-style variable substitution because the strings
|
|
|
|
* are so damn long. Values are identified by $_id_$, and then a regular
|
|
|
|
* expression is substituted in later (for html, in a separate function).
|
|
|
|
*/
|
|
|
|
|
|
|
|
function onCreateLabelHandler(domElement, node) {
|
|
|
|
var html = generateShowcardHTML();
|
|
|
|
html = replaceVariables(html, node);
|
|
|
|
|
|
|
|
var showCard = document.createElement('div');
|
|
|
|
showCard.className = 'showcard topic_' + node.id;
|
2013-01-23 18:43:01 +00:00
|
|
|
if (authorizeToEdit(node)) {
|
|
|
|
var perm = document.createElement('div');
|
|
|
|
perm.className = 'permission canEdit';
|
|
|
|
perm.innerHTML = html;
|
|
|
|
showCard.appendChild(perm);
|
|
|
|
} else {
|
|
|
|
showCard.innerHTML = html;
|
|
|
|
}
|
|
|
|
showCard.style.display = "none";
|
2013-01-11 03:01:24 +00:00
|
|
|
domElement.appendChild(showCard);
|
|
|
|
|
|
|
|
// Create a 'name' button and add it to the main node label
|
|
|
|
var nameContainer = document.createElement('span'),
|
|
|
|
style = nameContainer.style;
|
|
|
|
nameContainer.className = 'name topic_' + node.id;
|
|
|
|
nameContainer.id = 'topic_' + node.id + '_label';
|
|
|
|
|
|
|
|
nameContainer.innerHTML = generateLittleHTML (node);
|
|
|
|
domElement.appendChild(nameContainer);
|
|
|
|
style.fontSize = "0.9em";
|
|
|
|
style.color = "#222222";
|
|
|
|
|
|
|
|
bindCallbacks(showCard, nameContainer, node);
|
|
|
|
}
|
|
|
|
|
|
|
|
function generateShowcardHTML() {
|
|
|
|
return ' \
|
|
|
|
<div class="CardOnGraph" \
|
|
|
|
id="topic_$_id_$"> \
|
|
|
|
<p class="type best_in_place best_in_place_metacode" \
|
|
|
|
data-url="/topics/$_id_$" \
|
|
|
|
data-object="topic" \
|
|
|
|
data-collection=$_metacode_choices_$ \
|
|
|
|
data-attribute="metacode" \
|
|
|
|
data-type="select">$_metacode_$</p> \
|
|
|
|
<img alt="$_metacode_$" \
|
|
|
|
class="icon" \
|
|
|
|
title="Click to hide card" \
|
|
|
|
height="50" \
|
|
|
|
width="50" \
|
|
|
|
src="$_imgsrc_$" /> \
|
2013-01-24 03:05:24 +00:00
|
|
|
<div class="cardSettings"> \
|
|
|
|
<div class="mapPerm" \
|
|
|
|
title="$_permission_$"> \
|
|
|
|
$_mk_permission_$ \
|
|
|
|
</div> \
|
|
|
|
$_edit_permission_$ \
|
|
|
|
</div> \
|
2013-01-11 03:01:24 +00:00
|
|
|
<span class="title"> \
|
|
|
|
<span class="best_in_place best_in_place_name" \
|
|
|
|
data-url="/topics/$_id_$" \
|
|
|
|
data-object="topic" \
|
|
|
|
data-attribute="name" \
|
|
|
|
data-type="input">$_name_$</span> \
|
|
|
|
<a href="/topics/$_id_$" class="topic-go-arrow" target="_blank"> \
|
|
|
|
<img class="topic-go-arrow" \
|
|
|
|
title="Explore Topic" \
|
|
|
|
src="/assets/go-arrow.png" /> \
|
|
|
|
</a> \
|
|
|
|
<div class="clearfloat"></div> \
|
|
|
|
</span> \
|
|
|
|
<div class="contributor"> \
|
|
|
|
Added by: <a href="/users/$_userid_$" target="_blank">$_username_$ \
|
|
|
|
</a> \
|
|
|
|
</div> \
|
|
|
|
<div class="scroll"> \
|
|
|
|
<div class="desc"> \
|
|
|
|
<span class="best_in_place best_in_place_desc" \
|
|
|
|
data-url="/topics/$_id_$" \
|
|
|
|
data-object="topic" \
|
|
|
|
data-nil="$_desc_nil_$" \
|
|
|
|
data-attribute="desc" \
|
|
|
|
data-type="textarea">$_desc_$</span> \
|
|
|
|
<div class="clearfloat"></div> \
|
|
|
|
</div> \
|
|
|
|
</div> \
|
|
|
|
<div class="link"> \
|
|
|
|
$_go_link_$ \
|
|
|
|
$_a_tag_$<span class="best_in_place best_in_place_link" \
|
|
|
|
data-url="/topics/$_id_$" \
|
|
|
|
data-object="topic" \
|
2013-02-22 01:32:43 +00:00
|
|
|
data-nil="$_link_nil_$" \
|
2013-01-11 03:01:24 +00:00
|
|
|
data-attribute="link" \
|
|
|
|
data-type="input">$_link_$</span>$_close_a_tag_$ \
|
|
|
|
</div> \
|
|
|
|
<div class="clearfloat"></div> \
|
|
|
|
</div>';
|
|
|
|
}//generateShowcardHTML
|
|
|
|
|
|
|
|
function replaceVariables(html, node) {
|
|
|
|
//link is rendered differently if user is logged out or in
|
|
|
|
var go_link, a_tag, close_a_tag;
|
2013-01-24 03:05:24 +00:00
|
|
|
if (! authorizeToEdit(node)) {
|
2013-01-11 03:01:24 +00:00
|
|
|
go_link = '';
|
|
|
|
if (node.getData("link") != "") {
|
|
|
|
a_tag = '<a href="' + node.getData("link") + '">';
|
|
|
|
close_a_tag = '</a>';
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
a_tag = '';
|
|
|
|
close_a_tag = '';
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
go_link = '<a href="' + node.getData("link") + '" ' +
|
|
|
|
' class="go-link" target="_blank">[go]</a>';
|
|
|
|
a_tag = '';
|
|
|
|
close_a_tag = '';
|
|
|
|
}
|
|
|
|
|
|
|
|
//create metacode_choices array from imgArray
|
|
|
|
var metacodes = new Array();
|
|
|
|
for (var key in imgArray) {
|
|
|
|
if (imgArray.hasOwnProperty(key)) {
|
|
|
|
if (key != node.getData("metacode")) {
|
|
|
|
metacodes.push(key);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//Arrange it how we want it
|
|
|
|
metacodes.sort();
|
|
|
|
metacodes.unshift(node.getData("metacode"));
|
|
|
|
|
|
|
|
var metacode_choices = "'[";
|
|
|
|
for (var i in metacodes) {
|
|
|
|
metacode_choices += '["' + metacodes[i] + '","' + metacodes[i] + '"],';
|
|
|
|
}
|
|
|
|
//remove trailing comma and add ]
|
|
|
|
metacode_choices = metacode_choices.slice(0, -1);
|
|
|
|
metacode_choices += "]'";
|
|
|
|
|
|
|
|
var desc_nil = "<span class='gray'>Click to add description.</span>";
|
|
|
|
var link_nil = "<span class='gray'>Click to add link.</span>";
|
2013-01-24 03:05:24 +00:00
|
|
|
|
|
|
|
var edit_perm = '';
|
|
|
|
if (userid == node.getData("userid")) {
|
|
|
|
edit_perm = ' \
|
|
|
|
<div class="permActivator"> \
|
|
|
|
<div class="editSettings"> \
|
|
|
|
<span>Permissions: </span> \
|
|
|
|
<span title="Click to Edit"> \
|
|
|
|
<span class="best_in_place best_in_place_permission" \
|
|
|
|
id="best_in_place_topic_$_id_$_permission" \
|
|
|
|
data-url="/topics/$_id_$" \
|
|
|
|
data-object="topic" \
|
|
|
|
data-collection=$_permission_choices_$ \
|
|
|
|
data-attribute="permission" \
|
|
|
|
data-type="select" \
|
|
|
|
data-value="$_permission_$"> \
|
|
|
|
$_permission_$ \
|
|
|
|
</span> \
|
|
|
|
</span> \
|
|
|
|
<div class="clearfloat"></div> \
|
|
|
|
</div> \
|
|
|
|
</div>';
|
|
|
|
}
|
|
|
|
var permissions = ['commons','public','private'];
|
|
|
|
var permission_choices = "'[";
|
|
|
|
for (var i in permissions) {
|
|
|
|
permission_choices += '["' + permissions[i] + '","' + permissions[i] + '"],';
|
|
|
|
}
|
|
|
|
//remove trailing comma and add ]
|
|
|
|
permission_choices = permission_choices.slice(0, -1);
|
|
|
|
permission_choices += "]'";
|
|
|
|
edit_perm = edit_perm.replace(/\$_permission_choices_\$/g, permission_choices);
|
|
|
|
|
|
|
|
html = html.replace(/\$_edit_permission_\$/g, edit_perm);
|
|
|
|
html = html.replace(/\$_permission_\$/g, node.getData("permission"));
|
|
|
|
html = html.replace(/\$_mk_permission_\$/g, mk_permission(node));
|
2013-01-11 03:01:24 +00:00
|
|
|
html = html.replace(/\$_id_\$/g, node.id);
|
|
|
|
html = html.replace(/\$_metacode_\$/g, node.getData("metacode"));
|
|
|
|
html = html.replace(/\$_imgsrc_\$/g, imgArray[node.getData("metacode")].src);
|
|
|
|
html = html.replace(/\$_name_\$/g, node.name);
|
|
|
|
html = html.replace(/\$_userid_\$/g, node.getData("userid"));
|
|
|
|
html = html.replace(/\$_username_\$/g, node.getData("username"));
|
|
|
|
html = html.replace(/\$_metacode_choices_\$/g, metacode_choices);
|
|
|
|
html = html.replace(/\$_go_link_\$/g, go_link);
|
|
|
|
html = html.replace(/\$_a_tag_\$/g, a_tag);
|
|
|
|
html = html.replace(/\$_close_a_tag_\$/g, close_a_tag);
|
2013-02-22 01:32:43 +00:00
|
|
|
|
|
|
|
html = html.replace(/\$_link_nil_\$/g, link_nil);
|
2013-01-24 03:05:24 +00:00
|
|
|
if (node.getData("link") == "" && authorizeToEdit(node)) {
|
2013-01-11 03:01:24 +00:00
|
|
|
html = html.replace(/\$_link_\$/g, link_nil);
|
|
|
|
} else {
|
|
|
|
html = html.replace(/\$_link_\$/g, node.getData("link"));
|
|
|
|
}
|
|
|
|
|
|
|
|
html = html.replace(/\$_desc_nil_\$/g, desc_nil);
|
2013-01-24 03:05:24 +00:00
|
|
|
if (node.getData("desc") == "" && authorizeToEdit(node)) {
|
2013-01-11 03:01:24 +00:00
|
|
|
//logged in but desc isn't there so it's invisible
|
|
|
|
html = html.replace(/\$_desc_\$/g, desc_nil);
|
|
|
|
} else {
|
|
|
|
html = html.replace(/\$_desc_\$/g, node.getData("desc"));
|
|
|
|
}
|
|
|
|
return html;
|
|
|
|
}
|
|
|
|
|
|
|
|
function generateLittleHTML(node) {
|
|
|
|
var littleHTML = ' \
|
|
|
|
<div class="label">$_name_$</div> \
|
|
|
|
<div class="nodeOptions">';
|
|
|
|
|
2013-01-25 05:47:32 +00:00
|
|
|
if (userid == null || mapid == null || !mapperm) {
|
2013-01-11 03:01:24 +00:00
|
|
|
//unauthenticated, not on a map: can remove from canvas
|
|
|
|
littleHTML += ' \
|
|
|
|
<span class="removeFromCanvas" \
|
2013-01-25 05:47:32 +00:00
|
|
|
onclick="hideNode($_id_$)" \
|
2013-01-11 03:01:24 +00:00
|
|
|
title="Click to remove topic from canvas"> \
|
|
|
|
</span>';
|
2013-01-25 05:47:32 +00:00
|
|
|
} else if (mapperm) {
|
|
|
|
//permission to remove nodes from the map
|
2013-01-11 03:01:24 +00:00
|
|
|
littleHTML += ' \
|
|
|
|
<span class="removeFromCanvas" \
|
2013-01-25 05:47:32 +00:00
|
|
|
onclick="hideNode($_id_$)" \
|
2013-01-11 03:01:24 +00:00
|
|
|
title="Click to remove topic from canvas"> \
|
|
|
|
</span> \
|
2013-01-25 05:47:32 +00:00
|
|
|
<span class="removeFromMap" \
|
|
|
|
onclick="removeNode($_id_$)" \
|
|
|
|
title="Click to remove topic from map"> \
|
|
|
|
</span>';
|
2013-01-11 03:01:24 +00:00
|
|
|
}
|
|
|
|
|
2013-01-25 05:47:32 +00:00
|
|
|
if (userid == node.getData('userid')) {
|
|
|
|
//logged in, and owner of the topic, thus permission to delete
|
|
|
|
littleHTML += ' \
|
|
|
|
<span class="deleteTopic" \
|
2013-01-26 01:49:40 +00:00
|
|
|
onclick="var t = confirm(\'Are you sure you want to permanently delete this node and all synapses linking to it?\'); if (t) deleteNode($_id_$)" \
|
2013-01-25 05:47:32 +00:00
|
|
|
title="Click to delete this topic"> \
|
|
|
|
</span>';
|
2013-01-11 03:01:24 +00:00
|
|
|
}
|
|
|
|
littleHTML += '</div>';
|
|
|
|
littleHTML = littleHTML.replace(/\$_id_\$/g, node.id);
|
|
|
|
littleHTML = littleHTML.replace(/\$_mapid_\$/g, mapid);
|
|
|
|
littleHTML = littleHTML.replace(/\$_name_\$/g, node.name);
|
2013-01-11 03:19:44 +00:00
|
|
|
|
|
|
|
return littleHTML;
|
2013-01-11 03:01:24 +00:00
|
|
|
}
|
|
|
|
|
2013-02-15 03:23:14 +00:00
|
|
|
function hideCurrentCard() {
|
|
|
|
if (MetamapsModel.showcardInUse) {
|
|
|
|
var node = Mconsole.graph.getNode(MetamapsModel.showcardInUse);
|
|
|
|
hideCard(node);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-11 03:19:44 +00:00
|
|
|
function hideCard(node) {
|
2013-01-11 03:01:24 +00:00
|
|
|
var card = '.showcard';
|
|
|
|
if (node != null) {
|
2013-01-11 03:19:44 +00:00
|
|
|
card += '.topic_' + node.id;
|
2013-01-11 03:01:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$(card).fadeOut('fast', function(){
|
|
|
|
node.setData('dim', 25, 'current');
|
2013-02-15 03:23:14 +00:00
|
|
|
$('.name.topic_' + node.id).show();
|
2013-01-11 03:01:24 +00:00
|
|
|
Mconsole.plot();
|
|
|
|
});
|
2013-02-15 03:23:14 +00:00
|
|
|
|
|
|
|
MetamapsModel.showcardInUse = null;
|
2013-01-11 03:01:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function bindCallbacks(showCard, nameContainer, node) {
|
|
|
|
// add some events to the label
|
|
|
|
$(showCard).find('img.icon').click(function(){
|
2013-01-11 03:19:44 +00:00
|
|
|
hideCard(node);
|
2013-01-11 03:01:24 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
$(showCard).find('.scroll').mCustomScrollbar();
|
|
|
|
|
|
|
|
// add some events to the label
|
|
|
|
$(nameContainer).find('.label').click(function(e){
|
|
|
|
$('.name').css('display','block');
|
|
|
|
$('.name.topic_' + node.id).css('display','none');
|
|
|
|
$('.showcard.topic_' + node.id).fadeIn('fast');
|
2013-02-04 00:13:21 +00:00
|
|
|
$('.showcard.topic_' + node.id).find('.scroll').mCustomScrollbar("update");
|
2013-01-11 03:01:24 +00:00
|
|
|
node.setData('dim', 1, 'current');
|
2013-02-15 03:23:14 +00:00
|
|
|
|
|
|
|
hideCurrentCard();
|
|
|
|
MetamapsModel.showcardInUse = node.id;
|
2013-01-25 05:47:32 +00:00
|
|
|
Mconsole.plot();
|
2013-01-11 03:01:24 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
nameContainer.onmouseover = function(){
|
|
|
|
$('.name.topic_' + node.id + ' .nodeOptions').css('display','block');
|
|
|
|
}
|
|
|
|
|
|
|
|
nameContainer.onmouseout = function(){
|
|
|
|
$('.name.topic_' + node.id + ' .nodeOptions').css('display','none');
|
|
|
|
}
|
|
|
|
|
|
|
|
//bind best_in_place ajax callbacks
|
|
|
|
$(showCard).find('.best_in_place_metacode').bind("ajax:success", function() {
|
|
|
|
var metacode = $(this).html();
|
|
|
|
//changing img alt, img src for top card (topic view page)
|
|
|
|
//and on-canvas card. Also changing image of node
|
|
|
|
$(showCard).find('img.icon').attr('alt', metacode);
|
|
|
|
$(showCard).find('img.icon').attr('src', imgArray[metacode].src);
|
|
|
|
node.setData("metacode", metacode);
|
|
|
|
Mconsole.plot();
|
|
|
|
});
|
|
|
|
|
|
|
|
$(showCard).find('.best_in_place_name').bind("ajax:success", function() {
|
|
|
|
var name = $(this).html();
|
|
|
|
$(nameContainer).find('.label').html(name);
|
|
|
|
});
|
|
|
|
|
2013-02-04 00:13:21 +00:00
|
|
|
$(showCard).find('.best_in_place_desc').bind("ajax:success", function() {
|
|
|
|
$(showCard).find('.scroll').mCustomScrollbar("update");
|
|
|
|
});
|
2013-01-11 03:01:24 +00:00
|
|
|
|
|
|
|
$(showCard).find('.best_in_place_link').bind("ajax:success", function() {
|
|
|
|
var link = $(this).html();
|
|
|
|
$(showCard).find('.go-link').attr('href', link);
|
|
|
|
});
|
2013-01-24 03:05:24 +00:00
|
|
|
|
|
|
|
$(showCard).find(".permActivator").bind('mouseover',
|
|
|
|
function () {
|
2013-01-27 22:21:19 +00:00
|
|
|
clearTimeout(MetamapsModel.topicPermTimer2);
|
2013-01-24 03:05:24 +00:00
|
|
|
that = this;
|
2013-01-27 22:21:19 +00:00
|
|
|
MetamapsModel.topicPermTimer1 = setTimeout(function() {
|
|
|
|
if (! MetamapsModel.topicPermSliding) {
|
|
|
|
MetamapsModel.topicPermSliding = true;
|
2013-01-24 03:05:24 +00:00
|
|
|
$(that).animate({
|
|
|
|
width: '203px',
|
|
|
|
height: '37px'
|
|
|
|
}, 300, function() {
|
2013-01-27 22:21:19 +00:00
|
|
|
MetamapsModel.topicPermSliding = false;
|
2013-01-24 03:05:24 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}, 300);
|
|
|
|
});
|
|
|
|
|
|
|
|
$(showCard).find(".permActivator").bind('mouseout',
|
|
|
|
function () {
|
2013-01-27 22:21:19 +00:00
|
|
|
clearTimeout(MetamapsModel.topicPermTimer1);
|
2013-01-24 03:05:24 +00:00
|
|
|
that = this;
|
2013-01-27 22:21:19 +00:00
|
|
|
MetamapsModel.topicPermTimer2 = setTimeout(function() {
|
|
|
|
if (! MetamapsModel.topicPermSliding) {
|
|
|
|
MetamapsModel.topicPermSliding = true;
|
2013-01-24 03:05:24 +00:00
|
|
|
$(that).animate({
|
|
|
|
height: '16px',
|
|
|
|
width: '16px'
|
|
|
|
}, 300, function() {
|
2013-01-27 22:21:19 +00:00
|
|
|
MetamapsModel.topicPermSliding = false;
|
2013-01-24 03:05:24 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
},800);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
//bind best_in_place ajax callbacks
|
|
|
|
$(showCard).find('.best_in_place_permission').bind("ajax:success", function() {
|
|
|
|
var permission = $(this).html();
|
|
|
|
var el = $(this).parents('.cardSettings').find('.mapPerm');
|
|
|
|
el.attr('title', permission);
|
|
|
|
if (permission == "commons") el.html("co");
|
|
|
|
else if (permission == "public") el.html("pu");
|
|
|
|
else if (permission == "private") el.html("pr");
|
|
|
|
});
|
2013-01-11 03:01:24 +00:00
|
|
|
}
|