numerous 0.0.1 → 1.0.0
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.
- checksums.yaml +4 -4
- data/README.md +138 -8
- data/lib/numerous/version.rb +1 -1
- data/vendor/assets/javascripts/{numerous.js → numerous/numerous.js} +0 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3e171328d544adba51ab1f9e6b751750fc6de531
|
4
|
+
data.tar.gz: 094e754f7254e0363d46495951010634f59a4872
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 910b9271a851ccf48c4e126a43b36da506adf3f7245458a4407dd9061a803c1d9a73317041657729d6db2c602526a2721b513da129d137eb083ce2d00ab19325
|
7
|
+
data.tar.gz: 717c11e534d8fcd6bcfd022dc0226013d6b30cac3ce2029cd40758177b36d4ae2ef801fe4bc888c02a7da8438d71267faf0758b67aed127cf786cd0dcd5e304a
|
data/README.md
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
# Numerous
|
2
2
|
|
3
|
-
|
3
|
+
Gem for numerous plugin
|
4
|
+
* Source code available here: https://github.com/kbparagua/numerous.js
|
5
|
+
* Live demo available here: http://numerous-js.herokuapp.com/
|
4
6
|
|
5
7
|
## Installation
|
6
8
|
|
@@ -18,12 +20,140 @@ Or install it yourself as:
|
|
18
20
|
|
19
21
|
## Usage
|
20
22
|
|
21
|
-
|
23
|
+
### JS
|
22
24
|
|
23
|
-
|
25
|
+
In your application.js: `//= require numerous`
|
24
26
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
27
|
+
|
28
|
+
## Quick Start
|
29
|
+
|
30
|
+
1. Create an element where the new forms will be appended.
|
31
|
+
|
32
|
+
<div id="list"></div>
|
33
|
+
|
34
|
+
|
35
|
+
2. Create a `fields_for` template to be used when adding a new object.
|
36
|
+
|
37
|
+
<div id="fields-for-list" class="numerous">
|
38
|
+
|
39
|
+
<%= form.fields_for :objects, Object.new, :child_index => 'replace_this' do |f| %>
|
40
|
+
<%= f.text_field :object_field %>
|
41
|
+
<%= f.text_field :another_object_field %>
|
42
|
+
...
|
43
|
+
<%= link_to 'Remove', '#', :class => 'numerous-remove' %>
|
44
|
+
</div>
|
45
|
+
|
46
|
+
|
47
|
+
3. Create a link for adding new objects.
|
48
|
+
|
49
|
+
<%= link_to 'Add Object', '#', :id => 'add-to-list' %>
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
4. Call `Numerous.init()` when the document is ready:
|
54
|
+
|
55
|
+
$(document).ready(function(){
|
56
|
+
Numerous.init();
|
57
|
+
});
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
## Naming Conventions
|
62
|
+
|
63
|
+
1. The whole `fields_for` section must be under a div like this:
|
64
|
+
|
65
|
+
<div id="fields-for-[list id]" class="numerous">
|
66
|
+
|
67
|
+
2. `fields_for` objects must have 'replace_this' as the `:child_index` value.
|
68
|
+
|
69
|
+
<%= form.fields_for :objects, Object.new, :child_index => 'replace_this' do |f| %>
|
70
|
+
|
71
|
+
|
72
|
+
3. Put a `numerous-remove` link if you want the ability to delete objects.
|
73
|
+
|
74
|
+
<%= link_to 'Remove', '#', :class => 'numerous-remove' %>
|
75
|
+
|
76
|
+
|
77
|
+
Set `:allow_destroy => true` to the parent model if you want this functionality.
|
78
|
+
|
79
|
+
class Parent < ActiveRecord::Base
|
80
|
+
has_many :lists
|
81
|
+
accepts_nested_attributes_for :lists, :allow_destroy => true
|
82
|
+
end
|
83
|
+
|
84
|
+
|
85
|
+
4. The add link must follow this id template:
|
86
|
+
|
87
|
+
<%= link_to 'Add Object', '#', :id => 'add-to-[list id]' %>
|
88
|
+
|
89
|
+
|
90
|
+
## Callbacks
|
91
|
+
You can add callbacks which will be called after adding or removing a `fields_for` instance.
|
92
|
+
|
93
|
+
Numerous.init({
|
94
|
+
'list-name' : {
|
95
|
+
'add' : function(form){
|
96
|
+
alert("I'm adding another fields_for instance!");
|
97
|
+
// do something here
|
98
|
+
},
|
99
|
+
|
100
|
+
'remove' : function(form){
|
101
|
+
alert("I'm removing a fields_for instance!");
|
102
|
+
// do something here
|
103
|
+
}
|
104
|
+
}
|
105
|
+
});
|
106
|
+
|
107
|
+
The `add` and `remove` callbacks take 1 parameter which is the `fields_for` element that is added or removed.
|
108
|
+
|
109
|
+
|
110
|
+
## Updating Objects
|
111
|
+
By default numerous.js is adding `fields-for-[list id]` class to all `fields_for` instance you've added.
|
112
|
+
If you want to be able to remove existing objects, put the `fields_for` under a `fields-for-[list id]` div.
|
113
|
+
|
114
|
+
<% parent.lists.each do |list| %>
|
115
|
+
<div class='fields-for-list'>
|
116
|
+
<%= form.fields_for :list, list do |f| %>
|
117
|
+
<%= f.text_field :object_field %>
|
118
|
+
<%= f.text_field :another_object_field %>
|
119
|
+
...
|
120
|
+
<%= link_to 'Remove', '#', :class => 'numerous-remove' %>
|
121
|
+
<% end %>
|
122
|
+
</div>
|
123
|
+
<% end %>
|
124
|
+
|
125
|
+
## Initialization Options
|
126
|
+
|
127
|
+
`add : function()`
|
128
|
+
- A callback that will be called every time a new object is added.
|
129
|
+
|
130
|
+
`remove : function()`
|
131
|
+
- A callback that will be called every time an object is removed.
|
132
|
+
|
133
|
+
`initial : number | function()`
|
134
|
+
- An integer or a funtion that returns an integer.
|
135
|
+
- The list will initially have this number of object.
|
136
|
+
- defaults to 0.
|
137
|
+
|
138
|
+
`after-initialize : function()`
|
139
|
+
- A callback that will be called after initializing the list.
|
140
|
+
|
141
|
+
|
142
|
+
## Helper Methods
|
143
|
+
|
144
|
+
`Numerous.count(String list)`
|
145
|
+
- returns the current count (Number) of the visible objects under the passed list
|
146
|
+
|
147
|
+
|
148
|
+
`Numerous.get(String list)`
|
149
|
+
- returns all the objects (HTML Elements) under the passed list
|
150
|
+
|
151
|
+
|
152
|
+
`Numerous.removeAll(String list)`
|
153
|
+
- triggers the remove link of all the list objects
|
154
|
+
|
155
|
+
## Credits
|
156
|
+
|
157
|
+
Karl Bryan P. Paragua
|
158
|
+
|
159
|
+
www.daftcoder.com
|
data/lib/numerous/version.rb
CHANGED
File without changes
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: numerous
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Geoffrey Hervet
|
@@ -58,7 +58,7 @@ files:
|
|
58
58
|
- lib/numerous.rb
|
59
59
|
- lib/numerous/version.rb
|
60
60
|
- numerous.gemspec
|
61
|
-
- vendor/assets/javascripts/numerous.js
|
61
|
+
- vendor/assets/javascripts/numerous/numerous.js
|
62
62
|
homepage: https://github.com/kbparagua/numerous.js
|
63
63
|
licenses:
|
64
64
|
- MIT
|