apply code review hints

This commit is contained in:
Morris Jobke 2013-03-28 15:02:31 +01:00
parent 7c8a0a486b
commit df74c0e43a
2 changed files with 13 additions and 15 deletions

View File

@ -17,30 +17,27 @@ OC.Log={
levels:['Debug','Info','Warning','Error','Fatal'], levels:['Debug','Info','Warning','Error','Fatal'],
loaded:3,//are initially loaded loaded:3,//are initially loaded
getMore:function(count){ getMore:function(count){
if(!count){ count = count || 10;
count=10;
}
$.get(OC.filePath('settings','ajax','getlog.php'),{offset:OC.Log.loaded,count:count},function(result){ $.get(OC.filePath('settings','ajax','getlog.php'),{offset:OC.Log.loaded,count:count},function(result){
if(result.status=='success'){ if(result.status=='success'){
OC.Log.addEntries(result.data); OC.Log.addEntries(result.data);
$('html, body').animate({scrollTop: $(document).height()}, 800); $('html, body').animate({scrollTop: $(document).height()}, 800);
if(!result.remain){ if(!result.remain){
$('#moreLog').css('display', 'none'); $('#moreLog').hide();
} }
$('#lessLog').css('display', ''); $('#lessLog').show();
} }
}); });
}, },
showLess:function(count){ showLess:function(count){
count = count || 10; count = count || 10;
$('#moreLog').css('display', ''); //calculate remaining items - at least 3
while(OC.Log.loaded > 3 && count){ OC.Log.loaded = Math.max(3,OC.Log.loaded-count);
$('#log tr').last().remove(); $('#moreLog').hide();
OC.Log.loaded -= 1; // remove all non-remaining items
count--; $('#log tr').slice(OC.Log.loaded).remove();
}
if(OC.Log.loaded <= 3) if(OC.Log.loaded <= 3)
$('#lessLog').css('display', 'none'); $('#lessLog').hide();
}, },
addEntries:function(entries){ addEntries:function(entries){
for(var i=0;i<entries.length;i++){ for(var i=0;i<entries.length;i++){
@ -68,6 +65,7 @@ OC.Log={
} }
$(document).ready(function(){ $(document).ready(function(){
$('#lessLog').hide(); // initially hide the less button
$('#moreLog').click(function(){ $('#moreLog').click(function(){
OC.Log.getMore(); OC.Log.getMore();
}) })

View File

@ -201,7 +201,7 @@ if (!$_['internetconnectionworking']) {
<?php endif; <?php endif;
endfor;?> endfor;?>
</select> </select>
<table id='log'> <table id="log">
<?php foreach ($_['entries'] as $entry): ?> <?php foreach ($_['entries'] as $entry): ?>
<tr> <tr>
<td> <td>
@ -220,8 +220,8 @@ endfor;?>
<?php endforeach;?> <?php endforeach;?>
</table> </table>
<?php if ($_['entriesremain']): ?> <?php if ($_['entriesremain']): ?>
<input id='moreLog' type='button' value='<?php p($l->t('More'));?>...'> <input id="moreLog" type="button" value="<?php p($l->t('More'));?>...">
<input id='lessLog' type='button' style='display:none' value='<?php p($l->t('Less'));?>...'> <input id="lessLog" type="button" value="<?php p($l->t('Less'));?>...">
<?php endif; ?> <?php endif; ?>
</fieldset> </fieldset>