zip_file_imports i18n
Change-Id: I1785eeea3d7bbca6d524e0a54d02b35afb045583 Reviewed-on: https://gerrit.instructure.com/4128 Tested-by: Hudson <hudson@instructure.com> Reviewed-by: Zach Wily <zach@instructure.com>
This commit is contained in:
parent
e693123f82
commit
bf1f513206
|
@ -40,7 +40,10 @@ class ZipFileImportsController < ApplicationController
|
|||
@zfi = ZipFileImport.new(zip_params)
|
||||
respond_to do |format|
|
||||
if @zfi.process!
|
||||
flash[:notice] = "Uploaded and unzipped #{@zfi.zip_file.original_filename} into #{@zfi.root_directory.full_name}."
|
||||
flash[:notice] = t('notices.upload_and_unzip_done',
|
||||
"Uploaded and unzipped %{original_filename} into %{destination}.",
|
||||
:original_filename => @zfi.zip_file.original_filename,
|
||||
:destination => @zfi.root_directory.full_name)
|
||||
format.html { return_to(params[:return_to], named_context_url(@context, :context_url)) }
|
||||
format.json { render :json => @zfi.to_json }
|
||||
else
|
||||
|
|
|
@ -23,8 +23,8 @@ class ZipFileImport < Tableless
|
|||
|
||||
validates_presence_of :zip_file, :context, :folder_id
|
||||
validates_each :zip_file do |record, attr, value|
|
||||
record.errors.add attr, 'Must Upload A file' unless record.zip_file.class == Tempfile
|
||||
record.errors.add attr, 'The file must be a valid .zip archive' unless record.zip_file.respond_to?(:content_type) && record.zip_file.content_type.to_s.strip.match(/application\/(x-)?zip/)
|
||||
record.errors.add attr, t('errors.must_upload_file', 'Must Upload A file') unless record.zip_file.class == Tempfile
|
||||
record.errors.add attr, t('errors.file_must_be_zip', 'The file must be a valid .zip archive') unless record.zip_file.respond_to?(:content_type) && record.zip_file.content_type.to_s.strip.match(/application\/(x-)?zip/)
|
||||
end
|
||||
|
||||
def process!
|
||||
|
@ -39,7 +39,7 @@ class ZipFileImport < Tableless
|
|||
)
|
||||
rescue => e
|
||||
@error = ErrorReport.log_exception(:default, e)
|
||||
self.errors.add :zip_file, "Unexpected Error (#{@error.id}) while processing zipped files"
|
||||
self.errors.add :zip_file, t('errors.unexpected', "Unexpected Error (%{error_id}) while processing zipped files", :error_id => @error.id)
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,29 +1,30 @@
|
|||
<div id="uploading_please_wait_dialog" title="Uploading, Please Wait." style="display:none;">
|
||||
<div id="uploading_progressbar"></div>
|
||||
<p>Uploading and processing your zip file, if there are a lot of files in the zip file or it is very large, this may take a while.</p>
|
||||
<p><%= t 'notices.uploading_progress_info', 'Uploading and processing your zip file, if there are a lot of files in the zip file or it is very large, this may take a while.' %></p>
|
||||
</div>
|
||||
<% form_for((@zfi || ZipFileImport.new), :url => context_url(@context, :context_zip_file_imports_url), :html => { :id => "zip_file_import_form", :multipart => true }) do |form| %>
|
||||
<input type="hidden" name="batch_id" value="<%= AutoHandle.generate(@current_user.asset_string, 10) %>" id="zip_import_batch_id"/>
|
||||
<%= form.error_messages %>
|
||||
<div>
|
||||
<input type="file" name="zip_file" id="zip_file"/><br/>
|
||||
<span style="font-size: 0.8em; color: #a00; display: none;" id="zip_only_message">Please select a .zip file for uploading</span>
|
||||
<span style="font-size: 0.8em; color: #a00; display: none;" id="zip_only_message"><%= t 'prompts.select_file', 'Please select a .zip file for uploading' %></span>
|
||||
</div>
|
||||
<div id="upload_to" style="margin: 10px 0;">
|
||||
Upload to:
|
||||
<%= before_label :upload_to, 'Upload to' %>
|
||||
<select name="folder_id">
|
||||
<%= folders_as_options(Folder.root_folders(@context), :all_folders => @context.folders.active, :selected_folder_id => params[:folder_id].to_i) %>
|
||||
</select>
|
||||
<%= hidden_field_tag 'return_to', qti_or_content_link %>
|
||||
</div>
|
||||
<div class="button-container">
|
||||
<button type="submit" class="submit_button button big-button">Upload File</button>
|
||||
<a class="cancel_button button button-secondary" href="#">Cancel</a>
|
||||
<button type="submit" class="submit_button button big-button"><%= t 'buttons.upload_file', 'Upload File' %></button>
|
||||
<a class="cancel_button button button-secondary" href="#"><%= t '#buttons.cancel', 'Cancel' %></a>
|
||||
</div>
|
||||
<a href="<%= context_url(@context, :import_status_context_zip_file_imports_url) %>" class="zip_file_import_status_url" style="display: none;"> </a>
|
||||
<% end %>
|
||||
<% js_block do %>
|
||||
<script>
|
||||
I18n.scoped("zip_file_imports", function(I18n) {
|
||||
$(document).ready(function() {
|
||||
$("#zip_file_import_form #zip_file").change(function() {
|
||||
var val = $(this).val();
|
||||
|
@ -57,8 +58,9 @@
|
|||
$("#zip_file_import_form .errors").hide();
|
||||
var importFailed = function(errors) {
|
||||
var $div = $("<div class='errors' style='color: #a00; font-weight: bold;'/>");
|
||||
$div.text("There were some errors extracting the zip file. Please try again");
|
||||
$.flashError("There were some errors extracting the zip file. Please try again");
|
||||
var error_message = I18n.t('errors.extracting_file', "There were some errors extracting the zip file. Please try again");
|
||||
$div.text(error_message);
|
||||
$.flashError(error_message);
|
||||
$("#zip_import_batch_id").val($("#zip_import_batch_id").val() + "0");
|
||||
var $ul = $("<ul class='errors'/>");
|
||||
for(var idx in errors) {
|
||||
|
@ -78,13 +80,13 @@
|
|||
importFailed(data.errors);
|
||||
} else if(data && data.complete) {
|
||||
$("#uploading_progressbar").progressbar('value', 100);
|
||||
$("#uploading_please_wait_dialog").prepend("Uploading complete!");
|
||||
$("#uploading_please_wait_dialog").prepend(I18n.t('notices.uploading_complete', "Uploading complete!"));
|
||||
location.href = $("#return_to").val();
|
||||
} else if(hadSomeProgress && (!data || data.progress == null)) {
|
||||
pollImport.blankCount = pollImport.blankCount || 0;
|
||||
pollImport.blankCount++;
|
||||
if(pollImport.blankCount > 10) {
|
||||
importFailed(["The server stopped returning a valid status"]);
|
||||
importFailed([I18n.t('errors.server_status', "The server stopped returning a valid status")]);
|
||||
} else {
|
||||
setTimeout(pollImport, 2000);
|
||||
}
|
||||
|
@ -99,7 +101,7 @@
|
|||
pollImport.errorCount = pollImport.errorCount || 0;
|
||||
pollImport.errorCount++;
|
||||
if(pollImport.errorCount > 10) {
|
||||
importFailed(["The server stopped responding to status requests"]);
|
||||
importFailed([I18n.t('errors.server_stopped_responding', "The server stopped responding to status requests")]);
|
||||
} else {
|
||||
setTimeout(pollImport, 2000);
|
||||
}
|
||||
|
@ -108,5 +110,6 @@
|
|||
setTimeout(pollImport, 5000);
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
<% end %>
|
||||
|
|
Loading…
Reference in New Issue