SUZUKI Miho
null+****@clear*****
Wed Dec 12 19:41:47 JST 2012
SUZUKI Miho 2012-12-12 19:41:47 +0900 (Wed, 12 Dec 2012) New Revision: 8960845e1c597c5ca3227da0b68e4d1a9f062019 https://github.com/logaling/logaling-server/commit/8960845e1c597c5ca3227da0b68e4d1a9f062019 Log: Enable multiple add - TODO: logaling-command's index run each time Modified files: app/assets/javascripts/user_glossaries.js.coffee app/controllers/terms_controller.rb app/views/terms/_form.html.haml Modified: app/assets/javascripts/user_glossaries.js.coffee (+11 -7) =================================================================== --- app/assets/javascripts/user_glossaries.js.coffee 2012-12-12 17:54:00 +0900 (11d7a02) +++ app/assets/javascripts/user_glossaries.js.coffee 2012-12-12 19:41:47 +0900 (2000bb3) @@ -1,15 +1,19 @@ copy_block = (i) -> increament_id = (class_name, i) -> - $("#term" + i).children("." + class_name).attr "id", class_name + i + $("#term" + i).children("." + class_name). + attr("name", "glossary_entry[" + i + "][" + class_name + "]"). + attr("id", class_name + i) target = $("#term" + (i - 1)) target.clone().insertAfter(target).attr "id", "term" + i - increament_id "glossary_entry_source_term", i - increament_id "glossary_entry_target_term", i - increament_id "glossary_entry_note", i - $("#glossary_entry_source_term" + i).val "" - $("#glossary_entry_target_term" + i).val "" - $("#glossary_entry_note" + i).val "" + + increament_id "source_term", i + increament_id "target_term", i + increament_id "note", i + + $("#source_term" + i).val "" + $("#target_term" + i).val "" + $("#note" + i).val "" $ -> $("#add_btn").click -> Modified: app/controllers/terms_controller.rb (+5 -2) =================================================================== --- app/controllers/terms_controller.rb 2012-12-12 17:54:00 +0900 (d024481) +++ app/controllers/terms_controller.rb 2012-12-12 19:41:47 +0900 (a51f0e0) @@ -8,8 +8,11 @@ class TermsController < ApplicationController end def create - @term = GlossaryEntry.new(params[:glossary_entry]) - @user_glossary.add!(@term) + params[:glossary_entry].each do |key, glossary_entry| + @term = GlossaryEntry.new(glossary_entry) + # TODO: 毎回command側のindexが走るので注意。あとで改善する + @user_glossary.add!(@term) + end redirect_to user_glossary_path(current_user, @user_glossary), notice: 'Term was successfully added.' rescue ArgumentError, Logaling::GlossaryNotFound Modified: app/views/terms/_form.html.haml (+3 -3) =================================================================== --- app/views/terms/_form.html.haml 2012-12-12 17:54:00 +0900 (b939015) +++ app/views/terms/_form.html.haml 2012-12-12 19:41:47 +0900 (2ce1afa) @@ -12,9 +12,9 @@ = f.label :note, :class => 'control-label' .control-group#term1 - = f.text_field :source_term, :id => 'glossary_entry_source_term1', :class => 'glossary_entry_source_term' - = f.text_field :target_term, :id => 'glossary_entry_target_term1', :class => 'glossary_entry_target_term' - = f.text_field :note, :id => 'glossary_entry_note1', :class => 'glossary_entry_note' + = f.text_field :source_term, :id => 'source_term1', :class => 'source_term', :name => 'glossary_entry[1][source_term]' + = f.text_field :target_term, :id => 'target_term1', :class => 'target_term', :name => 'glossary_entry[1][target_term]' + = f.text_field :note, :id => 'note1', :class => 'note', :name => 'glossary_entry[1][note]' .control-group = f.button 'フォームを追加する', :id => 'add_btn', :class => 'btn btn-small', :type => 'button' -------------- next part -------------- An HTML attachment was scrubbed... Download