canvas-lms/public/javascripts/content_exports.js

120 lines
4.3 KiB
JavaScript
Raw Normal View History

/**
* Copyright (C) 2011 Instructure, Inc.
*
* This file is part of Canvas.
*
* Canvas is free software: you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License as published by the Free
* Software Foundation, version 3 of the License.
*
* Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
define([
AMD Conversion "Trivial" JavaScript / CoffeeScript changes -------------------------------------------------- For the most part, all javascript was simply wrapped in `require` or `define`. The dependencies were found with a script that matched regexes in the files, it errs on the side of listing too many dependencies, so its worth double checking each file's dependencies (over time, anyway). i18n API changes -------------------------------------------------- No longer have to do I18n.scoped calls, just list i18n as a dependency with the scope and it's imported already scoped require ['i18n!some_scope'], (I18n) -> I18n.t 'im_scoped', 'I'm scoped!' JS bundling now done with r.js, not Jammit -------------------------------------------------- We don't use jammit to bundle JS anymore. Simply list dependencies for your JS modules in the file and RequireJS handles the rest. To optimize the JavaScript, first make sure you have node.js 0.4.12+ installed and then run: $ rake js:build The app defaults to the optimized build in production. You can use non-optimized in production by putting ?debug_assets=true in the url just like before. You can also test the optimized JavaScript in development with ?optimized_js=true. Significant changes -------------------------------------------------- These files have "real" changes to them (unlike the JavaScript that is simply wrapped in require and define). Worth taking a really close look at: - app/helpers/application_helper.rb - app/views/layouts/application.html.erb - config/assets.yml - config/build.js - lib/handlebars/handlebars.rb - lib/i18n_extraction/js_extractor.rb - lib/tasks/canvas.rake - lib/tasks/i18n.rake - lib/tasks/js.rake Change-Id: I4bc5ecb1231f331aaded0fef2bcc1f3a9fe482a7 Reviewed-on: https://gerrit.instructure.com/6986 Tested-by: Hudson <hudson@instructure.com> Reviewed-by: Ryan Florence <ryanf@instructure.com>
2011-11-11 00:31:45 +08:00
'i18n!content_exports',
'jquery' /* $ */,
'jquery.ajaxJSON' /* ajaxJSON */,
'jquery.instructure_forms' /* formSubmit */,
'jqueryui/progressbar' /* /\.progressbar/ */
], function(I18n, $) {
$(document).ready(function(event) {
var state = 'nothing';
var current_id = null;
AMD Conversion "Trivial" JavaScript / CoffeeScript changes -------------------------------------------------- For the most part, all javascript was simply wrapped in `require` or `define`. The dependencies were found with a script that matched regexes in the files, it errs on the side of listing too many dependencies, so its worth double checking each file's dependencies (over time, anyway). i18n API changes -------------------------------------------------- No longer have to do I18n.scoped calls, just list i18n as a dependency with the scope and it's imported already scoped require ['i18n!some_scope'], (I18n) -> I18n.t 'im_scoped', 'I'm scoped!' JS bundling now done with r.js, not Jammit -------------------------------------------------- We don't use jammit to bundle JS anymore. Simply list dependencies for your JS modules in the file and RequireJS handles the rest. To optimize the JavaScript, first make sure you have node.js 0.4.12+ installed and then run: $ rake js:build The app defaults to the optimized build in production. You can use non-optimized in production by putting ?debug_assets=true in the url just like before. You can also test the optimized JavaScript in development with ?optimized_js=true. Significant changes -------------------------------------------------- These files have "real" changes to them (unlike the JavaScript that is simply wrapped in require and define). Worth taking a really close look at: - app/helpers/application_helper.rb - app/views/layouts/application.html.erb - config/assets.yml - config/build.js - lib/handlebars/handlebars.rb - lib/i18n_extraction/js_extractor.rb - lib/tasks/canvas.rake - lib/tasks/i18n.rake - lib/tasks/js.rake Change-Id: I4bc5ecb1231f331aaded0fef2bcc1f3a9fe482a7 Reviewed-on: https://gerrit.instructure.com/6986 Tested-by: Hudson <hudson@instructure.com> Reviewed-by: Ryan Florence <ryanf@instructure.com>
2011-11-11 00:31:45 +08:00
function startPoll() {
$("#exporter_form").html(I18n.t('messages.processing', "Processing") + "<div style='font-size: 0.8em;'>" + I18n.t('messages.this_may_take_a_bit', "this may take a bit...") + "</div>")
.attr('disabled', true);
$(".instruction").hide();
$(".progress_bar_holder").slideDown();
$(".export_progress").progressbar();
state = "nothing";
var fakeTickCount = 0;
var tick = function() {
if(state == "nothing") {
fakeTickCount++;
var progress = ($(".export_progress").progressbar('option', 'value') || 0) + 0.25;
if(fakeTickCount < 10) {
$(".export_progress").progressbar('option', 'value', progress);
}
setTimeout(tick, 2000);
} else {
state = "nothing";
fakeTickCount = 0;
setTimeout(tick, 10000);
}
};
var checkup = function() {
var lastProgress = null;
var waitTime = 1500;
$.ajaxJSON(location.href + "/" + current_id, 'GET', {}, function(data) {
state = "updating";
var content_export = data.content_export;
var progress = 0;
if(content_export) {
progress = Math.max($(".export_progress").progressbar('option', 'value') || 0, content_export.progress);
$(".export_progress").progressbar('option', 'value', progress);
}
if(content_export.workflow_state == 'exported') {
$("#exporter_form").hide();
$(".export_progress").progressbar('option', 'value', 100);
$(".progress_message").html("The course has been exported.");
$("#exports").append('<p>' + I18n.t('labels.new_course_export', "New Course Export:") + ' <a href="' + content_export.download_url + '">' + I18n.t('links.download_plain', "Click here to download") + '</a> </p>')
} else if(content_export.workflow_state == 'failed') {
code = "content_export_" + content_export.id;
$(".progress_bar_holder").hide();
$("#exporter_form").hide();
var message = I18n.t('errors.error', "There was an error exporting your course. Please notify your system administrator and give them the following export identifier: \"%{code}\"", {code: code});
$(".export_messages .error_message").html(message);
$(".export_messages").show();
} else {
if(progress == lastProgress) {
waitTime = Math.max(waitTime + 500, 30000);
} else {
waitTime = 1500;
}
lastProgress = progress;
setTimeout(checkup, 1500);
}
}, function() {
setTimeout(checkup, 3000);
});
};
setTimeout(checkup, 2000);
setTimeout(tick, 1000)
}
$("#exporter_form").formSubmit({
success: function(data) {
if(data && data.content_export) {
current_id = data.content_export.id
startPoll();
} else {
//show error message
$(".export_messages .error_message").text(data.error_message);
$(".export_messages").show();
}
},
error: function(data) {
$(this).find(".submit_button").attr('disabled', false).text(I18n.t('buttons.process', "Process Data"));
}
});
function check_if_exporting() {
//state = "checking";
if( $('#current_export_id').size() ){
//state = "nothing";
current_id = $('#current_export_id').text()
startPoll();
}
}
check_if_exporting();
});
});