added new/edit experiment modals

This commit is contained in:
zmagod 2016-07-28 14:44:44 +02:00
parent 9d23cfd940
commit 352944fc33
11 changed files with 123 additions and 15 deletions

View file

@ -0,0 +1,29 @@
// Place all the behaviors and hooks related to the matching controller here.
// All this logic will automatically be available in application.js.
(function(){
// Initialize new experiment form
function initializeNewExperimentModal(){
$("#new-experiment")
.on("ajax:beforeSend", function(){
animateSpinner(this);
})
.on("ajax:success", function(e, data){
$('body').append($.parseHTML(data.html));
$('#new-experiment-modal').modal('show',{
backdrop: true,
keyboard: false,
});
})
.on("ajax:error", function() {
animateSpinner(this, false);
// TODO
})
.on("ajax:complete", function(){
animateSpinner(this, false);
});
}
initializeNewExperimentModal();
})();

View file

@ -8,18 +8,28 @@ class ExperimentsController < ApplicationController
def new
@experiment = Experiment.new
respond_to do |format|
format.json {
render json:{
html: render_to_string( {
partial: "new_modal.html.erb",
locals: { experiment: @experiment }
})
}
}
end
end
def create
@experiment = Experiment.new(experiment_params)
@experiment.created_by = current_user
# @experiment.last_modified_by = current_user
@experiment.last_modified_by = current_user
@experiment.project = @project
if @experiment.save
@project.experiments << @experiment
flash[:success] = t('experiments.create.success_flash', name: @experiment.name)
respond_to do |format|
format.json{}
end
# have to change to experiments path
redirect_to root_path
else
flash[:danger] = t('experiments.create.error_flash', name: @experiment.name)
render :new
@ -35,9 +45,8 @@ class ExperimentsController < ApplicationController
@experiment.last_modified_by = current_user
if @experiment.save
flash[:success] = t('experiments.update.success_flash', name: @experiment.name)
respond_to do |format|
format.json{}
end
# have to change to experiments path
redirect_to root_path
else
flash[:danger] = t('experiments.create.error_flash', name: @experiment.name)
render :edit
@ -50,9 +59,8 @@ class ExperimentsController < ApplicationController
@experiment.archived_on = DateTime.now
if @experiment.save
flash[:success] = t('experiments.archive.success_flash', name: @experiment.name)
respond_to do |format|
format.json{}
end
# have to change to experiments path
redirect_to root_path
else
flash[:danger] = t('experiments.archive.error_flash', name: @experiment.name)
end
@ -65,11 +73,11 @@ class ExperimentsController < ApplicationController
end
def set_project
@project = @experiment.project
@project = Project.find_by_id(params[:project_id])
end
def experiment_params
params.require(:experiment).permit(:name, :description, :archived)
params.require(:experiment).permit(:name, :description)
end
def choose_layout

View file

@ -0,0 +1,20 @@
<!-- Edit experiment modal -->
<div class="modal" id="edit-experiment-modal" tabindex="-1" role="dialog" aria-labelledby="edit-experiment-modal-label">
<%= bootstrap_form_for [@project, @experiment], remote: true do |f| %>
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<h4 class="modal-title" id="edit-eperiment-modal-label"><%= t("experiments.edit.modal_title", experiment: @experiment.name ) %></h4>
</div>
<div class="modal-body">
<%= render partial: "form.html.erb", locals: { form: f } %>
</div>
<div class="modal-footer">
<%= f.submit t("experiments.edit.modal_create"), class: "btn btn-primary" %>
<button type="button" class="btn btn-default" data-dismiss="modal"><%=t "general.cancel" %></button>
</div>
</div>
</div>
<% end %>
</div>

View file

@ -0,0 +1,15 @@
<div class="row">
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
<div class="form-group">
<%= form.text_field :name, label: t("experiments.new.name"), autofocus: true, placeholder: t("experiments.new.name_placeholder") %>
</div>
</div>
</div>
<div class="row">
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
<div class="form-group">
<%= form.text_area :description, label: t('experiments.new.description') %>
</div>
</div>
</div>

View file

@ -0,0 +1,20 @@
<!-- New experiment modal -->
<div class="modal" id="new-experiment-modal" tabindex="-1" role="dialog" aria-labelledby="new-experiment-modal-label">
<%= bootstrap_form_for [@project, @experiment] do |f| %>
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<h4 class="modal-title" id="new-eperiment-modal-label"><%= t("experiments.new.modal_title") %></h4>
</div>
<div class="modal-body">
<%= render partial: "form.html.erb", locals: { form: f } %>
</div>
<div class="modal-footer">
<%= f.submit t("experiments.new.modal_create"), class: "btn btn-primary" %>
<button type="button" class="btn btn-default" data-dismiss="modal"><%=t "general.cancel" %></button>
</div>
</div>
</div>
<% end %>
</div>

View file

@ -37,3 +37,4 @@
<%= javascript_include_tag("eventPause-min") %>
<%= javascript_include_tag("projects/canvas") %>
<%= javascript_include_tag("experiments/index") %>

View file

@ -13,4 +13,4 @@
</div>
</div>
<%= form.enum_btn_group :visibility, label: t("projects.index.modal_new_project.visibility"), btn_names: { hidden: t("projects.index.modal_new_project.visibility_hidden"), visible: t("projects.index.modal_new_project.visibility_visible") } %>
<%= form.enum_btn_group :visibility, label: t("projects.index.modal_new_project.visibility"), btn_names: { hidden: t("projects.index.modal_new_project.visibility_hidden"), visible: t("projects.index.modal_new_project.visibility_visible") } %>

View file

@ -33,7 +33,9 @@
</ul>
</li>
<li>
<a href="#"><span class="glyphicon glyphicon-plus"></span> <i>New experiment...</i></a>
<%= link_to new_project_experiment_path(@project), id: 'new-experiment', remote: true do %>
<span class="glyphicon glyphicon-plus"></span> <i><%= t('experiments.new.create') %></i></a>
<% end %>
</li>
</ul>
</div>

View file

@ -35,6 +35,7 @@ Rails.application.config.assets.precompile += %w( samples/sample_datatable.js )
Rails.application.config.assets.precompile += %w( projects/index.js )
Rails.application.config.assets.precompile += %w( samples/samples_importer.js )
Rails.application.config.assets.precompile += %w( projects/canvas.js )
Rails.application.config.assets.precompile += %w( experiments/index.js )
Rails.application.config.assets.precompile += %w( reports/index.js )
Rails.application.config.assets.precompile += %w( reports/new.js )
Rails.application.config.assets.precompile += %w( protocols/index.js )

View file

@ -659,6 +659,18 @@ en:
no_activities: "There are no activities for this task."
more_activities: "Load older activities"
experiments:
new:
create: 'New experiment...'
modal_title: 'Create new experiment'
modal_create: 'Create experiment'
name: 'Experiment name'
name_placeholder: 'My experiment'
description: 'Description'
edit:
modal_title: 'Edit experiment %{experiment}'
modal_create: 'Update experiment'
my_module_tags:
new:
head_title: "%{project} | %{module} | Add tag"

View file

@ -88,7 +88,7 @@ Rails.application.routes.draw do
post 'destroy', as: :destroy # Destroy multiple entries at once
end
end
resources :experiments, only: [:new, :create, :edit, :update, :archive]
resources :experiments, only: [:new, :create, :edit, :update, :archive], defaults: { format: 'json' }
member do
get 'notifications' # Notifications popup for individual project in projects index
get 'samples' # Samples for single project