new config widget for user quota

This commit is contained in:
Robin Appelman 2012-02-24 14:38:40 +01:00
parent 9f5bce81b0
commit 4230e217af
5 changed files with 94 additions and 45 deletions

View File

@ -11,10 +11,11 @@ $username = $_POST["username"];
$quota=$_POST["quota"]; $quota=$_POST["quota"];
if($quota!='none' and $quota!='default'){ if($quota!='none' and $quota!='default'){
$quota= OC_Helper::computerFileSize($quota); $quota= OC_Helper::computerFileSize($quota);
$quota=OC_Helper::humanFileSize($quota); if($quota==0){
} $quota='default';
if($quota==0){ }else{
$quota='default'; $quota=OC_Helper::humanFileSize($quota);
}
} }
// Return Success story // Return Success story

View File

@ -29,6 +29,9 @@ li.selected { background-color:#ddd; }
#content>table:not(.nostyle) { margin-top:3em; } #content>table:not(.nostyle) { margin-top:3em; }
table:not(.nostyle) { width:100%; } table:not(.nostyle) { width:100%; }
#rightcontent { padding-left: 1em; } #rightcontent { padding-left: 1em; }
td.quota { position:relative }
select.quota { position:absolute; left:0px; top:0px; width:10em; }
input.quota-other { display:none; position:absolute; left:0.1em; top:0.1em; width:7em; border:none; -webkit-box-shadow: none -mox-box-shadow:none ; box-shadow:none; }
/* APPS */ /* APPS */
li { color:#888; } li { color:#888; }

View File

@ -5,6 +5,18 @@
*/ */
$(document).ready(function(){ $(document).ready(function(){
function setQuota(uid,quota,ready){
$.post(
OC.filePath('settings','ajax','setquota.php'),
{username:uid,quota:quota},
function(result){
if(ready){
ready(result.data.quota);
}
}
);
}
function applyMultiplySelect(element){ function applyMultiplySelect(element){
var checked=[]; var checked=[];
var user=element.data('username'); var user=element.data('username');
@ -82,48 +94,63 @@ $(document).ready(function(){
$('td.password').live('click',function(event){ $('td.password').live('click',function(event){
$(this).children('img').click(); $(this).children('img').click();
}); });
$('td.quota>img').live('click',function(event){ $('select.quota').live('change',function(){
event.stopPropagation(); var select=$(this);
var img=$(this); var uid=$(this).parent().parent().data('uid');
var uid=img.parent().parent().data('uid'); var quota=$(this).val();
var input=$('<input>'); var other=$(this).next();
var quota=img.parent().children('span').text(); if(quota!='other'){
if(quota=='None'){ other.hide();
quota=''; select.data('previous',quota);
setQuota(uid,quota);
}else{
other.show();
other.focus();
} }
input.val(quota); });
img.css('display','none'); $('select.quota').each(function(i,select){
img.parent().children('span').replaceWith(input); $(select).data('previous',$(select).val());
input.focus(); })
input.keypress(function(event) {
if(event.keyCode == 13) { $('input.quota-other').live('change',function(){
$(this).parent().attr('data-quota',$(this).val()); var uid=$(this).parent().parent().data('uid');
if($(this).val().length>0){ var quota=$(this).val();
$.post( var select=$(this).prev();
OC.filePath('settings','ajax','setquota.php'), var other=$(this);
{username:uid,quota:$(this).val()}, if(quota){
function(result){ setQuota(uid,quota,function(quota){
img.parent().children('span').text(result.data.quota) select.children().attr('selected',null);
$(this).parent().attr('data-quota',result.data.quota); var existingOption=select.children().filter(function(i,option){
} return ($(option).val()==quota);
); });
input.blur(); if(existingOption.length){
existingOption.attr('selected','selected');
}else{ }else{
input.blur(); var option=$('<option/>');
option.attr('selected','selected').attr('value',quota).text(quota);
select.children().last().before(option);
} }
} select.val(quota);
}); other.val(null);
input.blur(function(){ other.hide();
var quota=$(this).parent().attr('data-quota'); });
$(this).replaceWith($('<span>'+quota+'</span>')); }else{
img.css('display',''); var previous=select.data('previous');
}); select.children().attr('selected',null);
}); select.children().each(function(i,option){
$('td.quota').live('click',function(event){ if($(option).val()==previous){
$(this).children('img').click(); $(option).attr('selected','selected');
}
});
other.hide();
}
}); });
$('input.quota-other').live('blur',function(){
$(this).change();
})
$('#newuser').submit(function(event){ $('#newuser').submit(function(event){
event.preventDefault(); event.preventDefault();
var username=$('#newusername').val(); var username=$('#newusername').val();
@ -166,5 +193,9 @@ $(document).ready(function(){
} }
applyMultiplySelect(select); applyMultiplySelect(select);
$('#content table tbody').last().after(tr); $('#content table tbody').last().after(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');
}); });
}); });

View File

@ -48,9 +48,17 @@ foreach($_["groups"] as $group) {
<?php endforeach;?> <?php endforeach;?>
</select> </select>
</td> </td>
<td class="quota" data-quota="<?php echo $user['quota']?>"> <td class="quota">
<span><?php echo ($user['quota']>0)?$user['quota']:'None';?></span> <select class='quota'>
<img class="svg action" src="<?php echo image_path('core','actions/rename.svg')?>" alt="set new password" title="set quota" /> <?php foreach($_['quota_preset'] as $preset):?>
<option <?php if($user['quota']==$preset) echo 'selected="selected"';?> value='<?php echo $preset;?>'><?php echo $preset;?></option>
<?php endforeach;?>
<?php if(array_search($user['quota'],$_['quota_preset'])===false):?>
<option selected="selected" value='<?php echo $user['quota'];?>'><?php echo $user['quota'];?></option>
<?php endif;?>
<option value='other'><?php echo $l->t('Other');?>...</option>
</select>
<input class='quota-other'></input>
</td> </td>
<td class="remove"> <td class="remove">
<?php if($user['name']!=OC_User::getUser()):?> <?php if($user['name']!=OC_User::getUser()):?>

View File

@ -18,17 +18,23 @@ $users = array();
$groups = array(); $groups = array();
foreach( OC_User::getUsers() as $i ){ foreach( OC_User::getUsers() as $i ){
$users[] = array( "name" => $i, "groups" => join( ", ", OC_Group::getUserGroups( $i ) ),'quota'=>OC_Preferences::getValue($i,'files','quota',0)); $users[] = array( "name" => $i, "groups" => join( ", ", OC_Group::getUserGroups( $i ) ),'quota'=>OC_Preferences::getValue($i,'files','quota','default'));
} }
foreach( OC_Group::getGroups() as $i ){ foreach( OC_Group::getGroups() as $i ){
// Do some more work here soon // Do some more work here soon
$groups[] = array( "name" => $i ); $groups[] = array( "name" => $i );
} }
$quotaPreset=OC_Appconfig::getValue('files','quota_preset','default,none,1 GB, 5 GB, 10 GB');
$quotaPreset=explode(',',$quotaPreset);
foreach($quotaPreset as &$preset){
$preset=trim($preset);
}
$tmpl = new OC_Template( "settings", "users", "user" ); $tmpl = new OC_Template( "settings", "users", "user" );
$tmpl->assign( "users", $users ); $tmpl->assign( "users", $users );
$tmpl->assign( "groups", $groups ); $tmpl->assign( "groups", $groups );
$tmpl->assign( 'quota_preset', $quotaPreset);
$tmpl->printPage(); $tmpl->printPage();
?> ?>