<commit_before>React = require 'react'

module.exports = React.createClass
  displayName: 'EditProjectVisibility'

  getDefaultProps: ->
    project: null

  getInitialState: ->
    error: null
    setting:
      private: false
      beta: false
      launch: false

  render: ->
    <div>
      <p className="form-label">Project state and visibility</p>

      {if @state.error
        <p className="form-help error">{@state.error.toString()}</p>}

      <table className="standard-table">
        <tbody>
          <tr>
            <td style={whiteSpace: 'nowrap'}>
              <label>
                <input type="checkbox" name="live" value={true} data-json-value={true} checked={@props.project.live} disabled={@state.setting.live} onChange={(e) => @set 'live', e.target.checked} />
                Live
              </label>
            </td>
            <td className="form-help">No workflow changes can be made a "live" project. Check this when you’ve finished development or want to apply for a beta test.</td>
          </tr>

          <tr>
            <td style={whiteSpace: 'nowrap'}>
              <label>
                <input type="radio" name="private" value={true} data-json-value={true} checked={@props.project.private} disabled={@state.setting.private} onChange={@set.bind this, 'private', true} />
                Private
              </label>
              &emsp;
              <label>
                <input type="radio" name="private" value={false} data-json-value={true} checked={not @props.project.private} disabled={@state.setting.private} onChange={@set.bind this, 'private', false} />
                Public
              </label>
            </td>
            <td className="form-help">Only users with assigned <strong>roles</strong> can view a private project. Anyone with the URL can access a public project.</td>
          </tr>

          <tr>
            <td>
              <button type="button" className="standard-button full" disabled={not @props.project.live or @state.setting.beta or @props.project.beta} onClick={@set.bind this, 'beta', true}>Apply for beta</button>{' '}
            </td>
            <td className="form-help">
              <div>Pending approval, expose this project to users who have opted in to be beta testers.</div>
              {unless @props.project.live
                <div>Only <strong>live projects</strong> can apply for a beta.</div>}
              {if @props.project.beta_approved
                <div>Beta status for this project has been approved.</div>
              else if @props.project.beta
                <div>Beta status has been applied for. <button type="button" disabled={@state.setting.beta} onClick={@set.bind this, 'beta', false}>Cancel application</button></div>}
            </td>
          </tr>

          <tr>
            <td>
              <button type="button" className="standard-button full" disabled={not @props.project.beta_approved or @state.setting.launch or @props.project.launch} onClick={@set.bind this, 'launch', true}>Apply for full launch</button>
            </td>
            <td className="form-help">
              <div>Pending approval, expose this project to the entire Zooniverse through the main projects listing.</div>
              {unless @props.project.beta_approved
                <div>Only <strong>project in beta</strong> can apply for a full launch.</div>}
              {if @props.project.launch_approved
                <div>Beta status for this project has been approved.</div>
              else if @props.project.launch
                <div>Launch is awaiting Zooniverse approval. <button type="button" disabled={@state.setting.launch} onClick={@set.bind this, 'launch', false}>Cancel application</button></div>}
            </td>
          </tr>
        </tbody>
      </table>
    </div>

  set: (property, value) ->
    @state.error = null
    @state.setting[property] = true
    @forceUpdate()

    changes = {}
    changes[property] = value

    @props.project.update(changes).save()
      .catch (error) =>
        @setState {error}
      .then =>
        @state.setting[property] = false
        @forceUpdate()<commit_msg>Redesign visibility UI<commit_after>React = require 'react'

module.exports = React.createClass
  displayName: 'EditProjectVisibility'

  getDefaultProps: ->
    project: null

  getInitialState: ->
    error: null
    setting:
      private: false
      beta: false
      launch: false

  render: ->
    looksDisabled =
      opacity: 0.6
      pointerEvents: 'none'

    <div>
      <p className="form-label">Project state and visibility</p>

      {if @state.error
        <p className="form-help error">{@state.error.toString()}</p>}

      <p>
        <label style={whiteSpace: 'nowrap'}>
          <input type="radio" name="private" value={true} data-json-value={true} checked={@props.project.private} disabled={@state.setting.private} onChange={@set.bind this, 'private', true} />
          Private
        </label>
        &emsp;
        <label style={whiteSpace: 'nowrap'}>
          <input type="radio" name="private" value={false} data-json-value={true} checked={not @props.project.private} disabled={@state.setting.private} onChange={@set.bind this, 'private', false} />
          Public
        </label>
      </p>

      <p className="form-help">Only the assigned <strong>collaborators</strong> can view a private project. Anyone with the URL can access a public project.</p>

      <hr />

      <label style={whiteSpace: 'nowrap'}>
        <input type="radio" name="live" value={true} data-json-value={true} checked={not @props.project.live} disabled={@state.setting.live} onChange={@set.bind this, 'live', false} />
        Development
      </label>
      &emsp;
      <label style={whiteSpace: 'nowrap'}>
        <input type="radio" name="live" value={false} data-json-value={true} checked={@props.project.live} disabled={@state.setting.live} onChange={@set.bind this, 'live', true} />
        Live
      </label>

      <p className="form-help">In a live project, workflows are locked and can no longer be edited. Classifications count toward subject retirement.</p>

      <div style={looksDisabled if @props.project.private or not @props.project.live}>
        <hr />

        <p>
          <button type="button" className="standard-button" disabled={@props.project.private or not @props.project.live or @state.setting.beta or @props.project.beta} onClick={@set.bind this, 'beta', true}>Apply for beta</button>{' '}
          {if @props.project.private
            <span>Only <strong>public projects</strong> can apply for a beta.</span>
          else if not @props.project.live
            <span>Only <strong>live projects</strong> can apply for a beta.</span>
          else if @props.project.beta
            <span>Beta status has been applied for. <button type="button" disabled={@state.setting.beta} onClick={@set.bind this, 'beta', false}>Cancel application</button></span>}
        </p>

        <p className="form-help">Pending approval, expose this project to users who have opted in to help test new projects.</p>

        {if @props.project.beta_approved
          <p>
            Beta status for this project has been approved. To end the beta test and make changes, switch back to <em>development</em> mode.
            {unless @props.project.launch or @props.project.launch_approved
              <span>If you’re ready to launch this project, see the next section.</span>}
          </p>}

        <div style={looksDisabled unless @props.project.beta_approved}>
          <hr />

          <p>
            <button type="button" className="standard-button" disabled={not @props.project.beta_approved or @state.setting.launch or @props.project.launch} onClick={@set.bind this, 'launch', true}>Apply for full launch</button>{' '}

            {unless @props.project.beta_approved
              <span>Only <strong>projects in beta</strong> can apply for a full launch.</span>}
            {if @props.project.launch_approved
              <span>This project is available to the whole Zooniverse!</span>
            else if @props.project.launch
              <span>Launch is awaiting Zooniverse approval. <button type="button" disabled={@state.setting.launch} onClick={@set.bind this, 'launch', false}>Cancel application</button></span>}
          </p>

          <p className="form-help">Pending approval, expose this project to the entire Zooniverse through the main projects listing.</p>
        </div>
      </div>
    </div>

  set: (property, value) ->
    @state.error = null
    @state.setting[property] = true
    @forceUpdate()

    changes = {}
    changes[property] = value

    @props.project.update(changes).save()
      .catch (error) =>
        @setState {error}
      .then =>
        @state.setting[property] = false
        @forceUpdate()
{'fraction_non_alphanumeric': 0.136676832712075, 'fraction_numerical': 0.00022591212018524794, 'mean_word_length': 2.5120983736612454, 'pattern_counts': {'":': 0, '<': 149, '<?xml version=': 0, '>': 162, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6692396', 'n_tokens_mistral': 2493, 'n_tokens_neox': 2425, 'n_words': 678}