Merge pull request #889 from okriuchykhin/ok_SCI_1747

Improve server side assets validation display for steps [SCI-1747]
This commit is contained in:
okriuchykhin 2017-12-04 14:12:43 +01:00 committed by GitHub
commit b3b0e367e8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 29 additions and 27 deletions

View file

@ -123,6 +123,7 @@
initPreviewModal();
SmartAnnotation.preventPropagation('.atwho-user-popover');
TinyMCE.destroyAll();
DragNDropSteps.clearFiles();
}, 1000);
})
@ -148,8 +149,8 @@
initializeCheckboxSorting();
animateSpinner(null, false);
initPreviewModal();
TinyMCE.refresh()
DragNDropSteps.clearFiles();
TinyMCE.refresh();
$("#new-step-checklists fieldset.nested_step_checklists ul").each(function () {
enableCheckboxSorting(this);
});
@ -371,6 +372,7 @@
newStepHandler();
});
toggleButtons(true);
DragNDropSteps.clearFiles();
});
}
@ -592,22 +594,17 @@
});
animateSpinner(null, false);
setupAssetsLoading();
DragNDropSteps.clearFiles();
},
error: function(e) {
$form.after(xhr.responseJSON.html);
var $new_form = $form.next();
$form.remove();
$errInput = $new_form.find(".form-group.has-error")
.first()
.find("input");
renderFormError(e, $errInput);
formCallback($form);
applyCancelOnNew();
error: function(xhr) {
if (xhr.responseJSON['assets.file']) {
$('#new-step-assets-group').addClass('has-error');
$('#new-step-assets-tab').addClass('has-error');
$.each(xhr.responseJSON['assets.file'], function(_, value) {
$('#new-step-assets-group').prepend('<span class="help-block">' + value + '</span>');
});
}
animateSpinner(null, false);
TinyMCE.destroyAll();
SmartAnnotation.preventPropagation('.atwho-user-popover');
}
});

View file

@ -19,6 +19,10 @@
return filesValid;
}
function clearFiles() {
droppedFiles = [];
}
// loops through a list of files and display each file in a separate panel
function listItems() {
totalSize = 0;
@ -26,7 +30,7 @@
$('.panel-step-attachment-new').remove();
_dragNdropAssetsOff();
for(var i = 0; i < droppedFiles.length; i++) {
$('#new-step-assets')
$('#new-step-assets-group')
.append(_uploadedAssetPreview(droppedFiles[i], i))
.promise()
.done(function() {
@ -49,7 +53,6 @@
var name = 'step[assets_attributes][' + index + '][file]';
fd.append(name, droppedFiles[i]);
}
droppedFiles = [];
filesValid = true;
totalSize = 0;
_dragNdropAssetsOff();
@ -144,7 +147,8 @@
init: init,
appendFilesToForm: appendFilesToForm,
listItems: listItems,
filesStatus: filesStatus
filesStatus: filesStatus,
clearFiles: clearFiles
});
})();

View file

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

View file

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

View file

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