import-course.html 1.27 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
<%! from django.core.urlresolvers import reverse %>

<section>
  <div class="course-upload">
    You can import an existing .tar.gz file of your course
    <form action="${reverse('import_course')}" method="post" enctype="multipart/form-data">
      <input type="file" name="file">
      <input type="submit" value="Upload File">
    </form>
    <div class="progress" style="position:relative; width:400px; border: 1px solid #ddd; padding: 1px; border-radius: 3px;">
      <div class="bar" style="background-color: #B4F5B4; width:0%; height:20px; border-radius: 3px;"></div>
      <div class="percent">0%</div>
    </div>

    <div id="status"></div>
  </div>

</section>

<script>
21 22
require(["domReady!", "jquery", "jquery.form"], function(doc, $) {

23 24 25
var bar = $('.bar');
var percent = $('.percent');
var status = $('#status');
26

27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
$('form').ajaxForm({
    beforeSend: function() {
        status.empty();
        var percentVal = '0%';
        bar.width(percentVal)
        percent.html(percentVal);
    },
    uploadProgress: function(event, position, total, percentComplete) {
        var percentVal = percentComplete + '%';
        bar.width(percentVal)
        percent.html(percentVal);
    },
    complete: function(xhr) {
      status.html(xhr.responseText);
    }
42 43 44 45
});

}); // end require();
</script>