{% extends "filemanager/filemanager_base.html" %}

{% load i18n static %}

{% block content %}
{% include "filemanager/filemanager_breadcrumbs.html" %}

<table class="table">
  <thead>
    <tr>
      {% if popup %}<th>{% trans "Select" %}</th>{% endif %}
      <th>{% trans "Type" %}</th>
      <th>{% trans "Name" %}</th>
      <th>{% trans "Size" %}</th>
      <th>{% trans "Date" %}</th>
      {% if not popup %}<th>{% trans "Actions" %}</th>{% endif %}
    </tr>
  </thead>
  <tbody>
    {% for file in files %}
    <tr>
      {% if popup %}
      {% if file.filetype == "Directory" %}
      <td></td>
      {% else %}
      <td><a href="javascript: Filemanager.select('{{file.filepath}}');">{% trans "Select" %}</a></td>
      {% endif %}
      {% endif %}
      <td>{{file.filetype}}</td>
      {% if file.filetype == "Directory" %}
      <td><a href="?path={{file.filepath}}{% if popup %}&amp;popup=1{% endif %}">{{file.filename}}</a></td>
      {% else %}
      <td class='get_img' data-patch='{{file.filepath}}'>{{file.filename}}</td>
      {% endif %}
      <td>{{file.filesize}}</td>
      <td>{{file.filedate}}</td>
      {% if not popup %}<td><a href="{% url 'filemanager:detail' %}?path={{file.filepath}}">{% trans "Details" %}</a></td>{% endif %}
    </tr>
    {% empty %}
    <tr>
      <td colspan="5">
        {% trans "Nothing to see here." %}
      </td>
    </tr>
    {% endfor %}
  </tbody>
</table>
<div>
  <a href="{% url 'filemanager:create-directory' %}?path={{path}}{% if popup %}&amp;popup=1{% endif %}" class="btn btn-default">{% trans "Create directory" %}</a>
  <a href="{% url 'filemanager:upload' %}?path={{path}}{% if popup %}&amp;popup=1{% endif %}" class="btn btn-default">{% trans "Upload" %}</a>
</div>

{% if popup %}
<script src="{% static 'js/filemanager.js' %}"></script>
{% endif %}
{% endblock %}

{% block js %}
<script src="{% static '/static/tinymce_4/tinymce/tinymce.min.js' %} "></script>
<script>
$(".table").on( "click", ".get_img", function(e){
    console.log('click');
    e.preventDefault();
    img = '/media/uploads/' + $(this).data('patch');
    //top.tinymce.activeEditor.windowManager.close();
    //var selectedImage = img;
    
    console.log(img);

    var args = top.tinymce.activeEditor.windowManager.getParams();
    win = (args.window);
    input = (args.input);
    win.document.getElementById(input).value = img;
    console.log(win.document.getElementById(input).value)
    top.tinymce.activeEditor.windowManager.close();
});
</script>
{% endblock %}

