good start on more persistent permissions throughout the platform
This commit is contained in:
parent
aa911d4bdf
commit
02ac167444
14 changed files with 153 additions and 78 deletions
|
@ -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
|
||||
|
|
5
app/assets/javascripts/Jit/permissions.js
Normal file
5
app/assets/javascripts/Jit/permissions.js
Normal file
|
@ -0,0 +1,5 @@
|
|||
|
||||
function authorizeToEdit(obj) {
|
||||
if (userid && (obj.data.$permission == "commons" || obj.data.$userid == userid)) return true;
|
||||
else return false;
|
||||
}
|
|
@ -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() {
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
<title>Metamaps</title>
|
||||
<% if authenticated? %>
|
||||
<script type="text/javascript">
|
||||
var userid = "<%= user.id %>";
|
||||
var userid = <%= user.id %>;
|
||||
var username = "<%= user.name %>";
|
||||
</script>
|
||||
<% else %>
|
||||
|
|
|
@ -12,19 +12,19 @@
|
|||
<p class="type">Map</p>
|
||||
<%= image_tag 'map.png', :class => 'icon', :size => '50x50' %>
|
||||
<div class="cardSettings">
|
||||
<div class="mapPerm" title="<%= map.permission %>"><%= map.mk_permission %></div>
|
||||
<% if map.user == user %>
|
||||
<div class="permActivator">
|
||||
<div class="editSettings">
|
||||
<span>Permissions: </span>
|
||||
<span title="Click to Edit"><%= best_in_place map, :permission, :type => :select, :collection => [['commons', 'commons'], ['public','public'], ['private','private']] %></span>
|
||||
<span title="Click to Edit"><%= best_in_place map, :permission, :type => :select, :collection => [['commons', 'commons'], ['public','public'], ['private','private']], :classes => 'best_in_place_permission' %></span>
|
||||
<div class="clearfloat"></div>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
<div class="mapPerm"><%= map.mk_permission %></div>
|
||||
</div>
|
||||
<span class="title">
|
||||
<span><%= best_in_place map, :name, :type => :input %></span>
|
||||
<span><%= best_in_place map, :name, :type => :input, :classes => 'best_in_place_name' %></span>
|
||||
<a href="/maps/<%=map.id %>" class="topic-go-arrow">
|
||||
<img class="topic-go-arrow"
|
||||
title="Go to map"
|
||||
|
@ -39,7 +39,7 @@
|
|||
<div class="scroll">
|
||||
<div class="desc">
|
||||
<p class="mapdata"><%= map.topics.count %> topics and <%= map.synapses.count %> synapses</p>
|
||||
<p><%= best_in_place map, :desc, :type => :textarea, :nil => "<span class='gray'>Click to add description.</span>" %></p>
|
||||
<p><%= best_in_place map, :desc, :type => :textarea, :nil => "<span class='gray'>Click to add description.</span>", :classes => 'best_in_place_desc' %></p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
|
|
@ -9,7 +9,9 @@
|
|||
<%= form.text_field :name %>
|
||||
<label for="map_desc">Description</label>
|
||||
<%= form.text_area :desc, class: "description", :rows => 5 %>
|
||||
<label for="map_perm">Permission</label>
|
||||
<%= form.select :permission, options_for_select(['commons', 'public', 'private'], @map.permission) %>
|
||||
<% if @map.user == user %>
|
||||
<label for="map_perm">Permission</label>
|
||||
<%= form.select :permission, options_for_select(['commons', 'public', 'private'], @map.permission) %>
|
||||
<% end %>
|
||||
<%= form.submit "Update", class: "update" %>
|
||||
<% end %>
|
||||
|
|
|
@ -19,7 +19,9 @@
|
|||
<label for="node2_id">Choose Second Topic</label>
|
||||
<%= select "node2_id", "node2", Topic.order("name ASC").visibleToUser(user, nil).map {|p| [ p.name, p.id ] }, { :selected => @synapse.node2_id } %>
|
||||
<% end %>
|
||||
<label for="synapse_permission">Permission</label>
|
||||
<%= form.select :permission, options_for_select(['commons', 'public', 'private'], @synapse.permission) %>
|
||||
<% if @synapse.user == user %>
|
||||
<label for="synapse_permission">Permission</label>
|
||||
<%= form.select :permission, options_for_select(['commons', 'public', 'private'], @synapse.permission) %>
|
||||
<% end %>
|
||||
<%= form.submit "Update", class: "update" %>
|
||||
<% end %>
|
||||
|
|
|
@ -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 %></p>
|
||||
<%= image_tag topic.metacode.icon, :class => 'icon', :size => '50x50' %>
|
||||
<%= image_tag topic.metacode.icon, :class => 'icon', :size => '50x50' %>
|
||||
<div class="cardSettings">
|
||||
<div class="mapPerm" title="<%= topic.permission %>"><%= topic.mk_permission %></div>
|
||||
<% if topic.user == user %>
|
||||
<div class="permActivator">
|
||||
<div class="editSettings">
|
||||
<span>Permissions: </span>
|
||||
<span title="Click to Edit"><%= best_in_place topic, :permission, :type => :select, :collection => [['commons', 'commons'], ['public','public'], ['private','private']], :classes => 'best_in_place_permission' %></span>
|
||||
<div class="clearfloat"></div>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
<span class="title">
|
||||
<span class="best_in_place best_in_place_name"
|
||||
data-url="/topics/<%=topic.id %>"
|
||||
|
|
|
@ -14,7 +14,9 @@
|
|||
<%= form.text_area :desc, class: "description", :rows => 5 %>
|
||||
<label for="topic_link">Link</label>
|
||||
<%= form.text_field :link, class: "link" %>
|
||||
<label for="topic_permission">Permission</label>
|
||||
<%= form.select :permission, options_for_select(['commons', 'public', 'private'], @topic.permission) %>
|
||||
<% if @topic.user == user %>
|
||||
<label for="topic_permission">Permission</label>
|
||||
<%= form.select :permission, options_for_select(['commons', 'public', 'private'], @topic.permission) %>
|
||||
<% end %>
|
||||
<%= form.submit "Update", class: "update" %>
|
||||
<% end %>
|
||||
|
|
Loading…
Reference in a new issue