ensured map info box action buttons only show at proper times. enabled deletion of maps

This commit is contained in:
Connor Turland 2014-10-14 23:20:40 -04:00
parent bfc8c796c7
commit c37c846fbd
7 changed files with 53 additions and 1 deletions

View file

@ -126,6 +126,9 @@ Metamaps.Backbone.MapsCollection = Backbone.Collection.extend({
}
});
}
else {
self.trigger('successOnFetch');
}
}
});

View file

@ -250,6 +250,9 @@ Metamaps.GlobalUI.CreateMap = {
success: function (model) {
var self = Metamaps.GlobalUI.CreateMap;
//push the new map onto the collection of 'my maps'
Metamaps.Maps.Mine.add(model);
var formId = Metamaps.GlobalUI.lightbox === 'forkmap' ? '#fork_map' : '#new_map';
var form = $(formId);

View file

@ -66,6 +66,8 @@
},
explore: function (section) {
// just capitalize the variable section
// either 'mine', 'featured', or 'active'
var capitalize = section.charAt(0).toUpperCase() + section.slice(1);
document.title = 'Explore ' + capitalize + ' Maps | Metamaps';

View file

@ -36,6 +36,7 @@ Metamaps.Views.init = function () {
setCollection: function (collection) {
if (this.collection) this.stopListening(this.collection);
this.collection = collection;
this.listenTo(this.collection, 'add', this.render);
this.listenTo(this.collection, 'successOnFetch', this.handleSuccess);
this.listenTo(this.collection, 'errorOnFetch', this.handleError);
},

View file

@ -3654,6 +3654,7 @@ Metamaps.Map.InfoBox = {
$('.mapInfoBox').fadeOut(200, function () {
self.changing = false;
self.isOpen = false;
self.hidePermissionSelect();
});
}
},
@ -3666,6 +3667,7 @@ Metamaps.Map.InfoBox = {
var isCreator = map.authorizePermissionChange(Metamaps.Active.Mapper);
var canEdit = map.authorizeToEdit(Metamaps.Active.Mapper);
var shareable = map.get('permission') !== 'private';
obj["name"] = canEdit ? Hogan.compile(self.nameHTML).render({id: map.id, name: map.get("name")}) : map.get("name");
obj["desc"] = canEdit ? Hogan.compile(self.descHTML).render({id: map.id, desc: map.get("desc")}) : map.get("desc");
@ -3678,6 +3680,7 @@ Metamaps.Map.InfoBox = {
var classes = isCreator ? "yourMap" : "";
classes += canEdit ? " canEdit" : "";
classes += shareable ? " shareable" : "";
$(".mapInfoBox").removeClass("yourMap canEdit")
.addClass(classes)
.html(self.generateBoxHTML.render(obj));
@ -3715,7 +3718,11 @@ Metamaps.Map.InfoBox = {
});
$('.yourMap .mapPermission').unbind().click(self.onPermissionClick);
// .yourMap in the unbind/bind is just a namespace for the events
// not a reference to the class .yourMap on the .mapInfoBox
$('.mapInfoBox.yourMap').unbind('.yourMap').bind('click.yourMap', self.hidePermissionSelect);
$('.yourMap .mapInfoDelete').unbind().click(self.deleteActiveMap);
},
createContributorList: function () {
var self = Metamaps.Map.InfoBox;
@ -3777,9 +3784,33 @@ Metamaps.Map.InfoBox = {
Metamaps.Active.Map.save({
permission: permission
});
shareable = permission === 'private' ? '' : 'shareable';
$('.mapPermission').removeClass('commons public private minimize').addClass(permission);
$('.mapPermission .permissionSelect').remove();
$('.mapInfoBox').removeClass('shareable').addClass(shareable);
event.stopPropagation();
},
deleteActiveMap: function () {
var confirmString = 'Are you sure you want to delete this map? ';
confirmString += 'This action is irreversible. It will not delete the topics and synapses on the map.';
var doIt = confirm(confirmString);
var map = Metamaps.Active.Map;
var mapper = Metamaps.Active.Mapper;
var authorized = map.authorizePermissionChange(mapper);
if (doIt && authorized) {
Metamaps.Map.InfoBox.close();
Metamaps.Maps.Active.remove(map);
Metamaps.Maps.Featured.remove(map);
Metamaps.Maps.Mine.remove(map);
map.destroy();
Metamaps.Router.home();
Metamaps.GlobalUI.notifyUser('Map eliminated!');
}
else if (!authorized) {
alert('Hey now. We can\'t just go around willy nilly deleting other people\'s maps now can we? Run off and find something constructive to do, eh?');
}
}
}; // end Metamaps.Map.InfoBox

View file

@ -1646,6 +1646,7 @@ float: left;
text-align: center;
position: relative;
cursor: pointer;
display: none;
}
.mapInfoShareIcon {
width: 24px;
@ -1658,11 +1659,19 @@ float: left;
.mapInfoShare:hover .mapInfoShareIcon {
background-position: 0 0;
}
/* only display share button if 'public' or 'commons' */
.shareable .mapInfoShare {
display: block;
}
.mapInfoDelete {
background-image: url(delete_mapinfo.png);
background-repeat: no-repeat;
background-position: center 8px;
}
/* only display delete button if it's a map you created */
.yourMap .mapInfoDelete {
display: block;
}
.mapInfoButtonsWrapper span {
position: absolute;
width: 100%;

View file

@ -2,7 +2,10 @@
# Partial rendering form for a new topic on a map
# This code is called when viewing a metamap in show.html.erb in the views/maps folder
#%>
<div class="mapInfoBox mapElement mapElementHidden permission <%= @map && @map.user == user ? " yourMap" : "" %><%= @map && @map.authorize_to_edit(user) ? " canEdit" : "" %>">
<div class="mapInfoBox mapElement mapElementHidden permission
<%= @map && @map.user == user ? " yourMap" : "" %>
<%= @map && @map.authorize_to_edit(user) ? " canEdit" : "" %>
<%= @map && @map.permission != 'private' ? " shareable" : "" %>">
<% if @map %>
<div class="mapInfoName" id="mapInfoName"><%= best_in_place @map, :name, :type => :textarea, :activator => "#mapInfoName", :classes => 'best_in_place_name' %></div>