2017-03-06 22:49:46 -05:00
|
|
|
/* global $ */
|
|
|
|
|
|
|
|
import React from 'react'
|
|
|
|
import ReactDOM from 'react-dom'
|
|
|
|
|
|
|
|
import Active from '../Active'
|
|
|
|
import Visualize from '../Visualize'
|
2017-03-11 01:49:27 -05:00
|
|
|
import GlobalUI, { ReactApp } from '../GlobalUI'
|
2017-03-06 22:49:46 -05:00
|
|
|
|
|
|
|
const TopicCard = {
|
2017-03-11 01:49:27 -05:00
|
|
|
openTopic: null, // stores the topic that's currently open
|
2017-03-06 22:49:46 -05:00
|
|
|
metacodeSets: [],
|
2017-03-11 01:49:27 -05:00
|
|
|
updateTopic: () => {},
|
|
|
|
onTopicFollow: () => {},
|
|
|
|
redrawCanvas: () => {
|
|
|
|
Visualize.mGraph.plot()
|
|
|
|
},
|
2017-03-06 22:49:46 -05:00
|
|
|
init: function(serverData) {
|
|
|
|
const self = TopicCard
|
|
|
|
self.metacodeSets = serverData.metacodeSets
|
|
|
|
},
|
|
|
|
populateShowCard: function(topic) {
|
|
|
|
const self = TopicCard
|
2017-03-11 01:49:27 -05:00
|
|
|
TopicCard.updateTopic = obj => {
|
|
|
|
topic.save(obj, { success: topic => self.populateShowCard(topic) })
|
|
|
|
}
|
|
|
|
TopicCard.onTopicFollow = () => {
|
|
|
|
const isFollowing = topic.isFollowedBy(Active.Mapper)
|
|
|
|
$.post({
|
|
|
|
url: `/topics/${topic.id}/${isFollowing ? 'un' : ''}follow`
|
|
|
|
})
|
|
|
|
if (isFollowing) {
|
|
|
|
GlobalUI.notifyUser('You are no longer following this topic')
|
|
|
|
Active.Mapper.unfollowTopic(topic.id)
|
|
|
|
} else {
|
|
|
|
GlobalUI.notifyUser('You are now following this topic')
|
|
|
|
Active.Mapper.followTopic(topic.id)
|
|
|
|
}
|
|
|
|
self.populateShowCard(topic)
|
|
|
|
}
|
2017-03-06 22:49:46 -05:00
|
|
|
// initialize draggability
|
|
|
|
$('.showcard').draggable({
|
|
|
|
handle: '.metacodeImage',
|
|
|
|
stop: function() {
|
|
|
|
$(this).height('auto')
|
|
|
|
}
|
|
|
|
})
|
2017-03-11 01:49:27 -05:00
|
|
|
ReactApp.render()
|
2017-03-06 22:49:46 -05:00
|
|
|
},
|
2017-03-11 01:49:27 -05:00
|
|
|
showCard: function(node, opts = {}) {
|
2017-03-06 22:49:46 -05:00
|
|
|
var self = TopicCard
|
|
|
|
var topic = node.getData('topic')
|
2017-03-11 01:49:27 -05:00
|
|
|
self.openTopic = topic
|
2017-03-06 22:49:46 -05:00
|
|
|
// populate the card that's about to show with the right topics data
|
|
|
|
self.populateShowCard(topic)
|
|
|
|
return $('.showcard').fadeIn('fast', () => opts.complete && opts.complete())
|
|
|
|
},
|
|
|
|
hideCard: function() {
|
|
|
|
var self = TopicCard
|
|
|
|
$('.showcard').fadeOut('fast')
|
2017-03-11 01:49:27 -05:00
|
|
|
self.openTopic = null
|
2017-03-06 22:49:46 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default TopicCard
|