{% extends "polemictweet_base.html" %}
{% load i18n %}
{% load thumbnail %}

	{% block css_import %}
			<link rel="stylesheet" href="{{STATIC_URL}}css/create_event.css" />
		
	{% endblock %}
	{% block js_import %}
		<script type="text/javascript" src="{{STATIC_URL}}js/tiny_mce/tiny_mce.js"></script>
		<script type="text/javascript" src="{{STATIC_URL}}js/jquery.min.js"></script>
		<script type="text/javascript" src="{{STATIC_URL}}js/jquery.qtip.min.js"></script>
		<script type="text/javascript" src="{{STATIC_URL}}js/jquery-ui.min.js"></script>
		<script type="text/javascript" src="{{STATIC_URL}}js/jquery.textchange.min.js"></script>
		
		<script type="text/javascript" src="{{STATIC_URL}}js/jquery.formset.js"></script>
		<script type="text/javascript" src="{{STATIC_URL}}js/event.js"></script>
	{% endblock %}
	{% block js_declaration %}
		
	<script type="text/javascript">
	
	var $j = jQuery.noConflict(); 

	// 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;}
	    }
	
	tinyMCE.init({
	    mode: "textareas",
	    theme: "advanced",
        plugins : "autolink,lists,spellchecker,layer,table,save,advhr,advlink,emotions,iespell,insertdatetime,preview,media,searchreplace,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras",
	
     	theme_advanced_buttons1 : "save,newdocument,bold,italic,underline,strikethrough,justifyleft,justifycenter,justifyright,justifyfull,formatselect,fontselect,fontsizeselect",
        theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,search,replace,bullist,numlist,outdent,indent,blockquote,undo,redo,link,unlink,anchor,cleanup,help,code,insertdate,inserttime,preview,forecolor,backcolor",
        theme_advanced_buttons3 : "tablecontrols,hr,removeformat,visualaid,sub,sup,charmap,emotions,iespell,advhr,ltr,rtl,fullscreen",
        theme_advanced_toolbar_location : "top",
        theme_advanced_toolbar_align : "left",
        theme_advanced_statusbar_location : "bottom",
        theme_advanced_resizing : true,
	});
	
	$j(document).ready(function(){
		init_events();
		
		$j("#elemslistcontainer").selectable({
			filter: ".shareline",
		});
		
		$j("#selectedpartnercontainer").selectable({
			filter: ".shareline",
		});
		
		$j("#selectedorganisatorcontainer").selectable({
			filter: ".shareline",
		});
			
		
    });

	document.onkeypress = stopRKey;
	
	</script>	
	{% endblock %}

	{% block content %}
	{{ event_form.errors }}
    
	<div id="add_event" class="span-18 last">
	{% if event_slug %}
		<div class="projectseventstitle">{% trans "Modify this event" %}</div>
	{% else %}
		<div class="projectseventstitle">{% trans "Create event" %}</div>
	{% endif %}
    
	<form action="{{ create_event_action }}" enctype="multipart/form-data" id="my_form" method="POST" enctype="multipart/form-data" >
	
        <div id="eventformhidden">
		{% csrf_token %}
            <input type="hidden" name="form_status" value="{{form_status}}" id="event_form_status" />
            {% for hidden in form.hidden_fields %}
                {{ hidden }}
            {% endfor %}
        </div>

        <div id="eventformfields" class="span-18 last">
            	<div>{{ event_form.title.errors }}{{ event_form.title.label_tag }}{{event_form.title}}</div>
            	
            	<a id="displayTranslateTitle" class="translateTitle">
					<span class="title">{% trans "Add translations" %}</span>
				</a>
                <div id="translate_title">
                {% for language_code in translation_languages %}
                    <div>
                        <label for="id_title_{{language_code}}">event.title_{{language_code}}</label>
                        <input type = "text" name = "title_{{language_code}}" id="id_title_{{language_code}}" ></input>
                    </div>
                {% endfor %}
                </div>
               
                <div>{{ event_form.description.errors }}{{ event_form.description.label_tag }}{{event_form.description}}</div>
                <a id="displayTranslateDescription" class="translateDescription">
					<span class="title">{% trans "Add translations" %}</span>
				</a>
                <div id="translate_description">
                {% for language_code in translation_languages %}
                    <div>
                        <label for="id_description_{{language_code}}">event.description_{{language_code}}</label>
                        <textarea name = "description_{{language_code}}" id="id_description_{{language_code}}" ></textarea>
                    </div>
                {% endfor %}
                </div>
                <div>{{ event_form.program.errors }}{{ event_form.program.label_tag }}{{event_form.program}}</div>
                <a id="displayTranslateProgram" class="translateProgram">
					<span class="title">{% trans "Add translations" %}</span>
				</a>
                <div id="translate_program">
                {% for language_code in translation_languages %}
                    <div>
                        <label for="id_program_{{language_code}}">event.program_{{language_code}}</label>
                        <textarea name = "program_{{language_code}}" id="id_program_{{language_code}}" ></textarea>
                    </div>
                {% endfor %}
                </div>
               
                <div>{{ event_form.date_begin.errors }}{{ event_form.date_begin.label_tag }}{{event_form.date_begin}}</div>
                <div>{{ event_form.date_end.errors }}{{ event_form.date_end.label_tag }}{{event_form.date_end}}</div>
                <div>{{ event_form.hashtag.errors }}{{ event_form.hashtag.label_tag }}{{event_form.hashtag}}</div>
                
                <div>
				{% trans "choose an event image" %}
				</div>
				
				<table id="chooseeventpicturecontainer" >
				    <tr>
				        <td class="leftcolumn">
				            {% trans "Upload a new picture" %}<br/> (JPG, PNG, &lt;&nbsp;1&nbsp;Mo)
				        </td>
				        <td>
				        	<div>{{ event_form.event_image.errors }}{{event_form.event_image.label_tag}}{{event_form.event_image}}</div>
				        </td>
				    </tr>
				</table>  
				  
		    	 <a id="displayTranslateEventImage" class="translateEventImage">
					<span class="title">{% trans "Add translations" %}</span>
				</a>
		   
			    <div id="translate_event_image">
				    {% for language_code in translation_languages %}
                   	<div>
	                        <label for="id_event_image_{{language_code}}">event.event_image_{{language_code}}</label>
	                        <input name = "event_image_{{language_code}}" id="id_event_image_{{language_code}}" type="file" ></input>
                    </div>
                	{% endfor %}
               	</div>
               	
               	 <div>
				{% trans "choose an image for the organisator" %}
				</div>
				
				<table id="chooseeventpicturecontainer">
				    <tr>
				        <td class="leftcolumn">
				            {% trans "Upload a new picture" %}<br/> (JPG, PNG, &lt;&nbsp;1&nbsp;Mo)
				        </td>
				        <td>
				        	<div>{{ event_form.event_logo.errors }}{{event_form.event_logo.label_tag}}{{event_form.event_logo}}</div>
				        </td>
				    </tr>
				</table>
			
				<div>
					<label for="id_groups">{% trans "add your event to a group" %}</label></br>
					<select multiple="multiple" id="id_groups" name="groups">
						{% for group in groups %}
							{% if group in init_groups %}
								<option value="{{group.id}}" selected="selected" >{{group.title}}</option>
							{% else %}
								<option value="{{group.id}}" >{{group.title}}</option>
							{% endif %}
						{% endfor %}
					</select>
				</div>
				<div>
					<label for="id_partners">{% trans "add partners and organisators to your event" %}</label></br>
				</div>
				</br> 
				
				<div id="sharecontainer">
				<div class="partner_selector">
					
					<label for="id_partners">{% trans "All partners" %}</label></br>
					

					<table id="elemslistcontainer" class="multiple_choice_box">
						{% for partner in partners %}
							{% if partner not in old_partners and partner not in old_organisators %}
								<tr class="shareline">	
							        <td>{{ partner.name }}</td>
							        <input type="hidden" value="{{ partner.id }}"/>
							    </tr>	
							{% endif %}
						{% endfor %}
					</table>
				</div>	
				 <div id="selectors_partner" class="choice_button">
					<a href="#" id="selectpartners">{% trans "select partners" %}</a><br />
					<a href="#" id="removepartners">{% trans "remove partners" %}</a>
				</div>
				
				<div class="partner_selector">
					<label for="id_partners_event">{% trans "Partners" %}</label></br>
					
					<table id="selectedpartnercontainer" class="multiple_choice_box">
						{% for partner in old_partners %}
							<tr class="shareline">	
							      <td>{{ partner.name }}</td>
							     <input type="hidden" value="{{ partner.id }}"/>
							 </tr>
						{% endfor %}
					</table>
				</div>
				
				<div id="selectors_organisator" class="choice_button">
					<a href="#" id="selectorganisator">{% trans "select organisators" %}</a><br />
					<a href="#" id="removeorganisator">{% trans "remove organisators" %}</a>
				</div>
				<div class="partner_selector"> 
					<label for="id_partners_event">{% trans "Organisators" %}</label></br>
					
					<table id="selectedorganisatorcontainer" class="multiple_choice_box">
						{% for organisator in old_organisators %}
							<tr class="shareline">	
							      <td>{{ organisator.name }}</td>
							     <input type="hidden" value="{{ organisator.id }}"/>
							 </tr>
						{% endfor %}
					</table>
				</div>
			</div> 
		
			<div id="partners_event">
				{% for partner in old_partners %}
					<input type="hidden" value="{{ partner.id }}" name="partners"/>
				{% endfor %}
			
			</div>
		
			<div id="organisators_event">
				{% for organisator in old_organisators %}
					<input type="hidden" value="{{ organisator.id }}" name="organisators" />
				{% endfor %}
			</div>			  
				
        </div>
        </br> 
        
    
        <div id="submitevent">
            <div id="submitevent-buttons">
                <button type="submit" value="close" name="submit_button" id="submit_button_close">{% trans 'close_cancel' %}</button>
                <button type="submit" value="write" name="submit_button" id="submit_button_write">{% trans "write" %}</button>
            </div>
        </div>
	
	</form>
	</div>

{% endblock %}