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

{% load file_tags %}
{% load styled_forms %}
{% load i18n %}

{% block title %}{{ block.super }}Edit{% endblock %}

{% block extra_head %}
{{ block.super }}
<link rel="stylesheet" href="{{ STATIC_URL }}css/files.css">
<script type="text/javascript" src="{{ TINYMCE_JS_URL }}"></script>
{% endblock %}

{% block body %}
<div class="t">

    {% file_nav request.user %}

    <h1>{% trans "File Edit" %}</h1>

    <div class="forms">
	    <form action="{% url file.edit file.pk %}" method="post" enctype="multipart/form-data">{% csrf_token %}
	        {{ form|styled_form }}
	        <fieldset class="boxy-grey" >
                <legend id="category-title" style="cursor: pointer"><span>+</span> {% trans "Category" %}</legend>
                <div id="category-form">
                    {{ categoryform|styled_form }}
                </div>
            </fieldset>
	        <input type="submit" value="Save changes" />
	    </form>
    </div>

    <div class="loading-message">
        <img src="{{ STATIC_URL }}images/loadingicon.gif"/>
    </div>

</div>

{% endblock %}

{% block extra_body %}
    {{ block.super }}
    <script type="text/javascript" src="{{ STATIC_URL }}js/jquery-blockUI.js"></script>
    <script type="text/javascript">
		$(document).ready(function(){
			// delete confirmation
			$('.add-category').click(function(){
				select_box = $(this).parent().prev().find('select');
				var category = prompt('Category Name?','').toLowerCase();
				category = category.replace('"','')
				var option_html = '<option selected="selected" value="' + category + '">' + category + '</option>';
				if (category) select_box.append(option_html) 
				return false;
			});
			$('.add-sub-category').click(function(){
				select_box = $(this).parent().prev().find('select');
				var sub_category = prompt('Category Name?','').toLowerCase();
				sub_category = sub_category.replace('"','')
				var option_html = '<option selected="selected" value="' + sub_category + '">' + sub_category + '</option>';
				if (sub_category) select_box.append(option_html) 
				return false;
			});
            $('.loading-message').hide();
		});
    </script>
    <script type="text/javascript">
        $('#category-form').hide();
        $('#category-title').click(function() {
            $('#category-form').slideToggle('fast');
             if ($('#category-title span').text() == '+') {
                $('#category-title span').text('-');}
            else {$('#category-title span').text('+');}
        });
        $('.forms form input[type="submit"]').click(function() { 
            $.blockUI({
                message: $('.loading-message')
            });
        });
    </script>
{% endblock %}
