{% extends "base.html" %}
{% load i18n %}

{% block title %}
  {% if booking and booking.id %}
    {% trans "Booking" %} {{ booking.id }}: {{ booking.get_title }}
  {% endif %}
{% endblock %}

{% block page-title %}

  {% if booking and booking.id %}
    {% include "booking_star.html" %}
    {% trans "Booking" %} <a href="">{{ booking.id }}</a>: {{ booking.get_title }} {% if booking.is_closed %}({% trans "closed" %}){% endif %}
  {% else %}
    {{ date }}, {{ page_title }}
  {% endif %}


{% endblock %}

{% block sub-navigation %}
{% endblock %}

{% block sidebar %}

{% endblock %}

{% block content %}

  <aside id="right">
    {% if booking and booking.id %}
      {% if booking.is_closed %}
        <strong>{% trans "Can't edit" %}</strong><br/>
        {{ booking.get_closing_reason }}<br/><br/>
      {% endif %}
      <strong>{% trans "Created" %}:</strong><br/>
      {{ booking.created|date}} {% trans "by" %} {{ booking.created_by_id|show_user_link }}</a><br/>
      <strong>{% trans "Updated" %}:</strong><br/>
      {{ booking.updated|date }} {% trans "by" %} {{ booking.updated_by_id|show_user_link }}</a><br/>
      {% if booking.invoice_no %}
        <br/>
	<strong>{% trans "Invoice no." %}:</strong><br/>
	{{ booking.invoice_no }}<br/>
      {% endif %}
      {% if booking.issue %}
	<br/>
	<strong>{% trans "Issue" %}:</strong><br/>
	{{ booking.issue.tracker }} {{ booking.issue }}<br/>
	<br/>
      {% endif %}
    {% endif %}
  </aside>

  <section id="xxx" style="width: 72%;">
  <form action="" method="post">

    <div class="module">
      <h3 class="header" id="blue">
        {% trans 'Contract' %}
      </h3>
      <div class="body" id="blue">
        <table>
          <tr>
            <th><label for="id_customer">{{ form.customer.label }}:</label></th>
            <td>{% if booking.is_closed %}{{ booking.project.customer }}{% else %}{{ form.customer }}{% endif %}</td>
          </tr>
          <tr>
            <th><label for="id_project">{{ form.project.label }}:</label></th>
            <td>{% if booking.is_closed %}{{ booking.project }}{% else %}{{ form.project }}{% endif %}</td>
          </tr>
          <tr>
            <th><label for="id_step">{{ form.step.label }}:</label></th>
            <td>{% if booking.is_closed %}{{ booking.step }}{% else %}{{ form.step }}{% endif %}</td>
          </tr>
        </table>
      </div>
    </div>

    <div class="module">
      <h3 class="header" id="blue">
        {% trans 'Time' %}
      </h3>
      <div class="body" id="blue">
        <table>
          <tr>
            <th><label for="id_date">{{ form.date.label }}:</label></th>
            <td>{% if booking.is_closed %}{{ booking.day.date|date }}{% else %}{{ form.date }}{% endif %} {% trans 'Start' %} / {% trans 'End' %}: {% if booking.is_closed %}{{ booking.start_time }} {{ booking.end_time }}{% else %}{{ form.from_time }} {{ form.to_time }} <span class="eg">{% trans 'e.g. 08:30' %}</span>{% endif %}</td>
          </tr>
          <tr>
            <th><label for="id_duration">{% trans 'Duration' %}:</label></th>
            <td>{% if booking.is_closed %}{{ booking.duration|format_minutes_to_time }}{% else %}{{ form.hours }} {{ form.minutes }} <span class="eg">{% trans 'hours' %} / {% trans 'minutes' %}</span>{% endif %}</td>
          </tr>
		  <tr>
		    <th><label for="id_location">{% trans 'Location' %}:</label></th>
			<td>{% if booking.is_closed %}{{ booking.location }}{% else %}{{ form.location }}{% endif %}</td>
		  </tr>
        </table>
      </div>
    </div>

    <div class="module">
      <h3 class="header">
        <a id="general-information-pointer" href="javascript:JS_toggleSection('general-information');" class="toggled-section "><span id="general-information-image" class="sprite {% if not expand_boxes %}plus{% else %}minus{% endif %}"></span>{% trans 'General information' %}</a>
      </h3>
      <div class="body" id="general-information" style="{% if not expand_boxes %}display:none;{% endif %}">
        <table>
          <tr>
            <th><label for="id_title">{{ form.title.label }}:</label></th>
            <td>{% if booking.is_closed %}{{ booking.title }}{% else %}{{ form.title }}{% endif %}</td>
          </tr>
          <tr>
            <th><label for="id_description">{{ form.description.label }}:</label></th>
            <td>{% if booking.is_closed %}{{ booking.description }}{% else %}{{ form.description }}{% endif %}</td>
          </tr>
        </table>
      </div>
    </div>

    <div class="module">
      <h3 class="header">
        <a id="ticket-information-pointer" href="javascript:JS_toggleSection('ticket-information');" class="toggled-section "><span id="ticket-information-image" class="sprite {% if not expand_boxes %}plus{% else %}minus{% endif %}"></span>
		  {% trans 'Issue information' %}
		</a>
      </h3>
      <div class="body" id="ticket-information" style="{% if not expand_boxes %}display:none;{% endif %}">
        <table>
          <tr>
            <th><label for="id_tracker">{{ form.tracker.label }}:</label></th>
            <td>{% if booking.is_closed %}{{ booking.issue.tracker }}{% else %}{{ form.tracker }}{% endif %}</td>
          </tr>
          <tr>
            <th><label for="id_issue_no">{{ form.issue_no.label }}:</label></th>
            <td>{% if booking.is_closed %}{{ booking.issue.no }}{% else %}{{ form.issue_no }}{% endif %}</td>
          </tr>
        </table>
      </div>
    </div>
    <table>
      <tr>
	{% if not booking or not booking.is_closed %}
          <td><input name="save" type="submit" value="{{ submit_value }}"></td>
	{% endif %}
        <td><input name="cancel" type="submit" value="{{ cancel_value }}"></td>
      </tr>
    </table>
  </form>
  </section>
{% endblock %}
