From 5510cb2e99f71b2e4f34c01f05200a7fb4b29ef8 Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Sun, 7 Aug 2016 15:34:30 +0800 Subject: [PATCH] enable removal of topics from topic view - fixes #467 --- .../javascripts/src/Metamaps.Control.js | 13 +++++++++++-- app/assets/javascripts/src/Metamaps.JIT.js | 19 +++++++------------ app/assets/javascripts/src/Metamaps.Map.js | 2 ++ 3 files changed, 20 insertions(+), 14 deletions(-) diff --git a/app/assets/javascripts/src/Metamaps.Control.js b/app/assets/javascripts/src/Metamaps.Control.js index 4db7f82b..a6058ac2 100644 --- a/app/assets/javascripts/src/Metamaps.Control.js +++ b/app/assets/javascripts/src/Metamaps.Control.js @@ -111,6 +111,14 @@ Metamaps.Control = { } }, removeSelectedNodes: function () { // refers to removing topics permanently from a map + if (Metamaps.Active.Topic) { + // hideNode will handle synapses as well + _.each(Metamaps.Selected.Nodes, function(node) { + Metamaps.Control.hideNode(node.id) + Metamaps.Topics.remove(node.id) + }) + return + } if (!Metamaps.Active.Map) return var l = Metamaps.Selected.Nodes.length, @@ -285,12 +293,13 @@ Metamaps.Control = { } }, removeSelectedEdges: function () { + // Topic view is handled by removeSelectedNodes + if (!Metamaps.Active.Map) return + var l = Metamaps.Selected.Edges.length, i, edge - if (!Metamaps.Active.Map) return - var authorized = Metamaps.Active.Map.authorizeToEdit(Metamaps.Active.Mapper) if (!authorized) { diff --git a/app/assets/javascripts/src/Metamaps.JIT.js b/app/assets/javascripts/src/Metamaps.JIT.js index 01b321f7..3aaf0ceb 100644 --- a/app/assets/javascripts/src/Metamaps.JIT.js +++ b/app/assets/javascripts/src/Metamaps.JIT.js @@ -1313,6 +1313,7 @@ Metamaps.JIT = { if (Metamaps.Active.Map) menustring += '
  • Hide until refresh
    Ctrl+H
  • ' if (Metamaps.Active.Map && Metamaps.Active.Mapper) menustring += '
  • Remove from map
    Ctrl+M
  • ' + if (Metamaps.Active.Topic) menustring += '
  • Remove from view
    Ctrl+M
  • ' if (Metamaps.Active.Map && Metamaps.Active.Mapper) menustring += '
  • Delete
    Ctrl+D
  • ' if (Metamaps.Active.Topic) { @@ -1397,7 +1398,7 @@ Metamaps.JIT = { } // remove the selected things from the map - if (authorized) { + if (Metamaps.Active.Topic || authorized) { $('.rc-remove').click(function () { $('.rightclickmenu').remove() Metamaps.Control.removeSelectedEdges() @@ -1440,11 +1441,11 @@ Metamaps.JIT = { }) // fetch relatives - var fetched = false + var fetch_sent = false $('.rc-siblings').hover(function () { - if (!fetched) { + if (!fetch_sent) { Metamaps.JIT.populateRightClickSiblings(node) - fetched = true + fetch_sent = true } }) $('.rc-siblings .fetchAll').click(function () { @@ -1457,13 +1458,6 @@ Metamaps.JIT = { var self = Metamaps.JIT // depending on how many topics are selected, do different things - /*if (Metamaps.Selected.Nodes.length > 1) { - // we don't bother filling the submenu with - // specific numbers, because there are too many topics - // selected to find those numbers - $('#loadingSiblings').remove() - return - }*/ var topic = node.getData('topic') @@ -1494,7 +1488,7 @@ Metamaps.JIT = { } $.ajax({ - type: 'Get', + type: 'GET', url: '/topics/' + topic.id + '/relative_numbers.json?network=' + topics_string, success: successCallback, error: function () {} @@ -1567,6 +1561,7 @@ Metamaps.JIT = { if (Metamaps.Active.Map) menustring += '
  • Hide until refresh
    Ctrl+H
  • ' if (Metamaps.Active.Map && Metamaps.Active.Mapper) menustring += '
  • Remove from map
    Ctrl+M
  • ' + if (Metamaps.Active.Topic) menustring += '
  • Remove from view
    Ctrl+M
  • ' if (Metamaps.Active.Map && Metamaps.Active.Mapper) menustring += '
  • Delete
    Ctrl+D
  • ' if (Metamaps.Active.Map && Metamaps.Active.Mapper) menustring += '
  • ' diff --git a/app/assets/javascripts/src/Metamaps.Map.js b/app/assets/javascripts/src/Metamaps.Map.js index 34374614..ec3b946f 100644 --- a/app/assets/javascripts/src/Metamaps.Map.js +++ b/app/assets/javascripts/src/Metamaps.Map.js @@ -673,6 +673,8 @@ Metamaps.Map.InfoBox = { return string }, updateNumbers: function () { + if (!Metamaps.Active.Map) return + var self = Metamaps.Map.InfoBox var mapper = Metamaps.Active.Mapper var relevantPeople = Metamaps.Active.Map.get('permission') === 'commons' ? Metamaps.Mappers : Metamaps.Collaborators