[% WRAPPER layout.tt title=(create ? "New machine" : "Editing machine '$machine.hostname'") %]
[% PROCESS common.tt %]

<form action="[% IF create %][% c.uri_for('/admin/create-machine/submit') %][% ELSE %][% c.uri_for('/admin/machine' machine.hostname 'submit') %][% END %]" method="post">

<h2>Machine[% IF ! create %] '[% machine.hostname %]'[% END %]</h2>

<table class="layoutTable">
  [% IF create %]
  <tr>
    <th>Hostname:</th>
    <td>[% INCLUDE maybeEditString param="hostname" value=machine.hostname %]</td>
  </tr>
  [% END %]
  <tr>
    <th>Username:</th>
    <td>[% INCLUDE maybeEditString param="username" value=machine.username %]</td>
  </tr>
  <tr>
    <th>SSH key location:</th>
    <td>[% INCLUDE maybeEditString param="ssh_key" value=machine.ssh_key %]</td>
  </tr>
  <tr>
    <th>Options:</th>
    <td>
        [% INCLUDE maybeEditString param="options" value=machine.options %]
    </td>
  </tr>
  <tr>
    <th>Max concurrent builds:</th>
    <td><tt>[% INCLUDE maybeEditString param="maxconcurrent" value=machine.maxconcurrent %]</tt></td>
  </tr>
  <tr>
    <th>Speed factor:</th>
    <td>
      [% INCLUDE maybeEditString param="speedfactor" value=machine.speedfactor %]
    </td>
  </tr>
  <tr>
    <th>Systems:</th>
    <td>
        <select multiple name="systems" style="width: 27em;">
            [% FOREACH s IN systemtypes %]
                <option value="[% s.system %]"
                [% checked = false %]
                [% FOREACH ms IN machine.buildmachinesystemtypes %]
                    [% checked = ms.system == s.system  %]
                    [% BREAK IF checked %]
                [% END %] 
                [% IF checked %]
                    SELECTED
                [% END %]
                >[% s.system %]</option>
            [% END %]
        </select>
    </td>
  </tr>
</table>

<p><button type="submit"><img src="/static/images/success.gif" />[%IF create %]Create[% ELSE %]Apply changes[% END %]</button></p>

</form>

[% IF !create %]

    <form action="[% c.uri_for('/admin/machine' machine.hostname 'delete') %]" method="post">
      <p><button id="delete-machine" type="submit"><img src="/static/images/failure.gif" />Remove this machine</button></p>
    </form>
      
    <script type="text/javascript">
      $("#delete-machine").click(function() {
        return confirm("Are you sure you want to delete this machine?");
      });
    </script>
[% END %]

[% END %]
