removed embed. fixed switch metacode set lightbox overflow. disabled topic creation and topic deletion from public maps by non-owner

This commit is contained in:
Connor Turland 2014-11-03 08:46:22 -05:00
parent 2a9a27c6c5
commit ee1ca7853f
9 changed files with 191 additions and 172 deletions

View file

@ -757,6 +757,8 @@ Metamaps.JIT = {
var positionsToSend = {};
var topic;
var authorized = Metamaps.Active.Map && Metamaps.Active.Map.authorizeToEdit(Metamaps.Active.Mapper);
if (node && !node.nodeFrom) {
var pos = eventInfo.getPos();
// if it's a left click, or a touch, move the node
@ -821,7 +823,7 @@ Metamaps.JIT = {
Metamaps.Visualize.mGraph.plot();
}
// if it's a right click or holding down alt, start synapse creation ->third option is for firefox
else if ((e.button == 2 || (e.button == 0 && e.altKey) || e.buttons == 2) && Metamaps.Active.Mapper) {
else if ((e.button == 2 || (e.button == 0 && e.altKey) || e.buttons == 2) && authorized) {
if (tempInit == false) {
tempNode = node;
tempInit = true;
@ -886,6 +888,9 @@ Metamaps.JIT = {
$(document).trigger(Metamaps.JIT.events.mouseMove, [pos]);
}
}
else if ((e.button == 2 || (e.button == 0 && e.altKey) || e.buttons == 2) && !authorized) {
Metamaps.GlobalUI.notifyUser("Cannot edit Public map.");
}
}
}, // onDragMoveTopicHandler
onDragCancelHandler: function (node, eventInfo, e) {
@ -927,6 +932,9 @@ Metamaps.JIT = {
// check whether to save mappings
var checkWhetherToSave = function() {
var map = Metamaps.Active.Map;
if (!map) return false;
var mapper = Metamaps.Active.Mapper;
// this case
// covers when it is a public map owned by you
@ -967,7 +975,13 @@ Metamaps.JIT = {
var now = Date.now(); //not compatible with IE8 FYI
Metamaps.Mouse.lastCanvasClick = now;
var authorized = Metamaps.Active.Map && Metamaps.Active.Map.authorizeToEdit(Metamaps.Active.Mapper);
if (now - storedTime < Metamaps.Mouse.DOUBLE_CLICK_TOLERANCE && !Metamaps.Mouse.didPan) {
if (Metamaps.Active.Map && !authorized) {
Metamaps.GlobalUI.notifyUser("Cannot edit Public map.");
return;
}
// DOUBLE CLICK
//pop up node creation :)
Metamaps.Create.newTopic.addSynapse = false;
@ -1269,12 +1283,16 @@ Metamaps.JIT = {
// add the proper options to the menu
var menustring = '<ul>';
menustring += '<li class="rc-hide"><div class="rc-icon"></div>Hide until refresh</li>';
if (Metamaps.Active.Map && Metamaps.Active.Mapper) menustring += '<li class="rc-remove"><div class="rc-icon"></div>Remove from map</li>';
if (Metamaps.Active.Mapper) menustring += '<li class="rc-delete"><div class="rc-icon"></div>Delete</li>';
var authorized = Metamaps.Active.Map && Metamaps.Active.Map.authorizeToEdit(Metamaps.Active.Mapper);
var disabled = authorized ? "" : "disabled";
if (Metamaps.Active.Map) menustring += '<li class="rc-hide"><div class="rc-icon"></div>Hide until refresh</li>';
if (Metamaps.Active.Map && Metamaps.Active.Mapper) menustring += '<li class="rc-remove ' + disabled + '"><div class="rc-icon"></div>Remove from map</li>';
if (Metamaps.Active.Map && Metamaps.Active.Mapper) menustring += '<li class="rc-delete ' + disabled + '"><div class="rc-icon"></div>Delete</li>';
if (!Metamaps.Active.Map) menustring += '<li class="rc-center"><div class="rc-icon"></div>Center this topic</li>';
if (Metamaps.Active.Topic) menustring += '<li class="rc-center"><div class="rc-icon"></div>Center this topic</li>';
menustring += '<li class="rc-popout"><div class="rc-icon"></div>Open in new tab</li>';
if (Metamaps.Active.Mapper) {
var options = '<ul><li class="changeP toCommons"><div class="rc-perm-icon"></div>commons</li> \
@ -1331,17 +1349,21 @@ Metamaps.JIT = {
// attach events to clicks on the list items
// delete the selected things from the database
$('.rc-delete').click(function () {
$('.rightclickmenu').remove();
Metamaps.Control.deleteSelected();
});
if (authorized) {
$('.rc-delete').click(function () {
$('.rightclickmenu').remove();
Metamaps.Control.deleteSelected();
});
}
// remove the selected things from the map
$('.rc-remove').click(function () {
$('.rightclickmenu').remove();
Metamaps.Control.removeSelectedEdges();
Metamaps.Control.removeSelectedNodes();
});
if (authorized) {
$('.rc-remove').click(function () {
$('.rightclickmenu').remove();
Metamaps.Control.removeSelectedEdges();
Metamaps.Control.removeSelectedNodes();
});
}
// hide selected nodes and synapses until refresh
$('.rc-hide').click(function () {
@ -1445,11 +1467,13 @@ Metamaps.JIT = {
// add the proper options to the menu
var menustring = '<ul>';
menustring += '<li class="rc-hide"><div class="rc-icon"></div>Hide until refresh</li>';
if (Metamaps.Active.Map && Metamaps.Active.Map.authorizeToEdit(Metamaps.Active.Mapper)) {
menustring += '<li class="rc-remove"><div class="rc-icon"></div>Remove from map</li>';
}
if (Metamaps.Active.Mapper) menustring += '<li class="rc-delete"><div class="rc-icon"></div>Delete</li>';
var authorized = Metamaps.Active.Map && Metamaps.Active.Map.authorizeToEdit(Metamaps.Active.Mapper);
var disabled = authorized ? "" : "disabled";
if (Metamaps.Active.Map) menustring += '<li class="rc-hide"><div class="rc-icon"></div>Hide until refresh</li>';
if (Metamaps.Active.Map && Metamaps.Active.Mapper) menustring += '<li class="rc-remove ' + disabled + '"><div class="rc-icon"></div>Remove from map</li>';
if (Metamaps.Active.Map && Metamaps.Active.Mapper) menustring += '<li class="rc-delete ' + disabled + '"><div class="rc-icon"></div>Delete</li>';
if (Metamaps.Active.Mapper) {
var permOptions = '<ul><li class="changeP toCommons"><div class="rc-perm-icon"></div>commons</li> \
@ -1500,17 +1524,21 @@ Metamaps.JIT = {
// attach events to clicks on the list items
// delete the selected things from the database
$('.rc-delete').click(function () {
$('.rightclickmenu').remove();
Metamaps.Control.deleteSelected();
});
if (authorized) {
$('.rc-delete').click(function () {
$('.rightclickmenu').remove();
Metamaps.Control.deleteSelected();
});
}
// remove the selected things from the map
$('.rc-remove').click(function () {
$('.rightclickmenu').remove();
Metamaps.Control.removeSelectedEdges();
Metamaps.Control.removeSelectedNodes();
});
if (authorized) {
$('.rc-remove').click(function () {
$('.rightclickmenu').remove();
Metamaps.Control.removeSelectedEdges();
Metamaps.Control.removeSelectedNodes();
});
}
// hide selected nodes and synapses until refresh
$('.rc-hide').click(function () {

View file

@ -2566,12 +2566,22 @@ Metamaps.Control = {
Metamaps.Selected.Nodes.indexOf(node), 1);
},
deleteSelected: function () {
if (!Metamaps.Active.Map) return;
var n = Metamaps.Selected.Nodes.length;
var e = Metamaps.Selected.Edges.length;
var ntext = n == 1 ? "1 topic" : n + " topics";
var etext = e == 1 ? "1 synapse" : e + " synapses";
var text = "You have " + ntext + " and " + etext + " selected. ";
var authorized = Metamaps.Active.Map.authorizeToEdit(Metamaps.Active.Mapper);
if (!authorized) {
Metamaps.GlobalUI.notifyUser("Cannot edit Public map.");
return;
}
var r = confirm(text + "Are you sure you want to permanently delete them all? This will remove them from all maps they appear on.");
if (r == true) {
Metamaps.Control.deleteSelectedEdges();
@ -2579,6 +2589,16 @@ Metamaps.Control = {
}
},
deleteSelectedNodes: function () { // refers to deleting topics permanently
if (!Metamaps.Active.Map) return;
var authorized = Metamaps.Active.Map.authorizeToEdit(Metamaps.Active.Mapper);
if (!authorized) {
Metamaps.GlobalUI.notifyUser("Cannot edit Public map.");
return;
}
var l = Metamaps.Selected.Nodes.length;
for (var i = l - 1; i >= 0; i -= 1) {
var node = Metamaps.Selected.Nodes[i];
@ -2586,6 +2606,16 @@ Metamaps.Control = {
}
},
deleteNode: function (nodeid) { // refers to deleting topics permanently
if (!Metamaps.Active.Map) return;
var authorized = Metamaps.Active.Map.authorizeToEdit(Metamaps.Active.Mapper);
if (!authorized) {
Metamaps.GlobalUI.notifyUser("Cannot edit Public map.");
return;
}
var node = Metamaps.Visualize.mGraph.graph.getNode(nodeid);
var topic = node.getData('topic');
var topicid = topic.id;
@ -2598,33 +2628,45 @@ Metamaps.Control = {
Metamaps.Control.hideNode(nodeid);
},
removeSelectedNodes: function () { // refers to removing topics permanently from a map
if (!Metamaps.Active.Map) return;
var l = Metamaps.Selected.Nodes.length,
i,
node,
mapperm = Metamaps.Active.Map.authorizeToEdit(Metamaps.Active.Mapper);
authorized = Metamaps.Active.Map.authorizeToEdit(Metamaps.Active.Mapper);
if (mapperm) {
for (i = l - 1; i >= 0; i -= 1) {
node = Metamaps.Selected.Nodes[i];
Metamaps.Control.removeNode(node.id);
}
if (!authorized) {
Metamaps.GlobalUI.notifyUser("Cannot edit Public map.");
return;
}
for (i = l - 1; i >= 0; i -= 1) {
node = Metamaps.Selected.Nodes[i];
Metamaps.Control.removeNode(node.id);
}
},
removeNode: function (nodeid) { // refers to removing topics permanently from a map
var mapperm = Metamaps.Active.Map.authorizeToEdit(Metamaps.Active.Mapper);
if (!Metamaps.Active.Map) return;
var authorized = Metamaps.Active.Map.authorizeToEdit(Metamaps.Active.Mapper);
var node = Metamaps.Visualize.mGraph.graph.getNode(nodeid);
if (mapperm) {
var topic = node.getData('topic');
var topicid = topic.id;
var mapping = node.getData('mapping');
mapping.destroy();
Metamaps.Topics.remove(topic);
$(document).trigger(Metamaps.JIT.events.removeTopic, [{
topicid: topicid
}]);
Metamaps.Control.hideNode(nodeid);
if (!authorized) {
Metamaps.GlobalUI.notifyUser("Cannot edit Public map.");
return;
}
var topic = node.getData('topic');
var topicid = topic.id;
var mapping = node.getData('mapping');
mapping.destroy();
Metamaps.Topics.remove(topic);
$(document).trigger(Metamaps.JIT.events.removeTopic, [{
topicid: topicid
}]);
Metamaps.Control.hideNode(nodeid);
},
hideSelectedNodes: function () {
var l = Metamaps.Selected.Nodes.length,
@ -2709,6 +2751,16 @@ Metamaps.Control = {
deleteSelectedEdges: function () { // refers to deleting topics permanently
var edge,
l = Metamaps.Selected.Edges.length;
if (!Metamaps.Active.Map) return;
var authorized = Metamaps.Active.Map.authorizeToEdit(Metamaps.Active.Mapper);
if (!authorized) {
Metamaps.GlobalUI.notifyUser("Cannot edit Public map.");
return;
}
for (var i = l - 1; i >= 0; i -= 1) {
edge = Metamaps.Selected.Edges[i];
Metamaps.Control.deleteEdge(edge);
@ -2716,6 +2768,15 @@ Metamaps.Control = {
},
deleteEdge: function (edge) {
if (!Metamaps.Active.Map) return;
var authorized = Metamaps.Active.Map.authorizeToEdit(Metamaps.Active.Mapper);
if (!authorized) {
Metamaps.GlobalUI.notifyUser("Cannot edit Public map.");
return;
}
if (edge.getData("synapses").length - 1 === 0) {
Metamaps.Control.hideEdge(edge);
}
@ -2743,16 +2804,32 @@ Metamaps.Control = {
i,
edge;
if (Metamaps.Active.Map) {
for (i = l - 1; i >= 0; i -= 1) {
edge = Metamaps.Selected.Edges[i];
Metamaps.Control.removeEdge(edge);
}
Metamaps.Selected.Edges = new Array();
if (!Metamaps.Active.Map) return;
var authorized = Metamaps.Active.Map.authorizeToEdit(Metamaps.Active.Mapper);
if (!authorized) {
Metamaps.GlobalUI.notifyUser("Cannot edit Public map.");
return;
}
for (i = l - 1; i >= 0; i -= 1) {
edge = Metamaps.Selected.Edges[i];
Metamaps.Control.removeEdge(edge);
}
Metamaps.Selected.Edges = new Array();
},
removeEdge: function (edge) {
if (!Metamaps.Active.Map) return;
var authorized = Metamaps.Active.Map.authorizeToEdit(Metamaps.Active.Mapper);
if (!authorized) {
Metamaps.GlobalUI.notifyUser("Cannot edit Public map.");
return;
}
if (edge.getData("mappings").length - 1 === 0) {
Metamaps.Control.hideEdge(edge);
}

View file

@ -1180,6 +1180,13 @@ h3.realtimeBoxTitle {
background-color: #E0E0E0;
cursor: pointer;
}
.rightclickmenu li.disabled {
opacity: 0.4;
}
.rightclickmenu li.disabled:hover {
background-color: transparent;
cursor: default;
}
.rightclickmenu > ul > li .rc-icon {
position: absolute;
top: 0;
@ -1976,6 +1983,8 @@ and it won't be important on password protected instances */
font-family: 'din-medium', helvetica, sans-serif;
color: #424242;
font-size: 14px;
text-align: justify;
padding-right: 16px;
}
#switchMetacodes > p {
margin: 16px 0 16px 0;
@ -1990,10 +1999,17 @@ and it won't be important on password protected instances */
#metacodeSwitchTabs li.ui-state-active a {
color: #00BCD4;
}
.metacodeSwitchTab {
max-height: 300px;
overflow-y: auto;
margin-bottom: 16px;
}
.customMetacodeList {
overflow-y: auto;
}
.customMetacodeList,
.metacodeSetList {
height: 301px;
overflow-y: auto;
margin: 5px 0 15px 0;
}
.customMetacodeList ul li {

View file

@ -113,6 +113,7 @@
font-size: 12px;
line-height:15px;
font-family: helvetica, sans-serif;
overflow-y: scroll;
}
.CardOnGraph.hasAttachment .scroll {
height: auto;

View file

@ -81,8 +81,8 @@ class MapsController < ApplicationController
respond_to do |format|
format.html {
@allmappers = @map.contributors
@alltopics = @map.topics # should limit to topics visible to user
@allsynapses = @map.synapses # should also be limited
@alltopics = @map.topics.delete_if {|t| t.permission == "private" && (!authenticated? || (authenticated? && @current.id != t.user_id)) }
@allsynapses = @map.synapses.delete_if {|s| s.permission == "private" && (!authenticated? || (authenticated? && @current.id != s.user_id)) }
@allmappings = @map.mappings
respond_with(@allmappers, @allmappings, @allsynapses, @alltopics, @map)
@ -102,8 +102,8 @@ class MapsController < ApplicationController
end
@allmappers = @map.contributors
@alltopics = @map.topics # should limit to topics visible to user
@allsynapses = @map.synapses # should also be limited
@alltopics = @map.topics.delete_if {|t| t.permission == "private" && (!authenticated? || (authenticated? && @current.id != t.user_id)) }
@allsynapses = @map.synapses.delete_if {|s| s.permission == "private" && (!authenticated? || (authenticated? && @current.id != s.user_id)) }
@allmappings = @map.mappings
@json = Hash.new()
@ -118,27 +118,6 @@ class MapsController < ApplicationController
end
end
# GET maps/:id/embed
def embed
@current = current_user
@map = Map.find(params[:id]).authorize_to_show(@current)
if not @map
redirect_to root_url and return
end
@alltopics = @map.topics # should limit to topics visible to user
@allsynapses = @map.synapses # should also be limited
@allmappings = @map.mappings
@allmetacodes = Metacode.all
respond_to do |format|
format.html { respond_with(@allmetacodes, @allmappings, @allsynapses, @alltopics, @map, @user) }
format.json { render json: @map }
end
end
# POST maps
def create

View file

@ -34,8 +34,8 @@ class TopicsController < ApplicationController
respond_to do |format|
format.html {
@alltopics = [@topic] + @topic.relatives # should limit to topics visible to user
@allsynapses = @topic.synapses # should also be limited
@alltopics = ([@topic] + @topic.relatives).delete_if {|t| t.permission == "private" && (!authenticated? || (authenticated? && @current.id != t.user_id)) } # should limit to topics visible to user
@allsynapses = @topic.synapses.delete_if {|s| s.permission == "private" && (!authenticated? || (authenticated? && @current.id != s.user_id)) }
respond_with(@allsynapses, @alltopics, @topic)
}
@ -52,8 +52,8 @@ class TopicsController < ApplicationController
redirect_to root_url and return
end
@alltopics = @topic.relatives # should limit to topics visible to user
@allsynapses = @topic.synapses # should also be limited
@alltopics = @topic.relatives.delete_if {|t| t.permission == "private" && (!authenticated? || (authenticated? && @current.id != t.user_id)) }
@allsynapses = @topic.synapses.delete_if {|s| s.permission == "private" && (!authenticated? || (authenticated? && @current.id != s.user_id)) }
@json = Hash.new()
@json['topic'] = @topic

View file

@ -1,83 +0,0 @@
<%#
# @file
# Code to display a map
# /maps/:id
#%>
<% content_for :title, @map.name + " | Metamaps" %>
<div id="preloaded-images">
<img src="/assets/MMCCicon_realtime_blue.png" />
</div>
<% if authenticated? %>
<div class="sidebarFork">
<div class="sidebarForkIcon">
</div>
<div class="sidebarForkBox"></div>
</div>
<% if @map.permission == "commons" || @map.user == user %>
<div class="sidebarCollaborate">
<div class="sidebarCollaborateIcon blue"></div>
<div class="sidebarCollaborateBox">
<h3 class="realtimeBoxTitle">Realtime: </h3>
<span class="realtimeOnOff rtOn">ON</span>
<div class="clearfloat"></div>
<div class="realtimeMapperList">
<ul>
<li class="rtMapper littleRtOn rtMapperSelf">
<%= user.name %> (me)
</li>
</ul>
</div>
</div>
</div>
<% end %>
<% end %>
<div class="sidebarFilter <%= authenticated? ? 'loggedin' : 'loggedout' %>">
<div class="sidebarFilterIcon"></div>
<div class="sidebarFilterBox">
<h3 class="filterByMetacode">Filter By Metacode</h3><span class="showAll">all</span><span class="hideAll">none</span>
<div class="clearfloat"></div>
<%= render :partial => 'shared/filterbymetacode' %>
</div>
</div>
<div class="index">
<div class="openCheatsheet openLightbox" data-open="cheatsheet"></div>
<span class="mapInfo"></span>
<div class="clearfloat"></div>
<%= render :partial => 'maps/mapinfobox' %>
</div>
<div class="maps onMap" id="container">
<div id="center-container">
<div id="infovis"></div>
</div>
<div class="showcard" id="showcard"></div>
</div>
<div class="clearfloat"></div>
<% if authenticated? %>
<% # add these if you have edit permissions on the map %>
<% if @map.permission == "commons" || @map.user == user %>
<% # for creating and pulling in topics and synapses %>
<%= render :partial => 'newtopic' %>
<%= render :partial => 'newsynapse' %>
<% end %>
<% # for populating the change metacode list on the topic card %>
<%= render :partial => 'shared/metacodeoptions' %>
<% end %>
<script>
Metamaps.Active.Map = <%= @map.to_json.html_safe %>;
Metamaps.Metacodes = <%= @allmetacodes.to_json.html_safe %>;
Metamaps.Topics = <%= @alltopics.to_json.html_safe %>;
Metamaps.Synapses = <%= @allsynapses.to_json.html_safe %>;
Metamaps.Mappings = <%= @allmappings.to_json.html_safe %>;
Metamaps.Settings.embed = true;
</script>

View file

@ -30,12 +30,14 @@
<% m.metacodes.sort{|x,y| x.name <=> y.name }.each_with_index do |m, index| %>
<% @list += '<li><img src="' + m.icon + '" alt="' + m.name + '" /><p>' + m.name.downcase + '</p><div class="clearfloat"></div></li>' %>
<% end %>
<p class="setDesc"><%= m.desc %></p>
<div class="metacodeSetList">
<ul>
<%= @list.html_safe %>
</ul>
<div class="clearfloat"></div>
<div class="metacodeSwitchTab">
<p class="setDesc"><%= m.desc %></p>
<div class="metacodeSetList">
<ul>
<%= @list.html_safe %>
</ul>
<div class="clearfloat"></div>
</div>
</div>
<button class="button" onclick="Metamaps.Create.updateMetacodeSet(<%= m.id %>, <%= localindex %>, false);">
Switch Set

View file

@ -29,7 +29,6 @@ Metamaps::Application.routes.draw do
match 'maps/mappers/:id', to: 'maps#index', via: :get, as: :usermaps
match 'maps/topics/:id', to: 'maps#index', via: :get, as: :topicmaps
resources :maps, except: [:new, :edit]
match 'maps/:id/embed', to: 'maps#embed', via: :get, as: :embed
match 'maps/:id/contains', to: 'maps#contains', via: :get, as: :contains
devise_for :users, controllers: { registrations: 'users/registrations', passwords: 'users/passwords', sessions: 'devise/sessions' }, :skip => [:sessions]