SUZUKI Miho
null+****@clear*****
Wed Dec 12 17:54:00 JST 2012
SUZUKI Miho 2012-12-12 17:54:00 +0900 (Wed, 12 Dec 2012) New Revision: 330c28604efe70ef0f3489820453cf7312e0a269 https://github.com/logaling/logaling-server/commit/330c28604efe70ef0f3489820453cf7312e0a269 Merged 2027dad: Merge pull request #46 from logaling/enable-adding-multiple-terms Log: Add CoffeScript for multiple-input Added files: app/assets/javascripts/user_glossaries.js.coffee Modified files: app/assets/javascripts/application.js app/views/layouts/application.html.haml app/views/terms/_form.html.haml Modified: app/assets/javascripts/application.js (+0 -1) =================================================================== --- app/assets/javascripts/application.js 2012-11-29 13:30:40 +0900 (5733810) +++ app/assets/javascripts/application.js 2012-12-12 17:54:00 +0900 (f9d5554) @@ -13,4 +13,3 @@ //= require jquery //= require jquery_ujs //= require twitter/bootstrap -//= require_tree . Added: app/assets/javascripts/user_glossaries.js.coffee (+18 -0) 100644 =================================================================== --- /dev/null +++ app/assets/javascripts/user_glossaries.js.coffee 2012-12-12 17:54:00 +0900 (11d7a02) @@ -0,0 +1,18 @@ +copy_block = (i) -> + increament_id = (class_name, i) -> + $("#term" + i).children("." + 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 "" + +$ -> + $("#add_btn").click -> + i = 1 + i++ until $("#term" + i).length is 0 + copy_block i Modified: app/views/layouts/application.html.haml (+1 -0) =================================================================== --- app/views/layouts/application.html.haml 2012-11-29 13:30:40 +0900 (6a67ad9) +++ app/views/layouts/application.html.haml 2012-12-12 17:54:00 +0900 (9a18363) @@ -66,5 +66,6 @@ \================================================== / Placed at the end of the document so the pages load faster = javascript_include_tag "application" + = javascript_include_tag params[:controller] = javascript_tag do jQuery(document).ready(function() {jQuery('#query').focus()}); Modified: app/views/terms/_form.html.haml (+8 -8) =================================================================== --- app/views/terms/_form.html.haml 2012-11-29 13:30:40 +0900 (f0927b5) +++ app/views/terms/_form.html.haml 2012-12-12 17:54:00 +0900 (b939015) @@ -8,16 +8,16 @@ .control-group = f.label :source_term, :class => 'control-label required' - .controls - = f.text_field :source_term - .control-group = f.label :target_term, :class => 'control-label required' - .controls - = f.text_field :target_term - .control-group = f.label :note, :class => 'control-label' - .controls - = f.text_field :note + + .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' + + .control-group + = f.button 'フォームを追加する', :id => 'add_btn', :class => 'btn btn-small', :type => 'button' .control-group .controls -------------- next part -------------- An HTML attachment was scrubbed... Download