{% extends "blog/base.html" %}

{% block extra_scripts %}
  <script type="text/javascript" src="/scripts/blog_admin.js"></script>
{% endblock %}

{% block extra_sheets %}
  <link rel="stylesheet" type="text/css" href="/stylesheets/admin.css" />
{% endblock %}

{% block title %}
  <title>loopvid blog admin page</title>
{% endblock %}

{% block page_title %}
{% endblock %}

{% block page %}
  <div class="admin page">
    <div class="admin_list_form">
      <div class="admin_form">
        <div>
          <div {% if not show_check_all %}class="hidden"{% endif %}>
            <input type="checkbox" id="check_all" />
            apply to all
          </div>
          <form action="/blog/json/admin/update_entries" id="admin_page_form">
            <input type="hidden" name="videos" id="videos" class="text_input" />

            <select name="db_action" id="select_action">
              <option value="" selected="selected">Select action</option>
              <option value="add_tags">Add tags</option>
              <option value="remove_tags">Remove tags</option>
              <option value="change_source">Change source</option>
              <option value="update_thumbs">Update thumbnails</option>
              <option value="remove_videos">Delete videos</option>
              <option value="rename_videos">Rename videos</option>
            </select>

            <input id="source_url" name="source_url" type="text" class="text_input hidden" placeholder="URL" />
            <input id="source_text" name="source_text" type="text" class="text_input hidden" placeholder="Title" />
            <input id="tags" name="tags" type="text" class="text_input hidden" placeholder="Space-separated list of tags" />
            <input id="new_names" name="new_names" type="text" class="text_input hidden" placeholder="Space-separated list of video names" />

            <div><input type="submit" id="submit_button" value="Submit" /></div>
          </form>
        </div>
        <div class="hidden"><pre id="messages"></pre></div>
      </div>
    </div>

    <div class="admin_list">
      {#- avoid leaving spaces here so they don't mess up the margins -#}
      {%- for entry in entries -%}
        <div class="admin_list_item">
          <div class="admin_list_thumb">
            <a class="thumb_link" href="/{{ entry['name'] | e }}" target="_blank">
              <img class="thumbnail" src="{{ entry['img'] | e }}" alt="{{ entry['name'] | e }}" />
            </a>
          </div>
          <div>
            <input type="checkbox" name="{{ entry['name'] | e }}" class="video_checkbox" data-num="{{ loop.index }}" />
            <a class="video_link" href="/{{ entry['name'] | e }}">{{ entry['name'] | e }}</a>
          </div>

          <div class="source">
            Source:
            <div class="inner_source">
              {% if entry['source_url'] %}
                <a rel="noreferrer" href="{{ entry['source_url'] | e }}" class="source_url" id="url{{ loop.index }}">
                  {{- entry['source_url'] | e -}}
                </a>
              {% endif %}
            </div>
            <div class="inner_source">
              <span class="source_text" id="text{{ loop.index }}">{{ entry['source_text'] | e }}</span>
            </div>
            <div class="inner_source">
              <a href="/blog/admin?source={{ entry['source_shortlink'] }}" class="source_shortlink">
                {{ entry['source_shortlink'] }}
              </a>
            </div>
          </div>

          <div class="tags">
            tagged:
            {% for tag in entry['tags'] %}
              <a class="page_link" href="/blog/admin/list?tags={{ tag | urlquote }}">{{ tag | e }}</a>
            {% endfor %}
          </div>

          <div class="posted_at">
            posted at: {{ entry['posted_at'] }}
          </div>

          <form class="video_new_tags_form" action="/blog/json/admin/update_entries">
            <input type="hidden" name="videos" value="{{ entry['name'] | e }}" />
            <input type="hidden" name="db_action" value="add_tags" />
            <input name="tags"
              type="text"
              class="text_input"
              id="tags_for_{{ entry['name'] | e }}"
              placeholder="New tags for this video"
            />
            <input type="submit" class="submit_video_tags" value="Submit" data-video="{{ entry['name'] | e }}" />
          </form>
          <div class="video_messages" id="messages_for_{{ entry['name'] | e }}"></div>
        </div>
      {%- endfor -%}
    </div>
  </div>
{% endblock %}
