{% extends g.theme.master %}
{% macro role_select(name) %}
<select name="{{name}}">
{% for r in c.project.roles %}
<option value="{{r._id}}">{{r.display()}}</option>
{% endfor %}
</select>
{% endmacro %}
{% block title %}{{c.project.name}} / Roles{% endblock %}
{% block header %}Project Roles for {{c.project.shortname}}{% endblock %}
{% block content %}
{% if c.project.deleted %}
<div class="notice">This project has been deleted and is not visible to non-admin users</div>
{% endif %}
<p>
Each user on the project has a private role.
Each role can have subroles. A role inherits all the permissions
that its subroles have. All users who have read access should
automatically appear here.
</p>
<form method="POST" action="update_roles" id="roles_form">
{% for r in c.project.roles %}
<input py:for=""
type="hidden"
name="role-{{loop.index0}}.id"
value="{{r._id}}"/>
{% endfor %}
<table>
<thead>
<tr>
<th>User</th>
<th>Roles</th>
<th>Edit</th>
<th/>
</tr>
</thead>
<tbody>
{% for r in c.project.roles %}
<tr class="{{loop.cycle('', 'even')}}">
<td>{{r.display()}}</td>
<td>
{% set i = loop.index0 %}
{% for sr in h.make_roles(r.roles) %}
<span class="removable">
{{sr.display()}}
<input type="hidden" name="role-{{i}}.subroles-{{loop.index0}}.id" value="{{sr._id}}"/>
<!-- <input type="submit" name="role-{{i}}.subroles-{{loop.index0}}.delete" value="Del"/> -->
</span>
{% endfor %}
</td>
<td>
Acts as
<select name="role-{{loop.index0}}.new.id" style="width: 100px" class="add_role">
<option value=""> </option>
{% for r in roles if not r.special %}
<option value="{{r._id}}">
{{r.display()}}
</option>
{% endfor %}
</select>
{% if not r.special %}
<input name="role-{{loop.index0}}.delete" type="submit" value="Delete" />
{% endif %}
</td>
</tr>
{% endfor %}
<tr>
<td><input name="new.name" class="title"/></td>
<td colspan="3">
<input type="submit" name="new.add" value="Create Role"
/>
</td>
</tr>
</tbody>
</table>
</form>
{% endblock %}
{% block extra_js %}
<script type="text/javascript">
/*<![CDATA[*/
$('span.removable').click(function(e){
var vals = $('#roles_form').serialize();
var del_name = $('input', this)[0].name.replace('.id','.delete');
$.post($('#roles_form')[0].action, vals+'&'+del_name+'=Del', function(){
e.target.parentNode.removeChild(e.target);
});
});
$('select.add_role').change(function(e){
var vals = $('#roles_form').serialize();
var add_name = e.target.name.replace('.id','.add');
$.post($('#roles_form')[0].action, vals+'&'+add_name+'=Add', function(){
window.location.reload();
});
});
/*]]>*/
</script>
{% endblock %}