/* global $ */
import React, { PropTypes, Component } from 'react'
import Metacode from './Metacode'
import Permission from './Permission'
const inmaps = (topic) => {
const inmapsArray = topic.get('inmaps') || []
const inmapsLinks = topic.get('inmapsLinks') || []
let html = ''
if (inmapsArray.length < 6) {
for (let i = 0; i < inmapsArray.length; i++) {
const url = '/maps/' + inmapsLinks[i]
html += '
' + inmapsArray[i] + ''
}
} else {
for (let i = 0; i < 5; i++) {
const url = '/maps/' + inmapsLinks[i]
html += '' + inmapsArray[i] + ''
}
const extra = inmapsArray.length - 5
html += 'See ' + extra + ' more...'
for (let i = 5; i < inmapsArray.length; i++) {
const url = '/maps/' + inmapsLinks[i]
html += ''
}
}
return html
}
// TODO all of these should be largely turned into passed-in callbacks
const bindShowCardListeners = (topic, ActiveMapper) => {
$('.links .mapCount').unbind().click(function(event) {
$('.mapCount .tip').toggle()
$('.showcard .hoverTip').toggleClass('hide')
})
$('.showcard').unbind('.hideTip').bind('click.hideTip', function() {
$('.mapCount .tip').hide()
$('.showcard .hoverTip').removeClass('hide')
})
var originalText = $('.showMore').html()
$('.mapCount .tip .showMore').unbind().toggle(
function(event) {
$('.extraText').toggleClass('hideExtra')
$('.showMore').html('Show less...')
},
function(event) {
$('.extraText').toggleClass('hideExtra')
$('.showMore').html(originalText)
}
)
}
class Links extends Component {
componentDidMount = () => {
bindShowCardListeners(this.props.topic, this.props.ActiveMapper)
}
render = () => {
const { topic, ActiveMapper } = this.props
const topicId = topic.isNew() ? topic.cid : topic.id // TODO should we really be using cid here?!?
const metacode = topic.getMetacode()
return (
)
}
}
Links.propTypes = {
topic: PropTypes.object, // backbone object
ActiveMapper: PropTypes.object,
updateTopic: PropTypes.func,
metacodeSets: PropTypes.arrayOf(PropTypes.shape({
name: PropTypes.string,
metacodes: PropTypes.arrayOf(PropTypes.shape({
id: PropTypes.number,
icon_path: PropTypes.string, // url
name: PropTypes.string
}))
}))
}
export default Links