<commit_before>var React = require('react');
var actions = require('../actions/EventActions');
var tags = require('../tags.js');

module.exports = React.createClass({
    getInitialState: function() {
        return ({
            editing: false,
            info: {
                name: this.props.info.name,
                location: this.props.info.location,
                description: this.props.info.description,
                date: new Date(this.props.info.date),
                tags: this.props.info.tags,
                owner: this.props.info.owner,
                contactName: this.props.info.contactName,
                contactEmail: this.props.info.contactEmail,
                id: this.props.info._id,
                edited: this.props.info.edited,
                editDate: new Date(this.props.info.editDate)
            }
        })
    },

    deleteEvent: function(e) {
        e.preventDefault();
        actions.deleteEvent(this.props.info)

        // redirect if on detail page
        var path = window.location.pathname;
        var split = path.split('/')
        var folder = split[1]
        var id = split[2] || null
        if (id != null) {
            window.location.href = '/' + folder;
        }
    },

    editEvent: function(e) {
        e.preventDefault();
        var info = this.state.info;
        info.edited = true;
        info.editDate = new Date(Date.now());
        console.log(info);
        actions.editEvent(info);
        this.setState({ editing: false });
    },

    openForm: function() {
        this.setState({ editing: true })
        var date = new Date(this.props.info.date)

        // wait for rendering to complete
        var toggleTag = this.toggleTag;
        window.requestAnimationFrame(function() {
            // set up form
            $('#tags :input').change(function() {
                toggleTag(this.name);
            })

            $(function () {
                var datePicker = $('#date');
                datePicker.datetimepicker({
                    format: "MM/DD/YYYY"
                })
                datePicker.data('DateTimePicker').date(date)
            });
        })
    },

    closeForm: function(e) {
        e.preventDefault();
        this.setState({ editing: false });
    },

    toggleTag: function(name) {
        var info = this.state.info;
        var index = info.tags.indexOf(name)
        if (index === -1) {
            info.tags.push(name);
        } else {
            info.tags.splice(index, 1);
        }
        this.setState({
            info: info
        })
    },

    handleInputChange: function(e) {
        e.preventDefault();
        var name = e.target.name;
        if (name === 'date') {
            var value = new Date(e.target.value);
        } else {
            var value = e.target.value;
        }

        var info = this.state.info;
        info[name] = value;

        this.setState({
            info: info
        });
    },

    render: function() {
        var props = this.props.info;
        var eventID = props._id;

        // create owner management buttons if necessary
        var ownerID = "",
            myEvent = false;

        if (this.props.login.status === true) {
            ownerID = this.props.login.user._id;
        }

        if (ownerID !== "" && ownerID === props.owner) {
            myEvent = true;
        }

        var ownerButtons = null;
        if (myEvent === true) {
            ownerButtons = <div className = 'btn-group pull-right' role = 'group' aria-label='...'>
                <a onClick = { this.openForm } role = 'button' className = 'btn btn-default'>
                    <span className="glyphicon glyphicon-pencil" aria-hidden="true"></span>
                </a>
                <a onClick = { this.deleteEvent } role = 'button' className = 'btn btn-default'>
                    <span className="glyphicon glyphicon-remove" aria-hidden="true"></span>
                </a>
            </div>
        }

        var eventPage = Boolean(window.location.pathname.match(/^\/events\/\w/));

        // set tags
        var tagString = '';
        props.tags.map(function(tag, index) {
            if (index === props.tags.length - 1) {
                tagString += tag;
            } else {
                tagString += tag + ', ';
            }
        })

        if (!this.state.editing) {
            var contactLink = "mailto:" + props.contactEmail + "?subject=" + props.name;
            return (
                <div className = 'event' id = { eventID }>
                    <span className = 'event-name'>
                        { props.name }&nbsp;
                    </span>

                    { props.location ? <span className = 'event-place'>{ props.location },&nbsp;</span> : null }

                    <span className = 'event-date'>
                        { new Date(props.date).toLocaleDateString() }
                    </span>
                        { !eventPage ?
                        <div className = 'btn-group pull-right' role = 'group' aria-label='...'>

                            <a href = { '/events/' + eventID } role = 'button' className = 'btn btn-default'>
                                <span className="glyphicon glyphicon-zoom-in" aria-hidden="true"></span>
                            </a>
                        </div>
                            :
                        <div className = 'pull-right'>{ ownerButtons }</div>
                    }
                    <br />

                    <div className = 'event-description'>
                        { props.description }
                        { props.edited && eventPage ?
                            <p>(Edited on { new Date(props.editDate).toLocaleDateString() })</p>
                            : null
                        }
                    </div>
                    <div className = 'event-contact'>
                        { props.contactName !== undefined && props.contactName !== "" ?
                            <p>Contact: { props.contactName }&nbsp;
                                { props.contactEmail !== "" ?
                                <a href={ contactLink }>{ props.contactEmail }</a>
                                :
                                null }
                            </p>
                        :
                        null
                        }
                    </div>
                    { props.tags.length > 0 ?
                        <div className = 'event-tags'>
                            <span className = 'glyphicon glyphicon-tag' aria-hidden = 'true'></span>&nbsp;
                            { tagString }
                        </div>
                        : null
                    }
                </div>
            )
        } else {

            var tagButtons = [];
            var allTags = tags.geographic.concat(tags.musical).concat(tags.conceptual);
            allTags.map(function(tag, index) {
                var preChecked = (props.tags.indexOf(tag) !== -1)
                tagButtons.push(
                    <label className = { preChecked ? 'tag btn btn-default btn-xs active' : 'tag btn btn-default btn-xs' }
                           onChange = { this.toggleTag }
                           key = { 'check' + tag }>
                        <input type = 'checkbox'
                               name = { tag }
                               autocomplete='off'
                               defaultChecked = { preChecked } /> { tag }
                    </label>)
            });
            return (
                <div className = 'event' id = { eventID }>
                    <form onSubmit = { this.editEvent } id = 'editEventForm'>
                        <div className="form-group">
                            <label className = 'control-label' HTMLfor="name">Title of the event</label>
                            <input type="text" className="form-control"
                                   id="name"
                                   name = 'name'
                                   placeholder="Title"
                                   defaultValue = { props.name }
                                   onChange = { this.handleInputChange } />
                        </div>
                        <div className="form-group">
                            <label className = 'control-label' HTMLfor="location">City, State or Province, and Country</label>
                            <input type="text" className="form-control"
                                   id="location"
                                   name = 'location'
                                   placeholder="City"
                                   defaultValue = { props.location }
                                   onChange = { this.handleInputChange } />
                            <p className="help-block">Use the description to provide more details</p>
                        </div>
                        <div className="form-group">
                            <label className = 'control-label' HTMLfor="date">Date of the event</label>
                            <input type="text" className="form-control"
                                   id="date"
                                   name = 'date'
                                   onBlur = { this.handleInputChange } />
                            <p className="help-block">Use the description to provide times</p>
                        </div>
                        <div className="form-group">
                            <label className = 'control-label' HTMLfor="description">Some information about the event</label>
                            <textarea className="form-control" rows = "3"
                                      id="description"
                                      name = 'description'
                                      placeholder="Details"
                                      defaultValue = { props.description }
                                      onChange = { this.handleInputChange } />
                        </div>
                        <div className="form-group">
                            <label className = 'control-label' HTMLfor="description">Contact name</label>
                            <input type = "text" className="form-control"
                                      id="contactName"
                                      name = 'contactName'
                                      defaultValue = { props.contactName }
                                      onChange = { this.handleInputChange } />
                        </div>
                        <div className="form-group">
                            <label className = 'control-label' HTMLfor="description">Contact email</label>
                            <input type = "text" className="form-control"
                                      id="contactEmail"
                                      name = 'contactEmail'
                                      defaultValue = { props.contactEmail }
                                      onChange = { this.handleInputChange } />
                        </div>
                        <div className="form-group">
                            <label className = 'control-label'>Select Tags</label>
                            <div id = 'tags' class = 'btn-group' data-toggle='buttons'>
                                { tagButtons }
                            </div>
                        </div>

                        <button type="submit" className="btn btn-default">Submit</button>&nbsp;
                        <button className="btn btn-danger" onClick = { this.closeForm }>Cancel</button>
                    </form>
                </div>
            )
        }

    }
})
<commit_msg>add contactName, contactEmail to events, editing function is set to work with logged in user<commit_after>var React = require('react');
var actions = require('../actions/EventActions');
var tags = require('../tags.js');

module.exports = React.createClass({
    getInitialState: function() {
        return ({
            editing: false,
            info: {
                name: this.props.info.name,
                location: this.props.info.location,
                description: this.props.info.description,
                date: new Date(this.props.info.date),
                tags: this.props.info.tags,
                owner: this.props.info.owner,
                contactName: this.props.info.contactName,
                contactEmail: this.props.info.contactEmail,
                id: this.props.info._id,
                edited: this.props.info.edited,
                editDate: new Date(this.props.info.editDate)
            }
        })
    },

    deleteEvent: function(e) {
        e.preventDefault();
        actions.deleteEvent(this.props.info)

        // redirect if on detail page
        var path = window.location.pathname;
        var split = path.split('/')
        var folder = split[1]
        var id = split[2] || null
        if (id != null) {
            window.location.href = '/' + folder;
        }
    },

    editEvent: function(e) {
        e.preventDefault();
        var info = this.state.info;
        info.edited = true;
        info.editDate = new Date(Date.now());
        console.log(info);
        actions.editEvent(info);
        this.setState({ editing: false });
    },

    openForm: function() {
        this.setState({ editing: true })
        var date = new Date(this.props.info.date)

        // wait for rendering to complete
        var toggleTag = this.toggleTag;
        window.requestAnimationFrame(function() {
            // set up form
            $('#tags :input').change(function() {
                toggleTag(this.name);
            })

            $(function () {
                var datePicker = $('#date');
                datePicker.datetimepicker({
                    format: "MM/DD/YYYY"
                })
                datePicker.data('DateTimePicker').date(date)
            });
        })
    },

    closeForm: function(e) {
        e.preventDefault();
        this.setState({ editing: false });
    },

    toggleTag: function(name) {
        var info = this.state.info;
        var index = info.tags.indexOf(name)
        if (index === -1) {
            info.tags.push(name);
        } else {
            info.tags.splice(index, 1);
        }
        this.setState({
            info: info
        })
    },

    handleInputChange: function(e) {
        e.preventDefault();
        var name = e.target.name;
        if (name === 'date') {
            var value = new Date(e.target.value);
        } else {
            var value = e.target.value;
        }

        var info = this.state.info;
        info[name] = value;

        this.setState({
            info: info
        });
    },

    render: function() {
        var props = this.props.info;
        var eventID = props._id;

        // create owner management buttons if necessary
        var ownerID = "",
            myEvent = false;

        if (this.props.login.status === true) {
            ownerID = this.props.login.user._id;
        }

        if (ownerID !== "" && ownerID === props.owner) {
            myEvent = true;
        }

        var ownerButtons = null;
        if (myEvent === true) {
            ownerButtons = <div className = 'btn-group pull-right' role = 'group' aria-label='...'>
                <a onClick = { this.openForm } role = 'button' className = 'btn btn-default'>
                    <span className="glyphicon glyphicon-pencil" aria-hidden="true"></span>
                </a>
                <a onClick = { this.deleteEvent } role = 'button' className = 'btn btn-default'>
                    <span className="glyphicon glyphicon-remove" aria-hidden="true"></span>
                </a>
            </div>
        }

        var eventPage = Boolean(window.location.pathname.match(/^\/events\/\w/));

        // set tags
        var tagString = '';
        props.tags.map(function(tag, index) {
            if (index === props.tags.length - 1) {
                tagString += tag;
            } else {
                tagString += tag + ', ';
            }
        })

        if (!this.state.editing) {
            var contactLink = "mailto:" + props.contactEmail + "?subject=" + props.name;
            return (
                <div className = 'event' id = { eventID }>
                    <span className = 'event-name'>
                        { props.name }&nbsp;
                    </span>

                    { props.location ? <span className = 'event-place'>{ props.location },&nbsp;</span> : null }

                    <span className = 'event-date'>
                        { new Date(props.date).toLocaleDateString() }
                    </span>
                        { !eventPage ?
                        <div className = 'btn-group pull-right' role = 'group' aria-label='...'>

                            <a href = { '/events/' + eventID } role = 'button' className = 'btn btn-default'>
                                <span className="glyphicon glyphicon-zoom-in" aria-hidden="true"></span>
                            </a>
                        </div>
                            :
                        <div className = 'pull-right'>{ ownerButtons }</div>
                    }
                    <br />

                    <div className = 'event-description'>
                        { props.description } &nbsp;
                        { props.edited && eventPage ?
                            <span>(Edited on { new Date(props.editDate).toLocaleDateString() })</span>
                            : null
                        }
                    </div>
                    <div className = 'event-contact'>
                        { props.contactName !== undefined && props.contactName !== "" ?
                            <p>Contact: { props.contactName }&nbsp;
                                { props.contactEmail !== "" ?
                                <a href={ contactLink }>{ props.contactEmail }</a>
                                :
                                null }
                            </p>
                        :
                        null
                        }
                    </div>
                    { props.tags.length > 0 ?
                        <div className = 'event-tags'>
                            <span className = 'glyphicon glyphicon-tag' aria-hidden = 'true'></span>&nbsp;
                            { tagString }
                        </div>
                        : null
                    }
                </div>
            )
        } else {

            var tagButtons = [];
            var allTags = tags.geographic.concat(tags.musical).concat(tags.conceptual);
            allTags.map(function(tag, index) {
                var preChecked = (props.tags.indexOf(tag) !== -1)
                tagButtons.push(
                    <label className = { preChecked ? 'tag btn btn-default btn-xs active' : 'tag btn btn-default btn-xs' }
                           onChange = { this.toggleTag }
                           key = { 'check' + tag }>
                        <input type = 'checkbox'
                               name = { tag }
                               autocomplete='off'
                               defaultChecked = { preChecked } /> { tag }
                    </label>)
            });
            return (
                <div className = 'event' id = { eventID }>
                    <form onSubmit = { this.editEvent } id = 'editEventForm'>
                        <div className="form-group">
                            <label className = 'control-label' HTMLfor="name">Title of the event</label>
                            <input type="text" className="form-control"
                                   id="name"
                                   name = 'name'
                                   placeholder="Title"
                                   defaultValue = { props.name }
                                   onChange = { this.handleInputChange } />
                        </div>
                        <div className="form-group">
                            <label className = 'control-label' HTMLfor="location">City, State or Province, and Country</label>
                            <input type="text" className="form-control"
                                   id="location"
                                   name = 'location'
                                   placeholder="City"
                                   defaultValue = { props.location }
                                   onChange = { this.handleInputChange } />
                            <p className="help-block">Use the description to provide more details</p>
                        </div>
                        <div className="form-group">
                            <label className = 'control-label' HTMLfor="date">Date of the event</label>
                            <input type="text" className="form-control"
                                   id="date"
                                   name = 'date'
                                   onBlur = { this.handleInputChange } />
                            <p className="help-block">Use the description to provide times</p>
                        </div>
                        <div className="form-group">
                            <label className = 'control-label' HTMLfor="description">Some information about the event</label>
                            <textarea className="form-control" rows = "3"
                                      id="description"
                                      name = 'description'
                                      placeholder="Details"
                                      defaultValue = { props.description }
                                      onChange = { this.handleInputChange } />
                        </div>
                        <div className="form-group">
                            <label className = 'control-label' HTMLfor="description">Contact name</label>
                            <input type = "text" className="form-control"
                                      id="contactName"
                                      name = 'contactName'
                                      defaultValue = { props.contactName }
                                      onChange = { this.handleInputChange } />
                        </div>
                        <div className="form-group">
                            <label className = 'control-label' HTMLfor="description">Contact email</label>
                            <input type = "text" className="form-control"
                                      id="contactEmail"
                                      name = 'contactEmail'
                                      defaultValue = { props.contactEmail }
                                      onChange = { this.handleInputChange } />
                        </div>
                        <div className="form-group">
                            <label className = 'control-label'>Select Tags</label>
                            <div id = 'tags' class = 'btn-group' data-toggle='buttons'>
                                { tagButtons }
                            </div>
                        </div>

                        <button type="submit" className="btn btn-default">Submit</button>&nbsp;
                        <button className="btn btn-danger" onClick = { this.closeForm }>Cancel</button>
                    </form>
                </div>
            )
        }

    }
})

{'fraction_non_alphanumeric': 0.11290050590219225, 'fraction_numerical': 0.0006745362563237774, 'mean_word_length': 1.0456191790272509, 'pattern_counts': {'":': 0, '<': 187, '<?xml version=': 0, '>': 189, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 66, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '778521', 'n_tokens_mistral': 5644, 'n_tokens_neox': 5375, 'n_words': 1171}