From 02ac1674446474d27a109ce86cf15a74e93da9dc Mon Sep 17 00:00:00 2001
From: Connor Turland
Date: Wed, 23 Jan 2013 13:43:01 -0500
Subject: [PATCH] good start on more persistent permissions throughout the
platform
---
.../javascripts/Jit/onCreateLabelHandler.js | 11 ++-
app/assets/javascripts/Jit/permissions.js | 5 ++
.../Jit/select-edit-delete-nodes-and-edges.js | 82 ++++++++++---------
app/assets/javascripts/application.js | 44 +++++++---
app/assets/stylesheets/base.css | 25 +++---
app/models/map.rb | 2 +
app/models/synapse.rb | 11 ++-
app/models/topic.rb | 9 +-
app/views/layouts/application.html.erb | 2 +-
app/views/maps/_map.html.erb | 8 +-
app/views/maps/edit.html.erb | 6 +-
app/views/synapses/edit.html.erb | 6 +-
app/views/topics/_topic.html.erb | 14 +++-
app/views/topics/edit.html.erb | 6 +-
14 files changed, 153 insertions(+), 78 deletions(-)
create mode 100644 app/assets/javascripts/Jit/permissions.js
diff --git a/app/assets/javascripts/Jit/onCreateLabelHandler.js b/app/assets/javascripts/Jit/onCreateLabelHandler.js
index f11b2968..533a865c 100644
--- a/app/assets/javascripts/Jit/onCreateLabelHandler.js
+++ b/app/assets/javascripts/Jit/onCreateLabelHandler.js
@@ -20,8 +20,15 @@ function onCreateLabelHandler(domElement, node) {
var showCard = document.createElement('div');
showCard.className = 'showcard topic_' + node.id;
- showCard.innerHTML = html;
- showCard.style.display = "none";
+ 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";
domElement.appendChild(showCard);
// Create a 'name' button and add it to the main node label
diff --git a/app/assets/javascripts/Jit/permissions.js b/app/assets/javascripts/Jit/permissions.js
new file mode 100644
index 00000000..e08c47f1
--- /dev/null
+++ b/app/assets/javascripts/Jit/permissions.js
@@ -0,0 +1,5 @@
+
+function authorizeToEdit(obj) {
+ if (userid && (obj.data.$permission == "commons" || obj.data.$userid == userid)) return true;
+ else return false;
+}
\ No newline at end of file
diff --git a/app/assets/javascripts/Jit/select-edit-delete-nodes-and-edges.js b/app/assets/javascripts/Jit/select-edit-delete-nodes-and-edges.js
index 56da2ff8..98dcfbff 100644
--- a/app/assets/javascripts/Jit/select-edit-delete-nodes-and-edges.js
+++ b/app/assets/javascripts/Jit/select-edit-delete-nodes-and-edges.js
@@ -1,46 +1,54 @@
function editEdge(edge, e) {
- //reset so we don't interfere with other edges
- $('#edit_synapse').remove();
+ 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 edit_div = document.createElement('div');
- edit_div.setAttribute('id', 'edit_synapse');
- $('.main .wrapper').append(edit_div);
- $('#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"));
+ 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').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').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();
- });
+ $('#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();
+ //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)) {
+ alert("You don't have the permissions to edit this synapse.");
+ }
}
function deselectAllEdges() {
diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js
index 5bf1dba0..0d14278c 100644
--- a/app/assets/javascripts/application.js
+++ b/app/assets/javascripts/application.js
@@ -87,21 +87,25 @@ var labelType, useGradients, nativeTextSupport, animate, json, Mconsole = null,
// controls the sliding hover of the settings for cards
var sliding2 = false;
- var lT2;
+ var lT1,lT2;
$(".permActivator").hover(
function () {
- clearTimeout(lT2);
- if (! sliding2) {
- sliding2 = true;
- $(this).animate({
- width: '203px',
- height: '37px'
- }, 300, function() {
- sliding2 = false;
- });
- }
+ clearTimeout(lT2);
+ that = this;
+ lT1 = setTimeout(function() {
+ if (! sliding2) {
+ sliding2 = true;
+ $(that).animate({
+ width: '203px',
+ height: '37px'
+ }, 300, function() {
+ sliding2 = false;
+ });
+ }
+ }, 300);
},
function () {
+ clearTimeout(lT1);
that = this;
lT2 = setTimeout(function() {
if (! sliding2) {
@@ -116,6 +120,24 @@ var labelType, useGradients, nativeTextSupport, animate, json, Mconsole = null,
},800);
}
);
+ //bind best_in_place ajax callbacks
+ $('.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");
+ });
+
+ //bind best_in_place ajax callbacks
+ $('.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
+ $(this).parents('.CardOnGraph').find('img.icon').attr('alt', metacode);
+ $(this).parents('.CardOnGraph').find('img.icon').attr('src', imgArray[metacode].src);
+ });
// this is to save the layout of maps when you're on a map page
$("#saveLayout").click(function(event) {
diff --git a/app/assets/stylesheets/base.css b/app/assets/stylesheets/base.css
index 416154e4..4d8c2c0a 100644
--- a/app/assets/stylesheets/base.css
+++ b/app/assets/stylesheets/base.css
@@ -72,39 +72,40 @@
padding-bottom:5px;
}
-.CardOnGraph .best_in_place_name {
+.best_in_place_name {
max-width:130px;
float:left;
}
-.CardOnGraph .best_in_place_name input{
+.best_in_place_name input{
max-width:130px;
}
-.CardOnGraph .desc {
+.desc {
font-size:15px;
font-family:Arial, Helvetica, sans-serif;
}
-.CardOnGraph .desc h3 {
+.desc h3 {
font-style:normal;
margin-top:5px;
}
-.CardOnGraph .best_in_place_desc input {
+.best_in_place_desc input {
float: right;
margin: 2px 0px 0px 2px;
padding: 1px 5px;
}
-.CardOnGraph .best_in_place_desc {
+.best_in_place_desc {
width:155px;
display:block;
margin-top:2px;
}
-.CardOnGraph .best_in_place_desc input[value="Save"] {
-margin-right: -8px;
+.best_in_place_desc textarea{
+ width:150px;
+ display:block;
}
.CardOnGraph .link {
@@ -139,7 +140,7 @@ margin-right: -8px;
.cardSettings {
position: absolute;
left: 12px;
- top: 13px;
+ top: 12px;
}
.editSettings {
@@ -152,6 +153,7 @@ margin-right: -8px;
opacity: 0.98;
box-shadow: 4px 4px 5px #888888;
border: 1px solid #AAA;
+ z-index: 5;
}
.editSettings span {
@@ -163,6 +165,9 @@ margin-right: -8px;
height: 16px;
background: url('settings.png') no-repeat 0 0;
overflow:hidden;
+ position: absolute;
+ left: 0px;
+ top: 30px;
}
.mapPerm {
@@ -172,7 +177,7 @@ margin-right: -8px;
border: 1px solid #AAA;
position: absolute;
left: -7px;
- top: 18px;
+ top: 0px;
width:16px;
text-align:center;
}
diff --git a/app/models/map.rb b/app/models/map.rb
index 9f4df383..5eb088f9 100644
--- a/app/models/map.rb
+++ b/app/models/map.rb
@@ -46,6 +46,7 @@ end
@synapsedata['$userid'] = synapse.user.id
@synapsedata['$username'] = synapse.user.name
@synapsedata['$direction'] = [synapse.node1_id.to_s(), synapse.node2_id.to_s()]
+ @synapsedata['$permission'] = synapse.permission
json.data @synapsedata
end
@@ -65,6 +66,7 @@ end
@topicdata['$xloc'] = @mapping.xloc
@topicdata['$yloc'] = @mapping.yloc
@topicdata['$mappingid'] = @mapping.id
+ @topicdata['$permission'] = topic.permission
json.data @topicdata
json.id topic.id
json.name topic.name
diff --git a/app/models/synapse.rb b/app/models/synapse.rb
index c7fe44e1..5abd3b03 100644
--- a/app/models/synapse.rb
+++ b/app/models/synapse.rb
@@ -16,10 +16,11 @@ has_many :maps, :through => :mappings
@synapsedata['$desc'] = self.desc
@synapsedata['$showDesc'] = false
@synapsedata['$category'] = self.category
- @synapsedata['$id'] = synapse.id
- @synapsedata['$userid'] = synapse.user.id
- @synapsedata['$username'] = synapse.user.name
- @synapsedata['$direction'] = [synapse.node1_id.to_s(), synapse.node2_id.to_s()]
+ @synapsedata['$id'] = self.id
+ @synapsedata['$userid'] = self.user.id
+ @synapsedata['$username'] = self.user.name
+ @synapsedata['$direction'] = [self.node1_id.to_s(), self.node2_id.to_s()]
+ @synapsedata['$permission'] = self.permission
json.data @synapsedata
end
end
@@ -43,6 +44,7 @@ has_many :maps, :through => :mappings
@synapsedata['$userid'] = synapse.user.id
@synapsedata['$username'] = synapse.user.name
@synapsedata['$direction'] = [synapse.node1_id.to_s(), synapse.node2_id.to_s()]
+ @synapsedata['$permission'] = synapse.permission
json.data @synapsedata
end
@@ -58,6 +60,7 @@ has_many :maps, :through => :mappings
@topicdata['$inmaps'] = @inmaps
@topicdata['$userid'] = topic.user.id
@topicdata['$username'] = topic.user.name
+ @topicdata['$permission'] = topic.permission
json.data @topicdata
json.id topic.id
json.name topic.name
diff --git a/app/models/topic.rb b/app/models/topic.rb
index cb6960a7..f85e6110 100644
--- a/app/models/topic.rb
+++ b/app/models/topic.rb
@@ -28,7 +28,7 @@ belongs_to :metacode
def mk_permission
if self.permission == "commons"
- "cc"
+ "co"
elsif self.permission == "public"
"pu"
elsif self.permission == "private"
@@ -58,11 +58,12 @@ belongs_to :metacode
@topicdata = Hash.new
@topicdata['$desc'] = self.desc
- @topicdata['$link'] = self.link
+ @topicdata['$link'] = self.link
@topicdata['$metacode'] = self.metacode.name
@topicdata['$inmaps'] = @inmaps
@topicdata['$userid'] = self.user.id
@topicdata['$username'] = self.user.name
+ @topicdata['$permission'] = self.permission
json.data @topicdata
json.id self.id
json.name self.name
@@ -87,6 +88,7 @@ belongs_to :metacode
@topicdata['$xloc'] = @mapping.xloc
@topicdata['$yloc'] = @mapping.yloc
@topicdata['$mappingid'] = @mapping.id
+ @topicdata['$permission'] = self.permission
json.data @topicdata
json.id self.id
json.name self.name
@@ -113,6 +115,7 @@ belongs_to :metacode
@synapsedata['$userid'] = synapse.user.id
@synapsedata['$username'] = synapse.user.name
@synapsedata['$direction'] = [synapse.node1_id.to_s(), synapse.node2_id.to_s()]
+ @synapsedata['$permission'] = synapse.permission
json.data @synapsedata
end
@@ -128,6 +131,7 @@ belongs_to :metacode
@topicdata['$inmaps'] = @inmaps
@topicdata['$userid'] = topic.user.id
@topicdata['$username'] = topic.user.name
+ @topicdata['$permission'] = topic.permission
json.data @topicdata
json.id topic.id
json.name topic.name
@@ -146,6 +150,7 @@ belongs_to :metacode
@topicdata['$inmaps'] = @inmaps
@topicdata['$userid'] = topic.user.id
@topicdata['$username'] = topic.user.name
+ @topicdata['$permission'] = topic.permission
json.data @topicdata
json.id topic.id
json.name topic.name
diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb
index 25514526..03d66914 100644
--- a/app/views/layouts/application.html.erb
+++ b/app/views/layouts/application.html.erb
@@ -11,7 +11,7 @@
Metamaps
<% if authenticated? %>
<% else %>
diff --git a/app/views/maps/_map.html.erb b/app/views/maps/_map.html.erb
index fdf5a566..1f81d3ec 100644
--- a/app/views/maps/_map.html.erb
+++ b/app/views/maps/_map.html.erb
@@ -12,19 +12,19 @@
Map
<%= image_tag 'map.png', :class => 'icon', :size => '50x50' %>
+
<%= map.mk_permission %>
<% if map.user == user %>
Permissions:
-
<%= best_in_place map, :permission, :type => :select, :collection => [['commons', 'commons'], ['public','public'], ['private','private']] %>
+
<%= best_in_place map, :permission, :type => :select, :collection => [['commons', 'commons'], ['public','public'], ['private','private']], :classes => 'best_in_place_permission' %>
<% end %>
-
<%= map.mk_permission %>
- <%= best_in_place map, :name, :type => :input %>
+ <%= best_in_place map, :name, :type => :input, :classes => 'best_in_place_name' %>
<%= map.topics.count %> topics and <%= map.synapses.count %> synapses
-
<%= best_in_place map, :desc, :type => :textarea, :nil => "Click to add description." %>
+
<%= best_in_place map, :desc, :type => :textarea, :nil => "Click to add description.", :classes => 'best_in_place_desc' %>
diff --git a/app/views/maps/edit.html.erb b/app/views/maps/edit.html.erb
index 65bdc588..f52f29c4 100644
--- a/app/views/maps/edit.html.erb
+++ b/app/views/maps/edit.html.erb
@@ -9,7 +9,9 @@
<%= form.text_field :name %>
<%= form.text_area :desc, class: "description", :rows => 5 %>
-
- <%= form.select :permission, options_for_select(['commons', 'public', 'private'], @map.permission) %>
+ <% if @map.user == user %>
+
+ <%= form.select :permission, options_for_select(['commons', 'public', 'private'], @map.permission) %>
+ <% end %>
<%= form.submit "Update", class: "update" %>
<% end %>
diff --git a/app/views/synapses/edit.html.erb b/app/views/synapses/edit.html.erb
index 25528183..710e3b79 100644
--- a/app/views/synapses/edit.html.erb
+++ b/app/views/synapses/edit.html.erb
@@ -19,7 +19,9 @@
<%= select "node2_id", "node2", Topic.order("name ASC").visibleToUser(user, nil).map {|p| [ p.name, p.id ] }, { :selected => @synapse.node2_id } %>
<% end %>
-
- <%= form.select :permission, options_for_select(['commons', 'public', 'private'], @synapse.permission) %>
+ <% if @synapse.user == user %>
+
+ <%= form.select :permission, options_for_select(['commons', 'public', 'private'], @synapse.permission) %>
+ <% end %>
<%= form.submit "Update", class: "update" %>
<% end %>
diff --git a/app/views/topics/_topic.html.erb b/app/views/topics/_topic.html.erb
index 6dd5af7d..56be87fd 100644
--- a/app/views/topics/_topic.html.erb
+++ b/app/views/topics/_topic.html.erb
@@ -19,7 +19,19 @@
data-collection='[["Action","Action"],["Activity","Activity"],["Bizarre","Bizarre"],["Catalyst","Catalyst"],["Closed","Closed"],["Experience","Experience"],["Future Dev","Future Dev"],["Group","Group"],["Idea","Idea"],["Implication","Implication"],["Insight","Insight"],["Intention","Intention"],["Knowledge","Knowledge"],["Location","Location"],["Open Issue","Open Issue"],["Opinion","Opinion"],["Opportunity","Opportunity"],["Person","Person"],["Platform","Platform"],["Problem","Problem"],["Question","Question"],["Reference","Reference"],["Requirement","Requirement"],["Resource","Resource"],["Role","Role"],["Task","Task"],["Tool","Tool"],["Trajectory","Trajectory"]]'
data-attribute="metacode"
data-type="select"><%= topic.metacode.name %>
- <%= image_tag topic.metacode.icon, :class => 'icon', :size => '50x50' %>
+ <%= image_tag topic.metacode.icon, :class => 'icon', :size => '50x50' %>
+
+
<%= topic.mk_permission %>
+ <% if topic.user == user %>
+
+
+
Permissions:
+
<%= best_in_place topic, :permission, :type => :select, :collection => [['commons', 'commons'], ['public','public'], ['private','private']], :classes => 'best_in_place_permission' %>
+
+
+
+ <% end %>
+
5 %>
<%= form.text_field :link, class: "link" %>
-
- <%= form.select :permission, options_for_select(['commons', 'public', 'private'], @topic.permission) %>
+ <% if @topic.user == user %>
+
+ <%= form.select :permission, options_for_select(['commons', 'public', 'private'], @topic.permission) %>
+ <% end %>
<%= form.submit "Update", class: "update" %>
<% end %>