{% extends "ldt/ldt_raw_base.html" %}
{% load static %}
{% load i18n %} {# form of creation of content #}

{% block js_import %}
	{{ block.super }}
    <script type="text/javascript" src='{% static "ldt/js/jquery.nyroModal.min.js" %}'></script>
    <script type="text/javascript" src="{% url 'ldt.jsi18n' packages='ldt' %}" ></script> 
    <script type="text/javascript" src='{% static "ldt/js/projectscontents.js" %}'></script>  
	<script type="text/javascript" src='{% static "ldt/js/tiny_mce/tiny_mce.js" %}'></script>
	{{ content_form.media.js }}
{% endblock %}

{% block css_import %}
	{{ block.super }}
	{{ content_form.media.css }}
	<link rel="stylesheet" href='{% static "ldt/css/ldt.css" %}' />
	<link rel="stylesheet" href='{% static "ldt/css/ldtform.css" %}' />
	<link rel="stylesheet" href='{% static "ldt/css/workspace.css" %}' />	
{% endblock %}

{% block js_declaration %}
	{{ block.super }}
	<script type="text/javascript">
	
	$(document).ready(function() {
		check_uncheck_all("content");
		
		var form_status = $("input[name=form_status]").val();
		var redirect_to = '{{ redirect_to }}';
		
		if (form_status == "saved" && redirect_to) {
			parent.location.href = redirect_to;
			parent.$.nmTop.close();
		}
		
		$("#close_button").click(function (e) {
			e.preventDefault();
			parent.$.nmTop().close();
		});	
		
		$("#moreoptions").click(function () {
			var container = $("#moreoptionscontainer");
			
			if (container.is(':visible')) {
				$("#moreoptionscontainer").hide();
				$("#moreoptions").html("{% trans 'more options' %}");
				resize_modal_window($("#add_contribution"));
			} else {
				$("#moreoptionscontainer").show();
				$("#moreoptions").html("{% trans 'hide' %}");
				resize_modal_window($("#add_contribution"));
			}
		});
		
	});
	
    tinyMCE.init({
        plugins : '-example', 
        mode : "textareas",
        theme : "advanced",
        language : "{{ LANGUAGE_CODE }}",
        theme_advanced_buttons1 : "bold,italic,underline,separator,justifyleft,justifycenter,justifyfull,undo,redo,link,unlink",
        theme_advanced_buttons2 : "",
        theme_advanced_buttons3 : "",
        theme_advanced_toolbar_location : "top",
        theme_advanced_toolbar_align : "left",
        width: "250",
        height: "150",
        entity_encoding : "raw"
	});
	
	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 body %}
	<div id="add_contribution" class="span-18 last">
	<div class="projectscontentstitle span-18 last">{% if ldt_id %}{% trans "Update your project" %}{% else %}{% trans "Create your project" %}{% endif %}</div>
	<form action="{{create_project_action}}" enctype="multipart/form-data" method="POST" {% if target_parent %}target="_parent"{% endif %}>
	{% csrf_token %} 
	<input type="hidden" name="form_status" value="{{form_status}}" id="project_form_status" />	

	<div id="contentleft" class="span-9">
	<label for="title">{% trans "Title" %}:</label>
	{{form.title}}
	{% for error in form.title.errors %}
	<span class="error">{{ error }}</span>
	{% endfor %}
	<label for="description" class="projectdesc">{% trans "Description :" %}</label>
	{{form.description}}
	</div>	
     
   	<div id="contentright" class="span-9 last">
	<label>{% trans "List of contents" %}</label>

		<div class="span-8 last" id="ldtcreatecontentslistcontainer">
			<div class="span-8 last projectscontentstablediv" id="ldtcreatecontentstablediv">
				<table class="projectscontentstable">
				
					<tr class="projectscontentsheader last" id="contentslistheader">
						<td class="cellcheckbox">
						{% if not ldt_id %}
							{% if contents|length > 1 %}
							<input class="selectallcontents" id="global_checkbox_content" type="checkbox" checked="true" />	 
							{% endif %}
						{% endif %}	
						</td>				
						<td class="projectcontentsheadertitle">{% trans "name" %}</td>
					</tr>
				
				    <tbody class="projectscontentsbody">
				{% for content in contents %}
					<tr class="imageline {% cycle 'projectscontentsoddline' 'projectscontentsevenline'%}">
					    <td class="cellcheckbox"><input type="checkbox" class="checkbox_content" name="contents" value="{{ content.id }}" checked="true" {% if ldt_id %}disabled="disabled"{% endif %} /></td>
					    <td class="contenttitle">{{ content.title }}</td>
					</tr>
				{% endfor %}
					</tbody>
				</table>			
			</div>
		</div>
	</div>		
	
	<div id="moreoptions">{% trans 'More options' %}</div>
	<div id="moreoptionscontainer">
	{% include "ldt/ldt_utils/partial/picture.html" %}
	{% include "ldt/ldt_utils/partial/permissions.html" %}
    </div>      
            
    <div id="submitcontent" class="span-18 last">
                   
	    <div id="submitcontent-buttons" class="span-18 last">
			<button type="button" id="close_button"  value="close">{% trans 'close_cancel' %}</button>
			{% if ldt_id %}
			<button class="button" id="ldt_submit" type="submit" value="prepare_delete" name="submit_button">{% trans "delete_project" %}</button>
			{% if display_reset %}
			<button class="button" id="ldt_submit" type="submit" value="prepare_reset" name="submit_button">{% trans "reset_front_project" %}</button>
			{% endif %}
			<button class="button" id="ldt_submit" type="submit" value="update" name="submit_button">{% trans "update_project" %}</button>
			{% else %}
			<button class="button" id="ldt_submit" type="submit" value="create" name="submit_button">{% trans "create_project" %}</button>
			{% endif %}
	    </div>
	  </div>
    
    </form> 
    </div>  
		
{% endblock %}

