Move import-related js to import.js
This commit is contained in:
@@ -16,7 +16,6 @@ from uuid import uuid4
|
||||
from pymongo import MongoClient
|
||||
|
||||
from .utils import CourseTestCase
|
||||
from django.contrib.auth.models import User
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.test.utils import override_settings
|
||||
from django.conf import settings
|
||||
|
||||
@@ -250,6 +250,25 @@ PIPELINE_CSS = {
|
||||
# test_order: Determines the position of this chunk of javascript on
|
||||
# the jasmine test page
|
||||
PIPELINE_JS = {
|
||||
'main': {
|
||||
'source_filenames': sorted(
|
||||
rooted_glob(COMMON_ROOT / 'static/', 'coffee/src/**/*.js') +
|
||||
rooted_glob(PROJECT_ROOT / 'static/', 'coffee/src/**/*.js')
|
||||
) + ['js/hesitate.js', 'js/base.js', 'js/views/feedback.js',
|
||||
'js/models/course.js',
|
||||
'js/models/section.js', 'js/views/section.js',
|
||||
'js/models/metadata_model.js', 'js/views/metadata_editor_view.js',
|
||||
'js/models/uploads.js', 'js/views/uploads.js',
|
||||
'js/models/textbook.js', 'js/views/textbook.js',
|
||||
'js/src/utility.js',
|
||||
'js/models/settings/course_grading_policy.js',
|
||||
'js/models/asset.js', 'js/models/assets.js',
|
||||
'js/views/assets.js',
|
||||
'js/views/import.js',
|
||||
'js/views/assets_view.js', 'js/views/asset_view.js'],
|
||||
'output_filename': 'js/cms-application.js',
|
||||
'test_order': 0
|
||||
},
|
||||
'module-js': {
|
||||
'source_filenames': (
|
||||
rooted_glob(COMMON_ROOT / 'static/', 'xmodule/descriptors/js/*.js') +
|
||||
|
||||
115
cms/static/js/views/import.js
Normal file
115
cms/static/js/views/import.js
Normal file
@@ -0,0 +1,115 @@
|
||||
/**
|
||||
* Course import-related js.
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
/**
|
||||
* Entry point for server feedback. Makes status list visible and starts
|
||||
* sending requests to the server for status updates.
|
||||
* @param {string} url The url to send Ajax GET requests for updates.
|
||||
*/
|
||||
var startServerFeedback = function (url){
|
||||
$('div.wrapper-status').removeClass('is-hidden');
|
||||
$('.status-info').show();
|
||||
getStatus(url, 500);
|
||||
};
|
||||
|
||||
/**
|
||||
* Toggle the spin on the progress cog.
|
||||
* @param {boolean} isSpinning Turns cog spin on if true, off otherwise.
|
||||
*/
|
||||
var updateCog = function (elem, isSpinning) {
|
||||
var cogI = elem.find('i.icon-cog');
|
||||
if (isSpinning) { cogI.addClass("icon-spin");}
|
||||
else { cogI.removeClass("icon-spin");}
|
||||
};
|
||||
|
||||
/**
|
||||
* Manipulate the DOM to reflect current status of upload.
|
||||
* @param {int} stageNo Current stage.
|
||||
*/
|
||||
var updateStage = function (stageNo){
|
||||
var all = $('ol.status-progress').children();
|
||||
var prevList = all.slice(0, stageNo);
|
||||
_.map(prevList, function (elem){
|
||||
$(elem).removeClass("is-not-started").removeClass("is-started").addClass("is-complete");
|
||||
updateCog($(elem), false);
|
||||
});
|
||||
var curList = all.eq(stageNo);
|
||||
curList.removeClass("is-not-started").addClass("is-started");
|
||||
updateCog(curList, true);
|
||||
};
|
||||
|
||||
/**
|
||||
* Give error message at the list element that corresponds to the stage where
|
||||
* the error occurred.
|
||||
* @param {int} stageNo Stage of import process at which error occured.
|
||||
* @param {string} msg Error message to display.
|
||||
*/
|
||||
var stageError = function (stageNo, msg) {
|
||||
var all = $('ol.status-progress').children();
|
||||
// Make all stages up to, and including, the error stage 'complete'.
|
||||
var prevList = all.slice(0, stageNo + 1);
|
||||
_.map(prevList, function (elem){
|
||||
$(elem).removeClass("is-not-started").removeClass("is-started").addClass("is-complete");
|
||||
updateCog($(elem), false);
|
||||
});
|
||||
var message = msg || "There was an error with the upload";
|
||||
var elem = $('ol.status-progress').children().eq(stageNo);
|
||||
elem.removeClass('is-started').addClass('has-error');
|
||||
elem.find('p.copy').hide().after("<p class='copy error'>" + message + "</p>");
|
||||
};
|
||||
|
||||
/**
|
||||
* Check for import status updates every `timemout` milliseconds, and update
|
||||
* the page accordingly.
|
||||
* @param {string} url Url to call for status updates.
|
||||
* @param {int} timeout Number of milliseconds to wait in between ajax calls
|
||||
* for new updates.
|
||||
* @param {int} stage Starting stage.
|
||||
*/
|
||||
var getStatus = function (url, timeout, stage) {
|
||||
if (currentStage == 3 ) { return ;}
|
||||
if (window.stopGetStatus) { return ;}
|
||||
var currentStage = stage || 0;
|
||||
updateStage(currentStage);
|
||||
var time = timeout || 1000;
|
||||
$.getJSON(url,
|
||||
function (data) {
|
||||
setTimeout(function () {
|
||||
getStatus(url, time, data["ImportStatus"]);
|
||||
}, time);
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* Update DOM to set all stages as complete, and stop asking for status
|
||||
* updates.
|
||||
*/
|
||||
var displayFinishedImport = function () {
|
||||
window.stopGetStatus = true;
|
||||
var all = $('ol.status-progress').children();
|
||||
_.map(all, function (elem){
|
||||
$(elem).removeClass("is-not-started").removeClass("is-started").addClass("is-complete");
|
||||
updateCog($(elem), false);
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Update DOM to set all stages as not-started (for retrying an upload that
|
||||
* failed).
|
||||
*/
|
||||
var clearImportDisplay = function () {
|
||||
var all = $('ol.status-progress').children();
|
||||
_.map(all, function (elem){
|
||||
$(elem).removeClass("is-complete").
|
||||
removeClass("is-started").
|
||||
removeClass("has-error").
|
||||
addClass("is-not-started");
|
||||
$(elem).find('p.error').remove(); // remove error messages
|
||||
$(elem).find('p.copy').show();
|
||||
updateCog($(elem), false);
|
||||
});
|
||||
window.stopGetStatus = false;
|
||||
};
|
||||
Reference in New Issue
Block a user