{{/*
  Copyright 2014 Team 254. All Rights Reserved.
  Author: pat@patfairbank.com (Patrick Fairbank)

  UI for configuring event settings.
*/}}
{{define "title"}}Settings{{end}}
{{define "body"}}
<div class="row">
  {{if .ErrorMessage}}
    <div class="alert alert-dismissable alert-danger">
      <button type="button" class="close" data-dismiss="alert">×</button>
      {{.ErrorMessage}}
    </div>
  {{end}}
  <div class="col-lg-6 col-lg-offset-1">
    <div class="well">
      <form class="form-horizontal" action="/setup/settings" method="POST">
        <fieldset>
          <legend>Event Settings</legend>
          <div class="form-group">
            <label class="col-lg-5 control-label">Name</label>
            <div class="col-lg-7">
              <input type="text" class="form-control" name="name" placeholder="{{.Name}}">
            </div>
          </div>
          <div class="form-group">
            <label class="col-lg-5 control-label">Number of Alliances</label>
            <div class="col-lg-7">
              <input type="text" class="form-control" name="numElimAlliances" value="{{.NumElimAlliances}}">
            </div>
          </div>
          <div class="form-group">
            <label class="col-lg-5 control-label">Round 2 Selection Order</label>
            <div class="col-lg-7">
              <div class="radio">
                <label>
                  <input type="radio" name="selectionRound2Order" value="F"
                      {{if eq .SelectionRound2Order "F"}}checked{{end}}>
                  First to Last
                </label>
              </div>
              <div class="radio">
                <label>
                  <input type="radio" name="selectionRound2Order" value="L"
                      {{if eq .SelectionRound2Order "L"}}checked{{end}}>
                  Last to First
                </label>
              </div>
            </div>
          </div>
          <div class="form-group">
            <label class="col-lg-5 control-label">Round 3 Selection Order</label>
            <div class="col-lg-7">
              <div class="radio">
                <label>
                  <input type="radio" name="selectionRound3Order" value="F"
                      {{if eq .SelectionRound3Order "F"}}checked{{end}}>
                  First to Last
                </label>
              </div>
              <div class="radio">
                <label>
                  <input type="radio" name="selectionRound3Order" value="L"
                      {{if eq .SelectionRound3Order "L"}}checked{{end}}>
                  Last to First
                </label>
              </div>
              <div class="radio">
                <label>
                  <input type="radio" name="selectionRound3Order" value=""
                      {{if eq .SelectionRound3Order ""}}checked{{end}}>
                  None
                </label>
              </div>
            </div>
          </div>
        </fieldset>
        <fieldset>
          <legend>Automatic Team Info Download</legend>
          <div class="form-group">
            <label class="col-lg-9 control-label">Enable Automatic Team Info Download (From TBA)</label>
            <div class="col-lg-1 checkbox">
              <input type="checkbox" name="TBADownloadEnabled"{{if .TBADownloadEnabled}} checked{{end}}>
            </div>
          </div>
        </fieldset>
        <fieldset>
          <legend>Publishing</legend>
          <p>Contact The Blue Alliance to obtain an event code and credentials.</p>
          <div class="form-group">
            <label class="col-lg-7 control-label">Enable The Blue Alliance publishing</label>
            <div class="col-lg-1 checkbox">
              <input type="checkbox" name="tbaPublishingEnabled"{{if .TbaPublishingEnabled}} checked{{end}}>
            </div>
          </div>
          <div class="form-group">
            <label class="col-lg-5 control-label">TBA Event Code</label>
            <div class="col-lg-7">
              <input type="text" class="form-control" name="tbaEventCode" value="{{.TbaEventCode}}">
            </div>
          </div>
          <div class="form-group">
            <label class="col-lg-5 control-label">TBA Auth ID</label>
            <div class="col-lg-7">
              <input type="text" class="form-control" name="tbaSecretId" value="{{.TbaSecretId}}">
            </div>
          </div>
          <div class="form-group">
            <label class="col-lg-5 control-label">TBA Secret</label>
            <div class="col-lg-7">
              <input type="text" class="form-control" name="tbaSecret" value="{{.TbaSecret}}">
            </div>
          </div>
        </fieldset>
        <fieldset>
          <legend>Authentication</legend>
          <p>Configure password to enable authentication, or leave blank to disable.</p>
          <div class="form-group">
            <label class="col-lg-5 control-label">Password for 'admin' user</label>
            <div class="col-lg-7">
              <input type="password" class="form-control" name="adminPassword" value="{{.AdminPassword}}">
            </div>
          </div>
        </fieldset>
        <fieldset>
          <legend>Networking</legend>
          <p>Enable this setting if you have a Linksys WRT1900ACS access point and Catalyst 3500-series
              switch available, for isolating each team to its own SSID and VLAN.</p>
          <div class="form-group">
            <label class="col-lg-7 control-label">Enable advanced network security</label>
            <div class="col-lg-1 checkbox">
              <input type="checkbox" name="networkSecurityEnabled"{{if .NetworkSecurityEnabled}} checked{{end}}>
            </div>
          </div>
          <div class="form-group">
            <label class="col-lg-5 control-label">AP Address</label>
            <div class="col-lg-7">
              <input type="text" class="form-control" name="apAddress" value="{{.ApAddress}}">
            </div>
          </div>
          <div class="form-group">
            <label class="col-lg-5 control-label">AP Username</label>
            <div class="col-lg-7">
              <input type="text" class="form-control" name="apUsername" value="{{.ApUsername}}">
            </div>
          </div>
          <div class="form-group">
            <label class="col-lg-5 control-label">AP Password</label>
            <div class="col-lg-7">
              <input type="password" class="form-control" name="apPassword" value="{{.ApPassword}}">
            </div>
          </div>
          <div class="form-group">
            <label class="col-lg-5 control-label">AP Team Channel (5GHz)</label>
            <div class="col-lg-7">
              <select class="form-control" name="apTeamChannel" value="{{.ApTeamChannel}}">
                <option{{if eq .ApTeamChannel 36}} selected{{end}}>36</option>
                <option{{if eq .ApTeamChannel 40}} selected{{end}}>40</option>
                <option{{if eq .ApTeamChannel 44}} selected{{end}}>44</option>
                <option{{if eq .ApTeamChannel 48}} selected{{end}}>48</option>
                <option{{if eq .ApTeamChannel 149}} selected{{end}}>149</option>
                <option{{if eq .ApTeamChannel 153}} selected{{end}}>153</option>
                <option{{if eq .ApTeamChannel 157}} selected{{end}}>157</option>
                <option{{if eq .ApTeamChannel 161}} selected{{end}}>161</option>
              </select>
            </div>
          </div>
          <div class="form-group">
            <label class="col-lg-5 control-label">AP Admin Channel (2.4GHz)</label>
            <div class="col-lg-7">
              <select class="form-control" name="apAdminChannel" value="{{.ApAdminChannel}}">
                <option{{if eq .ApAdminChannel 0}} selected{{end}}>Disabled</option>
                <option{{if eq .ApAdminChannel 1}} selected{{end}}>1</option>
                <option{{if eq .ApAdminChannel 6}} selected{{end}}>6</option>
                <option{{if eq .ApAdminChannel 11}} selected{{end}}>11</option>
              </select>
            </div>
          </div>
          <div class="form-group">
            <label class="col-lg-5 control-label">AP Admin WPA Key</label>
            <div class="col-lg-7">
              <input type="password" class="form-control" name="apAdminWpaKey" value="{{.ApAdminWpaKey}}">
            </div>
          </div>
          <div class="form-group">
            <label class="col-lg-5 control-label">Switch Address</label>
            <div class="col-lg-7">
              <input type="text" class="form-control" name="switchAddress" value="{{.SwitchAddress}}">
            </div>
          </div>
          <div class="form-group">
            <label class="col-lg-5 control-label">Switch Password</label>
            <div class="col-lg-7">
              <input type="password" class="form-control" name="switchPassword" value="{{.SwitchPassword}}">
            </div>
          </div>
          <p>If you have a second access point available and want to use one for each alliance to increase available
            bandwidth, configure the second one below.</p>
          <div class="form-group">
            <label class="col-lg-5 control-label">Second AP Address</label>
            <div class="col-lg-7">
              <input type="text" class="form-control" name="ap2Address" value="{{.Ap2Address}}">
            </div>
          </div>
          <div class="form-group">
            <label class="col-lg-5 control-label">Second AP Username</label>
            <div class="col-lg-7">
              <input type="text" class="form-control" name="ap2Username" value="{{.Ap2Username}}">
            </div>
          </div>
          <div class="form-group">
            <label class="col-lg-5 control-label">Second AP Password</label>
            <div class="col-lg-7">
              <input type="password" class="form-control" name="ap2Password" value="{{.Ap2Password}}">
            </div>
          </div>
          <div class="form-group">
            <label class="col-lg-5 control-label">Second AP Team Channel (5GHz)</label>
            <div class="col-lg-7">
              <select class="form-control" name="ap2TeamChannel" value="{{.Ap2TeamChannel}}">
                <option{{if eq .Ap2TeamChannel 0}} selected{{end}}>Disabled</option>
                <option{{if eq .Ap2TeamChannel 36}} selected{{end}}>36</option>
                <option{{if eq .Ap2TeamChannel 40}} selected{{end}}>40</option>
                <option{{if eq .Ap2TeamChannel 44}} selected{{end}}>44</option>
                <option{{if eq .Ap2TeamChannel 48}} selected{{end}}>48</option>
                <option{{if eq .Ap2TeamChannel 149}} selected{{end}}>149</option>
                <option{{if eq .Ap2TeamChannel 153}} selected{{end}}>153</option>
                <option{{if eq .Ap2TeamChannel 157}} selected{{end}}>157</option>
                <option{{if eq .Ap2TeamChannel 161}} selected{{end}}>161</option>
              </select>
            </div>
          </div>
        </fieldset>
        <fieldset>
          <legend>PLC</legend>
          <div class="form-group">
            <label class="col-lg-5 control-label">PLC Address</label>
            <div class="col-lg-7">
              <input type="text" class="form-control" name="plcAddress" value="{{.PlcAddress}}">
            </div>
          </div>
        </fieldset>
        <fieldset>
          <legend>Game-Specific</legend>
          <div class="form-group">
            <label class="col-lg-5 control-label">Autonomous Period Duration (seconds)</label>
            <div class="col-lg-7">
              <input type="text" class="form-control" name="autoDurationSec" value="{{.AutoDurationSec}}">
            </div>
          </div>
          <div class="form-group">
            <label class="col-lg-5 control-label">Pause Duration (seconds)</label>
            <div class="col-lg-7">
              <input type="text" class="form-control" name="pauseDurationSec" value="{{.PauseDurationSec}}">
            </div>
          </div>
          <div class="form-group">
            <label class="col-lg-5 control-label">Teleoperated Period Duration (seconds)</label>
            <div class="col-lg-7">
              <input type="text" class="form-control" name="teleopDurationSec" value="{{.TeleopDurationSec}}">
            </div>
          </div>
          <div class="form-group">
            <label class="col-lg-5 control-label">Warning Remaining Duration (seconds)</label>
            <div class="col-lg-7">
              <input type="text" class="form-control" name="warningRemainingDurationSec"
                value="{{.WarningRemainingDurationSec}}">
            </div>
          </div>
        </fieldset>
        <div class="form-group">
          <div class="col-lg-7 col-lg-offset-5">
            <button type="submit" class="btn btn-info">Save</button>
          </div>
        </div>
      </form>
    </div>
  </div>
  <div class="col-lg-4">
    <div class="well">
      <legend>Database</legend>
      <p>
        <a href="/setup/db/save"><button class="btn btn-info">Save Copy of Database</button></a>
      </p>
      <p>
        <button type="button" class="btn btn-primary" onclick="$('#uploadDatabase').modal('show');">
          Load Database from Backup
        </button>
      </p>
      <p>
        <button type="button" class="btn btn-primary" onclick="$('#confirmClearData').modal('show');">
          Clear All Match Data
        </button>
      </p>
    </div>
  </div>
</div>
<div id="uploadDatabase" class="modal" style="top: 20%;">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
        <h4 class="modal-title">Choose Backup File</h4>
      </div>
      <form class="form-horizontal" action="/setup/db/restore" enctype="multipart/form-data" method="POST">
        <div class="modal-body">
          <p>Select the database file to load from. <b>This will overwrite any existing data.</b></p>
          <input type="file" name="databaseFile">
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
          <button type="submit" class="btn btn-primary">Load Database from Backup</button>
        </div>
      </form>
    </div>
  </div>
</div>
<div id="confirmClearData" class="modal" style="top: 20%;">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
        <h4 class="modal-title">Confirm</h4>
      </div>
      <div class="modal-body">
        <p>Are you sure you want to clear all match, ranking, and alliance selection data?</p>
      </div>
      <div class="modal-footer">
        <form class="form-horizontal" action="/setup/db/clear" method="POST">
          <button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
          <button type="submit" class="btn btn-primary">Clear All Match Data</button>
        </form>
      </div>
    </div>
  </div>
</div>
{{end}}
{{define "script"}}
{{end}}
