Changeset 8008


Ignore:
Timestamp:
Aug 12, 2021, 1:45:10 PM (10 months ago)
Author:
Nicklas Nordborg
Message:

References #2258: Drag and drop file upload

Added option to unpack compressed files automatically.

Location:
branches/3.19-stable/www/filemanager/upload
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/3.19-stable/www/filemanager/upload/drag_drop_upload.js

    r7992 r8008  
    2727{
    2828  var upload = {};
     29  var zipFormats = [];
    2930 
    3031  var filesAndFolders;
     
    5051  upload.initPage = function()
    5152  {
     53    zipFormats = Data.json('page-data', 'zip-formats');
     54
    5255    Buttons.addClickHandler('btnUpload', upload.beginFileUpload);
    5356    Buttons.addClickHandler('close', App.closeWindow);
     
    5760    filesAndFolders = window.opener.FileManager.getFilesToUpload();
    5861    upload.processFilesAndFolders();
     62  }
     63 
     64  /**
     65    Get the ID of the best matching compressed format
     66  */
     67  upload.getCompressedFormat = function(filename)
     68  {
     69    var longestMatch = 0;
     70    var bestFormat = null;
     71   
     72    for (var formatNo = 0; formatNo < zipFormats.length; formatNo++)
     73    {
     74      var zf = zipFormats[formatNo];
     75      for (var extNo = 0; extNo < zf.extensions.length; extNo++)
     76      {
     77        var ext = '.' + zf.extensions[extNo];
     78        var index = filename.lastIndexOf(ext);
     79        if (index > 0 && (index + ext.length == filename.length))
     80        {
     81          if (ext.length > longestMatch)
     82          {
     83            longestMatch = ext.length;
     84            bestFormat = zf;
     85          }
     86        }
     87      }
     88    }
     89    return bestFormat;
    5990  }
    6091 
     
    133164    {
    134165      files.sort(upload.sortFilesByFolder);
    135       var html = '<table class="filelist">';
     166      var html = '<table class="filelist" style="width: 100%;">';
    136167      var lastSubfolder = '';
    137168      var pad = '<td colspan="2" class="name">';
    138169      var numFolders = 1;
     170      var numCompressedFiles = 0;
    139171      for (var i = 0; i < files.length; i++)
    140172      {
     
    142174        totalBytesToUpload += f.size;
    143175        totalFiles++;
     176        if (upload.getCompressedFormat(f.name)) numCompressedFiles++;
    144177        if (totalFiles <= 500)
    145178        {
     
    158191        html += '<tr><td colspan="3" class="morefiles">+'+(totalFiles-500)+' more files...</td></tr>';
    159192      }
     193      if (numCompressedFiles > 0) Doc.show('unpackSection');
    160194      var numFilesMsg = totalFiles==1?'1 file' : totalFiles+' files';
    161195      document.title = 'Uploading '+numFilesMsg+' to '+Data.get('page-data', 'directory-path');
     
    270304    upl.set('autoSelect', totalFiles == 1 ? 1 : 0); // No automatic selection if we upload more than one file
    271305    upl.set('replace_existing', overwrite);
     306    if (frm.unpackCompressed.checked)
     307    {
     308      var zipFormat = upload.getCompressedFormat(file.name);
     309      if (zipFormat)
     310      {
     311        upl.set('zip_format', zipFormat.id);
     312        upl.set('zip_unpack', 1);
     313        upl.set('zip_overwrite', overwrite);
     314        upl.set('zip_keep', 0);
     315      }
     316    }
    272317    upl.set('description', frm.description.value);
    273318    upl.set('the_file', file);
  • branches/3.19-stable/www/filemanager/upload/drag_drop_upload.jsp

    r7991 r8008  
    7575  String numFilesText = numFiles == 1 ? "1 file" : numFiles+" files";
    7676  final String title = HTML.encodeTags("Uploading "+numFilesText+" to " + dir.getName());
     77 
     78  JSONArray jsonZipFormats = new JSONArray();
     79  // Query to retreive FileUnpacker plugins
     80  final ItemQuery<PluginDefinition> pluginQuery = PluginDefinition.getQuery(null, "net.sf.basedb.util.zip.FileUnpacker");
     81  pluginQuery.order(Orders.asc(Hql.property("name")));
     82  pluginQuery.include(Include.MINE, Include.SHARED, Include.IN_PROJECT, Include.OTHERS);
     83  List<PluginDefinition> plugins = pluginQuery.list(dc);
     84  for (PluginDefinition plugin : plugins)
     85  {
     86    FileUnpacker unpacker = plugin.newInstance(FileUnpacker.class, sc, null, null);
     87    JSONObject jsonZipFormat = new JSONObject();
     88    jsonZipFormat.put("id", plugin.getId());
     89    jsonZipFormat.put("name", unpacker.getFormatName());
     90    JSONArray jsonExtensions = new JSONArray();
     91    jsonExtensions.addAll(unpacker.getExtensions());
     92    jsonZipFormat.put("extensions", jsonExtensions);
     93    jsonZipFormats.add(jsonZipFormat);
     94  }
    7795  %>
    7896  <base:page type="popup" title="<%=title%>">
     
    121139    data-directory-id="<%=directoryId%>"
    122140    data-directory-path="<%=HTML.encodeTags(dir.getPath().toString()) %>"
     141    data-zip-formats="<%=HTML.encodeTags(jsonZipFormats.toJSONString()) %>"
    123142  ></div>
    124143
     
    128147    <div class="content">
    129148      <table class="fullform input100 bottomborder">
    130       <tr class="bottomborder" style="border-bottom-style: dotted;">
     149      <tr>
    131150        <th>Overwrite existing</th>
    132151        <td>
     
    137156        <td></td>
    138157      </tr>
    139       <tr class="big">
     158      <tr id="unpackSection" style="display: none;">
     159        <th class="subprompt"></th>
     160        <td>
     161          <label><input type="checkbox" name="unpackCompressed" id="unpackCompressed">Unpack compressed files</label>
     162        </td>
     163        <td></td>
     164      </tr>
     165      <tr class="big topborder" style="border-top-style: dotted;">
    140166        <th>Files</th>
    141167        <td colspan="2">
Note: See TracChangeset for help on using the changeset viewer.