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

{% load i18n %}
{% 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">
	$(document).ready(function() {	
		$("#close_button").click(function (e) {
			e.preventDefault();
			parent.$.nmTop().close();
		});
		
		var check_all = '{% trans "check all" %}';
		var uncheck_all = '{% trans "uncheck all" %}';
		
		$("#check_projects").attr('title', uncheck_all);
		$("#check_projects").change(function () {
			var members_checkboxes = $("input[name=members_list]");
			
			if ($("#check_projects").is(":checked")) {
				members_checkboxes.attr('checked', 'true');
				$("#check_projects").attr('title', uncheck_all );
			} else {
				members_checkboxes.removeAttr('checked');
				$("#check_projects").attr('title', check_all);
			}

			members_checkboxes.trigger("change");		
		});
		
		$("input[name=admin_list]").change(function () {
			var line = $(this).closest('tr');
			var is_member = $('input[name=members_list]', line)
			
			if ($(this).is(':checked') && !is_member.is(':checked')) {
				is_member.attr('checked', 'checked');
			}			
		});
		
		$("input[name=members_list]").change(function () {
			var line = $(this).closest('tr');
			var is_admin = $('input[name=admin_list]', line)

			if (!$(this).is(':checked') && is_admin.is(':checked')) {
				is_admin.prop('checked', false);
			}	
		});
				
	});
	</script>

{% endblock %}

{% block body %}
	<div id="add_contribution" class="span-12 last">
	<div class="projectscontentstitle span-12 last">{% if group_id %}{% trans "Update a group" %}{% else %}{% trans "Create a group" %}{% endif %}</div>
	<form action="{% if group_id %}{% url ldt.ldt_utils.views.update_group group_id %} {% else %}{% url ldt.ldt_utils.views.create_group %}{% endif %}" 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="name">{% trans "Name" %}:</label>
	{{form.name}}
	{% for error in form.errors.name %}
	<span class="error">{{ error }}</span>
	{% endfor %}
	<label>{% trans "List of members" %}:</label>	
	<div class="span-12 last projectscontentsdiv" id="ldtcreatecontentslistcontainer">
		<div class="span-12 last projectscontentstablediv" id="ldtcreatecontentstablediv">
			<table class="projectscontentstable">
			
				<tr class="projectscontentsheader last" id="contentslistheader">
					<td class="cellcheckbox">
					{% if user_list|length > 1 %}
						<input class="selectallprojects" id="check_projects" type="checkbox" />	 
					{% endif %}
					</td>				
					<td class="projectcontentsheadertitle">{% trans "name" %}</td>
					<td class="projectcontentsheadertitle">{% trans "admin" %}</td>
				</tr>				
			
			    <tbody class="projectscontentsbody">
				{% for user in user_list %}
					    <td class="cellcheckbox"><input type="checkbox" name="members_list" value="{{ user.id }}" title="{% trans "Check to include this user in the group" %}" {% if user.member %}checked="checked"{% endif %}/></td>
					    <td class="contenttitle">{{ user.username }}</td>
					    <td class="cellcheckbox"><input type="checkbox" name="admin_list" value="{{ user.id }}" title="{% trans "Check to give this user the right to change the group" %}" {% if user.admin %}checked="checked"{% endif %}/></td>
					 </tr>
				{% endfor %} 			
					
				</tbody>
			</table>			
		</div>	
	</div>
		
	<div id="submitcontent-buttons" class="span-12 last">
		<button type="button" id="close_button"  value="close">{% trans 'close_cancel' %}</button>
		{% if group_id %}
		<button class="button" id="ldt_submit" type="submit" value="update" name="submit_button">{% trans "update_group" %}</button>
		<button class="button" id="ldt_submit" type="submit" value="delete" name="submit_button">{% trans "delete_group" %}</button>
		{% else %}
		<button class="button" id="ldt_submit" type="submit" value="create" name="submit_button">{% trans "create_group" %}</button>
		{% endif %}
	</div>
	</form>
	</div>
		
{% endblock %}

