{% extends "ldt/ldt_raw_base.html" %}

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

{% block js_import %}
	{{ block.super }}
    <script type="text/javascript" src="{{LDT_MEDIA_PREFIX}}/js/jquery.nyroModal.min.js"></script>    
	{{ content_form.media.js }}
{% endblock %}

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

{% block js_declaration %}
	{{ block.super }}
	<script type="text/javascript">
	function check_uncheck_all(name) {
		var check_all = '{% trans "check all" %}';
		var uncheck_all = '{% trans "uncheck all" %}';
		var id_name = "#global_checkbox_" + name;
		
		$(id_name).attr('title', uncheck_all);
		
		$(id_name).change(function () {
			var checkbox_names = ".checkbox_" + name;
			if ($(id_name).is(":checked")) {
				$(checkbox_names).prop('checked', true);
				$(id_name).attr('title', uncheck_all );
			} else {
				$(checkbox_names).prop('checked', false);
				$(id_name).attr('title', check_all);
			}
			$(checkbox_names).trigger("change");
		});		
	}
	
	function activate_initial_permissions() {		
		$("#grouplist tr").each(function (e) {
			if ($("input[type=checkbox]", $(this)).is(":checked")) {
				var perm = $(".perm_field", $(this)).val();
				if (perm) {
					$(".perm_read, .perm_write", $(this)).addClass("permission");
				}				
				if (perm == 'read') {
					$(".perm_read", $(this)).addClass("choice");
				} else if (perm == 'write') {
					$(".perm_write", $(this)).addClass("choice");
				} 				
			}
		});
	}
	
	$(document).ready(function() {	
		
		$("#close_button").click(function (e) {
			e.preventDefault();
			parent.$.nmTop().close();
		});		

		check_uncheck_all("group");
				
	});
	</script>
	<script type="text/javascript" src="{{LDT_MEDIA_PREFIX}}js/tiny_mce/tiny_mce.js"></script>
    <script type="text/javascript">
    tinyMCE.init({
        plugins : '-example', 
        mode : "textareas",
        theme : "advanced",
        language : "{{ LANGUAGE_CODE }}",
        theme_advanced_buttons1 : "bold,italic,underline,separator,strikethrough,justifyleft,justifycenter,justifyright,justifyfull,undo,redo,link,unlink",
        theme_advanced_buttons2 : "",
        theme_advanced_buttons3 : "",
        theme_advanced_toolbar_location : "top",
        theme_advanced_toolbar_align : "left",
        width: "430",
        plugins : "autoresize"        
	});


    </script>

{% endblock %}

{% block body %}
	<div id="add_contribution" class="span-23 last">
	
	<div class="projectscontentstitle span-23 last">{% if ldt_id %}{% trans "Update your project" %}{% else %}{% trans "Create your project" %}{% endif %}</div>
	<form action="{{create_project_action}}" method="POST" {% if target_parent %}target="_parent"{% endif %}>
	{% csrf_token %} 
	<input type="hidden" name="form_status" value="{{form_status}}" id="project_form_status" />
	<label for="title">{% trans "Title" %}:</label>
	{{form.title}}
	{{ form.title.errors }}
	<label for="description" class="projectdesc">{% trans "Description :" %}</label>
	{{form.description}}
	
	<div id="lefttable" class="span-11">
	<label>{% trans "List of contents" %}</label>

		<div class="span-11 last" id="ldtcreatecontentslistcontainer">
			<div class="span-11 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>	
     
    {% include "ldt/ldt_utils/partial/permissions.html" %}
                   
    <div id="submitcontent-buttons" class="span-11 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>
		<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>
    
    </form> 
    </div>
          
    </div>    
		
{% endblock %}

