2011-08-23 03:40:13 +04:00
|
|
|
/**
|
|
|
|
* Copyright (c) 2011, Robin Appelman <icewind1991@gmail.com>
|
|
|
|
* This file is licensed under the Affero General Public License version 3 or later.
|
|
|
|
* See the COPYING-README file.
|
|
|
|
*/
|
|
|
|
|
2011-04-16 19:49:57 +04:00
|
|
|
$(document).ready(function(){
|
2011-08-10 22:51:35 +04:00
|
|
|
function applyMultiplySelect(element){
|
|
|
|
var checked=[];
|
2011-10-02 17:51:24 +04:00
|
|
|
var user=element.data('username');
|
2011-08-10 22:51:35 +04:00
|
|
|
if(element.data('userGroups')){
|
|
|
|
checked=element.data('userGroups').split(', ');
|
|
|
|
}
|
|
|
|
if(user){
|
|
|
|
var checkHandeler=function(group){
|
|
|
|
if(user==OC.currentUser && group=='admin'){
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
$.post(
|
2011-08-14 01:56:33 +04:00
|
|
|
OC.filePath('settings','ajax','togglegroups.php'),
|
2011-08-10 22:51:35 +04:00
|
|
|
{
|
|
|
|
username:user,
|
|
|
|
group:group
|
|
|
|
},
|
|
|
|
function(){}
|
|
|
|
);
|
2011-10-02 17:51:24 +04:00
|
|
|
};
|
2011-08-10 22:51:35 +04:00
|
|
|
}else{
|
|
|
|
checkHandeler=false;
|
|
|
|
}
|
|
|
|
element.multiSelect({
|
|
|
|
createText:'add group',
|
|
|
|
checked:checked,
|
|
|
|
oncheck:checkHandeler,
|
|
|
|
onuncheck:checkHandeler
|
|
|
|
});
|
|
|
|
}
|
|
|
|
$('select[multiple]').each(function(index,element){
|
|
|
|
applyMultiplySelect($(element));
|
|
|
|
});
|
2011-08-09 17:25:18 +04:00
|
|
|
|
|
|
|
$('td.remove>img').live('click',function(event){
|
|
|
|
var uid=$(this).parent().parent().data('uid');
|
|
|
|
$.post(
|
2011-08-14 01:56:33 +04:00
|
|
|
OC.filePath('settings','ajax','removeuser.php'),
|
2011-08-09 17:25:18 +04:00
|
|
|
{username:uid},
|
|
|
|
function(result){
|
|
|
|
|
2011-04-17 20:05:49 +04:00
|
|
|
}
|
2011-08-09 17:25:18 +04:00
|
|
|
);
|
|
|
|
$(this).parent().parent().remove();
|
|
|
|
});
|
|
|
|
|
2011-08-11 13:26:57 +04:00
|
|
|
$('td.password>img').live('click',function(event){
|
2011-08-11 22:59:17 +04:00
|
|
|
event.stopPropagation();
|
2011-08-11 13:26:57 +04:00
|
|
|
var img=$(this);
|
|
|
|
var uid=img.parent().parent().data('uid');
|
|
|
|
var input=$('<input type="password">');
|
|
|
|
img.css('display','none');
|
|
|
|
img.parent().children('span').replaceWith(input);
|
|
|
|
input.focus();
|
|
|
|
input.keypress(function(event) {
|
|
|
|
if(event.keyCode == 13) {
|
2011-08-11 13:38:37 +04:00
|
|
|
if($(this).val().length>0){
|
|
|
|
$.post(
|
2011-08-14 01:56:33 +04:00
|
|
|
OC.filePath('settings','ajax','changepassword.php'),
|
2011-08-11 13:38:37 +04:00
|
|
|
{username:uid,password:$(this).val()},
|
|
|
|
function(result){}
|
|
|
|
);
|
|
|
|
input.blur();
|
|
|
|
}else{
|
|
|
|
input.blur();
|
|
|
|
}
|
2011-08-11 13:26:57 +04:00
|
|
|
}
|
|
|
|
});
|
|
|
|
input.blur(function(){
|
|
|
|
$(this).replaceWith($('<span>●●●●●●●</span>'));
|
|
|
|
img.css('display','');
|
|
|
|
});
|
|
|
|
});
|
2011-08-11 22:59:17 +04:00
|
|
|
$('td.password').live('click',function(event){
|
|
|
|
$(this).children('img').click();
|
|
|
|
});
|
2011-08-15 23:06:29 +04:00
|
|
|
|
|
|
|
$('td.quota>img').live('click',function(event){
|
|
|
|
event.stopPropagation();
|
|
|
|
var img=$(this);
|
|
|
|
var uid=img.parent().parent().data('uid');
|
|
|
|
var input=$('<input>');
|
|
|
|
var quota=img.parent().children('span').text();
|
|
|
|
if(quota=='None'){
|
|
|
|
quota='';
|
|
|
|
}
|
|
|
|
input.val(quota);
|
|
|
|
img.css('display','none');
|
|
|
|
img.parent().children('span').replaceWith(input);
|
|
|
|
input.focus();
|
|
|
|
input.keypress(function(event) {
|
|
|
|
if(event.keyCode == 13) {
|
|
|
|
$(this).parent().attr('data-quota',$(this).val());
|
|
|
|
if($(this).val().length>0){
|
|
|
|
$.post(
|
|
|
|
OC.filePath('settings','ajax','setquota.php'),
|
|
|
|
{username:uid,quota:$(this).val()},
|
|
|
|
function(result){}
|
|
|
|
);
|
|
|
|
input.blur();
|
|
|
|
}else{
|
|
|
|
input.blur();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
input.blur(function(){
|
|
|
|
var quota=$(this).parent().data('quota');
|
|
|
|
$(this).replaceWith($('<span>'+quota+'</span>'));
|
|
|
|
img.css('display','');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
$('td.quota').live('click',function(event){
|
|
|
|
$(this).children('img').click();
|
|
|
|
});
|
2011-08-11 13:26:57 +04:00
|
|
|
|
2011-08-09 17:25:18 +04:00
|
|
|
$('#newuser').submit(function(event){
|
|
|
|
event.preventDefault();
|
|
|
|
var username=$('#newusername').val();
|
2011-10-08 15:10:49 +04:00
|
|
|
if(username == '') {
|
|
|
|
alert('Please provide a username!');
|
|
|
|
return false;
|
|
|
|
}
|
2011-08-09 17:25:18 +04:00
|
|
|
var password=$('#newuserpassword').val();
|
2011-08-10 22:51:35 +04:00
|
|
|
var groups=$('#newusergroups').prev().children('div').data('settings').checked;
|
2011-08-09 17:25:18 +04:00
|
|
|
$.post(
|
2011-08-14 01:56:33 +04:00
|
|
|
OC.filePath('settings','ajax','createuser.php'),
|
2011-08-09 17:25:18 +04:00
|
|
|
{
|
|
|
|
username:username,
|
|
|
|
password:password,
|
|
|
|
groups:groups,
|
|
|
|
},
|
|
|
|
function(result){
|
|
|
|
|
2011-04-16 19:49:57 +04:00
|
|
|
}
|
2011-08-09 17:25:18 +04:00
|
|
|
);
|
2011-08-20 07:07:58 +04:00
|
|
|
var tr=$('#content table tbody tr').first().clone();
|
2011-08-09 17:25:18 +04:00
|
|
|
tr.attr('data-uid',username);
|
|
|
|
tr.find('td.name').text(username);
|
2011-08-10 22:51:35 +04:00
|
|
|
var select=$('<select multiple="multiple" data-placehoder="Groups" title="Groups">');
|
|
|
|
select.data('username',username);
|
|
|
|
select.data('userGroups',groups.join(', '));
|
|
|
|
tr.find('td.groups').empty();
|
|
|
|
$.each($('#content table').data('groups').split(', '),function(i,group){
|
|
|
|
select.append($('<option value="'+group+'">'+group+'</option>'));
|
2011-08-09 17:25:18 +04:00
|
|
|
});
|
2011-08-10 22:51:35 +04:00
|
|
|
tr.find('td.groups').append(select);
|
2011-08-20 07:07:58 +04:00
|
|
|
if(tr.find('td.remove img').length==0){
|
2011-08-14 16:55:43 +04:00
|
|
|
tr.find('td.remove').append($('<img alt="Delete" title="'+t('settings','Delete')+'" class="svg action" src="'+OC.imagePath('core','actions/delete')+'"/>'));
|
2011-08-11 13:26:57 +04:00
|
|
|
}
|
2011-08-10 22:51:35 +04:00
|
|
|
applyMultiplySelect(select);
|
2011-08-20 07:07:58 +04:00
|
|
|
$('#content table tbody').last().after(tr);
|
2011-04-16 19:49:57 +04:00
|
|
|
});
|
2011-08-09 17:25:18 +04:00
|
|
|
});
|