{% extends 'warp_base.html' %}
{% load staticfiles %}
{% load l10n %}
{% comment %} {% endcomment %}

{% block custom_style_link %}{% endblock %}
{% block custom_style_inline %}

.glyphicon-none:before {
    content: "\2122";
    color: transparent !important;
}

.ops:hover {cursor: pointer; cursor: hand; color:blue}
.ops:hover {cursor: pointer; cursor: hand; color:blue}

{% endblock %}
{% block custom_js %}
<script src="/static/warp/js/bootbox.js"></script>
<script type="text/javascript">
$(document).ready(function() {
    $("tr").click(function(event) {
        if (event.target.tagName == 'SPAN'){
            event.stopPropagation();
            switch (event.target.id){
                case "edit":{
                    window.location = "/warp/editdataset/"+event.target.parentElement.parentElement.id+"/";
                }
                break;
                case "view":{
                    window.location = "/warp/viewdataset/"+event.target.parentElement.parentElement.id+"/";
                }
                break;
                case "download":{
                    window.location = "/warp/download_dataset/"+event.target.parentElement.parentElement.id+"/";
                }
                break;
                case "remove":{
                    bootbox.confirm("Do you really want to remove dataset? " + event.target.parentElement.parentElement.id.toString(), function(result) {
                        if (result) { window.location = "/warp/removedataset/" + event.target.parentElement.parentElement.id+"/"; }
                    });
                }
                break;
                case "trash":{
                    bootbox.confirm("Do you really want to empty trash? " + event.target.parentElement.parentElement.id.toString(), function(result) {
                        if (result) { window.location = "/warp/emptytrash/"; }
                    });
                }
                break;
            }
        } else {
            window.location = "/warp/"+event.target.parentElement.id+"/";
        }
    });

    $(".newds").click(function(event) {
        window.location = "/warp/newdataset/"
    });
    /*
    $("#edit, #remove", "none").click(function(event) {
        event.stopPropagation();
        window.location = event.target.href
    });*/
});
</script>
{% endblock %}
{% block onload %}{% endblock %}
{% block titolo %}DATASETS {% if source %}{{source.fileName}}{% endif %}{% endblock %}
{% block menu %}{% endblock %}
{% block contenuto %}


<div class="container">
    <div class="col-md-12">
            {% if alert %}
            <div class="alert {{ alert.class }}">
              <a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>
              <strong>{{ alert.message }}</strong>
            </div>
            {% endif %}
            <a type="button" class="newds btn btn-default">New Dataset</a>
            <table class="table table-hover">
              <caption></caption>
              <thead>
                <tr>
                  <th>#</th>
                  <th>Name</th>
                  <th>EPSG code</th>
                  <th>extents left/bottom/right/top</th>
                  <th></th>
                </tr>
              </thead>
              <tbody>
                  {% for item in items %}
                  <tr id="{{item.pk}}" {% if item.name == "__TRASH" %}class="active"{% endif %}>
                    <th scope="row">{% if item.name != "__TRASH" %}{{item.pk}}{% endif %}</th>
                    <td>{{item.name}}</td>
                    <td>{% if item.name != "__TRASH" %}{{item.epsg}}{% endif %}</td>
                    <td>{% if item.name != "__TRASH" %}{% localize off %}{{item.extentLeft}}/{{item.extentBottom}}/{{item.extentRight}}/{{item.extentTop}}{% endlocalize %}{% endif %}</td>
                    <td>
                         {% if item.name == "__TRASH" %}
                             <span id="trash" class="ops glyphicon glyphicon-trash" aria-hidden="true"></span>
                             <span id="none" class="glyphicon glyphicon-none" aria-hidden="true"></span>

                         {% else %}
                                <span id="view" class="ops glyphicon glyphicon-eye-open" aria-hidden="true"></span>
                                <span id="download" class="ops glyphicon glyphicon-download" aria-hidden="true"></span>
                                <span id="edit" class="ops glyphicon glyphicon-edit" aria-hidden="true"></span>
                             {% if item.pk in removable %}
                                <span id="remove" class="ops glyphicon glyphicon-remove" aria-hidden="true"></span>
                             {% else %}
                                <span id="none" class="ops glyphicon glyphicon-none" aria-hidden="true"></span>
                             {% endif %}
                         {% endif %}
                    </td>
                  </tr>
                  {% endfor %}
              </tbody>
            </table>
            <a type="button" class="newds btn btn-default">New Dataset</a>
    </div>
</div>

{% endblock %}
{% block piedipagina %}{% endblock %}
