Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

AJAXified the forms that start with intros... So awesome.

  • Loading branch information...
commit 1130b3fad00913742cf1e761ef47ad09385d3584 1 parent 6bbc7ed
@tumes authored
View
5 app/controllers/analytical_standards_controller.rb
@@ -12,6 +12,11 @@ def new
@analytes = @method.analytes
@analytical_standard = AnalyticalStandard.new
@method.analytes.count.times{ @analytical_standard.standard_amounts.build }
+
+ respond_to do |format|
+ format.js { render :partial => "analytical_standard_form"}
+ format.html
+ end
end
def create
View
3  app/helpers/pages_helper.rb
@@ -1,5 +1,2 @@
module PagesHelper
- def title(page_title)
- content_for(:title) { page_title }
- end
end
View
4 app/models/chromatographic_column.rb
@@ -11,4 +11,8 @@ class ChromatographicColumn < ActiveRecord::Base
def find_instrument
Instrument.find(self.instrument_id)
end
+
+ def find_method
+ AnalyticalMethod.find(self.analytical_method_id)
+ end
end
View
4 app/models/standard_amount.rb
@@ -2,6 +2,6 @@ class StandardAmount < ActiveRecord::Base
belongs_to :analytical_standard
attr_accessible :name, :amount, :batch, :analytical_standard_id
- validates_presence_of :name, :amount, :batch, :analytical_standard_id
- validates_numericality_of :amount, :analytical_standard_id
+ validates_presence_of :name, :amount, :batch
+ validates_numericality_of :amount
end
View
27 app/views/analytical_standards/_analytical_standard_form.html.haml
@@ -0,0 +1,27 @@
+= simple_form_for @analytical_standard do |f|
+
+ = f.hidden_field :analytical_method_id, :value => params[:method]
+ = f.input :user_id, :label => "Prepared by", :collection => users, :as => :select
+ = f.input :preparation_date, :label => "Preparation date"
+ = f.input :volume, :as => :string
+ %p
+ = f.label :notes
+ = f.text_area :notes, :rows => 2, :cols => 40
+
+ .polaroid-border
+ .polaroid-block
+ %h2= "Standard for #{@method.name}"
+ %table
+ %tr
+ %th Analyte
+ %th Amount(g)
+ %th Batch
+ - @method.analytes.each_with_index do |analyte, i|
+ %tr
+ %td= analyte.name
+ / %bigtext= analyte.name
+ = hidden_field_tag "analytical_standard[standard_amounts_attributes][#{i}][name]", analyte.name
+ %td= text_field_tag "analytical_standard[standard_amounts_attributes][#{i}][amount]"
+ %td= text_field_tag "analytical_standard[standard_amounts_attributes][#{i}][batch]"
+ .lowbuttons
+ = f.submit @analytical_standard.new_record? ? 'Log Standard' : 'Update Standard', :disable_with => "Submitting..."
View
18 app/views/analytical_standards/intro.html.haml
@@ -1,10 +1,12 @@
- title "Start Standard"
-- form_tag new_analytical_standard_path, :method => 'get' do
- %p
- = label_tag(:instrument, "Instrument")
- = select_tag :instrument, options_for_select([["Select one", ""]] + instruments.collect{ |i| [i.name, i.id] })
- %p
- = label_tag(:method, "Method")
- = select_tag :method
- = submit_tag "Start standard log", :disable_with => "Starting"
+.standard_intro
+ - form_tag new_analytical_standard_path, :method => 'get' do
+ %p
+ = label_tag(:instrument, "Instrument")
+ = select_tag :instrument, options_for_select([["Select one", ""]] + instruments.collect{ |i| [i.name, i.id] })
+ %p
+ = label_tag(:method, "Method")
+ = select_tag :method
+ = submit_tag "Start standard log", :disable_with => "Starting", :id => "standard_submit"
+%div{ :class => "standard_form display-none" }
View
27 app/views/analytical_standards/new.html.haml
@@ -1,29 +1,4 @@
- title "New Standard"
-= simple_form_for @analytical_standard do |f|
+= render :partial => 'analytical_standard_form'
- = f.hidden_field :analytical_method_id, :value => params[:method]
- = f.input :user_id, :label => "Prepared by", :collection => users, :as => :select
- = f.input :preparation_date, :label => "Preparation date"
- = f.input :volume, :as => :string
- %p
- = f.label :notes
- = f.text_area :notes, :rows => 2, :cols => 40
-
- .polaroid-border
- .polaroid-block
- %h2= "Standard for #{@method.name}"
- %table
- %tr
- %th Analyte
- %th Amount(g)
- %th Batch
- - @method.analytes.each_with_index do |analyte, i|
- %tr
- %td= analyte.name
- / %bigtext= analyte.name
- = hidden_field_tag "analytical_standard[standard_amounts_attributes][#{i}][name]", analyte.name
- %td= text_field_tag "analytical_standard[standard_amounts_attributes][#{i}][amount]"
- %td= text_field_tag "analytical_standard[standard_amounts_attributes][#{i}][batch]"
- .lowbuttons
- = f.submit @analytical_standard.new_record? ? 'Log Standard' : 'Update Standard', :disable_with => "Submitting..."
View
23 app/views/chromatographic_columns/_chromatographic_column_form.html.haml
@@ -1,14 +1,21 @@
= simple_form_for @chromatographic_column do |f|
= f.input :name
- = f.association :instrument, :input_html => { :id => 'instrument' }, :prompt => "Select one"
- = f.input :analytical_method_id, :collection => [], :as => :select, :input_html => { :id => 'method' }
+ - if @chromatographic_column.new_record?
+ = f.association :instrument, :input_html => { :id => 'instrument' }, :prompt => "Select one"
+ = f.input :analytical_method_id, :collection => [], :as => :select, :input_html => { :id => 'method' }
+ -else
+ %p
+ %label
+ Instrument:
+ %br/
+ = @chromatographic_column.find_instrument.name
+ %br/
+ Analytical Method:
+ %br/
+ = @chromatographic_column.find_method.name
= f.input :brand
- %p
- = f.label :description
- = f.text_area :description, :rows => 2, :cols => 40
+ = f.input :description, :input_html => { :rows => 2, :cols => 40 }
= f.input :serial
= f.input :received
- %p
- = f.label :notes
- = f.text_area :notes, :rows => 2, :cols => 40
+ = f.input :notes, :input_html => { :rows => 2, :cols => 40 }
= f.submit @chromatographic_column.new_record? ? 'Add column' : 'Edit column', :disable_with => "Submitting..."
View
10 public/javascripts/application.js
@@ -1,5 +1,15 @@
$(document).ready(function() {
+ $(".standard_intro form").submit(function(){
+ var queryString = $(this).serialize();
+ var url = $(this).attr("action");
+ $.get(url+"?"+queryString, function(data) {
+ $(".standard_form").html(data).slideDown();
+ });
+ $(".standard_intro").slideUp();
+ return false;
+ });
+
var $curr = $("#level:first");
var $next = $curr.next();
$curr.nextAll().addClass('display-none')
View
7 spec/models/chromatographic_column_spec.rb
@@ -39,6 +39,11 @@
@column = Factory(:chromatographic_column)
@column.find_instrument.should == @instrument
end
-
+
+ it "should find a column's parent method with find_method" do
+ @method = Factory(:analytical_method)
+ @column = Factory(:chromatographic_column)
+ @column.find_method.should == @method
+ end
end
Please sign in to comment.
Something went wrong with that request. Please try again.