jquery_dynamic_fields 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in jquery_dynamic_fields.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Aaron Cruz
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,65 @@
1
+ # JqueryDynamicFields
2
+
3
+ Most of code pulled from [Railscasts 196 (revised)](http://railscasts.com/episodes/196-nested-model-form-revised)
4
+
5
+ __WIP__: very alpha bro
6
+
7
+ ## Compatibility
8
+
9
+ * >= Rails 3.1
10
+ * >= Ruby 1.9.2
11
+
12
+ ## Installation
13
+
14
+ Add this line to your application's Gemfile:
15
+
16
+ gem 'jquery_dynamic_fields'
17
+
18
+ And then execute:
19
+
20
+ $ bundle
21
+
22
+ In your pipeline
23
+
24
+ // in app/assets/javascripts/application.js
25
+ //= require jquery_dynamic_fields
26
+
27
+ ## How to use
28
+
29
+ ```ruby
30
+ class TaskList < ActiveRecord::Base
31
+ has_many :tasks
32
+ accepts_nested_attributes_for :tasks
33
+ end
34
+
35
+ class Task < ActiveRecord::Base
36
+ belongs_to :task_list
37
+ end
38
+
39
+ ```
40
+
41
+ ```erb
42
+ <%# app/views/task_list %>
43
+
44
+ <%= form_for @task_list do |f| %>
45
+ <%= link_to_add_fields "Add a task", f, :tasks %>
46
+ <%= f.submit "Save!" %>
47
+ <% end %>
48
+
49
+ <%# the partial name must match (relation singular)_fields so in this case "task"
50
+ and be in the same directory as the template calling #link_to_add_fields %>
51
+
52
+ <%# app/views/task_list/_task_fields.html.erb %>
53
+ <fieldset>
54
+ <%= f.text_field :label %>
55
+ <%= link_to_delete_field f %>
56
+ </fieldset>
57
+ ```
58
+
59
+ ## Contributing
60
+
61
+ 1. Fork it
62
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
63
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
64
+ 4. Push to the branch (`git push origin my-new-feature`)
65
+ 5. Create new Pull Request
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,11 @@
1
+ jQuery ->
2
+ $('form').on 'click', '.remove_field', (event) ->
3
+ $(this).prev('input[type=hidden]').val('1')
4
+ $(this).closest('fieldset').hide()
5
+ event.preventDefault()
6
+
7
+ $('form').on 'click', '.add_fields', (event) ->
8
+ time = new Date().getTime()
9
+ regexp = new RegExp($(this).data('id'), 'g')
10
+ $(this).before($(this).data('fields').replace(regexp, time))
11
+ event.preventDefault()
@@ -0,0 +1,15 @@
1
+ module JqueryDynamicFieldsHelper
2
+ def link_to_add_fields name, f, association
3
+ new_object = f.object.send(association).klass.new
4
+ id = new_object.object_id
5
+ fields = f.fields_for(association, new_object, child_index: id) do |builder|
6
+ render(association.to_s.singularize + "_fields", f: builder)
7
+ end
8
+ link_to(name, '#', class: "add_fields", data: {id: id, fields: fields.gsub("\n", "")})
9
+ end
10
+
11
+ def link_to_remove_field f
12
+ (f.hidden_field :_destroy) +
13
+ link_to("remove", "#", class: "remove_field")
14
+ end
15
+ end
@@ -0,0 +1,17 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/jquery_dynamic_fields/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Aaron Cruz"]
6
+ gem.email = ["aaron@aaroncruz.com"]
7
+ gem.description = %q{Dynamically add and remove form fields in a Rails 3.1+ app}
8
+ gem.summary = %q{Dynamically add and remove form fields in a Rails 3.1+ app}
9
+ gem.homepage = "https://github.com/pferdefleisch/jquery_dynamic_fields"
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "jquery_dynamic_fields"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = JqueryDynamicFields::VERSION
17
+ end
@@ -0,0 +1,2 @@
1
+ require "jquery_dynamic_fields/engine"
2
+ require "jquery_dynamic_fields/version"
@@ -0,0 +1,4 @@
1
+ module JqueryDynamicFields
2
+ class Engine < Rails::Engine
3
+ end
4
+ end
@@ -0,0 +1,3 @@
1
+ module JqueryDynamicFields
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,56 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jquery_dynamic_fields
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Aaron Cruz
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-06-11 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Dynamically add and remove form fields in a Rails 3.1+ app
15
+ email:
16
+ - aaron@aaroncruz.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - .gitignore
22
+ - Gemfile
23
+ - LICENSE
24
+ - README.md
25
+ - Rakefile
26
+ - app/assets/javascripts/jquery_dynamic_fields.js.coffee
27
+ - app/helpers/jquery_dynamic_fields_helper.rb
28
+ - jquery_dynamic_fields.gemspec
29
+ - lib/jquery_dynamic_fields.rb
30
+ - lib/jquery_dynamic_fields/engine.rb
31
+ - lib/jquery_dynamic_fields/version.rb
32
+ homepage: https://github.com/pferdefleisch/jquery_dynamic_fields
33
+ licenses: []
34
+ post_install_message:
35
+ rdoc_options: []
36
+ require_paths:
37
+ - lib
38
+ required_ruby_version: !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ required_rubygems_version: !ruby/object:Gem::Requirement
45
+ none: false
46
+ requirements:
47
+ - - ! '>='
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ requirements: []
51
+ rubyforge_project:
52
+ rubygems_version: 1.8.23
53
+ signing_key:
54
+ specification_version: 3
55
+ summary: Dynamically add and remove form fields in a Rails 3.1+ app
56
+ test_files: []