metamaps--metamaps/frontend/src/Metamaps/Views/TopicCard.js

57 lines
1.4 KiB
JavaScript
Raw Normal View History

2017-01-13 00:45:21 -05:00
/* global $ */
import React from 'react'
import ReactDOM from 'react-dom'
import Active from '../Active'
import ReactTopicCard from '../../components/TopicCard'
const TopicCard = {
openTopicCard: null, // stores the topic that's currently open
2017-01-28 17:27:01 -05:00
metacodeSets: [],
init: function(serverData) {
const self = TopicCard
self.metacodeSets = serverData.metacodeSets
},
2017-01-13 00:45:21 -05:00
populateShowCard: function(topic) {
2017-01-28 17:27:01 -05:00
const self = TopicCard
2017-01-13 00:45:21 -05:00
const topicCardObj = {
topic: topic,
ActiveMapper: Active.Mapper,
updateTopic: obj => {
topic.save(obj, { success: topic => self.populateShowCard(topic) })
2017-01-28 17:27:01 -05:00
},
metacodeSets: self.metacodeSets
2017-01-13 00:45:21 -05:00
}
ReactDOM.render(
React.createElement(ReactTopicCard, topicCardObj),
document.getElementById('showcard')
)
2017-01-28 15:59:22 -05:00
// initialize draggability
$('.showcard').draggable({
handle: '.metacodeImage',
stop: function() {
$(this).height('auto')
}
})
2017-01-13 00:45:21 -05:00
},
showCard: function(node, opts) {
var self = TopicCard
if (!opts) opts = {}
var topic = node.getData('topic')
self.openTopicCard = topic
// 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')
self.openTopicCard = null
}
}
export default TopicCard