From c37c846fbd6af55b3b7a6a1a2c1eb4092cf9aba6 Mon Sep 17 00:00:00 2001 From: Connor Turland Date: Tue, 14 Oct 2014 23:20:40 -0400 Subject: [PATCH] ensured map info box action buttons only show at proper times. enabled deletion of maps --- .../javascripts/src/Metamaps.Backbone.js | 3 ++ .../javascripts/src/Metamaps.GlobalUI.js | 3 ++ app/assets/javascripts/src/Metamaps.Router.js | 2 ++ app/assets/javascripts/src/Metamaps.Views.js | 1 + app/assets/javascripts/src/Metamaps.js | 31 +++++++++++++++++++ app/assets/stylesheets/application.css | 9 ++++++ app/views/maps/_mapinfobox.html.erb | 5 ++- 7 files changed, 53 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/src/Metamaps.Backbone.js b/app/assets/javascripts/src/Metamaps.Backbone.js index dd9d5cfb..f8c89493 100644 --- a/app/assets/javascripts/src/Metamaps.Backbone.js +++ b/app/assets/javascripts/src/Metamaps.Backbone.js @@ -126,6 +126,9 @@ Metamaps.Backbone.MapsCollection = Backbone.Collection.extend({ } }); } + else { + self.trigger('successOnFetch'); + } } }); diff --git a/app/assets/javascripts/src/Metamaps.GlobalUI.js b/app/assets/javascripts/src/Metamaps.GlobalUI.js index 5a3e1b21..1d8745ff 100644 --- a/app/assets/javascripts/src/Metamaps.GlobalUI.js +++ b/app/assets/javascripts/src/Metamaps.GlobalUI.js @@ -249,6 +249,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); diff --git a/app/assets/javascripts/src/Metamaps.Router.js b/app/assets/javascripts/src/Metamaps.Router.js index b8df146a..fdb07178 100644 --- a/app/assets/javascripts/src/Metamaps.Router.js +++ b/app/assets/javascripts/src/Metamaps.Router.js @@ -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'; diff --git a/app/assets/javascripts/src/Metamaps.Views.js b/app/assets/javascripts/src/Metamaps.Views.js index cb399c62..3d00991e 100644 --- a/app/assets/javascripts/src/Metamaps.Views.js +++ b/app/assets/javascripts/src/Metamaps.Views.js @@ -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); }, diff --git a/app/assets/javascripts/src/Metamaps.js b/app/assets/javascripts/src/Metamaps.js index 41765a3f..c471314e 100644 --- a/app/assets/javascripts/src/Metamaps.js +++ b/app/assets/javascripts/src/Metamaps.js @@ -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 diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css index 61b08cc1..504b83cb 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.css @@ -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%; diff --git a/app/views/maps/_mapinfobox.html.erb b/app/views/maps/_mapinfobox.html.erb index a9536774..c628e084 100644 --- a/app/views/maps/_mapinfobox.html.erb +++ b/app/views/maps/_mapinfobox.html.erb @@ -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 #%> -
<%= @map && @map.authorize_to_edit(user) ? " canEdit" : "" %>"> +
+ <%= @map && @map.authorize_to_edit(user) ? " canEdit" : "" %> + <%= @map && @map.permission != 'private' ? " shareable" : "" %>"> <% if @map %>
<%= best_in_place @map, :name, :type => :textarea, :activator => "#mapInfoName", :classes => 'best_in_place_name' %>