diff --git a/frontend/src/Metamaps/DataModel/Map.js b/frontend/src/Metamaps/DataModel/Map.js index b64f9f89..c2dcbb8a 100644 --- a/frontend/src/Metamaps/DataModel/Map.js +++ b/frontend/src/Metamaps/DataModel/Map.js @@ -4,8 +4,7 @@ import _ from 'lodash' import Backbone from 'backbone' try { Backbone.$ = window.$ } catch (err) {} -import Active from '../Active' -import InfoBox from '../Map/InfoBox' +//import InfoBox from '../Map/InfoBox' import Mapper from '../Mapper' const Map = Backbone.Model.extend({ diff --git a/frontend/src/Metamaps/DataModel/Mapping.js b/frontend/src/Metamaps/DataModel/Mapping.js index 2cd2b0b8..4a8d3b38 100644 --- a/frontend/src/Metamaps/DataModel/Mapping.js +++ b/frontend/src/Metamaps/DataModel/Mapping.js @@ -2,10 +2,10 @@ import _ from 'lodash' import Backbone from 'backbone' try { Backbone.$ = window.$ } catch (err) {} -import Active from '../Active' +/*import Active from '../Active' import Map from '../Map' import Synapse from '../Synapse' -import Topic from '../Topic' +import Topic from '../Topic'*/ const Mapping = Backbone.Model.extend({ urlRoot: '/mappings', diff --git a/frontend/src/Metamaps/DataModel/Synapse.js b/frontend/src/Metamaps/DataModel/Synapse.js index d090d1ba..b244e3ae 100644 --- a/frontend/src/Metamaps/DataModel/Synapse.js +++ b/frontend/src/Metamaps/DataModel/Synapse.js @@ -3,10 +3,11 @@ import outdent from 'outdent' import Backbone from 'backbone' try { Backbone.$ = window.$ } catch (err) {} +/* import Active from '../Active' import Filter from '../Filter' import SynapseCard from '../SynapseCard' -import Visualize from '../Visualize' +import Visualize from '../Map/Visualize'*/ import DataModel from './index' diff --git a/frontend/src/Metamaps/DataModel/Topic.js b/frontend/src/Metamaps/DataModel/Topic.js index 10acc5b1..d081ef7f 100644 --- a/frontend/src/Metamaps/DataModel/Topic.js +++ b/frontend/src/Metamaps/DataModel/Topic.js @@ -2,10 +2,10 @@ import _ from 'lodash' import Backbone from 'backbone' try { Backbone.$ = window.$ } catch (err) {} -import Active from '../Active' -import Filter from '../Filter' -import TopicCard from '../Views/TopicCard' -import Visualize from '../Visualize' +import Active from '../Map/Active' +import Filter from '../Map/Filter' +import TopicCard from '../Map/TopicCard' +import Visualize from '../Map/Visualize' import DataModel from './index' diff --git a/frontend/src/Metamaps/GlobalUI/CreateMap.js b/frontend/src/Metamaps/GlobalUI/CreateMap.js index c0c2868b..e3a03048 100644 --- a/frontend/src/Metamaps/GlobalUI/CreateMap.js +++ b/frontend/src/Metamaps/GlobalUI/CreateMap.js @@ -2,7 +2,7 @@ import outdent from 'outdent' -import Active from '../Active' +//import Active from '../Active' import DataModel from '../DataModel' import DataModelMap from '../DataModel/Map' import GlobalUI from './index' diff --git a/frontend/src/Metamaps/GlobalUI/ImportDialog.js b/frontend/src/Metamaps/GlobalUI/ImportDialog.js index 63c47491..2f59bdb0 100644 --- a/frontend/src/Metamaps/GlobalUI/ImportDialog.js +++ b/frontend/src/Metamaps/GlobalUI/ImportDialog.js @@ -6,7 +6,7 @@ import outdent from 'outdent' import ImportDialogBox from '../../components/MapView/ImportDialogBox' -import PasteInput from '../PasteInput' +import PasteInput from '../Map/PasteInput' import Map from '../Map' const ImportDialog = { diff --git a/frontend/src/Metamaps/GlobalUI/ReactApp.js b/frontend/src/Metamaps/GlobalUI/ReactApp.js index cb99757f..4ab4d110 100644 --- a/frontend/src/Metamaps/GlobalUI/ReactApp.js +++ b/frontend/src/Metamaps/GlobalUI/ReactApp.js @@ -10,7 +10,7 @@ import ImportDialog from './ImportDialog' import Mapper from '../DataModel/Mapper' import ExploreMaps from '../ExploreMaps' import { mapControl } from '../Map' -import { topicControl } from '../Topic' +//import { topicControl } from '../Topic' import makeRoutes from '../../components/makeRoutes' let routes @@ -193,7 +193,7 @@ const ReactApp = { participants: [], messages: [] } - const { ChatView, Realtime } = self.openMap + const { ChatView, Realtime } = self.openMap return { unreadMessages: ChatView.unreadMessages, conversationLive: ChatView.conversationLive, @@ -217,7 +217,7 @@ const ReactApp = { getFilterProps: function() { const self = ReactApp if (!self.openMap) return {} - const { Filter } = self.openMap + const { Filter } = self.openMap return { filterData: Filter.dataForPresentation, allForFiltering: Filter.filters, diff --git a/frontend/src/Metamaps/GlobalUI/Search.js b/frontend/src/Metamaps/GlobalUI/Search.js index 7e28906c..45869f96 100644 --- a/frontend/src/Metamaps/GlobalUI/Search.js +++ b/frontend/src/Metamaps/GlobalUI/Search.js @@ -1,8 +1,8 @@ -/* global $, Hogan, Bloodhound, CanvasLoader */ +ReactApp.currentUserReactApp.currentUser/* global $, Hogan, Bloodhound, CanvasLoader */ import { browserHistory } from 'react-router' -import Active from '../Active' +import ReactApp from './ReactApp' const Search = { locked: false, @@ -41,8 +41,8 @@ const Search = { startTypeahead: function() { var self = Search - var mapheader = Active.Mapper ? '

Maps

' : '

Maps

' - var topicheader = Active.Mapper ? '

Topics

' : '

Topics

' + var mapheader = ReactApp.currentUser ? '

Maps

' : '

Maps

' + var topicheader = ReactApp.currentUser ? '

Topics

' : '

Topics

' var mapperheader = '

Mappers

' var topics = { @@ -71,8 +71,8 @@ const Search = { url: '/search/topics', prepare: function(query, settings) { settings.url += '?term=' + query - if (Active.Mapper && self.limitTopicsToMe) { - settings.url += '&user=' + Active.Mapper.id.toString() + if (ReactApp.currentUser && self.limitTopicsToMe) { + settings.url += '&user=' + ReactApp.currentUser.id.toString() } return settings } @@ -104,8 +104,8 @@ const Search = { url: '/search/maps', prepare: function(query, settings) { settings.url += '?term=' + query - if (Active.Mapper && self.limitMapsToMe) { - settings.url += '&user=' + Active.Mapper.id.toString() + if (ReactApp.currentUser && self.limitMapsToMe) { + settings.url += '&user=' + ReactApp.currentUser.id.toString() } return settings } diff --git a/frontend/src/Metamaps/GlobalUI/index.js b/frontend/src/Metamaps/GlobalUI/index.js index b2dd6654..af1c7816 100644 --- a/frontend/src/Metamaps/GlobalUI/index.js +++ b/frontend/src/Metamaps/GlobalUI/index.js @@ -2,8 +2,6 @@ import clipboard from 'clipboard-js' -import Create from '../Create' - import ReactApp from './ReactApp' import Search from './Search' import CreateMap from './CreateMap' @@ -67,7 +65,7 @@ const GlobalUI = { }, 200) if (which === 'switchMetacodes') { - Create.isSwitchingSet = true + ReactApp.openMap && (ReactApp.openMap.Create.isSwitchingSet = true) } }, @@ -91,8 +89,8 @@ const GlobalUI = { if (self.lightbox === 'forkmap') GlobalUI.CreateMap.reset('fork_map') if (self.lightbox === 'newmap') GlobalUI.CreateMap.reset('new_map') - if (Create && Create.isSwitchingSet) { - Create.cancelMetacodeSetSwitch() + if (ReactApp.openMap && ReactApp.openMap.Create.isSwitchingSet) { + ReactApp.openMap.Create.cancelMetacodeSetSwitch() } self.lightbox = null }, diff --git a/frontend/src/Metamaps/Map/Active.js b/frontend/src/Metamaps/Map/Active.js index 7c4a49e5..96db88bc 100644 --- a/frontend/src/Metamaps/Map/Active.js +++ b/frontend/src/Metamaps/Map/Active.js @@ -1,8 +1,8 @@ -const Active = (map = null, mapper = null, topic = null) => { +const Active = () => { return { - Map: map, - Mapper: mapper, - Topic: topic + Map: null, + Mapper: null, + Topic: null } } diff --git a/frontend/src/Metamaps/Map/Cable.js b/frontend/src/Metamaps/Map/Cable.js index 38a94ec8..ef8cd58f 100644 --- a/frontend/src/Metamaps/Map/Cable.js +++ b/frontend/src/Metamaps/Map/Cable.js @@ -2,9 +2,9 @@ import { indexOf } from 'lodash' -import Mapper from './Mapper' +import Mapper from '../Mapper' -const Cable = ({Active, Control, DataModel, Map, Synapse, Topic, ChatView, Visualize}) => { +const Cable = (map) => { const toExport = { subscribeToMap: id => { let self = toExport @@ -25,12 +25,12 @@ const toExport = { // containing only the information we need to determine whether the active mapper // can view this synapse and the two topics it connects, // then if we determine it can, we make a call for the full model - const m = Active.Mapper + const m = map.Active.Mapper const s = new DataModel.Synapse(event.synapse) const t1 = new DataModel.Topic(event.topic1) const t2 = new DataModel.Topic(event.topic2) - if (t1.authorizeToShow(m) && t2.authorizeToShow(m) && s.authorizeToShow(m) && !DataModel.Synapses.get(event.synapse.id)) { + if (t1.authorizeToShow(m) && t2.authorizeToShow(m) && s.authorizeToShow(m) && !map.DataModel.Synapses.get(event.synapse.id)) { // refactor the heck outta this, its adding wicked wait time var topic1, topic2, node1, node2, synapse, mapping, cancel, mapper @@ -41,24 +41,24 @@ const toExport = { topic2 = synapse.getTopic2() node2 = topic2.get('node') - Synapse.renderSynapse(mapping, synapse, node1, node2, false) + map.Synapse.renderSynapse(mapping, synapse, node1, node2, false) } else if (!cancel) { setTimeout(waitThenRenderSynapse, 10) } } - mapper = DataModel.Mappers.get(event.synapse.user_id) + mapper = map.DataModel.Mappers.get(event.synapse.user_id) if (mapper === undefined) { Mapper.get(event.synapse.user_id, function(m) { - DataModel.Mappers.add(m) + map.DataModel.Mappers.add(m) mapper = m }) } $.ajax({ url: '/synapses/' + event.synapse.id + '.json', success: function(response) { - DataModel.Synapses.add(response) - synapse = DataModel.Synapses.get(response.id) + map.DataModel.Synapses.add(response) + synapse = map.DataModel.Synapses.get(response.id) }, error: function() { cancel = true @@ -67,8 +67,8 @@ const toExport = { $.ajax({ url: '/mappings/' + event.mapping_id + '.json', success: function(response) { - DataModel.Mappings.add(response) - mapping = DataModel.Mappings.get(response.id) + map.DataModel.Mappings.add(response) + mapping = map.DataModel.Mappings.get(response.id) }, error: function() { cancel = true @@ -79,7 +79,7 @@ const toExport = { }, synapseUpdated: event => { // TODO: handle case where permission changed - var synapse = DataModel.Synapses.get(event.id) + var synapse = map.DataModel.Synapses.get(event.id) if (synapse) { // edge reset necessary because fetch causes model reset var edge = synapse.get('edge') @@ -92,12 +92,12 @@ const toExport = { } }, synapseRemoved: event => { - var synapse = DataModel.Synapses.get(event.id) + var synapse = map.DataModel.Synapses.get(event.id) if (synapse) { var edge = synapse.get('edge') var mapping = synapse.getMapping() if (edge.getData('mappings').length - 1 === 0) { - Control.hideEdge(edge) + map.Control.hideEdge(edge) } var index = indexOf(edge.getData('synapses'), synapse) @@ -106,41 +106,41 @@ const toExport = { if (edge.getData('displayIndex')) { delete edge.data.$displayIndex } - DataModel.Synapses.remove(synapse) - DataModel.Mappings.remove(mapping) + map.DataModel.Synapses.remove(synapse) + map.DataModel.Mappings.remove(mapping) } }, topicAdded: event => { - const m = Active.Mapper + const m = map.Active.Mapper // we receive a contentless model from the server // containing only the information we need to determine whether the active mapper // can view this topic, then if we determine it can, we make a call for the full model const t = new DataModel.Topic(event.topic) - if (t.authorizeToShow(m) && !DataModel.Topics.get(event.topic.id)) { + if (t.authorizeToShow(m) && !map.DataModel.Topics.get(event.topic.id)) { // refactor the heck outta this, its adding wicked wait time var topic, mapping, mapper, cancel const waitThenRenderTopic = () => { if (topic && mapping && mapper) { - Topic.renderTopic(mapping, topic, false, false) + map.Topic.renderTopic(mapping, topic, false, false) } else if (!cancel) { setTimeout(waitThenRenderTopic, 10) } } - mapper = DataModel.Mappers.get(event.topic.user_id) + mapper = map.DataModel.Mappers.get(event.topic.user_id) if (mapper === undefined) { Mapper.get(event.topic.user_id, function(m) { - DataModel.Mappers.add(m) + map.DataModel.Mappers.add(m) mapper = m }) } $.ajax({ url: '/topics/' + event.topic.id + '.json', success: function(response) { - DataModel.Topics.add(response) - topic = DataModel.Topics.get(response.id) + map.DataModel.Topics.add(response) + topic = map.DataModel.Topics.get(response.id) }, error: function() { cancel = true @@ -149,8 +149,8 @@ const toExport = { $.ajax({ url: '/mappings/' + event.mapping_id + '.json', success: function(response) { - DataModel.Mappings.add(response) - mapping = DataModel.Mappings.get(response.id) + map.DataModel.Mappings.add(response) + mapping = map.DataModel.Mappings.get(response.id) }, error: function() { cancel = true @@ -161,7 +161,7 @@ const toExport = { }, topicUpdated: event => { // TODO: handle case where permission changed - var topic = DataModel.Topics.get(event.id) + var topic = map.DataModel.Topics.get(event.id) if (topic) { var node = topic.get('node') topic.fetch({ @@ -174,38 +174,38 @@ const toExport = { }, topicMoved: event => { var topic, node, mapping - if (Active.Map) { - topic = DataModel.Topics.get(event.id) - mapping = DataModel.Mappings.get(event.mapping_id) + if (map.Active.Map) { + topic = map.DataModel.Topics.get(event.id) + mapping = map.DataModel.Mappings.get(event.mapping_id) mapping.set('xloc', event.x) mapping.set('yloc', event.y) if (topic) node = topic.get('node') if (node) node.pos.setc(event.x, event.y) - Visualize.mGraph.plot() + map.Visualize.mGraph.plot() } }, topicRemoved: event => { - var topic = DataModel.Topics.get(event.id) + var topic = map.DataModel.Topics.get(event.id) if (topic) { var node = topic.get('node') var mapping = topic.getMapping() - Control.hideNode(node.id) - DataModel.Topics.remove(topic) - DataModel.Mappings.remove(mapping) + map.Control.hideNode(node.id) + map.DataModel.Topics.remove(topic) + map.DataModel.Mappings.remove(mapping) } }, messageCreated: event => { - if (Active.Mapper && Active.Mapper.id === event.message.user_id) return - ChatView.addMessages(new DataModel.MessageCollection(event.message)) + if (map.Active.Mapper && map.Active.Mapper.id === event.message.user_id) return + map.ChatView.addMessages(new DataModel.MessageCollection(event.message)) }, mapUpdated: event => { - var map = Active.Map - var couldEditBefore = map.authorizeToEdit(Active.Mapper) + var map = map.Active.Map + var couldEditBefore = map.authorizeToEdit(map.Active.Mapper) var idBefore = map.id map.fetch({ success: function(model, response) { var idNow = model.id - var canEditNow = model.authorizeToEdit(Active.Mapper) + var canEditNow = model.authorizeToEdit(map.Active.Mapper) if (idNow !== idBefore) { Map.leavePrivateMap() // this means the map has been changed to private } else if (couldEditBefore && !canEditNow) { diff --git a/frontend/src/Metamaps/Map/Views/ChatView.js b/frontend/src/Metamaps/Map/ChatView.js similarity index 97% rename from frontend/src/Metamaps/Map/Views/ChatView.js rename to frontend/src/Metamaps/Map/ChatView.js index 3405bb67..7e4043b3 100644 --- a/frontend/src/Metamaps/Map/Views/ChatView.js +++ b/frontend/src/Metamaps/Map/ChatView.js @@ -5,7 +5,7 @@ import { Howl } from 'howler' import ReactApp from '../GlobalUI/ReactApp' -const ChatView = ({Active, DataModel}) => { +const ChatView = (map) => { const toExport = { isOpen: false, unreadMessages: 0, @@ -39,7 +39,7 @@ const toExport = { self.render() }, render: () => { - if (!Active.Map) return + if (!map.Active.Map) return const self = toExport ReactApp.render() }, @@ -127,7 +127,7 @@ const toExport = { if (toExport.alertSound) toExport.sound.play('sendchat') var m = new DataModel.Message({ message: message.message, - resource_id: Active.Map.id, + resource_id: map.Active.Map.id, resource_type: 'Map' }) m.save(null, { diff --git a/frontend/src/Metamaps/Map/Control.js b/frontend/src/Metamaps/Map/Control.js index c82dae11..1ac66b61 100644 --- a/frontend/src/Metamaps/Map/Control.js +++ b/frontend/src/Metamaps/Map/Control.js @@ -1,59 +1,59 @@ import _ from 'lodash' import outdent from 'outdent' -import GlobalUI from './GlobalUI' -import Settings from './Settings' +import GlobalUI from '../GlobalUI' +import Settings from '../Settings' -const Control = ({Active, DataModel, Filter, Mouse, Selected, Visualize}) => { +const Control = (map) => { return { selectNode: function(node, e) { var filtered = node.getData('alpha') === 0 - if (filtered || Selected.Nodes.indexOf(node) !== -1) return + if (filtered || map.Selected.Nodes.indexOf(node) !== -1) return node.selected = true node.setData('dim', 30, 'current') - Selected.Nodes.push(node) + map.Selected.Nodes.push(node) }, selectNeighbors: function() { - if (Selected.Nodes.length > 0) { + if (map.Selected.Nodes.length > 0) { //For each selected node, select all connected node and the synapses too - Selected.Nodes.forEach((item) => { - if (Visualize.mGraph.graph.getNode(item.id).adjacencies) { - for (const adjID in Visualize.mGraph.graph.getNode(item.id).adjacencies) { - Control.selectNode(Visualize.mGraph.graph.getNode(adjID)) - Control.selectEdge(Visualize.mGraph.graph.getNode(item.id).adjacencies[adjID]) + map.Selected.Nodes.forEach((item) => { + if (map.Visualize.mGraph.graph.getNode(item.id).adjacencies) { + for (const adjID in map.Visualize.mGraph.graph.getNode(item.id).adjacencies) { + map.Control.selectNode(map.Visualize.mGraph.graph.getNode(adjID)) + map.Control.selectEdge(map.Visualize.mGraph.graph.getNode(item.id).adjacencies[adjID]) } } }) - Visualize.mGraph.plot() + map.Visualize.mGraph.plot() } }, deselectAllNodes: function() { - var l = Selected.Nodes.length + var l = map.Selected.Nodes.length for (var i = l - 1; i >= 0; i -= 1) { - var node = Selected.Nodes[i] - Control.deselectNode(node) + var node = map.Selected.Nodes[i] + map.Control.deselectNode(node) } - Visualize.mGraph.plot() + map.Visualize.mGraph.plot() }, deselectNode: function(node) { delete node.selected node.setData('dim', 25, 'current') // remove the node - Selected.Nodes.splice( - Selected.Nodes.indexOf(node), 1) + map.Selected.Nodes.splice( + map.Selected.Nodes.indexOf(node), 1) }, deleteSelected: function() { - if (!Active.Map) return + if (!map.Active.Map) return - var n = Selected.Nodes.length - var e = Selected.Edges.length + var n = map.Selected.Nodes.length + var e = map.Selected.Edges.length var ntext = n === 1 ? '1 topic' : n + ' topics' var etext = e === 1 ? '1 synapse' : e + ' synapses' - var authorized = Active.Map.authorizeToEdit(Active.Mapper) + var authorized = map.Active.Map.authorizeToEdit(map.Active.Mapper) if (!authorized) { GlobalUI.notifyUser('Cannot edit Public map.') @@ -65,162 +65,162 @@ const Control = ({Active, DataModel, Filter, Mouse, Selected, Visualize}) => { to permanently delete them all? This will remove them from all maps they appear on.`) if (r) { - Control.deleteSelectedEdges() - Control.deleteSelectedNodes() + map.Control.deleteSelectedEdges() + map.Control.deleteSelectedNodes() } - if (DataModel.Topics.length === 0) { + if (map.DataModel.Topics.length === 0) { Map.setHasLearnedTopicCreation(false) } }, deleteSelectedNodes: function() { // refers to deleting topics permanently - if (!Active.Map) return + if (!map.Active.Map) return - var authorized = Active.Map.authorizeToEdit(Active.Mapper) + var authorized = map.Active.Map.authorizeToEdit(map.Active.Mapper) if (!authorized) { GlobalUI.notifyUser('Cannot edit Public map.') return } - var l = Selected.Nodes.length + var l = map.Selected.Nodes.length for (var i = l - 1; i >= 0; i -= 1) { - var node = Selected.Nodes[i] - Control.deleteNode(node.id) + var node = map.Selected.Nodes[i] + map.Control.deleteNode(node.id) } }, deleteNode: function(nodeid) { // refers to deleting topics permanently - if (!Active.Map) return + if (!map.Active.Map) return - var authorized = Active.Map.authorizeToEdit(Active.Mapper) + var authorized = map.Active.Map.authorizeToEdit(map.Active.Mapper) if (!authorized) { GlobalUI.notifyUser('Cannot edit Public map.') return } - var node = Visualize.mGraph.graph.getNode(nodeid) + var node = map.Visualize.mGraph.graph.getNode(nodeid) var topic = node.getData('topic') - var permToDelete = Active.Mapper.id === topic.get('user_id') || Active.Mapper.get('admin') + var permToDelete = map.Active.Mapper.id === topic.get('user_id') || map.Active.Mapper.get('admin') if (permToDelete) { var mapping = node.getData('mapping') topic.destroy() - DataModel.Mappings.remove(mapping) - Control.hideNode(nodeid) + map.DataModel.Mappings.remove(mapping) + map.Control.hideNode(nodeid) } else { GlobalUI.notifyUser('Only topics you created can be deleted') } }, removeSelectedNodes: function() { // refers to removing topics permanently from a map - if (Active.Topic) { + if (map.Active.Topic) { // hideNode will handle synapses as well - var nodeids = _.map(Selected.Nodes, function(node) { + var nodeids = _.map(map.Selected.Nodes, function(node) { return node.id }) _.each(nodeids, function(nodeid) { - if (Active.Topic.id !== nodeid) { - DataModel.Topics.remove(nodeid) - Control.hideNode(nodeid) + if (map.Active.Topic.id !== nodeid) { + map.DataModel.Topics.remove(nodeid) + map.Control.hideNode(nodeid) } }) return } - if (!Active.Map) return + if (!map.Active.Map) return - const l = Selected.Nodes.length - const authorized = Active.Map.authorizeToEdit(Active.Mapper) + const l = map.Selected.Nodes.length + const authorized = map.Active.Map.authorizeToEdit(map.Active.Mapper) if (!authorized) { GlobalUI.notifyUser('Cannot edit this map.') return } - if (Active.Mapper.get('follow_map_on_contributed')) { - Active.Mapper.followMap(Active.Map.id) + if (map.Active.Mapper.get('follow_map_on_contributed')) { + map.Active.Mapper.followMap(map.Active.Map.id) } for (let i = l - 1; i >= 0; i -= 1) { - const node = Selected.Nodes[i] - Control.removeNode(node.id) + const node = map.Selected.Nodes[i] + map.Control.removeNode(node.id) } }, removeNode: function(nodeid) { // refers to removing topics permanently from a map - if (!Active.Map) return + if (!map.Active.Map) return - var authorized = Active.Map.authorizeToEdit(Active.Mapper) - var node = Visualize.mGraph.graph.getNode(nodeid) + var authorized = map.Active.Map.authorizeToEdit(map.Active.Mapper) + var node = map.Visualize.mGraph.graph.getNode(nodeid) if (!authorized) { GlobalUI.notifyUser('Cannot edit this map.') return } - if (Active.Mapper.get('follow_map_on_contributed')) { - Active.Mapper.followMap(Active.Map.id) + if (map.Active.Mapper.get('follow_map_on_contributed')) { + map.Active.Mapper.followMap(map.Active.Map.id) } var topic = node.getData('topic') var mapping = node.getData('mapping') mapping.destroy() - DataModel.Topics.remove(topic) - Control.hideNode(nodeid) + map.DataModel.Topics.remove(topic) + map.Control.hideNode(nodeid) }, hideSelectedNodes: function() { - const l = Selected.Nodes.length + const l = map.Selected.Nodes.length for (let i = l - 1; i >= 0; i -= 1) { - const node = Selected.Nodes[i] - Control.hideNode(node.id) + const node = map.Selected.Nodes[i] + map.Control.hideNode(node.id) } }, hideNode: function(nodeid) { - var node = Visualize.mGraph.graph.getNode(nodeid) - var graph = Visualize.mGraph + var node = map.Visualize.mGraph.graph.getNode(nodeid) + var graph = map.Visualize.mGraph - Control.deselectNode(node) + map.Control.deselectNode(node) node.setData('alpha', 0, 'end') node.eachAdjacency(function(adj) { adj.setData('alpha', 0, 'end') }) - Visualize.mGraph.fx.animate({ + map.Visualize.mGraph.fx.animate({ modes: ['node-property:alpha', 'edge-property:alpha' ], duration: 500 }) setTimeout(function() { - if (nodeid === Visualize.mGraph.root) { // && Visualize.type === "RGraph" + if (nodeid === map.Visualize.mGraph.root) { // && map.Visualize.type === "RGraph" var newroot = _.find(graph.graph.nodes, function(n) { return n.id !== nodeid }) graph.root = newroot ? newroot.id : null } - Visualize.mGraph.graph.removeNode(nodeid) + map.Visualize.mGraph.graph.removeNode(nodeid) }, 500) - Filter.checkMetacodes() - Filter.checkMappers() + map.Filter.checkMetacodes() + map.Filter.checkMappers() }, selectEdge: function(edge) { var filtered = edge.getData('alpha') === 0 // don't select if the edge is filtered - if (filtered || Selected.Edges.indexOf(edge) !== -1) return + if (filtered || map.Selected.Edges.indexOf(edge) !== -1) return - var width = Mouse.edgeHoveringOver === edge ? 4 : 2 + var width = map.Mouse.edgeHoveringOver === edge ? 4 : 2 edge.setDataset('current', { showDesc: true, lineWidth: width, color: Settings.colors.synapses.selected }) - Visualize.mGraph.plot() + map.Visualize.mGraph.plot() - Selected.Edges.push(edge) + map.Selected.Edges.push(edge) }, deselectAllEdges: function() { - var l = Selected.Edges.length + var l = map.Selected.Edges.length for (var i = l - 1; i >= 0; i -= 1) { - var edge = Selected.Edges[i] - Control.deselectEdge(edge) + var edge = map.Selected.Edges[i] + map.Control.deselectEdge(edge) } - Visualize.mGraph.plot() + map.Visualize.mGraph.plot() }, deselectEdge: function(edge) { edge.setData('showDesc', false, 'current') @@ -230,39 +230,39 @@ const Control = ({Active, DataModel, Filter, Mouse, Selected, Visualize}) => { color: Settings.colors.synapses.normal }) - if (Mouse.edgeHoveringOver === edge) { + if (map.Mouse.edgeHoveringOver === edge) { edge.setDataset('current', { showDesc: true, lineWidth: 4 }) } - Visualize.mGraph.plot() + map.Visualize.mGraph.plot() // remove the edge - Selected.Edges.splice( - Selected.Edges.indexOf(edge), 1) + map.Selected.Edges.splice( + map.Selected.Edges.indexOf(edge), 1) }, deleteSelectedEdges: function() { // refers to deleting topics permanently - if (!Active.Map) return + if (!map.Active.Map) return - var authorized = Active.Map.authorizeToEdit(Active.Mapper) + var authorized = map.Active.Map.authorizeToEdit(map.Active.Mapper) if (!authorized) { GlobalUI.notifyUser('Cannot edit Public map.') return } - const l = Selected.Edges.length + const l = map.Selected.Edges.length for (let i = l - 1; i >= 0; i -= 1) { - const edge = Selected.Edges[i] - Control.deleteEdge(edge) + const edge = map.Selected.Edges[i] + map.Control.deleteEdge(edge) } }, deleteEdge: function(edge) { - if (!Active.Map) return + if (!map.Active.Map) return - var authorized = Active.Map.authorizeToEdit(Active.Mapper) + var authorized = map.Active.Map.authorizeToEdit(map.Active.Mapper) if (!authorized) { GlobalUI.notifyUser('Cannot edit Public map.') @@ -274,15 +274,15 @@ const Control = ({Active, DataModel, Filter, Mouse, Selected, Visualize}) => { var synapse = edge.getData('synapses')[index] var mapping = edge.getData('mappings')[index] - var permToDelete = Active.Mapper.id === synapse.get('user_id') || Active.Mapper.get('admin') + var permToDelete = map.Active.Mapper.id === synapse.get('user_id') || map.Active.Mapper.get('admin') if (permToDelete) { if (edge.getData('synapses').length - 1 === 0) { - Control.hideEdge(edge) + map.Control.hideEdge(edge) } synapse.destroy() // the server will destroy the mapping, we just need to remove it here - DataModel.Mappings.remove(mapping) + map.DataModel.Mappings.remove(mapping) edge.getData('mappings').splice(index, 1) edge.getData('synapses').splice(index, 1) if (edge.getData('displayIndex')) { @@ -294,43 +294,43 @@ const Control = ({Active, DataModel, Filter, Mouse, Selected, Visualize}) => { }, removeSelectedEdges: function() { // Topic view is handled by removeSelectedNodes - if (!Active.Map) return + if (!map.Active.Map) return - const l = Selected.Edges.length + const l = map.Selected.Edges.length - var authorized = Active.Map.authorizeToEdit(Active.Mapper) + var authorized = map.Active.Map.authorizeToEdit(map.Active.Mapper) if (!authorized) { GlobalUI.notifyUser('Cannot edit this map.') return } - if (Active.Mapper.get('follow_map_on_contributed')) { - Active.Mapper.followMap(Active.Map.id) + if (map.Active.Mapper.get('follow_map_on_contributed')) { + map.Active.Mapper.followMap(map.Active.Map.id) } for (let i = l - 1; i >= 0; i -= 1) { - const edge = Selected.Edges[i] - Control.removeEdge(edge) + const edge = map.Selected.Edges[i] + map.Control.removeEdge(edge) } - Selected.Edges = [ ] + map.Selected.Edges = [ ] }, removeEdge: function(edge) { - if (!Active.Map) return + if (!map.Active.Map) return - var authorized = Active.Map.authorizeToEdit(Active.Mapper) + var authorized = map.Active.Map.authorizeToEdit(map.Active.Mapper) if (!authorized) { GlobalUI.notifyUser('Cannot edit this map.') return } - if (Active.Mapper.get('follow_map_on_contributed')) { - Active.Mapper.followMap(Active.Map.id) + if (map.Active.Mapper.get('follow_map_on_contributed')) { + map.Active.Mapper.followMap(map.Active.Map.id) } if (edge.getData('mappings').length - 1 === 0) { - Control.hideEdge(edge) + map.Control.hideEdge(edge) } var index = edge.getData('displayIndex') ? edge.getData('displayIndex') : 0 @@ -339,7 +339,7 @@ const Control = ({Active, DataModel, Filter, Mouse, Selected, Visualize}) => { var mapping = edge.getData('mappings')[index] mapping.destroy() - DataModel.Synapses.remove(synapse) + map.DataModel.Synapses.remove(synapse) edge.getData('mappings').splice(index, 1) edge.getData('synapses').splice(index, 1) @@ -348,27 +348,27 @@ const Control = ({Active, DataModel, Filter, Mouse, Selected, Visualize}) => { } }, hideSelectedEdges: function() { - const l = Selected.Edges.length + const l = map.Selected.Edges.length for (let i = l - 1; i >= 0; i -= 1) { - const edge = Selected.Edges[i] - Control.hideEdge(edge) + const edge = map.Selected.Edges[i] + map.Control.hideEdge(edge) } - Selected.Edges = [ ] + map.Selected.Edges = [ ] }, hideEdge: function(edge) { var from = edge.nodeFrom.id var to = edge.nodeTo.id edge.setData('alpha', 0, 'end') - Control.deselectEdge(edge) - Visualize.mGraph.fx.animate({ + map.Control.deselectEdge(edge) + map.Visualize.mGraph.fx.animate({ modes: ['edge-property:alpha'], duration: 500 }) setTimeout(function() { - Visualize.mGraph.graph.removeAdjacence(from, to) + map.Visualize.mGraph.graph.removeAdjacence(from, to) }, 500) - Filter.checkSynapses() - Filter.checkMappers() + map.Filter.checkSynapses() + map.Filter.checkMappers() }, updateSelectedPermissions: function(permission) { var edge, synapse, node, topic @@ -380,12 +380,12 @@ const Control = ({Active, DataModel, Filter, Mouse, Selected, Visualize}) => { var sCount = 0 // change the permission of the selected synapses, if logged in user is the original creator - const edgesLength = Selected.Edges.length + const edgesLength = map.Selected.Edges.length for (let i = edgesLength - 1; i >= 0; i -= 1) { - edge = Selected.Edges[i] + edge = map.Selected.Edges[i] synapse = edge.getData('synapses')[0] - if (synapse.authorizePermissionChange(Active.Mapper)) { + if (synapse.authorizePermissionChange(map.Active.Mapper)) { synapse.save({ permission: permission }) @@ -394,12 +394,12 @@ const Control = ({Active, DataModel, Filter, Mouse, Selected, Visualize}) => { } // change the permission of the selected topics, if logged in user is the original creator - const nodesLength = Selected.Nodes.length + const nodesLength = map.Selected.Nodes.length for (let i = nodesLength - 1; i >= 0; i -= 1) { - node = Selected.Nodes[i] + node = map.Selected.Nodes[i] topic = node.getData('topic') - if (topic.authorizePermissionChange(Active.Mapper)) { + if (topic.authorizePermissionChange(map.Active.Mapper)) { topic.save({ permission: permission }) @@ -424,12 +424,12 @@ const Control = ({Active, DataModel, Filter, Mouse, Selected, Visualize}) => { var nCount = 0 // change the permission of the selected topics, if logged in user is the original creator - var l = Selected.Nodes.length + var l = map.Selected.Nodes.length for (var i = l - 1; i >= 0; i -= 1) { - node = Selected.Nodes[i] + node = map.Selected.Nodes[i] topic = node.getData('topic') - if (topic.authorizeToEdit(Active.Mapper)) { + if (topic.authorizeToEdit(map.Active.Mapper)) { topic.save({ 'metacode_id': metacodeId }) @@ -441,7 +441,7 @@ const Control = ({Active, DataModel, Filter, Mouse, Selected, Visualize}) => { var message = nString + ' you can edit updated to ' + metacode.get('name') GlobalUI.notifyUser(message) - Visualize.mGraph.plot() + map.Visualize.mGraph.plot() } } } diff --git a/frontend/src/Metamaps/Map/Create.js b/frontend/src/Metamaps/Map/Create.js index 11bbb409..c0db24ee 100644 --- a/frontend/src/Metamaps/Map/Create.js +++ b/frontend/src/Metamaps/Map/Create.js @@ -1,8 +1,8 @@ /* global $, Hogan, Bloodhound */ -import GlobalUI from './GlobalUI' +import GlobalUI from '../GlobalUI' -const toExport = ({DataModel, Map, Mouse, Selected, Synapse, Topic, Visualize}) => { +const toExport = (map) => { const toExport = { isSwitchingSet: false, // indicates whether the metacode set switch lightbox is open selectedMetacodeSet: null, @@ -103,8 +103,8 @@ const toExport = { toExport.newSelectedMetacodeNames = [] } else if (custom) { // uses .slice to avoid setting the two arrays to the same actual array - toExport.selectedMetacodes = Create.newSelectedMetacodes.slice(0) - toExport.selectedMetacodeNames = Create.newSelectedMetacodeNames.slice(0) + toExport.selectedMetacodes = map.Create.newSelectedMetacodes.slice(0) + toExport.selectedMetacodeNames = map.Create.newSelectedMetacodeNames.slice(0) codesToSwitchToIds = toExport.selectedMetacodes.slice(0) } @@ -137,7 +137,7 @@ const toExport = { var mdata = { 'metacodes': { - 'value': custom ? toExport.selectedMetacodes.toString() : Create.selectedMetacodeSet + 'value': custom ? toExport.selectedMetacodes.toString() : map.Create.selectedMetacodeSet } } $.ajax({ @@ -276,7 +276,7 @@ const toExport = { $('.pinCarousel').removeClass('isPinned') toExport.newTopic.pinned = false } - if (DataModel.Topics.length === 0) { + if (map.DataModel.Topics.length === 0) { Map.setHasLearnedTopicCreation(false) } toExport.newTopic.beingCreated = false @@ -301,7 +301,7 @@ const toExport = { remote: { url: '/search/synapses?topic1id=%TOPIC1&topic2id=%TOPIC2', prepare: function(query, settings) { - if (Selected.Nodes.length < 2 && toExport.newSynapse.topic1id && self.newSynapse.topic2id) { + if (map.Selected.Nodes.length < 2 && toExport.newSynapse.topic1id && self.newSynapse.topic2id) { settings.url = settings.url.replace('%TOPIC1', toExport.newSynapse.topic1id).replace('%TOPIC2', toExport.newSynapse.topic2id) return settings } else { @@ -353,7 +353,7 @@ const toExport = { $('#synapse_desc').focusout(function() { if (toExport.newSynapse.beingCreated) { - Synapse.createSynapseLocally() + map.Synapse.createSynapseLocally() } }) @@ -361,7 +361,7 @@ const toExport = { const TAB = 9 if (toExport.newSynapse.beingCreated && e.keyCode === TAB) { e.preventDefault() - Synapse.createSynapseLocally() + map.Synapse.createSynapseLocally() } }) @@ -370,7 +370,7 @@ const toExport = { Synapse.getSynapseFromAutocomplete(datum.id) } else { toExport.newSynapse.description = datum.value - Synapse.createSynapseLocally() + map.Synapse.createSynapseLocally() } }) }, @@ -392,8 +392,8 @@ const toExport = { toExport.newTopic.addSynapse = false toExport.newSynapse.topic1id = 0 toExport.newSynapse.topic2id = 0 - Mouse.synapseStartCoordinates = [] - if (Visualize.mGraph) Visualize.mGraph.plot() + map.Mouse.synapseStartCoordinates = [] + if (map.Visualize.mGraph) map.Visualize.mGraph.plot() } } } diff --git a/frontend/src/Metamaps/Map/Filter.js b/frontend/src/Metamaps/Map/Filter.js index c14b552b..9b19d284 100644 --- a/frontend/src/Metamaps/Map/Filter.js +++ b/frontend/src/Metamaps/Map/Filter.js @@ -2,10 +2,10 @@ import _ from 'lodash' -import GlobalUI, { ReactApp } from './GlobalUI' -import Settings from './Settings' +import GlobalUI, { ReactApp } from '../GlobalUI' +import Settings from '../Settings' -const Filter = ({Active, Control, DataModel, Visualize}) => { +const Filter = (map) => { const toExport = { dataForPresentation: { metacodes: {}, @@ -99,7 +99,7 @@ const toExport = { }, checkMappers: function() { var self = toExport - if (Active.Map) { + if (map.Active.Map) { self.updateFilters('Mappings', 'user_id', 'Mappers', 'mappers', 'mapper') } else { // on topic view @@ -160,16 +160,16 @@ const toExport = { var passesMetacode, passesMapper, passesSynapse - var opacityForFilter = Active.Map ? 0 : 0.4 + var opacityForFilter = map.Active.Map ? 0 : 0.4 - DataModel.Topics.each(function(topic) { + map.DataModel.Topics.each(function(topic) { var n = topic.get('node') var metacodeId = topic.get('metacode_id').toString() if (visible.metacodes.indexOf(metacodeId) === -1) passesMetacode = false else passesMetacode = true - if (Active.Map) { + if (map.Active.Map) { // when on a map, // we filter by mapper according to the person who added the // topic or synapse to the map @@ -193,10 +193,10 @@ const toExport = { } } else { if (n) { - Control.deselectNode(n, true) + map.Control.deselectNode(n, true) n.setData('alpha', opacityForFilter, 'end') n.eachAdjacency(function(e) { - Control.deselectEdge(e, true) + map.Control.deselectEdge(e, true) }) } else { console.log(topic) @@ -205,11 +205,11 @@ const toExport = { }) // flag all the edges back to 'untouched' - DataModel.Synapses.each(function(synapse) { + map.DataModel.Synapses.each(function(synapse) { var e = synapse.get('edge') e.setData('touched', false) }) - DataModel.Synapses.each(function(synapse) { + map.DataModel.Synapses.each(function(synapse) { var e = synapse.get('edge') var desc var userId = synapse.get('user_id').toString() @@ -241,7 +241,7 @@ const toExport = { } } - if (Active.Map) { + if (map.Active.Map) { // when on a map, // we filter by mapper according to the person who added the // topic or synapse to the map @@ -255,7 +255,7 @@ const toExport = { e.setData('alpha', 1, 'end') e.setData('color', color, 'end') } else { - Control.deselectEdge(e, true) + map.Control.deselectEdge(e, true) e.setData('alpha', opacityForFilter, 'end') } @@ -266,7 +266,7 @@ const toExport = { }) // run the animation - Visualize.mGraph.fx.animate({ + map.Visualize.mGraph.fx.animate({ modes: ['node-property:alpha', 'edge-property:alpha'], duration: 200 diff --git a/frontend/src/Metamaps/Map/Import.js b/frontend/src/Metamaps/Map/Import.js index b47299a4..579a9c24 100644 --- a/frontend/src/Metamaps/Map/Import.js +++ b/frontend/src/Metamaps/Map/Import.js @@ -3,9 +3,9 @@ import parse from 'csv-parse' import _ from 'lodash' -import GlobalUI from './GlobalUI' +import GlobalUI from '../GlobalUI' -const Import = ({Active, AutoLayout, DataModel, Map, Synapse, Topic}) => { +const Import = (map) => { const toExport = { // note that user is not imported topicWhitelist: [ @@ -213,7 +213,7 @@ const toExport = { parsedTopics.forEach(topic => { let coords = { x: topic.x, y: topic.y } if (!coords.x || !coords.y) { - coords = AutoLayout.getNextCoord({ mappings: DataModel.Mappings }) + coords = map.AutoLayout.getNextCoord({ mappings: map.DataModel.Mappings }) } if (!topic.name && topic.link || @@ -240,10 +240,10 @@ const toExport = { parsedSynapses.forEach(function(synapse) { // only createSynapseWithParameters once both topics are persisted // if there isn't a cidMapping, check by topic name instead - var topic1 = DataModel.Topics.get(self.cidMappings[synapse.topic1]) - if (!topic1) topic1 = DataModel.Topics.findWhere({ name: synapse.topic1 }) - var topic2 = DataModel.Topics.get(self.cidMappings[synapse.topic2]) - if (!topic2) topic2 = DataModel.Topics.findWhere({ name: synapse.topic2 }) + var topic1 = map.DataModel.Topics.get(self.cidMappings[synapse.topic1]) + if (!topic1) topic1 = map.DataModel.Topics.findWhere({ name: synapse.topic1 }) + var topic2 = map.DataModel.Topics.get(self.cidMappings[synapse.topic2]) + if (!topic2) topic2 = map.DataModel.Topics.findWhere({ name: synapse.topic2 }) if (!topic1 || !topic2) { console.error("One of the two topics doesn't exist!") @@ -282,8 +282,8 @@ const toExport = { console.warn("Couldn't find metacode " + metacodeName + ' so used Wildcard instead.') } - const topicPermision = permission || Active.Map.get('permission') - var deferToMapId = permission === topicPermision ? Active.Map.get('id') : null + const topicPermision = permission || map.Active.Map.get('permission') + var deferToMapId = permission === topicPermision ? map.Active.Map.get('id') : null var topic = new DataModel.Topic({ name: name, metacode_id: metacode.id, @@ -292,7 +292,7 @@ const toExport = { desc: desc || '', link: link || '' }) - DataModel.Topics.add(topic) + map.DataModel.Topics.add(topic) if (importId !== null && importId !== undefined) { self.cidMappings[importId] = topic.cid @@ -304,14 +304,14 @@ const toExport = { mappable_id: topic.cid, mappable_type: 'Topic' }) - DataModel.Mappings.add(mapping) + map.DataModel.Mappings.add(mapping) // this function also includes the creation of the topic in the database - Topic.renderTopic(mapping, topic, true, true, { + map.Topic.renderTopic(mapping, topic, true, true, { success: opts.success }) - Map.setHasLearnedTopicCreation(true) + map.Map.setHasLearnedTopicCreation(true) }, createSynapseWithParameters: function(desc, category, permission, @@ -331,21 +331,21 @@ const toExport = { topic1_id: topic1.id, topic2_id: topic2.id }) - DataModel.Synapses.add(synapse) + map.DataModel.Synapses.add(synapse) var mapping = new DataModel.Mapping({ mappable_type: 'Synapse', mappable_id: synapse.cid }) - DataModel.Mappings.add(mapping) + map.DataModel.Mappings.add(mapping) - Synapse.renderSynapse(mapping, synapse, node1, node2, true) + map.Synapse.renderSynapse(mapping, synapse, node1, node2, true) }, handleURL: function(url, opts = {}) { let coords = opts.coords if (!coords || coords.x === undefined || coords.y === undefined) { - coords = AutoLayout.getNextCoord({ mappings: DataModel.Mappings }) + coords = map.AutoLayout.getNextCoord({ mappings: map.DataModel.Mappings }) } const name = opts.name || 'Link' diff --git a/frontend/src/Metamaps/Map/InfoBox.js b/frontend/src/Metamaps/Map/InfoBox.js index f26aafc0..344f8edb 100644 --- a/frontend/src/Metamaps/Map/InfoBox.js +++ b/frontend/src/Metamaps/Map/InfoBox.js @@ -6,7 +6,7 @@ import { browserHistory } from 'react-router' import GlobalUI, { ReactApp } from '../GlobalUI' import Util from '../Util' -const InfoBox = ({Active, DataModel}) => { +const InfoBox = (map) => { const toExport = { isOpen: false, selectingPermission: false, @@ -86,13 +86,13 @@ const toExport = { load: function() { var self = toExport - var map = Active.Map + var map = map.Active.Map var obj = map.pick('permission', 'topic_count', 'synapse_count') - var isCreator = map.authorizePermissionChange(Active.Mapper) - var canEdit = map.authorizeToEdit(Active.Mapper) - var relevantPeople = map.get('permission') === 'commons' ? DataModel.Mappers : DataModel.Collaborators + var isCreator = map.authorizePermissionChange(map.Active.Mapper) + var canEdit = map.authorizeToEdit(map.Active.Mapper) + var relevantPeople = map.get('permission') === 'commons' ? map.DataModel.Mappers : map.DataModel.Collaborators var shareable = map.get('permission') !== 'private' obj['name'] = canEdit ? Hogan.compile(self.nameHTML).render({id: map.id, name: map.get('name')}) : map.get('name') @@ -139,8 +139,8 @@ const toExport = { $('.mapInfoName .best_in_place_name').unbind('ajax:success').bind('ajax:success', function() { var name = $(this).html() - Active.Map.set('name', name) - Active.Map.trigger('saved') + map.Active.Map.set('name', name) + map.Active.Map.trigger('saved') // mobile menu $('#header_content').html(name) $('.maptoExport').removeClass('mapRequestTitle') @@ -150,8 +150,8 @@ const toExport = { $('.mapInfoDesc .best_in_place_desc').unbind('ajax:success').bind('ajax:success', function() { var desc = $(this).html() - Active.Map.set('desc', desc) - Active.Map.trigger('saved') + map.Active.Map.set('desc', desc) + map.Active.Map.trigger('saved') }) $('.mapInfoDesc .best_in_place_desc, .mapInfoName .best_in_place_name').unbind('keypress').keypress(function(e) { @@ -186,7 +186,7 @@ const toExport = { addTypeahead: function() { var self = toExport - if (!Active.Map) return + if (!map.Active.Map) return // for autocomplete var collaborators = { @@ -217,7 +217,7 @@ const toExport = { } // for adding map collaborators, who will have edit rights - if (Active.Mapper && Active.Mapper.id === Active.Map.get('user_id')) { + if (map.Active.Mapper && map.Active.Mapper.id === map.Active.Map.get('user_id')) { $('.collaboratorSearchField').typeahead( { highlight: false @@ -232,24 +232,24 @@ const toExport = { }, removeCollaborator: function(collaboratorId) { var self = toExport - DataModel.Collaborators.remove(DataModel.Collaborators.get(collaboratorId)) - var mapperIds = DataModel.Collaborators.models.map(function(mapper) { return mapper.id }) - $.post('/maps/' + Active.Map.id + '/access', { access: mapperIds }) + map.DataModel.Collaborators.remove(map.DataModel.Collaborators.get(collaboratorId)) + var mapperIds = map.DataModel.Collaborators.models.map(function(mapper) { return mapper.id }) + $.post('/maps/' + map.Active.Map.id + '/access', { access: mapperIds }) self.updateNumbers() }, addCollaborator: function(newCollaboratorId) { var self = toExport - if (DataModel.Collaborators.get(newCollaboratorId)) { + if (map.DataModel.Collaborators.get(newCollaboratorId)) { GlobalUI.notifyUser('That user already has access') return } function callback(mapper) { - DataModel.Collaborators.add(mapper) - var mapperIds = DataModel.Collaborators.models.map(function(mapper) { return mapper.id }) - $.post('/maps/' + Active.Map.id + '/access', { access: mapperIds }) - var name = DataModel.Collaborators.get(newCollaboratorId).get('name') + map.DataModel.Collaborators.add(mapper) + var mapperIds = map.DataModel.Collaborators.models.map(function(mapper) { return mapper.id }) + $.post('/maps/' + map.Active.Map.id + '/access', { access: mapperIds }) + var name = map.DataModel.Collaborators.get(newCollaboratorId).get('name') GlobalUI.notifyUser(name + ' will be notified') self.updateNumbers() } @@ -269,13 +269,13 @@ const toExport = { $('.maptoExport .mapPermission').removeClass('commons public private').addClass(perm) }, createContributorList: function() { - var relevantPeople = Active.Map.get('permission') === 'commons' ? DataModel.Mappers : DataModel.Collaborators - var activeMapperIsCreator = Active.Mapper && Active.Mapper.id === Active.Map.get('user_id') + var relevantPeople = map.Active.Map.get('permission') === 'commons' ? map.DataModel.Mappers : map.DataModel.Collaborators + var activeMapperIsCreator = map.Active.Mapper && map.Active.Mapper.id === map.Active.Map.get('user_id') var string = '' string += '