Parent: [4f3301] (diff)

Child: [0d6290] (diff)

Download this file

project_perms.html    131 lines (125 with data), 4.5 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
{% 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}} / 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 %}
{% elif r.name == 'Admin' and users|length == 1 %}
<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 %}