Permalink
Browse files

cleaning up issue_298

  • Loading branch information...
1 parent 624ac11 commit be4b8f890cffa3ac7f0a82608024d46513c8c8fb @Ayaya Ayaya committed Mar 14, 2012
@@ -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
@@ -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
@@ -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>
@@ -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| %>
@@ -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 %>
@@ -0,0 +1 @@
+page.replace_html 'add_new_section_dialog', :partial => 'sections/student_form_add_section_dialog'
@@ -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>
View
@@ -261,6 +261,7 @@
post 'bulk_modify'
post 'populate'
get 'manage'
+ get 'add_new_section'
get 'download_student_list'
post 'upload_student_list'
end
@@ -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;
@@ -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,

0 comments on commit be4b8f8

Please sign in to comment.