Commit 8efadaec by Alessandro

Add timestamp on success step + refactoring

TNL-925
parent 4c0bf161
define([
'js/views/import', 'jquery', 'gettext', 'jquery.fileupload', 'jquery.cookie'
], function(Import, $, gettext) {
'domReady', 'js/views/import', 'jquery', 'gettext', 'jquery.fileupload', 'jquery.cookie'
], function(domReady, Import, $, gettext) {
'use strict';
return function (feedbackUrl, library) {
var dbError;
if (library) {
dbError = gettext('There was an error while importing the new library to our database.');
} else {
dbError = gettext('There was an error while importing the new course to our database.');
}
var bar = $('.progress-bar'),
fill = $('.progress-fill'),
submitBtn = $('.submit-button'),
chooseBtn = $('.choose-file-button'),
chooseBtn = $('.view-import .choose-file-button'),
defaults = [
gettext('There was an error during the upload process.') + '\n',
gettext('There was an error while unpacking the file.') + '\n',
gettext('There was an error while verifying the file you submitted.') + '\n',
dbError + '\n'
],
// Display the status of last file upload on page load
lastFileUpload = $.cookie('lastfileupload'),
previousImport = Import.storedImport(),
file;
if (lastFileUpload){
Import.getAndStartUploadFeedback(feedbackUrl.replace('fillerName', lastFileUpload), lastFileUpload);
Import.callbacks.complete = function () {
bar.hide();
chooseBtn
.find('.copy').html(gettext("Choose new file")).end()
.show();
};
// Display the status of last file upload on page load
if (previousImport) {
$('.file-name-block')
.find('.file-name').html(previousImport.file.name).end()
.show();
if (previousImport.completed !== true) {
chooseBtn.hide();
}
Import.resume();
}
$('#fileupload').fileupload({
......@@ -33,39 +52,41 @@ define([
maxChunkSize: 20 * 1000000, // 20 MB
autoUpload: false,
add: function(e, data) {
Import.clearImportDisplay();
Import.okayToNavigateAway = false;
Import.reset();
submitBtn.unbind('click');
file = data.files[0];
if (file.name.match(/tar\.gz$/)) {
submitBtn.click(function(event){
submitBtn.click(function(event) {
event.preventDefault();
$.cookie('lastfileupload', file.name);
Import.start(
file.name,
feedbackUrl.replace('fillerName', file.name)
);
submitBtn.hide();
Import.startUploadFeedback();
data.submit().complete(function(result, textStatus, xhr) {
window.onbeforeunload = null;
if (xhr.status != 200) {
data.submit().complete(function (result, textStatus, xhr) {
if (xhr.status !== 200) {
var serverMsg, errMsg, stage;
try{
serverMsg = $.parseJSON(result.responseText);
} catch (e) {
return;
}
errMsg = serverMsg.hasOwnProperty('ErrMsg') ? serverMsg.ErrMsg : '' ;
if (serverMsg.hasOwnProperty('Stage')) {
stage = Math.abs(serverMsg.Stage);
Import.stageError(stage, defaults[stage] + errMsg);
Import.error(defaults[stage] + errMsg, stage);
}
else {
alert(gettext('Your import has failed.') + '\n\n' + errMsg);
}
chooseBtn.html(gettext('Choose new file')).show();
bar.hide();
}
Import.stopGetStatus = true;
chooseBtn.html(gettext('Choose new file')).show();
bar.hide();
});
});
} else {
......@@ -87,30 +108,42 @@ define([
}
if (percentInt >= doneAt) {
bar.hide();
// Start feedback with delay so that current stage of import properly updates in session
setTimeout(
function () { Import.startServerFeedback(feedbackUrl.replace('fillerName', file.name));},
3000
);
// Start feedback with delay so that current stage of
// import properly updates in session
setTimeout(function () { Import.pollStatus(); }, 3000);
} else {
bar.show();
fill.width(percentVal).html(percentVal);
}
},
done: function(event, data){
bar.hide();
window.onbeforeunload = null;
Import.displayFinishedImport();
},
start: function(event) {
window.onbeforeunload = function() {
if (!Import.okayToNavigateAway) {
return "${_('Your import is in progress; navigating away will abort it.')}";
}
};
},
sequentialUploads: true,
notifyOnError: false
});
var showImportSubmit = function (e) {
var filepath = $(this).val();
if (filepath.substr(filepath.length - 6, 6) === 'tar.gz') {
$('.error-block').hide();
$('.file-name').html($(this).val().replace('C:\\fakepath\\', ''));
$('.file-name-block').show();
chooseBtn.hide();
submitBtn.show();
$('.progress').show();
} else {
$('.error-block').html(gettext('File format not supported. Please upload a file with a <code>tar.gz</code> extension.')).show();
}
};
domReady(function () {
// import form setup
$('.view-import .file-input').bind('change', showImportSubmit);
$('.view-import .choose-file-button, .view-import .choose-file-button-inline').bind('click', function (e) {
e.preventDefault();
$('.view-import .file-input').click();
});
});
};
});
......@@ -186,6 +186,17 @@
// TYPE: success
&.item-progresspoint-success {
.item-progresspoint-success-date {
display: none;
margin-left: 5px;
}
&.is-complete {
.item-progresspoint-success-date {
display: inline;
}
}
}
......@@ -217,6 +228,8 @@
}
.fa-cog {
@include animation(fa-spin 2s infinite linear);
visibility: visible;
opacity: 1.0;
}
......
......@@ -115,7 +115,7 @@ else:
<li class="item-progresspoint item-progresspoint-unpack is-started">
<span class="deco status-visual">
<i class="icon fa fa-cog fa-spin"></i>
<i class="icon fa fa-cog"></i>
<i class="icon fa fa-warning"></i>
</span>
......@@ -167,7 +167,10 @@ else:
</span>
<div class="status-detail">
<h3 class="title">${_("Success")}</h3>
<h3 class="title">
${_("Success")}
<span class="item-progresspoint-success-date"></span>
</h3>
<p class="copy">
%if library:
${_("Your imported content has now been integrated into this library")}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment