{% extends "webgateway/core_html.html" %}
{% load i18n %}

{% comment %}
<!--
  Copyright (C) 2011-2014 University of Dundee & Open Microscopy Environment.
  All rights reserved.

  This program is free software: you can redistribute it and/or modify
  it under the terms of the GNU Affero General Public License as
  published by the Free Software Foundation, either version 3 of the
  License, or (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU Affero General Public License for more details.

  You should have received a copy of the GNU Affero General Public License
  along with this program.  If not, see <http://www.gnu.org/licenses/>.
-->
{% endcomment %}

{% block link %}
    {{ block.super }}
    <link rel="stylesheet" href="{% static "webclient/css/layout.css"|add:url_suffix %}" type="text/css" />
    <link rel="stylesheet" href="{% static "webgateway/css/ome.login.css"|add:url_suffix %}" type="text/css" />
{% endblock %}

{% block title %}
    {% trans "OMERO.web - Login" %}
{% endblock %}


{% block script %}
    
	{% include "webgateway/base/includes/script_src_jquery.html" %}
	<script src="{% static 'webclient/javascript/jquery.infieldlabel-0.1.js' %}" type="text/javascript"></script>

    {% if show_download_links %}
    <script>
        function _update_download_href(tags) {
            var vermatch = RegExp("{{ client_download_tag_re }}");
            var insighttag;
            for (var i = 0; i < tags.length; i++) {
                if (tags[i].name && tags[i].name.match(vermatch)) {
                    insighttag = tags[i].name;
                    break;
                }
            }
            if (insighttag) {
                var insight_base = "https://github.com/" + "{{ client_download_repo }}" +
                    "/releases/download/" + insighttag + "/OMERO.insight-" + insighttag.substring(1);
                $("#download-insight-mac").attr("href", insight_base + ".dmg");
                $("#download-insight-win").attr("href", insight_base + ".exe");
                $("#download-insight-linux").attr("href", insight_base + ".zip");
            }
        }

        $(document).ready(function(){
            $.get("https://api.github.com/repos/" + "{{ client_download_repo }}" + "/tags", _update_download_href);
        });
    </script>
    {% endif %}

{% endblock %}


{% block head %}
    {{ block.super }}
	<meta name="viewport" content="width=device-width, initial-scale=1" />

	<script type="text/javascript" charset="utf-8">
			$(function(){ $("label").inFieldLabels(); });
		</script>
	
{% endblock %}

{% block body %}

<div style="margin: auto">

<div style="margin: 5% auto 0; height: 100px"></div>
<div class="login-logos">
    <div class="custom_logo">
        {% if LOGIN_LOGO %}
            <img src="{{ LOGIN_LOGO }}" />
        {% else %}
            <img src="{% static "webclient/image/custom_login_logo.png" %}" />
        {% endif %}
    </div>
    <img src="{% static "webclient/image/logo_login_web.png" %}" />
</div>

<div id="login">
    {% block login %}
    <form class="standard_form inlined" action="{% url 'weblogin' %}{% if url %}?{{url}}{% endif %}" method="post">{% csrf_token %}
            {% if error %}
				<span class="error">{% trans "Error:" %} {{ error | urlize }}</span>
			{% endif %}
			
			<div id="choose_server">
					
					{% comment %}
					{% trans form.server.label_tag %}
					{% endcomment %}
					
			  		{{ form.server }}
			   
			   <!-- Form Error -->
				{% if form.server.errors %}
	                 {% for error in form.server.errors %}
	                     <span class="form_error">{{ error|escape }}</span>
	                 {% endfor %}
				{% endif %}
		   </div>

			<div>
				{% trans form.username.label_tag %}
				<!--{% if form.username.field.required %}*{% endif %} -->
				{{ form.username }}
				<!-- Form Error -->
				{% if form.username.errors %}
                  {% for error in form.username.errors %}
                      <span class="form_error">{{ error|escape }}</span>
                  {% endfor %}
				{% endif %}
			</div>
			
			<div>
				{% trans form.password.label_tag %}
				<!--{% if form.password.field.required %}*{% endif %}-->
	            {{ form.password }}
				<!-- Form Error -->
				{% if form.password.errors %}
                  {% for error in form.password.errors %}
                      <span class="form_error">{{ error|escape }}</span>
                  {% endfor %}
				{% endif %}
			</div>

        	<input type="submit" value="Login" />

            <div>
                <p style="min-height: 15px">
		    {% if show_forgot_password %}
		        <a href="{% url 'waforgottenpassword' %}">Forgot your password?</a>
		    {% endif %}
                </p>
            </div>

            {% if public_enabled %}
                <hr class="login-divider"/>
                <div class="login-link">
                    <a class="login-link-text" href="{{ public_login_redirect }}">Log in as public user</a>
                </div>
            {% endif %}

    </form>

    {% endblock %}
</div>

<div id="login-footer">
	<p>
		OMERO.web {{ version }}.<br/>
		&copy; 2007-{{ build_year }} University of Dundee &amp; Open Microscopy Environment<br/>
		OMERO is distributed under the terms of the GNU GPL.
		For more information, visit <a href="https://www.openmicroscopy.org">openmicroscopy.org</a><br/>

        {% if show_download_links %}
            Download OMERO.insight for
            <a href="https://www.openmicroscopy.org/omero/downloads/" id="download-insight-mac">Mac OS X</a>,
            <a href="https://www.openmicroscopy.org/omero/downloads/" id="download-insight-win">Windows</a>,
            <a href="https://www.openmicroscopy.org/omero/downloads/" id="download-insight-linux">Linux</a><br>
        {% endif %}

        <img src="{% static 'webgateway/img/OME_logo_grey_110.png' %}"/>
    </p>
</div>
{% endblock %}
