import.html 9.74 KB
Newer Older
1
<%inherit file="base.html" />
2
<%namespace name='static' file='static_content.html'/>
3 4 5 6
<%!
  from django.core.urlresolvers import reverse
  from django.utils.translation import ugettext as _
%>
David Baumgold committed
7
<%block name="title">${_("Course Import")}</%block>
8
<%block name="bodyclass">is-signedin course tools view-import</%block>
9 10

<%block name="content">
11
<div class="wrapper-mast wrapper">
12
  <header class="mast has-subtitle">
Brian Talbot committed
13
    <h1 class="page-header">
David Baumgold committed
14 15
      <small class="subtitle">${_("Tools")}</small>
      <span class="sr">&gt; </span>${_("Course Import")}
Brian Talbot committed
16
    </h1>
17 18 19
  </header>
</div>

20 21 22 23 24 25 26
<div class="wrapper-content wrapper">
  <section class="content">
    <article class="content-primary" role="main">

      <div class="introduction">
        <p>${_("You may import existing course structure and content into Studio.")}</p>

Julian Arni committed
27 28
          <p>${_("Importing is not something to take lightly as the course content you successfully upload will be integrated into your course content and cannot be reversed.")}</p>
          <p>${_("During the initial stages of the import process, please do not navigate away from this page.")}</p>
Tom Giannattasio committed
29
      </div>
30

31 32
      <form id="fileupload" method="post" enctype="multipart/form-data"
          class="import-form" url="${reverse('import_course', kwargs=dict(org=context_course.location.org, course=context_course.location.course, name=context_course.location.name))}">
33 34 35

        <input type="hidden" name="csrfmiddlewaretoken" value="${csrf_token}" />

36
        ## Translators: ".tar.gz" is a file extension, and files with that extension are called "gzipped tar files": these terms should not be translated
37 38
        <h2 class="title">${_("Select a File (.tar.gz format) to Replace Your Course Content")}</h2>

39
        <p class="error-block"></p>
40 41 42 43 44

        <a href="#" class="action action-choose-file choose-file-button">${_("Choose File")}</a>

        <div class="wrapper wrapper-file-name file-name-block">
            <h3 class="title">
45
              <span class="label">${_("File Chosen:")}</span>
46 47 48 49 50 51
              <span class="file-name"></span>
            </h3>

          <input type="file" name="course-data" class="file-input" />

          <input type="submit" value="${_('Replace my course with the one above')}" class="submit-button" />
52
        </div>
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77

        <div class="wrapper wrapper-status is-hidden">
          <h3 class="title">${_("Course Import Status")}</h3>

          <ol class="status-progress list-progress">
            <li class="item-progresspoint item-progresspoint-upload is-complete">
              <span class="deco status-visual">
                <i class="icon-cog"></i>
                <i class="icon-warning-sign"></i>
              </span>

              <div class="status-detail">
                <h3 class="title">${_("Uploading")}</h3>
                <p class="copy">${_("Transferring your file to our servers")}</p>
              </div>
            </li>

            <li class="item-progresspoint item-progresspoint-unpack is-started">
              <span class="deco status-visual">
                <i class="icon-cog icon-spin"></i>
                <i class="icon-warning-sign"></i>
              </span>

              <div class="status-detail">
                <h3 class="title">${_("Unpacking")}</h3>
78
                <p class="copy">${_("Expanding and preparing folder/file structure (You can now leave this page safely, but avoid making drastic changes to content until this import is complete)")}</p>
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
              </div>
            </li>


            <li class="item-progresspoint item-progresspoint-verify is-not-started">
              <span class="deco status-visual">
                <i class="icon-cog"></i>
                <i class="icon-warning-sign"></i>
              </span>

              <div class="status-detail">
                <h3 class="title">${_("Verifying")}</h3>
                <p class="copy">${_("Reviewing semantics, syntax, and required data")}</p>
              </div>
            </li>

            <li class="item-progresspoint item-progresspoint-import is-not-started">
              <span class="deco status-visual">
                <i class="icon-cog"></i>
                <i class="icon-warning-sign"></i>
              </span>

              <div class="status-detail">
102
                <h3 class="title">${_("Updating Course")}</h3>
Julian Arni committed
103
                <p class="copy">${_("Integrating your imported content into this course. This may take a while with larger courses.")}</p>
104 105
              </div>
            </li>
106
            <li class="item-progresspoint item-progresspoint-success has-actions is-not-started">
107 108 109 110 111 112
              <span class="deco status-visual">
                <i class="icon-check"></i>
              </span>

              <div class="status-detail">
                <h3 class="title">${_("Success")}</h3>
Julian Arni committed
113
                <p class="copy">${_("Your imported content has now been integrated into this course")}</p>
114

115 116 117 118 119 120
                <ul class="list-actions">
                  <li class="item-action">
                    <a href="${successful_import_redirect_url}" class="action action-primary">${_("View Updated Outline")}</a>
                  </li>
                </ul>
              </div>
121
            </li>
122
          </ol>
123
        </div>
Tom Giannattasio committed
124 125
      </form>
    </article>
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140

    <aside class="content-supplementary" role="complimentary">
      <div class="bit">
        <h3 class="title-3">${_("Gzipped Tar Files (.tar.gz) Only")}</h3>
        ## Translators: ".tar.gz" is a file extension, and files with that extension are called "gzipped tar files": these terms should not be translated
        <p>${_("File uploads must be gzipped tar files (.tar.gz) containing, at a minimum, a {filename} file.").format(filename='<code>course.xml</code>')}</p>
      </div>

      <div class="bit">
        <h3 class="title-3">${_("Warning: Auto-generated Nodes")}</h3>
        ## Translators: ".tar.gz" is a file extension, and files with that extension are called "gzipped tar files": these terms should not be translated
        <p>${_("Please note that if your course has any problems with auto-generated {nodename} nodes, re-importing your course could cause the loss of student data associated with those problems.").format(nodename='<code>url_name</code>')}</p>
      </div>
    </aside>
  </section>
141
</div>
142 143 144 145
</%block>

<%block name="jsextra">
<script>
146 147 148
require(
        ["js/views/import", "jquery", "jquery.fileupload"],
        function(CourseImport, $) {
149

150
var file;
Julian Arni committed
151
var bar = $('.progress-bar');
152
var fill = $('.progress-fill');
153 154
var percent = $('.percent');
var status = $('#status');
155
var statusBlock = $('.status-block');
156
var submitBtn = $('.submit-button');
157
var chooseBtn = $('.choose-file-button');
158

159 160
var allStats = $('#status-infos');

161 162
var feedbackUrl = "${reverse('import_status', kwargs=dict(org=context_course.location.org, course=context_course.location.course, name='fillerName'))}"

163 164 165 166 167 168
var defaults = [
    '${_("There was an error during the upload process.")}\n',
    '${_("There was an error while unpacking the file.")}\n',
    '${_("There was an error while verifying the file you submitted.")}\n',
    '${_("There was an error while importing the new course to our database.")}\n'
];
169 170 171 172 173 174 175 176 177 178 179

$('#fileupload').fileupload({

    dataType: 'json',
    type: 'POST',

    maxChunkSize: 20 * 1000000, // 20 MB

    autoUpload: false,

    add: function(e, data) {
180
        CourseImport.clearImportDisplay();
Julian Arni committed
181
        submitBtn.unbind('click');
182
        file = data.files[0];
183
        if (file.name.match(/tar\.gz$/)) {
184 185
            submitBtn.click(function(e){
                e.preventDefault();
Julian Arni committed
186
                submitBtn.hide();
187
                data.submit().complete(function(result, textStatus, xhr) {
188 189
                    CourseImport.stopGetStatus = true;
                    window.onbeforeunload = null;
190
                    if (xhr.status != 200) {
191 192
                        var serverMsg = $.parseJSON(result.responseText);
                        var errMsg = serverMsg.hasOwnProperty("ErrMsg") ?  serverMsg.ErrMsg : "" ;
193
                        if (serverMsg.hasOwnProperty("Stage")) {
194 195
                            var stage = serverMsg.Stage;
                            CourseImport.stageError(stage, defaults[stage] + errMsg);
196 197 198 199
                        }
                        else {
                            alert('${_("Your import has failed.")}\n\n' + errMsg);
                        }
200
                        chooseBtn.html('${_("Choose new file")}').show();
201
                        bar.hide();
202
                    }
203 204
                    chooseBtn.html('${_("Choose new file")}').show();
                    bar.hide();
205
                });
Julian Arni committed
206
            });
207 208 209
        } else {
            data.files = [];
        }
210
    },
211 212

    progressall: function(e, data){
213 214
        var doneAt;
        var percentInt = data.loaded / data.total * 100
Julian Arni committed
215
        var percentVal = parseInt(percentInt, 10) + "%";
216 217 218 219 220 221 222 223 224
        // Firefox makes ProgressEvent.loaded equal ProgressEvent.total only
        // after receiving a response from the server (see Mozilla bug 637002),
        // so for Firefox we jump the gun a little.
        if (navigator.userAgent.toLowerCase().indexOf('firefox') > -1) {
            doneAt = 95;
        } else {
            doneAt = 99;
        }
        if (percentInt >= doneAt) {
Julian Arni committed
225
            bar.hide();
226
            CourseImport.startServerFeedback(feedbackUrl.replace("fillerName", file.name));
Julian Arni committed
227 228 229 230 231
        } else {
            bar.show();
            fill.width(percentVal);
            percent.html(percentVal);
        }
232
    },
233
    done: function(e, data){
Julian Arni committed
234
        bar.hide();
Julian Arni committed
235
        window.onbeforeunload = null;
236
        CourseImport.displayFinishedImport();
237
    },
Julian Arni committed
238 239
    start: function(e) {
        window.onbeforeunload = function() {
Julian Arni committed
240
            return '${_("Your import is in progress; navigating away will abort it.")}';
Julian Arni committed
241 242
        }
    },
243 244
    sequentialUploads: true,
    notifyOnError: false
245

246 247
});

248
}); // end define()
249
</script>
Brian Talbot committed
250
</%block>