{% load i18n %}

<script type="text/javascript">
	
	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("pointer");
				}				
				if (perm == 'read') {
					$(".perm_read", $(this)).addClass("bold");
				} else if (perm == 'write') {
					$(".perm_write", $(this)).addClass("bold");
				} 				
			}
		});
	}
	
	$(document).ready(function() {	
				
		$(".pointer").live("click", function () {
            var group_name = $(this).attr('value');
        	var group_id = group_name.split('_').pop();
            
            $("a[value=\"" + group_name + "\"]").removeClass('bold');
            $(this).addClass('bold');
            
            if ($(this).hasClass('perm_read')) {
            	var perm = 'read';
            } else {
            	var perm = 'write';            	
            }
            
            $(".perm_field",$(this).closest('tr')).attr('value', perm);
        });
        
        $(".checkbox_group").bind("change", function() {
            var line = $(this).closest('tr');
            
            if (!$(this).is(":checked")) {
                $(".bold", line).removeClass('bold');
                $(".perm_read, .perm_write", line).removeClass('pointer');
            } else {
                $(".perm_read", line).addClass('bold');
                $(".perm_read, .perm_write", line).addClass('pointer');
            }
        });        

		check_uncheck_all("group");
		activate_initial_permissions();	
				
	});
</script>


<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">
                    {{ management_form }}
                
                    <tr class="projectscontentsheader last" id="contentslistheader">
                        <td class="cellcheckbox">
                        {% if groups|length > 1 %}
                        	<input class="selectallgroups" id="global_checkbox_group" type="checkbox" checked="true"/>
                        {% endif %}                            
                        </td>				
                        <td class="projectcontentsheadertitle">{% trans "nom" %}</td>
                        <td class="projectcontentsheadertitle span-3" >{% trans "Permissions" %}</td>
                    </tr>
                
                    <tbody class="projectscontentsbody" id="grouplist">
                
				    {% for form, group in group_form %}			    			    
				    <tr class="imageline projectscontentsoddline">
				    	<td class="cellcheckbox">{{ form.share }}</td>
				    	<td class="projecttitle">{{ group.name }}</td>
				    	<td>
				    	<a value="group_{{group.id}}" class="perm_read" title="{% trans "This group can read the project" %}">{% trans "perm.read" %}</a>
				        <a value="group_{{group.id}}" class="perm_write" title="{% trans "This group can change the project" %}">{% trans "perm.write" %}</a>
				       	</td>
				       	{{ form.perms }}
				       	{{ form.group }}
				    </tr>
				    {% endfor %} 
				                
                    </tbody>
                </table>		
            </div>		
      </div>       
</div>      
