From daee441153a4037c4071c8c03db1dfbeb934d910 Mon Sep 17 00:00:00 2001
From: Tom Giannattasio <tom@mitx.mit.edu>
Date: Mon, 15 Oct 2012 14:34:30 -0400
Subject: [PATCH] client-side check for a .tar.gz extension

---
 cms/static/js/base.js        | 16 +++++++++++-----
 cms/static/sass/_import.scss | 17 +++++++++++++----
 cms/templates/import.html    |  8 +++++---
 3 files changed, 29 insertions(+), 12 deletions(-)

diff --git a/cms/static/js/base.js b/cms/static/js/base.js
index 787cd2f..a07ba77 100644
--- a/cms/static/js/base.js
+++ b/cms/static/js/base.js
@@ -80,11 +80,17 @@ $(document).ready(function() {
 });
 
 function showImportSubmit(e) {
-    $('.file-name').html($(this).val())
-    $('.file-name-block').show();
-    $('.import .choose-file-button').hide();
-    $('.submit-button').show();
-    $('.progress').show();
+    var filepath = $(this).val();
+    if(filepath.substr(filepath.length - 6, 6) == 'tar.gz') {
+        $('.error-block').hide();
+        $('.file-name').html($(this).val());
+        $('.file-name-block').show();
+        $('.import .choose-file-button').hide();
+        $('.submit-button').show();
+        $('.progress').show();    
+    } else {
+        $('.error-block').html('File format not supported. Please upload a file with a <code>tar.gz</code> extension.').show();
+    }
 }
 
 function syncReleaseDate(e) {
diff --git a/cms/static/sass/_import.scss b/cms/static/sass/_import.scss
index ac10447..54ea335 100644
--- a/cms/static/sass/_import.scss
+++ b/cms/static/sass/_import.scss
@@ -11,11 +11,15 @@
     margin-right: 3%;
     font-size: 14px;
 
-    h3 {
+    h2 {
+      font-weight: 700;
+      font-size: 19px;
       margin-bottom: 20px;
-      font-size: 18px;
+    }
+
+    strong {
       font-weight: 700;
-      color: $error-red;
+      // color: $error-red;
     }
 
     p + p {
@@ -39,12 +43,17 @@
       font-weight: 300;
     }
 
-    .file-name-block {
+    .file-name-block,
+    .error-block {
       display: none;
       margin-bottom: 15px;
       font-size: 13px;
     }
 
+    .error-block {
+      color: $error-red;
+    }
+
     .choose-file-button {
       @include blue-button;
       padding: 10px 50px 11px;
diff --git a/cms/templates/import.html b/cms/templates/import.html
index ffce24e..135acde 100644
--- a/cms/templates/import.html
+++ b/cms/templates/import.html
@@ -11,15 +11,17 @@
     <h1>Import</h1>
     <article class="import-overview">
       <div class="description">
-        <h3>Importing a new course will delete all course content currently associated with your course
-        and replace it with the contents of the uploaded file.</h3>
+        <h2>Please <a href="#">read the documentation</a> before attempting an import!</h2>
+        <p><strong>Importing a new course will delete all content currently associated with your course
+        and replace it with the contents of the uploaded file.</strong></p>
         <p>File uploads must be zip files containing, at a minimum, a <code>course.xml</code> file.</p>
         <p>Please note that if your course has any problems with auto-generated <code>url_name</code> nodes,
         re-importing your course could cause the loss of student data associated with those problems.</p>
       </div>
       <form action="${reverse('import_course', kwargs=dict(org=context_course.location.org, course=context_course.location.course, name=context_course.location.name))}" method="post" enctype="multipart/form-data" class="import-form">
         <h2>Course to import:</h2>
-        <a href="#" class="choose-file-button">Choose File</a>
+        <p class="error-block"></p>
+        <a href="#" class="choose-file-button">Choose File</a>        
         <p class="file-name-block"><span class="file-name"></span><a href="#" class="choose-file-button-inline">change</a></p>
         <input type="file" name="course-data" class="file-input">
         <input type="submit" value="Replace my course with the one above" class="submit-button">
--
libgit2 0.26.0