{% extends 'jinja_master/master.html' %}
{% 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}} / Permissions{% endblock %}
{% block header %}Project Permissions 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 %}
<form method="POST" class="can-retry" action="update_user_roles" id="roles_form">
{% for r in c.project.roles if r.name in ['Developer','Admin'] %}
<input
type="hidden"
name="role-{{loop.index0}}.id"
value="{{r._id}}"/>
{% endfor %}
<table>
<thead>
<tr>
<th>Role</th>
<th>Users</th>
<th>Add User</th>
<th/>
</tr>
</thead>
<tbody>
{% for r in c.project.roles if r.name in ['Developer','Admin'] %}
<tr class="{{loop.cycle('', 'even')}}">
<td>{{r.display()}}</td>
{% set users = r.users_with_role() %}
<td>
{% if r.name != 'Admin' or users|length > 1 %}
{% set i = loop.index0 %}
{% for u in users %}
<span class="removable">
{{u.display_name}}
<input type="hidden" name="role-{{i}}.users-{{loop.index0}}.id" value="{{u._id}}"/>
</span>
{% endfor %}
{% else %}
<span>
{{users[0].display_name}}
</span>
{% endif %}
</td>
<td class="add_role">
{{c.user_select.display(name="role-%s.new.id" % loop.index0, value='')}}
</td>
</tr>
{% endfor %}
</tbody>
</table>
<input type="submit" value="Save Changes"/>
</form>
<div id="delete-confirm" style="display:none">
Warning: You can not undo this. This will remove your permissions to manage this project.
</div>
{% endblock %}
{% block extra_js %}
<script type="text/javascript">
var user_id = '{{c.user._id}}';
var id_to_delete = null;
var roles_form = $('#roles_form');
/*<![CDATA[*/
var delete_user = function(){
var vals = roles_form.serializeArray();
var del_name = id_to_delete.name.replace('.id','.delete');
vals.push({name:del_name, value:'Del'});
$.post(roles_form[0].action, vals, function(){
var holder = id_to_delete.parentNode.parentNode;
holder.removeChild(id_to_delete.parentNode);
var remaining = $('span', holder);
if(remaining.length == 1){
$(remaining).removeClass('removable');
}
id_to_delete = null;
});
};
$("#delete-confirm").dialog({
resizable: false,
height:200,
modal: true,
autoOpen: false,
buttons: {
'Delete': function() {
delete_user();
$(this).dialog('close');
},
Cancel: function() {
$(this).dialog('close');
id_to_delete = null;
}
}
});
$('span.removable').click(function(e){
// make sure this is still removable when clicked
if($(e.target).hasClass('removable')){
var id_input = $('input', this)[0];
id_to_delete = id_input;
if(id_input.value == user_id){
$('#delete-confirm').dialog('open');
$('div.ui-dialog-buttonpane > button:last').focus();
}
else{
delete_user();
}
}
});
$('#roles_form').submit(function(e){
var roles_form = $(this);
var vals = roles_form.serialize();
$('td.add_role input', this).each(function(){
if(this.value){
roles_form.append('<input type="hidden" name="'+this.name.replace('.id','.add')+'" value="Add"/>');
}
});
});
/*]]>*/
</script>
{% endblock %}