Changeset 3010


Ignore:
Timestamp:
Dec 8, 2006, 11:58:59 AM (16 years ago)
Author:
Nicklas Nordborg
Message:

References #454: File upload times out

Use Ajax for updating the progress bar if the browser supports it.

Location:
branches/2.1.2/www
Files:
1 added
7 edited

Legend:

Unmodified
Added
Removed
  • branches/2.1.2/www/filemanager/files/list_files.jsp

    r2753 r3010  
    148148    {
    149149      var cmd = fileId ? 'UploadFile' : 'UploadNewFile';
    150       Main.openPopup('index.jsp?ID=<%=ID%>&cmd='+cmd+'&directory_id=<%=directoryId%>&item_id='+fileId, 'UploadFile', 540, 400);
     150      Main.openPopup('index.jsp?ID=<%=ID%>&cmd='+cmd+'&directory_id=<%=directoryId%>&item_id='+fileId, 'UploadFile', 640, 480);
    151151    }
    152152    function viewFile(fileId)
  • branches/2.1.2/www/filemanager/files/view_file.jsp

    r2753 r3010  
    101101    function uploadFile()
    102102    {
    103       Main.openPopup('index.jsp?ID=<%=ID%>&cmd=UploadFile&item_id=<%=itemId%>', 'UploadFile', 540, 400);
     103      Main.openPopup('index.jsp?ID=<%=ID%>&cmd=UploadFile&item_id=<%=itemId%>', 'UploadFile', 640, 480);
    104104    }
    105105    </script>
  • branches/2.1.2/www/filemanager/manager.jsp

    r2753 r3010  
    6767    if (directories) directories.style.height = (iframeElement.height-1)+'px';
    6868    var joust = iframe.frames['directories'].document.getElementById('joust');
    69     if (joust) joust.style.height = (iframeElement.height-1-30)+'px';
     69    if (joust) joust.style.height = (iframeElement.height-5-30)+'px';
    7070    var files = iframe.frames['files'].document.getElementById('main');
    7171    if (files) files.style.height = iframeElement.height+'px';
  • branches/2.1.2/www/filemanager/upload/index.jsp

    r3008 r3010  
    5858<base:page type="frameset" title="Upload file">
    5959  <base:head />
    60   <frameset rows="*,0,0" frameborder="yes" border="1">
     60  <frameset rows="*,0,0" frameborder="no" border="0">
    6161    <frame name="select" src="select.jsp?ID=<%=ID%>&directory_id=<%=directoryId%>&file_id=<%=fileId%>"
    6262      scrolling="no" frameborder="0">
  • branches/2.1.2/www/filemanager/upload/progress.jsp

    r3008 r3010  
    5050final String ID = sc.getId();
    5151final boolean abort = Values.getBoolean(request.getParameter("abort"));
     52final boolean ajax = Values.getBoolean(request.getParameter("ajax"));
    5253final FileUploadProgress progress = (FileUploadProgress)sc.getSessionSetting("FileUploadProgress");
    5354final SimpleAbsoluteProgressReporter unpackProgress = (SimpleAbsoluteProgressReporter)sc.getSessionSetting("UnpackProgress");
     
    5556boolean aborted = false;
    5657boolean transferIsComplete = false;
     58boolean failed = false;
    5759long total = 0;
    5860long transferred = 0;
     
    6567if (progress != null)
    6668{
     69  failed = progress.getException() != null;
    6770  if (abort) progress.setAbort();
    6871  currentFileName = progress.getCurrentFilename();
     
    7477  remain = transferRate != 0 ? (total-transferred)/transferRate : 0;
    7578  percent = (total==0 ? 0 : 100 * transferred / total);
    76   aborted = progress.getException() != null || abort;
    7779}
    7880if (unpackProgress != null)
     
    9294  onload = "uploadAborted()";
    9395}
     96else if (failed)
     97{
     98  onload = "";
     99}
    94100else if (progress != null)
    95101{
     
    100106  onload = "setTimeout('location.reload()', 1500)";
    101107}
     108if (ajax)
     109{
     110  %><%=currentFileName%>:<%=transferred%>:<%=total%>:<%=seconds%>:<%=remain%>:<%=unpackMessage == null ? "" : unpackMessage%><%
     111}
     112else
     113{
     114  %>
     115  <html>
     116  <head>
     117  </head>
     118  <body onload="<%=onload%>">
     119    <script language="javascript">
     120    function displayProgress(isComplete)
     121    {
     122      var fileName = '<%=HTML.javaScriptEncode(currentFileName)%>';
     123      //var percentDone = '<%=percent%>';
     124      var transferredBytes = <%=transferred%>;
     125      var totalBytes = <%=total%>;
     126      var transferTime = <%=seconds%>;
     127      //var transferRate = '<%=Values.formatBytes(transferRate)%>/s';
     128      var remainTime = <%=remain%>;
     129      var unpackMessage = '<%=HTML.javaScriptEncode(unpackMessage)%>';
     130      window.top.frames['select'].displayProgress(fileName, transferredBytes, totalBytes, transferTime, remainTime, unpackMessage);
     131      if (!isComplete)
     132      {
     133        setTimeout('location.reload()', 1500);
     134      }
     135    }
     136    function displayException()
     137    {
     138      window.top.frames['select'].location = 'show_exception.jsp?ID=<%=ID%>';
     139    }
     140    function uploadAborted()
     141    {
     142      window.top.location = '../../common/close_popup.jsp?refresh_opener=1&message=<%=HTML.urlEncode("The upload was aborted before it was completed.")%>';
     143    }
     144    </script>
     145  </body>
     146  </html>
     147  <%
     148}
    102149%>
    103 <html>
    104 <head>
    105 </head>
    106 <body onload="<%=onload%>">
    107   <script language="javascript">
    108   function displayProgress(isComplete)
    109   {
    110     var fileName = '<%=HTML.javaScriptEncode(currentFileName)%>';
    111     var percentDone = '<%=percent%>';
    112     var transferredBytes = '<%=Values.formatBytes(transferred)%>';
    113     var totalBytes = '<%=Values.formatBytes(total)%>';
    114     var transferTime = '<%=Values.formatTime(seconds)%>';
    115     var transferRate = '<%=Values.formatBytes(transferRate)%>/s';
    116     var remainTime = '<%=Values.formatTime(remain)%>';
    117     var unpackMessage = '<%=HTML.javaScriptEncode(unpackMessage)%>';
    118     window.top.frames['select'].displayProgress(fileName, percentDone, transferredBytes, totalBytes, transferTime, transferRate, remainTime, unpackMessage);
    119     if (!isComplete)
    120     {
    121       setTimeout('location.reload()', 1500);
    122     }
    123   }
    124   function displayException()
    125   {
    126     window.top.frames['select'].location = 'show_exception.jsp?ID=<%=ID%>';
    127   }
    128   function uploadAborted()
    129   {
    130     window.top.location = '../../common/close_popup.jsp?refresh_opener=1&message=<%=HTML.urlEncode("The upload was aborted before it was completed.")%>';
    131   }
    132   </script>
    133 </body>
    134 </html>
  • branches/2.1.2/www/filemanager/upload/select.jsp

    r3008 r3010  
    116116  final String requiredClazz = "class=\"text required\"";
    117117  %>
    118 
    119118  <base:page type="popup" title="<%=title%>">
    120   <base:head scripts="tabcontrol.js" styles="tabcontrol.css,progressbar.css">
     119  <base:head scripts="tabcontrol.js,ajax.js" styles="tabcontrol.css,progressbar.css">
    121120    <script language="JavaScript">
    122121    // Validate the "File" tab
     
    149148     
    150149        frm.submit();
    151         window.top.frames['progress'].location.href = 'progress.jsp?ID=<%=ID%>';
    152150        Main.hide('selectForm');
    153151        Main.show('progressForm');
    154       }
     152        if (!sendProgressUpdateWithAjax())
     153        {
     154          window.top.frames['progress'].location.href = 'progress.jsp?ID=<%=ID%>';
     155        }
     156      }
     157    }
     158   
     159    function sendProgressUpdateWithAjax()
     160    {
     161      var request = Ajax.getXmlHttpRequest();
     162      if (request != null)
     163      {
     164        var url = 'progress.jsp?ID=<%=ID%>&ajax=1&'+Math.random();
     165        request.open("GET", url, true);
     166        Ajax.setReadyStateHandler(request, updateProgressWithAjax);
     167        request.send(null);
     168      }
     169      return request != null;
     170    }
     171   
     172    function updateProgressWithAjax(request)
     173    {
     174      var response = request.responseText.split(':');
     175      //alert(response[0]+':'+response[1]+':'+response[2]+':'+response[3]+':'+response[4]+':'+response[5]);
     176      displayProgress(response[0],response[1],response[2],response[3],response[4],response.slice(5).join(':'));
     177      setTimeout('sendProgressUpdateWithAjax()', 1500);
    155178    }
    156179   
     
    212235    }
    213236   
    214     function displayProgress(fileName, percentDone, transferredBytes, totalBytes, transferTime, transferRate, remainTime, unpackMessage)
    215     {
     237    function displayProgress(fileName, transferredBytes, totalBytes, transferTime, remainTime, unpackMessage)
     238    {
     239      // File name
    216240      document.getElementById('fileName').innerHTML = 'Uploading ' + fileName + '...';
     241       
     242      // Percent done
     243      var percentDone = totalBytes == 0 ? 0 : Math.round(100 * transferredBytes / totalBytes);
    217244      document.getElementById('percent').innerHTML = '&nbsp;' + percentDone+'%';
    218245      var doneElement = document.getElementById('percentDone');
     
    221248      remainElement.style.width = (100-percentDone)+'%';
    222249      if (percentDone == 100) Main.hide('percentRemain');
    223       document.getElementById('transferredBytes').innerHTML = transferredBytes;
    224       document.getElementById('totalBytes').innerHTML = totalBytes;
    225       document.getElementById('transferTime').innerHTML = transferTime;
    226       document.getElementById('transferRate').innerHTML = '(' + transferRate + ')';
    227       document.getElementById('remainTime').innerHTML = remainTime + ' (estimated)';
    228       document.getElementById('unpackMessage').innerHTML = unpackMessage.replace(/(.*):(.*)/, '<b>$1:</b> $2');
     250     
     251      // Bytes
     252      document.getElementById('transferredBytes').innerHTML = Numbers.formatBytes(transferredBytes);
     253      document.getElementById('totalBytes').innerHTML = Numbers.formatBytes(totalBytes);
     254
     255      // Times and rate
     256      var transferRate = transferTime == 0 ? 0 : transferredBytes / transferTime;
     257      document.getElementById('transferTime').innerHTML = Numbers.formatSeconds(transferTime);
     258      document.getElementById('transferRate').innerHTML = '(' + Numbers.formatBytes(transferRate) + '/s)';
     259      document.getElementById('remainTime').innerHTML = Numbers.formatSeconds(remainTime) + ' (estimated)';
     260     
     261      // Message
     262      if (unpackMessage)
     263      {
     264        document.getElementById('unpackMessage').innerHTML = unpackMessage.replace(/(.*):(.*)/, '<b>$1:</b> $2');
     265      }
    229266    }
    230267   
     
    293330
    294331    <h3 class="docked"><%=title%></h3>
    295     <t:tabcontrol id="settings" contentstyle="<%="height: "+(int)(scale*280)+"px;"%>"
     332    <t:tabcontrol id="settings" contentstyle="<%="height: "+(int)(scale*340)+"px;"%>"
    296333      position="bottom" remember="false">
    297334    <t:tab id="info" title="File" validate="validateFile()">
  • branches/2.1.2/www/include/scripts/main.js

    r2765 r3010  
    744744    return charCode <= 31 || (charCode >= 48 && charCode <= 57) || charCode == 45 || charCode == 46;
    745745  }
     746 
     747  /*
     748    Format a number with the specified number of decimals
     749  */
     750  this.formatNumber = function(value, numDecimals, unit)
     751  {
     752    if (!value) return '';
     753    var result = '';
     754    if (value < 0)
     755    {
     756      result += "-";
     757      value = -value;
     758    }
     759    if (numDecimals < 0)
     760    {
     761      result += value;
     762    }
     763    else if (numDecimals == 0)
     764    {
     765      result += Math.round(value);
     766    }
     767    else
     768    {
     769      var intPart = Math.floor(value);
     770      var decimals = Math.round((value - intPart) * Math.pow(10, numDecimals));
     771      result += intPart + '.' + decimals;
     772    }
     773    if (unit) result += unit;
     774    return result;
     775  }
     776 
     777  this.GB = 1073741824;
     778  this.MB = 1048576;
     779  this.kB = 1024;
     780 
     781  this.formatBytes = function(value)
     782  {
     783    if (!value) return '';
     784    if (value > this.GB)
     785    {
     786      return this.formatNumber(value / this.GB, 1, ' GB');
     787    }
     788    else if (value > this.MB)
     789    {
     790      return this.formatNumber(value / this.MB, 1, ' MB');
     791    }
     792    else if (value > this.kB)
     793    {
     794      return this.formatNumber(value / this.kB, 1, ' kB');
     795    }
     796    else
     797    {
     798      return value + ' bytes';
     799    }
     800  }
     801 
     802  this.formatSeconds = function(seconds)
     803  {
     804    if (!seconds) return '';
     805    var result = '';
     806    var mustAppend = false;
     807    if (seconds >= 86400)
     808    {
     809      var days = Math.floor(seconds / 86400);
     810      seconds = seconds - 86400*days;
     811      result += days;
     812      result += days == 1 ? " day " : " days ";
     813      mustAppend = true;
     814    }
     815    if (seconds >= 3600 || mustAppend)
     816    {
     817      var hours = Math.floor(seconds / 3600);
     818      seconds = seconds - 3600*hours;
     819      result += hours;
     820      result += hours == 1 ? " hour " : " hours ";
     821      mustAppend = true;
     822    }
     823    if (seconds >= 60 || mustAppend)
     824    {
     825      var minutes = Math.floor(seconds / 60);
     826      seconds = seconds - 60*minutes;
     827      result += minutes;
     828      result += minutes == 1 ? " minute " : " minutes ";
     829      mustAppend = true;
     830    }
     831    result += seconds;
     832    result += seconds == 1 ? " second" : " seconds";
     833    return result;
     834  }
     835 
    746836}
    747837
Note: See TracChangeset for help on using the changeset viewer.