Skip to content

Commit

Permalink
Merge offering details views
Browse files Browse the repository at this point in the history
  • Loading branch information
ryansouza committed Feb 15, 2012
2 parents e7824b9 + 8f5b9e5 commit b237cf0
Show file tree
Hide file tree
Showing 10 changed files with 178 additions and 50 deletions.
7 changes: 7 additions & 0 deletions app/assets/stylesheets/offerings.css.scss
Expand Up @@ -23,3 +23,10 @@ table.content-and-mappings {
border-top: 1px solid #eee;
}
}

form.edit-offering textarea {
height: 8em;
}
.offering-details-view {
margin-bottom: 1em;
}
7 changes: 7 additions & 0 deletions app/controllers/offerings/details_controller.rb
Expand Up @@ -6,9 +6,16 @@ class Offerings::DetailsController < OfferingsController
before_filter { @nav_offering = :details }

def edit
@offering = Offering.find(params[:offering_id])
end

def show
@offering = Offering.find(params[:offering_id])
@course = @offering.course
@term = @offering.term
@instructors = @offering.instructors
@outcomes = @offering.outcomes
@objectives = @offering.objectives
end

def update
Expand Down
2 changes: 2 additions & 0 deletions app/models/user.rb
Expand Up @@ -34,4 +34,6 @@ def valid_password?(*args)
def to_s
name
end

scope :with_role, lambda { |role| { :conditions => "roles_mask & #{2**ROLES.index(role.to_sym)} > 0"} }
end
38 changes: 1 addition & 37 deletions app/views/offerings/_form.html.erb
@@ -1,37 +1 @@
<%= form_for(@offering) do |f| %>
<% if @offering.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@offering.errors.count, "error") %> prohibited this offering from being saved:</h2>

<ul>
<% @offering.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>

<div class="field">
<%= f.label :term_id, "Term" %><br />
<%= f.collection_select :term_id, AcademicTerm.all, :id, :title, :prompt => "Select a Term" %>
</div>
<div class="field">
<%= f.label :course_id, "Course" %><br />
<%= f.collection_select :course_id, Course.find(:all), :id, :course_field, :prompt => "Select a Course" %>
</div>
<div class="field">
<%= f.label :section %><br />
<%= f.text_field :section %>
</div>
<div class="field">
<%= f.label :crn %><br />
<%= f.text_field :crn %>
</div>
<div class="field">
<%= f.label :location %><br />
<%= f.text_field :location %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
<h1 class='fail'>Nothing here</h1>
86 changes: 85 additions & 1 deletion app/views/offerings/details/edit.html.erb
@@ -1,2 +1,86 @@
<h1 class="fail">Nothing here</h1>
<%= form_for(@offering, :html => {:class => 'form-horizontal edit-offering'}) do |f| %>
<% if @offering.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@offering.errors.count, "error") %> prohibited this offering from being saved:</h2>

<ul>
<% @offering.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>

<div class="field">
<%= f.label :crn %>
<%= f.text_field :crn %>
</div>
<div class="field">
<%= f.label :term_id, "Term" %>
<%= f.collection_select :term_id, AcademicTerm.all, :id, :title, :prompt => "Select a Term" %>
</div>
<div class="field">
<%= f.label :course_id, "Course" %>
<%= f.collection_select :course_id, Course.find(:all), :id, :course_field, :prompt => "Select a Course" %>
</div>
<div class="field">
<%= f.label :section %>
<%= f.text_field :section %>
</div>
<div class="field">
<%= f.label :credits %>
<%= f.text_field :credits %>
</div>

<div class="field">
<%= f.label :required %>
<%=
options = [
["Required for BSCE", "Required for BSCE"],
["Required for BSENVE", "Required for BSENVE"],
["Elective for BSCE", "Elective for BSCE"],
["Elective for BSENVE", "Elective for BSENVE"]
]
#f.select(:required_or_elective, options, {}, {:multiple=>true})

# FIXME Use a control like a multi-select or radio button groups
# instead of a textfield for required_or_elective
f.text_field :required_or_elective
%>
</div>
<div class="field">
<%= f.label :instructors %>
<%=
f.collection_select :instructor_ids, User.with_role(:instructor).all, :id,
:name, {}, {:multiple => true}
%>
</div>
<div class="field">
<%= f.label "Day/Time" %>
<%= f.text_field :day_and_time %>
</div>
<div class="field">
<%= f.label :prerequisites %>
<%= f.text_area :prerequisites %>
</div>
<div class="field">
<%= f.label :textbook %>
<%= f.text_area :textbook %>
</div>
<div class="field">
<%= f.label :additional_textbooks %>
<%= f.text_area :additional_textbooks %>
</div>
<div class="field">
<%= f.label :location %>
<%= f.text_field :location %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>

<p>
<%= link_to 'View', offering_details_path(@offering) %> |
<%= link_to 'Return to offering List', offerings_path %>
</p>
76 changes: 74 additions & 2 deletions app/views/offerings/details/show.html.erb
@@ -1,2 +1,74 @@
<h1 class="fail">Nothing here</h1>

<table class='offering-details-view'>
<tr>
<td>CRN#</td><td><%= @offering.crn %></td>
</tr>
<tr>
<td>Term</td><td><%= @term.title %></td>
</tr>
<tr>
<td>Course</td><td><%= "#{@course.dept_code} #{@course.course_num}" %></td>
</tr>
<tr>
<td>Title</td><td><%= @course.title %></td>
</tr>
<tr>
<td>Section</td><td><%= @offering.section %></td>
</tr>
<tr>
<td>Credits</td><td><%= @offering.credits %></td>
</tr>
<tr>
<td>Required/Elective</td>
<td>
<%= @offering.required_or_elective %>
</td>
</tr>
<tr>
<td>Instructor(s)</td>
<td>
<%=
str = ""
@instructors.each { |instructor| str << "#{instructor.name}, " }
str.chomp!(", ")
str
%>
</td>
</tr>
<tr>
<td>Day/Time</td>
<td>
<%= @offering.day_and_time %>
</td>
</tr>
<tr>
<td>Prerequisites</td>
<td>
<%= @offering.prerequisites %>
</td>
</tr>
<tr>
<td>Textbook</td>
<td>
<%= @offering.textbook %>
</td>
</tr>
<tr>
<td>Additional Textbook(s)</td>
<td>
<%= @offering.additional_textbooks %>
</td>
</tr>
<tr>
<td>Location</td>
<td>
<%= @offering.location %>
</td>
</tr>
</table>
<p>
<%=
link_to_if can?(:edit, @offering), 'Edit',
edit_offering_details_path(@offering)
%>
| <%= link_to 'Return to offering List', offerings_path %>
</p>
6 changes: 0 additions & 6 deletions app/views/offerings/edit.html.erb

This file was deleted.

2 changes: 1 addition & 1 deletion app/views/offerings/index.html.erb
Expand Up @@ -20,7 +20,7 @@
<td><%= offering.crn %></td>
<td><%= offering.location %></td>
<td><%= link_to 'Show', offering %></td>
<td><%= link_to_if can?(:edit, offering), 'Edit', edit_offering_path(offering) %></td>
<td><%= link_to_if can?(:edit, offering), 'Edit', edit_offering_details_path(offering) %></td>
<td><%= link_to_if can?(:destroy, offering), 'Destroy', offering, confirm: 'Are you sure?', method: :delete %></td>
</tr>
<% end %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/offerings/show.html.erb
Expand Up @@ -33,5 +33,5 @@

<br />

<%= link_to_if can?(:edit, @offering), 'Edit', edit_offering_path(@offering) %> |
<%= link_to_if can?(:edit, @offering), 'Edit', edit_offering_details_path(@offering) %> |
<%= link_to 'Back', offerings_path %>
2 changes: 0 additions & 2 deletions test/controllers/offerings/details_controller_test.rb
Expand Up @@ -10,14 +10,12 @@
it "respond with success" do
get :edit, @args
must_respond_with :success
must_render_nothing_here
end
end
describe "show action" do
it "respond with success" do
get :show, @args
must_respond_with :success
must_render_nothing_here
end
end
end
Expand Down

0 comments on commit b237cf0

Please sign in to comment.