sets front end validation for experiment move action [fixes SCI-400]

This commit is contained in:
zmagod 2016-09-02 16:31:17 +02:00
parent 73332ac7d1
commit 667fb67052
4 changed files with 39 additions and 8 deletions

View file

@ -14,6 +14,7 @@
backdrop: true,
keyboard: false,
});
validateMoveModal(id);
})
.on("ajax:error", function() {
animateSpinner(null, false);
@ -45,6 +46,24 @@
});
}
// Validates move action
function validateMoveModal(modal){
if ( modal.match(/#move-experiment-modal-[0-9]*/) ) {
var form = $(modal).find("form");
form
.on('ajax:success', function(e, data) {
animateSpinner(form, true);
window.location.replace(data.path);
})
.on('ajax:error', function(e, error) {
var msg = JSON.parse(error.responseText);
renderFormError(e,
form.find("#experiment_project_id"),
msg.message.toString());
})
.clearFormErrors();
}
}
// Initialize no description edit link
function initEditNoDescription(){
var modal = "#edit-experiment-modal-";
@ -55,7 +74,7 @@
}
// Bind modal to new-experiment action
initializeModal($("#new-experiment"), '#new-experiment-modal');
// Bind modal to big-plus new experiment actions
initializeModal('.big-plus', '#new-experiment-modal');

View file

@ -185,11 +185,22 @@ class ExperimentsController < ApplicationController
flash[:success] = t('experiments.move.success_flash',
experiment: @experiment.name)
redirect_to canvas_experiment_path(@experiment)
respond_to do |format|
format.json do
render json: { path: canvas_experiment_url(@experiment) }, status: :ok
end
end
else
flash[:error] = t('experiments.move.error_flash',
experiment: @experiment.name)
redirect_to project_path(@experiment.project)
# flash[:error] = t('experiments.move.error_flash',
# experiment: @experiment.name)
# redirect_to project_path(@experiment.project)
respond_to do |format|
format.json do
render json: { message: t('experiments.move.error_flash',
experiment: @experiment.name) },
status: :unprocessable_entity
end
end
end
end

View file

@ -5,7 +5,8 @@
role="dialog"
aria-labelledby="move-experiment-modal-label">
<%= bootstrap_form_for @experiment, url: move_experiment_path(),
method: :post do |f| %>
method: :post,
remote: true do |f| %>
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
@ -15,7 +16,7 @@
<div class="modal-body">
<% if !@projects.blank? %>
<%= f.select :project_id, options_for_select(@projects.collect { |p| [ p.name, p.id ] }),
{}, {class: "form-control selectpicker", "data-role" => "clear"} %>
{}, { class: "form-control selectpicker", "data-role" => "clear" } %>
<% else %>
<div>
<em>

View file

@ -637,7 +637,7 @@ en:
label_title: 'Move'
modal_submit: 'Move'
success_flash: "Successfully moved experiment %{experiment}"
error_flash: 'Could not move the experiment.'
error_flash: ' Could not move the experiment. Experiment name is already in use. '
no_projects: 'No projects to move this experiment to.'
canvas:
archive_confirm: "Are you sure to archive this experiment?"