Improve server side assets validation display for steps [SCI-1747]

This commit is contained in:
Oleksii Kriuchykhin 2017-11-21 13:48:06 +01:00
parent 038c15a1ee
commit fe8b7d26c1
5 changed files with 18 additions and 24 deletions

View file

@ -593,21 +593,15 @@
animateSpinner(null, false); animateSpinner(null, false);
setupAssetsLoading(); setupAssetsLoading();
}, },
error: function(e) { error: function(xhr) {
$form.after(xhr.responseJSON.html); if (xhr.responseJSON['assets.file'] != null) {
var $new_form = $form.next(); $('#new-step-assets-group').addClass('has-error');
$form.remove(); $('#new-step-assets-tab').addClass('has-error');
$.each(xhr.responseJSON['assets.file'], function(_, value) {
$errInput = $new_form.find(".form-group.has-error") $('#new-step-assets-group').prepend('<span class="help-block">' + value + '</span>');
.first() });
.find("input"); }
renderFormError(e, $errInput);
formCallback($form);
applyCancelOnNew();
animateSpinner(null, false); animateSpinner(null, false);
TinyMCE.destroyAll();
SmartAnnotation.preventPropagation('.atwho-user-popover'); SmartAnnotation.preventPropagation('.atwho-user-popover');
} }
}); });

View file

@ -26,7 +26,7 @@
$('.panel-step-attachment-new').remove(); $('.panel-step-attachment-new').remove();
_dragNdropAssetsOff(); _dragNdropAssetsOff();
for(var i = 0; i < droppedFiles.length; i++) { for(var i = 0; i < droppedFiles.length; i++) {
$('#new-step-assets') $('#new-step-assets-group')
.append(_uploadedAssetPreview(droppedFiles[i], i)) .append(_uploadedAssetPreview(droppedFiles[i], i))
.promise() .promise()
.done(function() { .done(function() {
@ -49,7 +49,6 @@
var name = 'step[assets_attributes][' + index + '][file]'; var name = 'step[assets_attributes][' + index + '][file]';
fd.append(name, droppedFiles[i]); fd.append(name, droppedFiles[i]);
} }
droppedFiles = [];
filesValid = true; filesValid = true;
totalSize = 0; totalSize = 0;
_dragNdropAssetsOff(); _dragNdropAssetsOff();

View file

@ -96,11 +96,9 @@ class StepsController < ApplicationController
status: :ok status: :ok
end end
else else
format.json { format.json do
render json: { render json: @step.errors.to_json, status: :bad_request
html: render_to_string(partial: 'new.html.erb') end
}, status: :bad_request
}
end end
end end
end end

View file

@ -50,10 +50,12 @@
style="display: none" multiple> style="display: none" multiple>
</label> </label>
</div> </div>
<div id="new-step-assets-group" class="form-group">
<%= f.nested_fields_for :assets do |ff| %> <%= f.nested_fields_for :assets do |ff| %>
<%= render "form_assets.html.erb", ff: ff, step: step %> <%= render "form_assets.html.erb", ff: ff, step: step %>
<% end %> <% end %>
</div> </div>
</div>
<div class="tab-pane" role="tabpanel" id="new-step-tables"> <div class="tab-pane" role="tabpanel" id="new-step-tables">
<%= f.nested_fields_for :tables do |ff| %> <%= f.nested_fields_for :tables do |ff| %>
<%= render "form_tables.html.erb", ff: ff %> <%= render "form_tables.html.erb", ff: ff %>

View file

@ -217,6 +217,7 @@ module Paperclip
application/vnd.sun.xml.calc.template application/vnd.sun.xml.calc.template
application/vnd.stardivision.calc application/vnd.stardivision.calc
application/x-starcalc application/x-starcalc
application/CDFV2-encrypted
)) || )) ||
# Presentation application # Presentation application
(Set[content_type, content_types_from_name].subset? Set.new %w( (Set[content_type, content_types_from_name].subset? Set.new %w(