Skip to content

Commit

Permalink
Added nested forms for classrooms and offices
Browse files Browse the repository at this point in the history
  • Loading branch information
Libranner committed Oct 7, 2013
1 parent 2d3692e commit 5300409
Showing 1 changed file with 47 additions and 8 deletions.
55 changes: 47 additions & 8 deletions app/views/buildings/_form.html.haml
Original file line number Diff line number Diff line change
@@ -1,8 +1,47 @@
= simple_form_for @building, :html => { :class => 'form-horizontal' } do |f|
= f.input :name
= f.input :abbreviation
= f.input :rooms
= f.input :floors
.form-actions
= f.button :submit, :class => 'btn-primary'
= link_to t('.cancel', :default => t("helpers.links.cancel")), buildings_path, :class => 'btn'
.row-fluid
= simple_nested_form_for @building, :html => { :class => 'form-horizontal' } do |f|
= f.input :name
= f.input :abbreviation
= f.input :rooms
= f.input :floors
%ul.nav.nav-tabs#tab
%li
%a{"data-toggle" => "tab", href: "#div_classrooms"} Classrooms
%li
%a{"data-toggle" => "tab", href: "#div_offices"} Offices
.tab-content
#div_classrooms.tab-pane.active
= f.link_to_add 'Add a Classroom', :classrooms, {class: 'btn btn-small btn-primary pull-right'}
.span10
= f.fields_for :classrooms
#div_offices.tab-pane
= f.link_to_add 'Add a Office', :offices, {class: 'btn btn-small btn-primary pull-right'}
.span10
= f.fields_for :offices

.span12
.form-actions
= f.button :submit, :class => 'btn-primary'
= link_to t('.cancel', :default => t("helpers.links.cancel")), buildings_path, :class => 'btn'

:javascript
$(document).ready(function() {
$('#tab a:last').click(function (e) {
e.preventDefault();
$(this).tab('show');
});

$('#tab a:first').click(function (e) {
e.preventDefault();
$(this).tab('show');
});

$('#add_classroom').click(function (e) {
e.preventDefault();
$(this).tab('show');
});

$(function() {
$('#tab a:first').tab('show');
})
});

0 comments on commit 5300409

Please sign in to comment.