<commit_before>'use strict';

var React            = require('react/addons');
var LinkedStateMixin = React.addons.LinkedStateMixin;

var Dialog = require('../components/dialog.jsx');

var props        = require('../constants/props');
var BoardActions = require('../actions/board');

/**
 * Displays an overlaid Dialog to edit the given Board.
 */
var EditBoardDialog = React.createClass({
	mixins: [LinkedStateMixin],

	propTypes: {
		/**
		 * Initial state of the board.
		 */
		board: props.Board.isRequired,

		/**
		 * Callback for dialog dismissal.
		 */
		onDismiss: React.PropTypes.func.isRequired,
	},

	getInitialState: function() {
		return {
			name:       this.props.board.name,
			background: this.props.board.background,
		}
	},

	/**
	 * Triggers persisting the edits.
	 */
	_submit: function() {
		BoardActions.editBoard(this.props.board.id, {
			name:       this.state.name,
			background: this.state.background,
		});
		return this.props.onDismiss();
	},

	/**
	 * Triggers the removal of the board.
	 */
	_remove: function() {
		BoardActions.removeBoard(this.props.board.id);
		return this.props.onDismiss();
	},

	/**
	 *
	 */
	_generateAccessCode: function() {
		return BoardActions.generateAccessCode(this.props.board.id);
	},

	/**
	 *
	 */
	_revokeAccessCode: function() {
		return BoardActions.revokeAccessCode(this.props.board.id);
	},

	render: function() {
		var shareButton = (
			/* jshint ignore:start */
			<button className="btn turquoise"
					onClick={this._generateAccessCode}>
				Share
			</button>
			/* jshint ignore:end */
		);
		var code = this.props.board.accessCode;
		if(code !== null && code.length > 0) {
			shareButton = (
				/* jshint ignore:start */
				<button className="btn red"
						onClick={this._revokeAccessCode}>
					Hide
				</button>
				/* jshint ignore:end */
			);
		}
		return (
			/* jshint ignore:start */
			<Dialog className="edit-board-dialog"
					onDismiss={this.props.onDismiss}>
				<div className="title">
					Edit Board
				</div>
				<div className="form">
					<input type="text" placeholder="Name"
						valueLink={this.linkState('name')} />
					<input type="text" placeholder="Background URL"
						valueLink={this.linkState('background')} />
					<div className="share">
						<input type="text" readOnly={true}
								value={this.props.board.accessCode} />
						{shareButton}
					</div>
				</div>
				<div className="controls">
					<button className="btn turquoise" onClick={this._submit}>
						Done
					</button>
					<button className="btn red" onClick={this._remove}>
						Delete
					</button>
				</div>
			</Dialog>
			/* jshint ignore:end */<commit_msg>Fix Shared URL not actually being an URL.<commit_after>'use strict';

var React            = require('react/addons');
var LinkedStateMixin = React.addons.LinkedStateMixin;

var Dialog = require('../components/dialog.jsx');

var props        = require('../constants/props');
var BoardActions = require('../actions/board');

/**
 * Displays an overlaid Dialog to edit the given Board.
 */
var EditBoardDialog = React.createClass({
	mixins: [LinkedStateMixin],

	propTypes: {
		/**
		 * Initial state of the board.
		 */
		board: props.Board.isRequired,

		/**
		 * Callback for dialog dismissal.
		 */
		onDismiss: React.PropTypes.func.isRequired,
	},

	getInitialState: function() {
		return {
			name:       this.props.board.name,
			background: this.props.board.background,
		}
	},

	/**
	 * Triggers persisting the edits.
	 */
	_submit: function() {
		BoardActions.editBoard(this.props.board.id, {
			name:       this.state.name,
			background: this.state.background,
		});
		return this.props.onDismiss();
	},

	/**
	 * Triggers the removal of the board.
	 */
	_remove: function() {
		BoardActions.removeBoard(this.props.board.id);
		return this.props.onDismiss();
	},

	/**
	 *
	 */
	_generateAccessCode: function() {
		return BoardActions.generateAccessCode(this.props.board.id);
	},

	/**
	 *
	 */
	_revokeAccessCode: function() {
		return BoardActions.revokeAccessCode(this.props.board.id);
	},

	render: function() {
		var shareURL = '';
		var shareButton = (
			/* jshint ignore:start */
			<button className="btn turquoise"
					onClick={this._generateAccessCode}>
				Share
			</button>
			/* jshint ignore:end */
		);

		var code = this.props.board.accessCode;

		if(code !== null && code.length > 0) {
			shareURL = location.host + '/boards/' + this.props.board.id +
				'/access/' + code + '';
			shareButton = (
				/* jshint ignore:start */
				<button className="btn red"
						onClick={this._revokeAccessCode}>
					Hide
				</button>
				/* jshint ignore:end */
			);
		}
		return (
			/* jshint ignore:start */
			<Dialog className="edit-board-dialog"
					onDismiss={this.props.onDismiss}>
				<div className="title">
					Edit Board
				</div>
				<div className="form">
					<input type="text" placeholder="Name"
						valueLink={this.linkState('name')} />
					<input type="text" placeholder="Background URL"
						valueLink={this.linkState('background')} />
					<div className="share">
						<input type="text" readOnly={true} value={shareURL} />
						{shareButton}
					</div>
				</div>
				<div className="controls">
					<button className="btn turquoise" onClick={this._submit}>
						Done
					</button>
					<button className="btn red" onClick={this._remove}>
						Delete
					</button>
				</div>
			</Dialog>
			/* jshint ignore:end */
{'fraction_non_alphanumeric': 0.15612903225806452, 'fraction_numerical': 0.0003686635944700461, 'mean_word_length': 2.9375907111756168, 'pattern_counts': {'":': 0, '<': 45, '<?xml version=': 0, '>': 47, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6637156', 'n_tokens_mistral': 2114, 'n_tokens_neox': 1720, 'n_words': 345}