summaryrefslogtreecommitdiffstats
path: root/admin/js/users.js
blob: 7e643fb60a280708fe227dbc5f4267dcd15af72a (plain)
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
$(document).ready(function(){
	$('select[multiple]').chosen();
	
	$('td.remove>img').live('click',function(event){
		var uid=$(this).parent().parent().data('uid');
		$.post(
			OC.filePath('admin','ajax','removeuser.php'),
			{username:uid},
			function(result){
			
			}
		);
		$(this).parent().parent().remove();
	});
	
	$('#newuser').submit(function(event){
		event.preventDefault();
		var username=$('#newusername').val();
		var password=$('#newuserpassword').val();
		var groups=$('#newusergroups').val();
		$.post(
			OC.filePath('admin','ajax','createuser.php'),
			{
				username:username,
				password:password,
				groups:groups,
			},
			function(result){
				
			}
		);
		var tr=$('#rightcontent tr').first().clone();
		tr.attr('data-uid',username);
		tr.find('td.name').text(username);
		tr.find('td.groups').text(groups.join(', '));
		$('#rightcontent tr').first().after(tr);
		if(groups.indexOf($('#leftcontent li.selected').text().trim())!=-1){
			tr.find('td.select input').attr('checked','checked');
		}
	});
	
	$('#newgroup').submit(function(event){
		event.preventDefault();
		var name=$('#newgroupname').val();
		$.post(
			OC.filePath('admin','ajax','creategroup.php'),
			{groupname:name},
			function(result){
			
			}
		);
		$('#newusergroups').append('<option value="'+name+'">'+name+'</option>');
		$('select[multiple]').trigger("liszt:updated");
		var li=$('#leftcontent li').first().next().clone();
		li.text(name);
		$('#leftcontent li').first().after(li);
	});
	
	$('#leftcontent li').live('click',function(event){
		$('#leftcontent li').removeClass('selected');
		$(this).addClass('selected');
		$('#rightcontent tr td.select input').show();
		$('#rightcontent tr td.select input').removeAttr('checked');
		var group=$(this).text().trim();
		var rows=$('#rightcontent tr').filter(function(i,tr){
			return ($(tr).children('td.groups').text().split(', ').indexOf(group)>-1);
		});
		rows.find('td.select input').attr('checked','checked');
	});
	$('#rightcontent tr td.select input').live('change',function(event){
		var group=$('#leftcontent li.selected').text().trim();
		var user=$(this).parent().parent().children('td.name').text().trim();
		if(group=='admin' && user==OC.currentUser){
			event.preventDefault();
			$(this).attr('checked','checked');
			return false;
		}
		if(group){
			$.post(
				OC.filePath('admin','ajax','togglegroups.php'),
				{
					username:user,
					group:group
				},
				function(result){
					
				}
			);
			var groups=$(this).parent().parent().children('td.groups').text().trim().split(', ');
			if(groups[0]=='') groups.pop();
			var index=groups.indexOf(group);
			if(index==-1){
				groups.push(group);
			}else{
				groups.splice(index,1);
			}
			$(this).parent().parent().children('td.groups').text(groups.join(', '));
		}
	});
});