{# Display edit-workspace #}
{% load i18n workspaces %}
<div id="edit-workspace"
     class="sidebarbox workspace"
     data-workspace-id="{{ workspace_edit.id }}"
     data-url-lizard-map-workspace-item-toggle="{% url lizard_map_workspace_item_toggle %}"
     data-url-lizard-map-workspace-item-delete="{% url lizard_map_workspace_item_delete %}"
     data-url-lizard-map-workspace-item-reorder="{% url lizard_map_workspace_item_reorder %}"
     data-url-lizard-map-workspace-item-edit="{% url lizard_map_workspace_edit_item %}"
     data-url-lizard-map-search-coordinates="{% url lizard_map.search_coordinates %}"
     data-url-lizard-map-search-name="{% url lizard_map.search_name %}"
     data-url-lizard-map-add-selection="{% url lizard_map_collage %}"
     data-url-lizard-map-workspace-item-extent="{% url lizard_map_workspace_item_extent %}"
     >
  <h2>
    <span title="{% trans 'This is your workspace. Hover your mouse over the containing items to see options.' %}">
      {% trans 'Layers' %}
    </span>
  </h2>

  <table id="edit-workspace-table" class="workspace-items ui-sortable wscol-table">
  <tbody>
    {% for workspace_item in workspace_edit.workspace_items.all %}
      <tr id="workspace-item-{{ workspace_item.id }}"
          class="workspace-item paddme"
          data-object-id="{{ workspace_item.id }}"
          data-adapter-class="{{ workspace_item.adapter_class }}"
          data-adapter-layer-json='{{ workspace_item.adapter_layer_json }}'
          data-visible="{{ workspace_item.visible }}">
        <td class="icontd">
          {# Symbol, appears left. #}
          {% if workspace_item.adapter.symbol_url %}
          <img class="workspace-item-image"
               src="{{ workspace_item.adapter.symbol_url }}"
               width="16"
               height="16" />
          {% endif %}
        </td>
        <td class="icontd">
          <input id="{{ workspace_item.id }}"
                 class="workspace-item-checkbox"
                 type="checkbox"
                 {% if workspace_item.visible %}
                   checked="checked"
                 {% endif %}
                 data-workspace-id="{{ workspace.id }}" />
        </td>
        <td class="maintd">
          {% firstof workspace_item.name '(noname)' %}
        </td>
        <td class="lasttd">
        {% if workspace_item.has_extent %}
          <span class="ss_sprite ss_magnifier sidebarbox-action-icon
                       workspace-item-pan-to"
                title="{% trans 'Zoom to extent' %}"></span>
        {% else %}
          <span class="no-image-spacer"></span>
        {% endif %}
          <span class="ss_sprite ss_delete sidebarbox-action-icon
                       workspace-item-delete"
                title="{% trans 'Delete item' %}"></span>
        {% comment TODO needs some refactoring %}
        {% legend workspace_item.name workspace_item.adapter session %}
        {% endcomment %}
        </td>
      </tr>
    {% empty %}
      {# No workspace items #}
      <tr><td>{% trans 'No map layers selected.' %}</td></tr>
    {% endfor %}
  </tbody>
  </table>

  <ul class="wscol-actions">
    <li>
      <a id="workspace-empty"
         href="{% url lizard_map_workspace_empty %}"
         class="btn btn-danger sidebarbox-action-icon action-post-workspace-empty"
         title="{% trans 'Empty your workspace' %}">
        <i class="icon-trash icon-white"></i>
      </a>
    </li>

    <li>
      <button id="workspace-save"
         href="{% url lizard_map_workspace_save %}"
         class="btn sidebarbox-action-icon popup-workspace-save"
         data-size="xs"
         title="{% trans 'Save your workspace' %}"
         {% if not workspace_edit.workspace_items.exists %} disabled="disabled" {% endif %}>
        <i class="ss_sprite ss_database_save"></i>
      </button>
    </li>

    {% comment %}
    The added value of next link might not be obvious to a user, because workspace-load
    seems to offer comparable functionality. A subtle difference is that it reveals a
    URL to a read-only workspace, which you can send around via email.
    {% endcomment %}
    {% comment %}
      <a id="workspace-link-to-stored"
         href="{% url lizard_map_workspace_storage_list %}"
         title="{% trans 'Stored workspaces...' %}"
         class="title ss_sprite ss_database sidebarbox-action-icon ajax-dialog"
         data-size="xs">&nbsp;</a>
    {% endcomment %}

    {% comment %}
      <a id="workspace-load"
         href="{% url lizard_map_workspace_load %}"
         title="{% trans 'Load workspace...' %}"
         class="title ss_sprite ss_database_go sidebarbox-action-icon ajax-dialog"
         data-size="xs">&nbsp;</a>
    {% endcomment %}
  </ul>
</div>
