{% extends "ldt/ldt_utils/workspace_base.html" %}
{% load i18n %}
{% load absstatic %}
{% load absurl %}

 {# form of creation of content #}
{% load adminmedia %}

{% block js_import %}
	{{ block.super }}
    <script type="text/javascript" src="{{ADMIN_MEDIA_PREFIX}}js/core.js" ></script>
    <script type="text/javascript" src="{{ADMIN_MEDIA_PREFIX}}js/jquery.init.js"></script>
    <script type="text/javascript" src="{{ADMIN_MEDIA_PREFIX}}js/jquery.min.js"></script>
    <script type="text/javascript" src="{% absurl ldt.jsi18n packages='ldt' %}" ></script>
    <script type="text/javascript" src='{% absstatic "ldt/js/projectscontents.js" %}'></script>
    <script type="text/javascript" src='{% absstatic "ldt/js/jquery.textchange.min.js" %}'></script>
    <script type="text/javascript" src='{% absstatic "ldt/js/jquery-ui.min.js" %}'></script>
    <script type="text/javascript" src='{% absstatic "ldt/js/swfupload/swfupload.js" %}'></script>
	
	{{ content_form.media.js }}
{% endblock %}

{% block js_declaration %}
	<script type="text/javascript">
	window.__admin_media_prefix__ = "{% filter escapejs %}{% admin_media_prefix %}{% endfilter %}";
	
	$(document).ready(function() {
		// url_upload, media_prefix, post_added_params, btn_label, success_label, wait_label, cancel_label, remove_url, get_dur_url
		post_added_params = {"csrfmiddlewaretoken" : "{{csrf_token}}",
                    		"{{cookie_name}}" : "{{session_key}}"};
		
		onCreateContentReady("{% url ldt.ldt_utils.views.content.upload %}",
							'{% absstatic "ldt" %}',
							post_added_params,
							'{% trans "Browse" %}',
							'{% trans "File uploaded" %}',
							'{% trans "Please wait, the upload is not finished yet" %}',
							'{% trans "Cancel upload" %}',
							"{% url ldt.ldt_utils.views.content.remove_temp_file %}",
							"{% url ldt.ldt_utils.views.content.get_duration %}");
		
	});
	// the function stopRKey prevents from the validation of the form if the user tape enter button while entering a field 
	function stopRKey(evt) {
		  var evt = (evt) ? evt : ((event) ? event : null);
		  var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
		  if ((evt.keyCode == 13) && (node.type=="text"))  {return false;}
		}

	document.onkeypress = stopRKey;

	
    </script>
{% endblock %}

{% block css_import %}
	{{ block.super }}
	{{ content_form.media.css }}
	<link rel="stylesheet" href='{% absstatic "ldt/css/ldtform.css" %}'/>
	<link rel="stylesheet" href='{% absstatic "ldt/css/style.css" %}'/>
	<link rel="stylesheet" href='{% absstatic "ldt/css/blueprint/screen.css" %}' type="text/css" media="screen, projection" />
	<link rel="stylesheet" href='{% absstatic "ldt/css/blueprint/print.css" %}' type="text/css" media="print" />
	<link rel="stylesheet" href='{% absstatic "ldt//css/workspace.css" %}'type="text/css"/>
	
	
{% endblock %}

{% block content %}

	
	{% if media_form.errors %}
	<div id="media-form-error">
		<p>{% trans "The operation could not be performed because one or more error(s) occurred.<br />Please resubmit the media form after making the following changes:" %}</p>
		<ul>
		{% for field in media_form %}
		{% if field.errors%}<li>{{field.name}} : {{ field.errors|striptags }}</li>{% endif %}
		{% endfor %}
		</ul>
	</div>
	{% endif %}

	{{ media_form.errors }}
	{{ picture_form.errors }}
	{{ content_form.errors }}

	<div id="add_content" class="span-18 last">
	<div class="projectscontentstitle">{% trans "Create content" %}</div>
	<form action="{{create_content_action}}" enctype="multipart/form-data" id="my_form" method="POST" enctype="multipart/form-data" >
	
	<div id="contentformhidden">
		{% csrf_token %}
		<input type="hidden" name="form_status" value="{{form_status}}" id="content_form_status" />
		{% for hidden in form.hidden_fields %}
	    	{{ hidden }}
	    {% endfor %}
	    {{content_form.iri_id}}
    </div>
    <div id="contentformfields" class="span-18 last">
	<div id="contentleft" class="span-9">
		<div>{{ content_form.src.errors }}{{ content_form.src.label_tag }}{{content_form.src}}</div>
		<div>{{ content_form.videopath.errors }}{{ content_form.videopath.label_tag }}{{content_form.videopath}}</div>
		<div>{{ content_form.title.errors }}{{ content_form.title.label_tag }}{{content_form.title}}</div>
		<div>{{ content_form.description.errors }}{{ content_form.description.label_tag }}{{content_form.description}}</div>
	</div>
	<div id="contentright" class="span-9 last" >
		<div>{{ content_form.external_id.errors }}{{ content_form.external_id.label_tag }}{{content_form.external_id}}</div>
		<div>{{ content_form.duration.errors }}{{ content_form.duration.label_tag }}{{content_form.duration}}</div>
		<div>{{ content_form.content_creation_date.errors }}{{ content_form.content_creation_date.label_tag }}{{content_form.content_creation_date}}</div>
		<div>{{ content_form.tags.errors }}{{ content_form.tags.label_tag }}{{content_form.tags}}</div>
		<div>{{ content_form.media_input_type.errors }}{{ content_form.media_input_type.label_tag }}{{content_form.media_input_type}}</div>
		<div id="media_fields_div">
			<div id="media_field_link" class="media_fields">{{ content_form.media_obj.errors }}{{ content_form.media_obj.label_tag }}{{content_form.media_obj}}</div>
			<div id="media_field_upload" class="media_fields">
				{{ media_form.media_file.errors }}
				{% comment %}{{ media_form.media_file.label_tag }}{{media_form.media_file}}{% endcomment %}
				<div id="upload_btn"></div>
				<input type="text" name="media-local_file_name" id="id_media-local_file_name" readonly/>
				<div id="upload_progress_bar"></div>
				<div id="upload_progress_info"></div>
			</div>
			<div id="media_field_url" class="media_fields">{{ media_form.external_src_url.errors }}{{ media_form.external_src_url.label_tag }}{{ media_form.external_src_url }}</div>
			<div id="media_field_create" class="media_fields">{{ media_form.src.errors }}{{ media_form.src.label_tag }}{{ media_form.src }}</div>
		</div>
	</div>	 
	
		{% if iri_id and user.is_staff %}
		<div>{% trans 'Actual front project' %} : {{ current_front_project }}
		<button type="submit" value="prepare_reset" name="submit_button">{% trans "reset_front_project" %}</button>
		{{ content_form.front_project.label_tag }}{{ content_form.front_project }}
		</div>
		
		{% else %}
		<div style="display:none">{{ content_form.front_project }}</div>
		{% endif %}
	{% include "ldt/ldt_utils/partial/picture.html"%}
	{% include "ldt/ldt_utils/partial/permissions.html" %}

		
	<div id="submitcontent" class="span-18 last">
		<div id="submitcontent-loader" class="span-10">
			<div id="submitcontent-loader-img" class="submitcontent-loader-content span-10 last"><img alt="loader" src='{% absstatic "ldt/img/ajax-loader-220x19.gif" %}'/></div>
			<div id="submitcontent-loader-msg" class="submitcontent-loader-content span-10 last">{% trans "media file is being processed please wait." %}</div>
			<span>&nbsp;</span>
		</div>
		<div id="submitcontent-buttons" class="span-8 last">
			<button type="submit" value="close" name="submit_button" id="submit_button_close">{% trans 'close_cancel' %}</button>
			{% if iri_id %}<button type="submit" value="prepare_delete" name="submit_button">{% trans "delete" %}</button>{% endif %}
			<button type="submit" value="write" name="submit_button" id="submit_button_write">{% trans "write" %}</button>
		</div>
	</div>
	
	</form>
	</div>
{% endblock %}
