{% extends 'hqwebapp/base_page.html' %}
{% load hq_shared_tags %}
{% load compress %}
{% load i18n %}

{% requirejs_main 'builds/js/edit-builds' %}

{% block stylesheets %}
  <style type="text/css">
    .container.ui-widget {
      border: none;
    }
    #menu-table td {
      line-height: 30px;
    }
  </style>
{% endblock %}

{% block page_title %}
  {% trans "Editing CommCare Builds" %}
{% endblock %}

{% block page_content %}
  {% initial_page_data 'doc' doc %}
  {% initial_page_data 'available_versions' all_versions %}
  {% initial_page_data 'j2me_enabled_versions' j2me_enabled_versions %}
  <div class="alert alert-info"><strong>{% trans "Editing" %} {{ doc.ID }}</strong></div>


  <div class="panel panel-default">
    <div class="panel-heading">
      <h3 class="panel-title">{% trans "Menu Options" %}</h3>
    </div>
    <div class="panel-body">
      <form id="menu-form" class="form-horizontal" action="." method="POST">{% csrf_token %}
        <table id="menu-table" class="table table-striped">
          <thead>
          <tr>
            <th></th>
            <th>{% trans "Version" %}</th>
            <th>{% trans "Label" %}</th>
            <th>{% trans "Superuser Only" %}</th>
            <th>{% trans "J2me Enabled" %}</th>
            <th></th>
          </tr>
          </thead>
          <tbody data-bind="sortable: versions">
          <tr>
            <td class="sortable-handle">
              <i class="fa fa-arrows-v"></i>
            </td>
            <td>
              <select class="form-control" data-bind="
                                    options: $root.available_versions,
                                    value: version
                                ">
              </select>
            </td>
            <td>
              <input class="form-control" type="text" data-bind="value: label">
            </td>
            <td>
              <input type="checkbox" value="superuser-only" data-bind="checked: superuser_only" />
            </td>
            <td class='j2me_enabled'>
              <i class="fa fa-check" data-bind="visible: j2me_enabled"></i>
            </td>
            <td>
              <button type="button" class="btn btn-danger" data-bind="click: $root.removeVersion">
                <i class="fa fa-remove"></i>
              </button>
            </td>
          </tr>
          </tbody>
          <tr>
            <td colspan="5">
              <button data-bind="click: addVersion" class="btn btn-default">
                <i class="fa fa-plus"></i>
                {% trans "Add a Version" %}
              </button>
            </td>
          </tr>
        </table>

        <hr />

        <fieldset>
          <legend>Defaults</legend>
          <div class="form-group">
            <label class="control-label col-sm-3" for="select-default-1">
              {% trans "Default 1.x Build" %}
            </label>
            <div class="col-sm-8">
              <select class="form-control" id="select-default-1" data-bind="
                                options: available_ones,
                                value: default_one"></select>
            </div>
          </div>
          <div class="form-group">
            <label class="control-label col-sm-3" for="select-default-2">
              {% trans "Default 2.x Build" %}
            </label>
            <div class="col-sm-8">
              <select class="form-control" id="select-default-2" data-bind="
                                    options: available_twos,
                                    value: default_two"></select>
            </div>
          </div>
          <div class="form-actions">
            <div class="col-sm-offset-3">
              <button class="btn btn-primary" type="button">Update Menu Options</button>
            </div>
          </div>
        </fieldset>
      </form>
      <form id="submit-menu-form" method="POST">
        {% csrf_token %}
      </form>
    </div>
  </div>
  <div class="panel panel-default">
    <div class="panel-heading">
      <h3 class="panel-title">
        {% trans "Import a new build from the build server" %}
      </h3>
    </div>
    <div class="panel-body">
      <form class="form-horizontal" action="{% url 'import_build' %}" method="post">
        {% csrf_token %}
        <div class="form-group">
          <label class="control-label col-sm-3" for="import_build_version">
            {% trans "Version*" %}
          </label>
          <div class="col-sm-8">
            <input id="import_build_version" type="text" name="version" class="form-control" />
          </div>
        </div>
        <div class="form-group">
          <label class="control-label col-sm-3" for="import_build_build_number">
            {% trans "Build Number*" %}
          </label>
          <div class="col-sm-8">
            <input id="import_build_build_number" type="text" name="build_number" class="form-control" />
            <ol class="help-block">
              <li><a href="http://jenkins.dimagi.com/view/CommCare%20Mobile/" target="_blank">{% trans "Browse builds" %}</a></li>
              <li>
                {% blocktrans %}
                  Click on the appropriate commcare-android-2.X link
                {% endblocktrans %}
              </li>
              <li>{% trans "Click on the most recent successful build in the table at left" %}</li>
              <li>{% trans "Grab the version, a six-digit number, from the URL" %}</li>
            </ol>
          </div>
        </div>
        <div class="form-group">
          <label class="control-label col-sm-3" for="import_build_name">
            {% trans "Source for artifacts.zip (J2ME only)" %}
          </label>
          <div class="col-sm-8">
            <input id="import_build_name" type="text" name="source" class="form-control" />
            <ol class="help-block">
              <li><a href="http://jenkins.dimagi.com/view/CommCare%20Mobile/" target="_blank">{% trans "Browse builds" %}</a></li>
              <li>
                {% blocktrans %}
                  Click on the appropriate commcare-core-2.X link
                {% endblocktrans %}
              </li>
              <li>{% trans "Click on the most recent successful build in the table at left" %}</li>
              <li>{% trans "Click 'Build Artifacts' -> 'application' -> 'posttmp'" %}</li>
              <li>{% trans "Right-click on 'artifacts.zip' and select 'Copy Link Address'" %}</li>
              <li>{% trans "Paste the address into the box above" %}</li>
            </ol>
          </div>
        </div>
        <div class="form-actions">
          <div class="col-sm-offset-3">
            <button type="submit" class="btn btn-primary">{% trans "Import Build" %}</button>
          </div>
        </div>
      </form>
    </div>
  </div>

{% endblock %}
