<commit_before>'use strict';

import React from 'react';
import Formsy from 'formsy-react';
import {FormsyText} from 'formsy-material-ui/lib';
import KeyBinding from 'react-keybinding-component';
import { defineMessages, injectIntl } from 'react-intl';

require('styles//EditSlideForm.scss');

const messages = defineMessages({
  labelUrl: {
    id: 'editslideformLabelUrl',
    defaultMessage: 'Url (required)',
  },
  errorUrl: {
    id: 'editslideformErrorUrl',
    defaultMessage: 'Please enter a valid url'
  },
  labelDuration: {
    id: 'editslideformLabelDuration',
    defaultMessage: 'Duration in seconds (required)'
  },
  errorDuration: {
    id: 'editslideformErrorDuration',
    defaultMessage: 'Please enter a valid duration'
  }
});

class EditSlideFormComponent extends React.Component {

  constructor(props) {
    super(props);
    this.state = {
      formInputsValid: false
    };
  }

  handleSave = () => {
    const slide = {
      'url': this.refs.url.getValue(),
      'duration': this.refs.duration.getValue() * 1000 // (transforming seconds to milliseconds)
    };

    if (typeof(this.props.slide) != 'undefined') {
      this.props.onEdit(this.props.slide._id, slide);
    }
    else {
      this.props.onAdd(slide);
    }

    this.props.handleCloseDialog();
  }

  handleControlsByKeyboard = (e) => {
    switch(e.keyCode) {
      case 13: // Enter key
        if(this.state.formInputsValid) {
          this.handleSave();
        }
        return 0;
    }
  }

  enableButton = () => {
    this.setState({
      formInputsValid: true
    })
    this.props.enableEditButton();
  }

  disableButton = () => {
    this.setState({
      formInputsValid: false
    })
    this.props.disableEditButton();
  }

  render() {
    const {formatMessage} = this.props.intl;

    return (
      <div className="editslideform-component">

        <KeyBinding onKey={ (e) => { this.handleControlsByKeyboard(e) } } />

        <Formsy.Form
          onValid={this.enableButton}
          onInvalid={this.disableButton}
          onValidSubmit={this.handleSave}
        >
          <FormsyText
            name='url'
            ref='url'
            validations='isUrl'
            validationError={formatMessage(messages.errorUrl)}
            required
            hintText='http://www.example.com'
            floatingLabelText={formatMessage(messages.labelUrl)}
            fullWidth={true}
            defaultValue={typeof(this.props.slide) != 'undefined' ? this.props.slide.url : ''}
          />

          <FormsyText<commit_msg>Minor refactoring - replaces double quotes<commit_after>'use strict';

import React from 'react';
import Formsy from 'formsy-react';
import {FormsyText} from 'formsy-material-ui/lib';
import KeyBinding from 'react-keybinding-component';
import { defineMessages, injectIntl } from 'react-intl';

require('styles//EditSlideForm.scss');

const messages = defineMessages({
  labelUrl: {
    id: 'editslideformLabelUrl',
    defaultMessage: 'Url (required)',
  },
  errorUrl: {
    id: 'editslideformErrorUrl',
    defaultMessage: 'Please enter a valid url'
  },
  labelDuration: {
    id: 'editslideformLabelDuration',
    defaultMessage: 'Duration in seconds (required)'
  },
  errorDuration: {
    id: 'editslideformErrorDuration',
    defaultMessage: 'Please enter a valid duration'
  }
});

class EditSlideFormComponent extends React.Component {

  constructor(props) {
    super(props);
    this.state = {
      formInputsValid: false
    };
  }

  handleSave = () => {
    const slide = {
      'url': this.refs.url.getValue(),
      'duration': this.refs.duration.getValue() * 1000 // (transforming seconds to milliseconds)
    };

    if (typeof(this.props.slide) != 'undefined') {
      this.props.onEdit(this.props.slide._id, slide);
    }
    else {
      this.props.onAdd(slide);
    }

    this.props.handleCloseDialog();
  }

  handleControlsByKeyboard = (e) => {
    switch(e.keyCode) {
      case 13: // Enter key
        if(this.state.formInputsValid) {
          this.handleSave();
        }
        return 0;
    }
  }

  enableButton = () => {
    this.setState({
      formInputsValid: true
    })
    this.props.enableEditButton();
  }

  disableButton = () => {
    this.setState({
      formInputsValid: false
    })
    this.props.disableEditButton();
  }

  render() {
    const {formatMessage} = this.props.intl;

    return (
      <div className='editslideform-component'>

        <KeyBinding onKey={ (e) => { this.handleControlsByKeyboard(e) } } />

        <Formsy.Form
          onValid={this.enableButton}
          onInvalid={this.disableButton}
          onValidSubmit={this.handleSave}
        >
          <FormsyText
            name='url'
            ref='url'
            validations='isUrl'
            validationError={formatMessage(messages.errorUrl)}
            required
            hintText='http://www.example.com'
            floatingLabelText={formatMessage(messages.labelUrl)}
            fullWidth={true}
            defaultValue={typeof(this.props.slide) != 'undefined' ? this.props.slide.url : ''}
          />

          <FormsyText
{'fraction_non_alphanumeric': 0.13184031158714704, 'fraction_numerical': 0.002726387536514119, 'mean_word_length': 2.579094076655052, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '3617633', 'n_tokens_mistral': 1574, 'n_tokens_neox': 1546, 'n_words': 277}