
{% 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>  
	<script type="text/javascript" src="{{LDT_MEDIA_PREFIX}}js/projectscontents.js" ></script> 
	<script type="text/javascript" src="{{LDT_MEDIA_PREFIX}}js/multiselect.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">
	  #userslist, #selecteduserslist {
	    width: 200px;
	    height: 200px;
	    margin: 5px;
	  }
	  
	  #userslistcontainer, #selectors {
	  	float: left;
	  }
	  
	  #memberslistcontainer {
	  	margin-top: 35px;
	  }
	  
	  #selecteduserslistfooter, #userslistfooter {
	  	text-align: center;
	  }
	  	  
	  #moveleftright {
	  	margin-top: 125px;
	  	margin-left: 10px;	  	
	  }
	  	   
	</style>
{% endblock %}

{% block js_declaration %}
	{{ block.super }}
	<script type="text/javascript">
	
	function init_events(container) {
		filter_elems($("#userslist"),$("#selecteduserslist"));
	}
	
	$(document).ready(function() {	
		$("#close_button").click(function (e) {
			e.preventDefault();
			parent.$.nmTop().close();
		});
		
		var search_url = "{% url ldt.ldt_utils.views.share_filter filter='__FILTER__' use_groups='false' %}";
		init_multi_select_events ($("#userslist"), $("#selecteduserslist"), $("#memberselection"), $("#adminselection"), "#searchuserinput", search_url);

	});
	</script>

{% endblock %}

{% block body %}
				 
	<div id="add_group" 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" />
	<input type="hidden" name="id_group" value="" id="id_group"/>
	<div>
		<label for="name">{% trans "Name" %}:</label>
		{{form.name}}
		{% for error in form.errors.name %}
		<span class="error">{{ error }}</span>
		{% endfor %}
	</div>

	<div id="userslistcontainer">
		<div id="userslistheader">
			{% trans "User list" %}<br />
			<div class="searchfield rounded span-4"><input type="text" name="search" id="searchuserinput" class="searchfieldinput searchfieldinputbase" value="{% trans 'search' %}"/><img id="projectsajaxloader" class="searchajaxloader" src="{{LDT_MEDIA_PREFIX}}/img/ajax-loader-16x16.gif" alt="loader"/><img id="projecsclear" class="searchclear" src="{{LDT_MEDIA_PREFIX}}img/clear-left.png"/></div>
		</div><br /><br />	
		<select multiple="multiple" id="userslist">
			{% include "ldt/ldt_utils/partial/sharewith.html" %}
		</select>
		<div id="userslistfooter">
			<a href="#" id="selectall" title="{% trans "select all" %}">{% trans "select all" %}</a>
		</div>
	</div>
	
	<div id="moveleftright" class="span-1">
		<a href="#" id="selectelems"><img src="{{LDT_MEDIA_PREFIX}}img/to-right.gif" title="{% trans "select users" %}"></a><br />
		<a href="#" id="removeelems"><img src="{{LDT_MEDIA_PREFIX}}img/to-left.gif" title="{% trans "remove users" %}"></a>
	</div>
	
	<div id="memberslistcontainer">
		<div id="selecteduserslistheader">
			{% trans "Members list" %}
		</div>				
		<select multiple="multiple" id="selecteduserslist" >
			{% for user in member_list %}
				<option value="{{ user.id }}-{{user.type}}" {% if is_owner_group and user.change %}style="color: #2181B1;"{% endif %}>{{ user.name }}</option>
			{% endfor %}
		</select>
		<div id="selecteduserslistfooter" >
			<a href="#" id="removeall" title="{% trans "remove all" %}">{% trans "remove all" %}</a>

			{% if is_owner_group %}
			| <a href="#" id="chooseaux" title="{% trans "Decide whether a user user can change this group" %}">{% trans "is admin" %}</a>
			| <a href="#" id="removeaux">{% trans "is not admin" %}</a>
			{% endif %}
		</div>
	</div>	
	
	<div id="adminselection">
	{% for user in admin_list %}
		<input name="write_list" type="hidden" value="{{ user.id }}-{{user.type}}" />
	{% endfor %}
	</div>
	
	<div id="memberselection">
	{% for user in member_list %}
		<input name="read_list" type="hidden" value="{{ user.id }}-{{user.type}}" />
	{% endfor %}
	</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>
			{% if is_owner_group %}
			<button class="button" id="ldt_submit" type="submit" value="delete" name="submit_button">{% trans "delete_group" %}</button>
			{% endif %}
		{% else %}
		<button class="button" id="ldt_submit" type="submit" value="create" name="submit_button">{% trans "create_group" %}</button>
		{% endif %}
	</div>
	</form>
	</div>
		
{% endblock %}

