Skip to content

Commit

Permalink
Merge pull request #719 from Ayaya/issue_298_new
Browse files Browse the repository at this point in the history
Merge fix for issue #298.

Add section modal dialog to Users tab in order to be able to create a section from that view directly.
  • Loading branch information
jerboaa committed Mar 14, 2012
2 parents 624ac11 + be4b8f8 commit cc5a330
Show file tree
Hide file tree
Showing 9 changed files with 65 additions and 6 deletions.
8 changes: 8 additions & 0 deletions app/controllers/sections_controller.rb
Expand Up @@ -20,10 +20,18 @@ def create
if @section.save
flash[:success] = I18n.t('section.create.success',
:name => @section.name)
if params[:section_modal]
redirect_to :controller => 'students', :action => 'new'
return
end
redirect_to :action => 'index'
return
else
flash[:error] = I18n.t('section.create.error')
if params[:section_modal]
redirect_to :controller => 'students', :action => 'new'
return
end
render :new
end
end
Expand Down
6 changes: 6 additions & 0 deletions app/controllers/students_controller.rb
Expand Up @@ -95,6 +95,12 @@ def create
end
end

# dummy action for remote rjs calls
# triggered by clicking on the "add a new section" link in the new student page
# please keep.
def add_new_section
@section = Section.new
end

#downloads users with the given role as a csv list
def download_student_list
Expand Down
12 changes: 12 additions & 0 deletions app/views/sections/_student_form_add_section_dialog.html.erb
@@ -0,0 +1,12 @@
<!-- Modal Window -->
<%= form_for @section do |f| %>
<h2><%= I18n.t("section.add_section") %></h2>
<%= raw(f.label :name, I18n.t("section.name")) %>
<%= raw(f.text_field :name) %> <br />
<%= hidden_field_tag "section_modal", "true" %>
<%= f.submit I18n.t(:save) %>
<%= button_to_function I18n.t(:close), 'modalAddNewSection.close()' %>
<% end %>
<script>
modalAddNewSection.open();
</script>
24 changes: 20 additions & 4 deletions app/views/students/_student_form.html.erb
@@ -1,3 +1,17 @@
<script type="text/javascript">
//<![CDATA[
document.observe("dom:loaded", function(){
modalAddNewSection = new Control.Modal($('add_new_section_dialog'),
{
overlayOpacity: 0.75,
className: 'modalAddNewSection',
fade: false
});
});
//]]>
</script>
<div id="add_new_section_dialog">
</div>
<div class="section">
<%= form_for @user, :as => :user do |f| %>
Expand All @@ -22,11 +36,13 @@
:selected => (@user.has_section?) ? (@user.section.id) : (["−"]) ) %>
<%= f.label(:section_id, I18n.t("section.legend") ) %> <br />

<% if defined?new_student %>
<%= link_to I18n.t("section.add_section"), add_new_section_students_path(), :remote => true, :class => "button link_button"%>
<% end %>
<%= f.hidden_field :id %>
<%= f.submit t(:submit), :name => 'submit', :class => 'button indent_button' %>
<%= link_to t(:cancel),
{:controller => 'students'},
:class => "button button_link" %>
<%= f.submit t(:submit), :name => 'submit', :class => 'button link_button' %>
<%= link_to t(:cancel), students_path(), :class => "button link_button" %>
<% end %>

Expand Down
1 change: 1 addition & 0 deletions app/views/students/add_new_section.rjs
@@ -0,0 +1 @@
page.replace_html 'add_new_section_dialog', :partial => 'sections/student_form_add_section_dialog'
4 changes: 2 additions & 2 deletions app/views/students/new.html.erb
Expand Up @@ -3,5 +3,5 @@
</div>

<div class="wrapLeft">
<%= render :partial => "student_form", :locals => {:action => 'create'} %>
</div>
<%= render :partial => "student_form", :locals => {:action => 'create', :new_student => true} %>
</div>
1 change: 1 addition & 0 deletions config/routes.rb
Expand Up @@ -261,6 +261,7 @@
post 'bulk_modify'
post 'populate'
get 'manage'
get 'add_new_section'
get 'download_student_list'
post 'upload_student_list'
end
Expand Down
10 changes: 10 additions & 0 deletions public/stylesheets/main.css
Expand Up @@ -929,6 +929,16 @@ input#extra_mark_description{
-webkit-border-radius: 5px;
}

#add_new_section_dialog {
background: white;
border: 1px solid #000000;
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
width: 375px;
height: 165px;
text-align: center;
}

#about_dialog {
background: white;
border: 1px solid #000000;
Expand Down
5 changes: 5 additions & 0 deletions test/functional/students_controller_test.rb
Expand Up @@ -64,6 +64,11 @@ def setup
assert_response :redirect
assert_not_nil Student.find_by_user_name('jdoe')
end

should "recognize remote action for add a new section modal" do
assert_recognizes( {:controller => "students", :action => "add_new_section" },
{:path => "students/add_new_section", :method => "get"} )
end

should "not be able to create a student with missing data" do
post_as @admin,
Expand Down

0 comments on commit cc5a330

Please sign in to comment.