{% 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" />
	<style type="text/css" >
		textarea {
			padding: 0px;
			width:390px;
			height: 100px;
		}
		
		#lefttable {
            float: left;
        }
        
        #righttable {
        }
        
        .choice {
            font-weight: bold;
        }
        
        .permission {
            cursor: pointer;
            text-decoration: none;
            color: black;
        }
        
        .permcol {
            width: 100px;
        }
        	
	</style>
{% endblock %}

{% block js_declaration %}
	{{ block.super }}
	<script type="text/javascript">
	function checkbox_selection(id_checkbox, checkbox_type) {
		var check_all = '{% trans "check all" %}';
		var uncheck_all = '{% trans "uncheck all" %}';
		var id_str = "#" + id_checkbox;
		
		$(id_str).attr('title', uncheck_all);
		
		$(id_str).change(function () {
			if ($(id_str).is(":checked")) {
				$(".cellcheckbox input[name=\"" + checkbox_type + "\"]").attr('checked', 'true');
				$(id_str).attr('title', uncheck_all );
			} else {
				$(".cellcheckbox input[name=\"" + checkbox_type + "\"]").removeAttr('checked');
				$(id_str).attr('title', check_all);
			}
		});		
	}
	
	$(document).ready(function() {	
		
		$("#close_button").click(function (e) {
			e.preventDefault();
			parent.$.nmTop().close();
		});

		checkbox_selection("check_contents", "contents");
		checkbox_selection("check_groups", "groups");

        $(".permission").click(function () {
            var name = $(this).attr('value');
        
            $("a[value=\"" + name + "\"]").removeClass('choice');
            $(this).addClass('choice');
        });
        
        $("input[name=\"groups\"]").change(function() {
            var line = $(this).closest('td').next().next();
            
            if (!$(this).is(":checked")) {
                $(".choice", line).removeClass('choice');
                $(".choice", line).removeClass('permission');
            } else {
                $(".perm_read", line).addClass('choice');
                $(".perm_read, .perm_write", line).addClass('permission');
            }
        });
				
	});
	</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: "470",
        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}}
	<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-10 last" id="ldtcreatecontentslistcontainer">
			<div class="span-10 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="check_contents" 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" name="contents" value="{{ content.id }}" checked="true"  /></td>
					    <td class="contenttitle">{{ content.title }}</td>
					</tr>
				{% endfor %}
					</tbody>
				</table>			
			</div>
		</div>
	</div>	
     
    
	<div id="righttable" class="span-11">
	    <label>{% trans "group list"%}</label>
	
        <div class="span-10 last" id="ldtcreatecontentslistcontainer">
            <div class="span-10 last projectscontentstablediv" id="ldtcreatecontentstablediv">
                <table class="projectscontentstable">
                
                    <tr class="projectscontentsheader last" id="contentslistheader">
                        <td class="cellcheckbox">
                        {% if groups|length > 1 %}
                        	<input class="selectallgroups" id="check_groups" type="checkbox" checked="true"/>
                        {% endif %}                            
                        </td>				
                        <td class="projectcontentsheadertitle">{% trans "nom" %}</td>
                        <td class="projectcontentsheadertitle permcol" >{% trans "Permissions" %}</td>
                    </tr>
                
                    <tbody class="projectscontentsbody">
                
                	{% for group in groups %}
                    <tr class="imageline projectscontentsoddline">
                        <td class="cellcheckbox"><input type="checkbox" name="groups" value="{{ group.id }}" checked="true" /></td>
                        <td class="projecttitle">{{ group.name }}</td>
                        <td><a value="group_{{group.id}}" class="perm_read permission choice" title="{% trans "This group can read the project" %}">{% trans "perm.read" %}</a> <a value="group_{{group.id}}" class="perm_write permission" title="{% trans "This group can change the project" %}">{% trans "perm.write" %}</a></td>
                    </tr>
                	{% endfor %}
                
                    </tbody>
                </table>			
            </div>		
        </div>
       
    </div>    
    
            
    <div id="submitcontent-buttons" class="span-10 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 %}

