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

View file

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

View file

@ -4,7 +4,7 @@
tabindex="-1" tabindex="-1"
role="dialog" role="dialog"
aria-labelledby="edit-experiment-modal-label"> 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-dialog" role="document">
<div class="modal-content"> <div class="modal-content">
<div class="modal-header"> <div class="modal-header">

View file

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