Bug 546528 - Add form to the directory list

Change-Id: I252bf75656d9485a2c2466b2025ffc867a56710c
Signed-off-by: Eric Poirier <eric.poirier@eclipse-foundation.org>
diff --git a/download.eclipse.org/404.html b/download.eclipse.org/404.html
index 288e6b7..56a69ea 100644
--- a/download.eclipse.org/404.html
+++ b/download.eclipse.org/404.html
@@ -294,5 +294,6 @@
       </footer>

       <!-- Placed at the end of the document so the pages load faster -->

       <script src="//www.eclipse.org/eclipse.org-common/themes/solstice/public/javascript/main.min.js?var=1.2"></script>

+      <script src="//www.eclipse.org/errors/download.eclipse.org/downloads_directory.js"></script>

    </body>

 </html>
\ No newline at end of file
diff --git a/download.eclipse.org/404.php b/download.eclipse.org/404.php
index c719fb1..eb8a004 100644
--- a/download.eclipse.org/404.php
+++ b/download.eclipse.org/404.php
@@ -9,7 +9,7 @@
  * SPDX-License-Identifier: EPL-2.0
  */
 
-  # If we are requesting a file and it is on archive.eclipse.org, redirect and exit. 
+  # If we are requesting a file and it is on archive.eclipse.org, redirect and exit.
   $dir = $_SERVER['DOCUMENT_ROOT'] . urldecode(strtok($_SERVER['REQUEST_URI'], "?"));
   $archive_dir = str_replace("download.eclipse.org", "archive.eclipse.org", $dir);
   if(is_file($archive_dir)) {
@@ -51,8 +51,9 @@
      echo "404 Not Found";
   }
   else {
-    $_SERVER['REQUEST_URI'] = str_replace("?d", "", $_SERVER['REQUEST_URI']);
-    $dir = $_SERVER['DOCUMENT_ROOT'] . urldecode($_SERVER['REQUEST_URI']);
+    require_once($_SERVER['DOCUMENT_ROOT'] . "/eclipse.org-common/classes/downloads/downloadDirectory.class.php");
+    $DownloadDirectory = new DownloadDirectory();
+    $dir = $DownloadDirectory->getCurrentDirectory();
     $dir_html = "";
     $is_p2 = false;
 
@@ -81,15 +82,7 @@
         asort($dirs);
         asort($files);
 
-        foreach ($dirs as $directory) {
-          if($directory != "." ) {
-            $dir_html .= "<img src='//dev.eclipse.org/small_icons/places/folder.png'><a href='" . $_SERVER['REQUEST_URI'] . "$directory/'> " . $directory . "</a><br />\n";
-          }
-        }
-        foreach ($files as $file) {
-          $dir_html .= "<img src='//dev.eclipse.org/small_icons/actions/edit-copy.png'><a href='" . $_SERVER['REQUEST_URI'] . "$file'> " . $file . "</a><br />\n";
-        }
-
+        $dir_html .= $DownloadDirectory->getFormOutput($files, $dirs);
         $dir_html .= "</div>";
       }
       if($is_p2) {
diff --git a/download.eclipse.org/downloads_directory.js b/download.eclipse.org/downloads_directory.js
new file mode 100644
index 0000000..a500920
--- /dev/null
+++ b/download.eclipse.org/downloads_directory.js
@@ -0,0 +1,27 @@
+(function($, document) {
+  $(document).ready(function() {
+    $('.downloads-directory').find('input').click(function(){
+      if ($(".downloads-directory input:checkbox:checked").length <= 0){
+        $('.downloads-directory').find('.btn').attr('disabled', 'disabled');
+        $('.download-directory-note').remove();
+      }
+      else {
+        $('.downloads-directory').find('.btn').removeAttr('disabled');
+        var domain = "eclipse.php53.dev.docker";
+        if ($('.download-directory-note').length <= 0 && location.host === domain) {
+          $('.downloads-directory').append('<div class="download-directory-note"><p class="small margin-top-10"></p></div>');
+        }
+      }
+    });
+
+    $('.downloads-directory').submit(function() {
+      var action = "archive";
+      if (window.location.href.indexOf("archive.eclispe.org") > 0) {
+        action = "delete";
+      }
+        var c = confirm("Are you sure you would like to "+ action +" the selected item(s)?");
+        return c;
+    });
+  });
+  
+})(jQuery, document);
\ No newline at end of file