console.log(); $(document).ready(function() { {% if mod.isie == 1 %} uchip = new $.Uchip(); {% else %} uchip = new Uchip(); {% endif %} loadTotal(); loadUsageFiles('', '#files_usage'); }); String.prototype.replaceAll = function(search, replacement) { var target = this; return target.replace(new RegExp(search, 'g'), replacement); }; function reSortFiles(){ renderFiles(original_files,'#files_usage') } function sortDirectory(directory){ let type = $('#sort_field').length > 0 ? $('#sort_field').val() : 'name'; let direction = $('#sort_direction').length > 0 ? $('#sort_direction').val() : 'asc'; function compare_size(a, b){ // a should come before b in the sorted order if(a.size < b.size){ return direction == 'asc' ? -1 : 1; // a should come after b in the sorted order }else if(a.size > b.size){ return direction == 'asc' ? 1 : -1; // a and b are the same }else{ return 0; } } function compare_path(a, b){ // a should come before b in the sorted order if(a.path < b.path){ return direction == 'asc' ? -1 : 1; // a should come after b in the sorted order }else if(a.path > b.path){ return direction == 'asc' ? 1 : -1; // a and b are the same }else{ return 0; } } if(type == 'name'){ directory.sort(compare_path); }else{ directory.sort(compare_size); } return directory; } let original_files = null; function loadUsageFiles(folder_name, container){ uchip.call('module=disk_usage&acc=load_directory', { data: 'folder_name=' + folder_name, callback: function(resp){ if(resp.result == 'success'){ renderFiles(resp.directory, container) } } }); } function renderFiles(directory_param, container){ let html_files = ''; let main_dir = ''; let sorter = ''; files_directory = sortDirectory(directory_param); files_directory.forEach(function(directory){ if(directory.ismain !== true){ let onclick = ''; let class_item = 'no-cursor'; let icons = ' '; if(directory.haschild === true){ onclick = 'onclick="displayFolder(this)"'; icons = ' ' + ' '; class_item = 'normal-item'; } html_files += '
  • ' + '' + '
    ' + '
    ' + icons + directory.path + '
    ' + '
    ' + uchip.humanFileSize(directory.size * 1024, true) + '
    ' + '
    ' + '
    ' + '
  • '; }else if(container == '#files_usage'){ original_files = directory_param; sorter = '
    ' + '' + '
    ' + '' + '
    ' + '
    ' + '' + '
    ' + '
    '; main_dir = '
  • ' + '
    ' + '
    ' + directory.path + '
    ' + '
    {{langmod.DUSAGELAB5}}: ' + uchip.humanFileSize(directory.size * 1024, true) + '
    ' + '
    ' + '
  • ' } }); if($('#sort_field').length == 0){ $('#sort_controls').html(sorter); } $(container).html(''); } function displayFolder(elem){ let parent = $(elem).parent(); let keyid = parent.data('key'); let folder = parent.data('path'); if(parent.find('.subdirectories-items').length < 1){ parent.append('
    '); loadUsageFiles(folder, '#' + keyid); } let div_sub = $('#' + keyid); if(div_sub.is(':visible')){ div_sub.slideUp('fast'); parent.find('.directory-item-root div').removeClass('opened'); parent.removeClass('opened'); }else{ parent.find('.directory-item-root:visible div').addClass('opened'); div_sub.slideDown('fast'); parent.addClass('opened'); } } function loadTotal(){ uchip.call('module=disk_usage&acc=load_total', { callback: function(res){ if(res.result == 'success'){ let limit = res.usage.home.limit; let homedir = res.usage.home.home; let mysql_usage = res.usage.mysql; let mail_usage = res.usage.email; let total_usage = homedir + mysql_usage + mail_usage; let homedir_percent = limit != -1 ? (homedir * 100) / limit : 0; let mysql_percent = limit != -1 ? (mysql_usage * 100) / limit : 0; let mail_percent = limit != -1 ? (mail_usage * 100) / limit : 0; let total_percent = limit != -1 ? (total_usage * 100) / limit : 0; let limit_total = limit != -1 ? uchip.humanFileSize(limit, true) : '' let html = '
    ' + '
    {{langmod.DUSAGELAB6}}
    ' + uchip.humanFileSize(homedir, true) + ' / ' + limit_total + '' + '
    ' + homedir_percent.toFixed(2) + '%
    ' + '
    ' + '
    ' + '
    ' + '
    ' + '
    MySQL
    ' + uchip.humanFileSize(mysql_usage, true) + ' / ' + limit_total + '' + '
    ' + mysql_percent.toFixed(2) + '%
    ' + '
    ' + '
    ' + '
    ' + '
    ' + '
    {{langmod.DUSAGELAB7}}
    ' + uchip.humanFileSize(mail_usage, true) + ' / ' + limit_total + '' + '
    ' + mail_percent.toFixed(2) + '%
    ' + '
    ' + '
    ' + '
    ' + '
    ' + '

    {{langmod.DUSAGELAB5}}

    ' + uchip.humanFileSize(total_usage, true) + ' / ' + limit_total + '' + '
    ' + total_percent.toFixed(2) + '%
    ' + '
    ' + '
    ' + '
    ' + '
    '; $('#total_usage').html(html); } } }); }