sets edit experiment validation

This commit is contained in:
zmagod 2016-09-02 14:13:59 +02:00
parent 9d469f9092
commit b44a284b54
4 changed files with 47 additions and 36 deletions

View file

@ -16,7 +16,7 @@
keyboard: false,
});
validateMoveModal(id);
validateExperimentForm();
validateExperimentForm($(id));
})
.on("ajax:error", function() {
animateSpinner(null, false);
@ -63,37 +63,41 @@
form.find("#experiment_project_id"),
msg.message.toString());
})
.clearFormErrors();
on('submit', function(){
form.clearFormErrors();
});
}
// Setup front-end validations for experiment form
function validateExperimentForm(){
var form = $("#new-experiment-modal").find("form");
form
.on('ajax:success' , function(){
animateSpinner(form, true);
location.reload();
})
.on('ajax:error', function(e, error){
var msg = JSON.parse(error.responseText);
if ( 'name' in msg ) {
renderFormError(e,
$('#new-experiment-name'),
msg.name.toString());
} else if ( 'description' in msg ) {
renderFormError(e,
$('#new-experiment-description'),
msg.description.toString());
} else {
renderFormError(e,
$('#new-experiment-name'),
error.statusText);
}
})
.on('submit', function(ev) {
textValidator(ev, $('#new-experiment-name'), false);
textValidator(ev, $('#new-experiment-description'), true);
})
.clearFormErrors();
function validateExperimentForm(element){
if ( element ) {
var form = element.find("form");
form
.on('ajax:success' , function(){
animateSpinner(form, true);
location.reload();
})
.on('ajax:error', function(e, error){
var msg = JSON.parse(error.responseText);
if ( 'name' in msg ) {
renderFormError(e,
element.find("#experiment-name"),
msg.name.toString());
} else if ( 'description' in msg ) {
renderFormError(e,
element.find("#experiment-description"),
msg.description.toString());
} else {
renderFormError(e,
element.find("#experiment-name"),
error.statusText);
}
})
.on('submit', function(ev) {
textValidator(ev, element.find("#experiment-name"), false);
textValidator(ev, element.find("#experiment-description"), true);
})
.clearFormErrors();
}
}
// Initialize no description edit link
function initEditNoDescription(){

View file

@ -76,10 +76,17 @@ class ExperimentsController < ApplicationController
@experiment.touch(:workflowimg_updated_at)
flash[:success] = t('experiments.update.success_flash',
experiment: @experiment.name)
redirect_to canvas_experiment_path(@experiment)
respond_to do |format|
format.json do
render json: {}, status: :ok
end
end
else
flash[:alert] = t('experiments.update.error_flash')
redirect_to :back
respond_to do |format|
format.json do
render json: @experiment.errors, status: :unprocessable_entity
end
end
end
end

View file

@ -4,7 +4,7 @@
tabindex="-1"
role="dialog"
aria-labelledby="edit-experiment-modal-label">
<%= bootstrap_form_for [@project, @experiment] do |f| %>
<%= bootstrap_form_for [@project, @experiment], remote: true do |f| %>
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">

View file

@ -5,7 +5,7 @@
label: t("experiments.new.name"),
autofocus: true,
placeholder: t("experiments.new.name_placeholder"),
id: 'new-experiment-name'%>
id: 'experiment-name'%>
</div>
</div>
</div>
@ -15,7 +15,7 @@
<div class="form-group">
<%= form.text_area :description,
label: t('experiments.new.description'),
id: 'new-experiment-description' %>
id: 'experiment-description' %>
</div>
</div>
</div>