{% extends "datebook/base.html" %}
{% load i18n autobreadcrumb crispy_forms_tags %}

{% block datebook_container_css_classes %} large-row-fluid{% endblock %}


{% block head_base_js %}{{ block.super }}
<script type="text/javascript">
//<![CDATA[
$(document).ready(function($) {
    // Switch calendar to mosaic/flat view
    $('#datebook-view-mode').calendar_view_mode();
    
    // Navigation within reveal modal for next/previous day
    $("body").calendar_days_modalnav();
    
    // Daymodels menu chooser
    $('#daymodels-menu').calendar_daymodel_form({
        'overlay_selector': ".daymodel-choose-overlay",
        'form_selector': "#daymodel-menu-chooser-form",
        'day_field_selector': "#id_days",
        'daymodel_field_selector': "#id_daymodel"
    });
});
//]]>
</script>
{% endblock %}


{% block datebook_maintitle %}
<div class="row row-fluid">
    <div class="large-10 columns">
        <h2>{% current_title_from_breadcrumbs %}</h2>
    </div>
    <div class="large-2 columns">
        {% comment %}View mode menu{% endcomment %}
        <ul class="button-group gregarious round" id="datebook-view-mode">
            <li><a href="#" class="button tiny to-mosaic" id="datebook-switch-to-mosaic" title="{% trans "Calendar view" %}"><i class="icon-calendar"></i></a></li>
            <li><a href="#" class="button tiny secondary to-flat" id="datebook-switch-to-flat" title="{% trans "Flat view" %}"><i class="icon-list-ul"></i></a></li>
        </ul>
    </div>
</div>
{% endblock %}


{% block datebook_content %}
<div class="row row-fluid">
    
    <div class="large-2 large-push-10 columns">
        <div class="clearfix">
            {% comment %}Weeks stats{% endcomment %}
            <table class="calendar-time-infos">
                <thead>
                    <tr>
                        <th class="text-center">{% trans "Week" %}</th>
                        <th class="text-center"><i class="icon-history" title="Elapsed"></i></th>
                        <th class="text-center"><i class="icon-star-full" title="Overtime"></i></th>
                        <th class="text-center"><i class="icon-sunumbrella" title="Vacations"></i></th>
                    </tr>
                </thead>
                <tbody>
                {% for week in datebook_calendar.weeks_totals %}
                    <tr>
                        <th class="text-right">{{ forloop.counter }}</th>
                        <td class="text-center">
                            {% blocktrans with time_clock=week.elapsed_time %}{{ time_clock }}h{% endblocktrans %}
                        </td>
                        <td class="text-center">
                            {% blocktrans with time_clock=week.overtime_time %}{{ time_clock }}h{% endblocktrans %}
                        </td>
                        <td class="text-center">
                            {% blocktrans with counter=week.vacations %}{{ counter }}d{% endblocktrans %}
                        </td>
                    </tr>
                {% endfor %}
                    <tr class="month_total">
                        <th class="text-right">{% trans "Total" %}</th>
                        <td class="text-center">
                            {% blocktrans with time_clock=datebook_calendar.elapsed_time %}{{ time_clock }}h{% endblocktrans %}
                        </td>
                        <td class="text-center">
                            {% if datebook_calendar.overtime_seconds > 0 %}
                                {% blocktrans with time_clock=datebook_calendar.overtime_time %}{{ time_clock }}h{% endblocktrans %}
                            {% else %}
                                {% blocktrans with time_clock=0 %}{{ time_clock }}h{% endblocktrans %}
                            {% endif %}
                        </td>
                        <td class="text-center">
                            {% if datebook_calendar.vacations > 0 %}
                                {% blocktrans with counter=datebook_calendar.vacations %}{{ counter }}d{% endblocktrans %}
                            {% else %}
                                {% blocktrans with counter=0 %}{{ counter }}d{% endblocktrans %}
                            {% endif %}
                        </td>
                </tbody>
            </table>
            
            {% if user == author or user.is_superuser or perms.datebook.change_dayentry %}
            <hr>
            {% comment %}Daymodel menu chooser{% endcomment %}
            <ul class="button-group gregarious" id="daymodels-menu">
                <li class="opener"><a href="#" class="button tiny"><i class="icon-insert-template"></i> {% blocktrans %}Use models{% endblocktrans %}</a></li>
                <li class="closer" style="display:none"><a href="#" class="button secondary tiny"><i class="icon-times-circle"></i> {% blocktrans %}Close models{% endblocktrans %}</a></li>
                <li class="form" style="display:none">
                    {% crispy daymodels_form %}
                </li>
            </ul>{% endif %}
        </div>
        
        <hr>
        <div class="calendar-notes-container">
            <h3>{% trans "Notes" %}</h3>
            {% if datebook.notes %}
                <div class="content">{% if DATEBOOK_TEXT_MARKUP_RENDER_TEMPLATE %}
                    {% include DATEBOOK_TEXT_MARKUP_RENDER_TEMPLATE with content=datebook.notes %}
                {% else %}
                    {{ datebook.notes|linebreaks }}
                {% endif %}</div>
            {% else %}
                <p class="empty text-center">{% trans "Empty" %}</p>
            {% endif %}
            {% if user == author or user.is_superuser or perms.datebook.change_datebook %}
            <a href="{% url 'datebook:month-notes' author=author year=datebook.period.year month=datebook.period.month %}" class="button expand"><i class="icon-pencil"></i> {% blocktrans %}Edit{% endblocktrans %}</a>
            {% endif %}
        </div>

    </div>
    
    <div class="large-10 large-pull-2 columns">

        {% comment %}The Month calendar{% endcomment %}
        <div class="datebook-month calendar">
            {% comment %}Week day names{% endcomment %}
            <div class="head">
                {% spaceless %}
                    <span class="weekno"></span>
                    {% for classname, name in datebook_calendar.weekheader %}
                    <span class="{% cycle 'mon' 'tue' 'wed' 'thu' 'fri' 'sat' 'sun' %}">{% trans name %}</span>
                    {% endfor %}
                {% endspaceless %}
            </div>
            
            {% spaceless %}
            {% for week in datebook_calendar.month %}
            <div class="week">
                <div class="item weekno">
                    <span class="label radius">{% trans "Week" %}&nbsp;{{ forloop.counter }}</span>
                </div>
                {% comment %}Days looping on the calendar object{% endcomment %}
                {% for day in week %}
                    {% cycle 'mon' 'tue' 'wed' 'thu' 'fri' 'sat' 'sun' as day_name silent %}
                    <div class="item {{ day_name }}{% if day.entry %} has-entry{% if day.entry.vacation %} vacation{% endif %}{% endif %}{% if day.is_current %} current{% endif %}{% if day.noday %} noday{% endif %}{% if day.entry.projected %} projected{% endif %}"
                    {% if not day.noday %}
                    data-date="{{ day.date.day }}"
                    id="{{ day_name }}-{{ day.date.day }}"{% endif %}
                    >
                        {% if not day.noday %}
                            <h3>{{ day.date|date:"l d F" }}</h3>
                            <div class="container">
                                {% if day.entry %}
                                    {% if day.entry.vacation %}
                                        <p class="vacation-label">{% trans "Vacation" %}</p>
                                    {% else %}
                                        <ul class="inline-list time-infos">
                                            {% if not day.entry.projected %}
                                            <li><span class="label round secondary"><i class="icon-history"></i> {{ day.entry.get_working_hours }}</span></li>
                                            <li><span class="label round secondary"><i class="icon-hour-glass"></i> {{ day.entry.get_elapsed_time }}</span></li>
                                            {% if day.entry.get_overtime_seconds > 0 %}<li><span class="label round secondary"><i class="icon-star-full"></i> {{ day.entry.get_overtime_time }}</span></li>{% endif %}
                                            {% else %}
                                            <li><span class="label round secondary"><i class="icon-binoculars"></i> {% blocktrans with time_clock=day.entry.get_elapsed_time %}Expectation: {{ time_clock }}{% endblocktrans %}</span></li>
                                            {% endif %}
                                        </ul>
                                        {% if day.entry.content %}
                                            <div class="content restructuredtext">{% if DATEBOOK_TEXT_MARKUP_RENDER_TEMPLATE %}
                                                {% include DATEBOOK_TEXT_MARKUP_RENDER_TEMPLATE with content=day.entry.content %}
                                            {% else %}
                                                {{ day.entry.content|linebreaks }}
                                            {% endif %}</div>
                                        {% else %}
                                            <p class="empty">{% trans "Empty content" %}</p>
                                        {% endif %}
                                    {% endif %}
                                {% else %}
                                    {% if user == author or user.is_superuser or perms.datebook.add_dayentry %}
                                        {% url 'datebook:day-add' author=author year=datebook.period.year month=datebook.period.month day=day.date.day as add_url %}
                                        <p class="empty">{% blocktrans with add_url=add_url %}There is no entry yet, <a href="{{ add_url }}">add it</a>{% endblocktrans %}</p>
                                    {% else %}
                                        <p class="empty">{% blocktrans %}There is no entry yet{% endblocktrans %}</p>
                                    {% endif %}
                                {% endif %}
                            </div>
                            
                            {% if day.entry %}
                            <div class="menu">
                                <a title="{% trans 'Read' %}" class="read action" href="{% url 'datebook:day-detail' author=author year=datebook.period.year month=datebook.period.month day=day.date.day %}" data-reveal-id="revealDayModal" data-reveal-ajax="true">
                                    <i class="icon-eye"></i>
                                </a> 
                                {% if user == author or user.is_superuser or perms.datebook.change_dayentry %}
                                    <a title="{% trans 'Edit' %}" class="edit action" href="{% url 'datebook:day-edit' author=author year=datebook.period.year month=datebook.period.month day=day.date.day %}"{% comment %} data-reveal-id="revealDayModal" data-reveal-ajax="true"{% endcomment %}>
                                        <i class="icon-pencil"></i>
                                    </a>
                                {% endif %}
                            </div>
                            {% elif user == author or user.is_superuser or perms.datebook.add_dayentry %}
                            <div class="menu">
                                <a title="{% trans 'Add' %}" class="add action" href="{{ add_url }}">
                                    <i class="icon-plus-circle"></i>
                                </a> 
                            </div>
                            {% endif %}
                            {% comment %}
                                Overlay to select item for daymodel assignment
                            {% endcomment %}
                            <div class="daymodel-choose-overlay" style="display:none" data-day-date="{{ day.date.day }}"><div class="inner">
                                {% comment %}<p>Fill this day</p>{% endcomment %}
                                <p class="checkbox-action"><i class="icon-square-o unchecked"></i><i class="icon-check-square-o checked"></i></p>
                            </div></div>
                        {% endif %}
                    </div>
                {% endfor %}
            </div>
            {% endfor %}
            {% endspaceless %}
            
        </div>
        
    </div>
</div>

{% endblock %}

{% block foot_more_js %}<div id="revealDayModal" class="reveal-modal medium" data-reveal="true"></div>{% endblock %}