Enhance user creation (avoid create+delete row), clear create user form after action

This commit is contained in:
Brice Maron 2012-05-07 21:27:03 +00:00
parent 43978abd80
commit 5962a0d4ac
1 changed files with 29 additions and 27 deletions

View File

@ -167,32 +167,7 @@ $(document).ready(function(){
}
var password=$('#newuserpassword').val();
var groups=$('#newusergroups').prev().children('div').data('settings').checked;
var tr=$('#content table tbody tr').first().clone();
tr.attr('data-uid',username);
tr.find('td.name').text(username);
var select=$('<select multiple="multiple" data-placehoder="Groups" title="Groups">');
select.data('username',username);
select.data('userGroups',groups.join(', '));
tr.find('td.groups').empty();
var allGroups=$('#content table').data('groups').split(', ');
for(var i=0;i<groups.length;i++){
if(allGroups.indexOf(groups[i])==-1){
allGroups.push(groups[i]);
}
}
$.each(allGroups,function(i,group){
select.append($('<option value="'+group+'">'+group+'</option>'));
});
tr.find('td.groups').append(select);
if(tr.find('td.remove img').length==0){
tr.find('td.remove').append($('<img alt="Delete" title="'+t('settings','Delete')+'" class="svg action" src="'+OC.imagePath('core','actions/delete')+'"/>'));
}
applyMultiplySelect(select);
$('#content table tbody').last().append(tr);
tr.find('select.quota option').attr('selected',null);
tr.find('select.quota option').first().attr('selected','selected');
tr.find('select.quota').data('previous','default');
$('#newuser').get(0).reset();
$.post(
OC.filePath('settings','ajax','createuser.php'),
{
@ -202,9 +177,36 @@ $(document).ready(function(){
},
function(result){
if(result.status!='success'){
tr.remove();
OC.dialogs.alert(result.data.message, 'Error creating user');
}
else {
var tr=$('#content table tbody tr').first().clone();
tr.attr('data-uid',username);
tr.find('td.name').text(username);
var select=$('<select multiple="multiple" data-placehoder="Groups" title="Groups">');
select.data('username',username);
select.data('userGroups',groups.join(', '));
tr.find('td.groups').empty();
var allGroups=$('#content table').data('groups').split(', ');
for(var i=0;i<groups.length;i++){
if(allGroups.indexOf(groups[i])==-1){
allGroups.push(groups[i]);
}
}
$.each(allGroups,function(i,group){
select.append($('<option value="'+group+'">'+group+'</option>'));
});
tr.find('td.groups').append(select);
if(tr.find('td.remove img').length==0){
tr.find('td.remove').append($('<img alt="Delete" title="'+t('settings','Delete')+'" class="svg action" src="'+OC.imagePath('core','actions/delete')+'"/>'));
}
applyMultiplySelect(select);
$('#content table tbody').last().append(tr);
tr.find('select.quota option').attr('selected',null);
tr.find('select.quota option').first().attr('selected','selected');
tr.find('select.quota').data('previous','default');
}
}
);
});