Merge pull request #962 from Zanz2/missing_error_SCI1993

A red error messagge is now displayed when not selecting protocol [SCI-1993]
This commit is contained in:
Zanz2 2018-01-26 16:00:15 +01:00 committed by GitHub
commit e8f6dc0d24
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 1 deletions

View file

@ -601,8 +601,17 @@ class ProtocolsController < ApplicationController
def protocolsio_import_create
@protocolsio_too_big = false
@protocolsio_invalid_file = false
@protocolsio_no_file = false
if params[:json_file].nil?
@protocolsio_no_file = true
respond_to do |format|
format.js {}
end
return 0 # return 0 stops the rest of the controller code from executing
end
extension = File.extname(params[:json_file].path)
file_size = File.size(params[:json_file].path)
if extension != '.txt' && extension != '.json'
@protocolsio_invalid_file = true
respond_to do |format|

View file

@ -18,6 +18,7 @@
<div class="modal-body">
<%= file_field_tag 'json_file', accept: '.txt,.json' %>
<div id="pio_no_file_error_span"></div>
</div>
<div class="modal-footer">

View file

@ -1,4 +1,6 @@
$('#modal-import-json-protocol').on('hidden.bs.modal', function () {
$('#pio_no_file_error_span').empty();
})
<% if @protocolsio_too_big %>
$('#modal-import-json-protocol').modal('hide');
HelperModule.flashAlertMsg(' <%= t('my_modules.protocols.load_from_file_size_error',
@ -6,6 +8,9 @@ HelperModule.flashAlertMsg(' <%= t('my_modules.protocols.load_from_file_size_err
<% elsif @protocolsio_invalid_file %>
$('#modal-import-json-protocol').modal('hide');
HelperModule.flashAlertMsg(' <%= t('my_modules.protocols.load_from_file_invalid_error') %>','danger');
<% elsif @protocolsio_no_file %>
$('#pio_no_file_error_span').addClass('has-error').html('<span class="help-block"> <%= t('teams.parse_sheet.errors.no_file_selected') %></span>');
<% @protocolsio_no_file = false %>
<% else %>
$('#modal-import-json-protocol').modal('hide');
<% if remotipart_submitted? %> <%# a workaround to a bug with remotipart, that caused alot of headache, courtesy of github.com/dhampik %>