require('./metadataEditor.less'); const React = require('react'); const createClass = require('create-react-class'); const _ = require('lodash'); const cx = require('classnames'); const request = require('superagent'); const SYSTEMS = ['5e', '4e', '3.5e', 'Pathfinder']; const MetadataEditor = createClass({ getDefaultProps : function() { return { metadata : { editId : null, title : '', description : '', tags : '', published : false, authors : [], systems : [], renderer : 'legacy' }, onChange : ()=>{} }; }, handleFieldChange : function(name, e){ this.props.onChange(_.merge({}, this.props.metadata, { [name] : e.target.value })); }, handleSystem : function(system, e){ if(e.target.checked){ this.props.metadata.systems.push(system); } else { this.props.metadata.systems = _.without(this.props.metadata.systems, system); } this.props.onChange(this.props.metadata); }, handleRenderer : function(renderer, e){ if(e.target.checked){ this.props.metadata.renderer = renderer; } this.props.onChange(this.props.metadata); }, handlePublish : function(val){ this.props.onChange(_.merge({}, this.props.metadata, { published : val })); }, handleDelete : function(){ if(this.props.metadata.authors.length <= 1){ if(!confirm('Are you sure you want to delete this brew? Because you are the only owner of this brew, the document will be deleted permanently.')) return; if(!confirm('Are you REALLY sure? You will not be able to recover the document.')) return; } else { if(!confirm('Are you sure you want to remove this brew from your collection? This will remove you as an editor, but other owners will still be able to access the document.')) return; if(!confirm('Are you REALLY sure? You will lose editor access to this document.')) return; } request.delete(`/api/${this.props.metadata.editId}`) .send() .end(function(err, res){ window.location.href = '/'; }); }, getRedditLink : function(){ const meta = this.props.metadata; const title = `${meta.title} [${meta.systems.join(' ')}]`; const text = `Hey guys! I've been working on this homebrew. I'd love your feedback. Check it out. **[Homebrewery Link](http://homebrewery.naturalcrit.com/share/${meta.shareId})**`; return `https://www.reddit.com/r/UnearthedArcana/submit?title=${encodeURIComponent(title)}&text=${encodeURIComponent(text)}`; }, renderSystems : function(){ return _.map(SYSTEMS, (val)=>{ return ; }); }, renderPublish : function(){ if(this.props.metadata.published){ return ; } else { return ; } }, renderDelete : function(){ if(!this.props.metadata.editId) return; return