activeadmin-magicfields 0.4.1 → 0.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE.txt +1 -1
- data/README.md +24 -21
- data/lib/activeadmin-magicfields/version.rb +1 -1
- metadata +1 -4
- data/lib/app/views/admin/field_inputs/_product.html.erb +0 -1
- data/lib/app/views/admin/field_inputs/_site_page.html.erb +0 -1
- data/lib/app/views/admin/parts/_part_old.arb +0 -32
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b48d7e0bf63ef822aeb651550b37344562e8f3be
|
4
|
+
data.tar.gz: 87135d72fc1f961eda506107f8327ef0dc7f9202
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: de40ae1e30e31bf0ad6a1a2f463264171278c029e007b06d34f4cf6aa4fd00a11395b44b1fb7540600ed0b529c721970022fa6dcb3d9aed17653e9afb518da09
|
7
|
+
data.tar.gz: 8b2bf333c471c70ec8ae786bc500ec71e89f79f67e91997277d4a426a19f29cc8660a1b6fcf81f983c4a52ec378ef281d367826dffcd50c1aeba9ab83e4bc9d5
|
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -46,23 +46,23 @@ Include assets in js and css manifests
|
|
46
46
|
|
47
47
|
# Usage
|
48
48
|
|
49
|
-
To use the gem, you need to enable parts on one of your models
|
49
|
+
To use the gem, you need to enable parts on one of your models (in the following example, we add parts to the Page model)
|
50
50
|
|
51
|
-
```
|
51
|
+
``` ruby
|
52
52
|
# db/migrate
|
53
|
-
class
|
53
|
+
class CreatePagesParts < ActiveRecord::Migration
|
54
54
|
def change
|
55
|
-
create_table :
|
56
|
-
t.integer :
|
55
|
+
create_table :pages_parts do |t|
|
56
|
+
t.integer :page_id
|
57
57
|
t.integer :part_id
|
58
58
|
end
|
59
59
|
end
|
60
60
|
end
|
61
61
|
```
|
62
62
|
|
63
|
-
```
|
64
|
-
# models/
|
65
|
-
class
|
63
|
+
``` ruby
|
64
|
+
# models/page.rb
|
65
|
+
class Page < ActiveRecord::Base
|
66
66
|
# ...
|
67
67
|
|
68
68
|
has_many :part_objects, dependent: :destroy, inverse_of: :base_model, foreign_key: "base_model_id"
|
@@ -76,9 +76,9 @@ end
|
|
76
76
|
|
77
77
|
The gem extends activeadmin's form builder, so to enable it you need to override the form builder using `builder` option:
|
78
78
|
|
79
|
-
```
|
80
|
-
#admin/
|
81
|
-
ActiveAdmin.register
|
79
|
+
``` ruby
|
80
|
+
#admin/page.rb
|
81
|
+
ActiveAdmin.register Page do
|
82
82
|
# ...
|
83
83
|
|
84
84
|
form builder: ActiveadminMagicfields::FormBuilder, html: { :enctype => "multipart/form-data" } do |f|
|
@@ -101,29 +101,32 @@ There are few parameters available, currently none of which can be changed:
|
|
101
101
|
|
102
102
|
# Adding a custom field type
|
103
103
|
|
104
|
-
To add a custom field type, just create a table called 'field_[your_field_type]s', a model in models/field/your_field_type.rb, and a form partial. This will enable you to use your_field_type as a part's custom field.
|
104
|
+
To add a custom field type, just create a table called 'field_[your_field_type]s', a model in models/field/your_field_type.rb, and a form partial. This will enable you to use your_field_type as a part's custom field. In the following example, we create the textarea field type.
|
105
|
+
(In `views/admin/field_inputs/_textarea.html.erb`, you can also find how to make this field a WYSIWYG field)
|
105
106
|
|
106
|
-
```
|
107
|
+
``` ruby
|
107
108
|
# db/migrate
|
108
|
-
class
|
109
|
+
class CreateFieldTextarea < ActiveRecord::Migration
|
109
110
|
def change
|
110
|
-
create_table :
|
111
|
+
create_table :field_textareas do |t|
|
111
112
|
t.string :title #required for all field types
|
112
113
|
t.integer :field_template_id #required for all field types
|
113
114
|
|
114
|
-
t.
|
115
|
+
t.text :textarea
|
115
116
|
|
116
117
|
t.timestamps
|
117
118
|
end
|
118
119
|
end
|
119
120
|
end
|
120
|
-
|
121
|
+
|
121
122
|
|
122
123
|
```
|
123
|
-
|
124
|
+
|
125
|
+
``` ruby
|
126
|
+
# models/field/textarea.rb
|
124
127
|
module Field
|
125
128
|
class YourFieldType < ActiveRecord::Base
|
126
|
-
self.table_name = "
|
129
|
+
self.table_name = "field_textareas"
|
127
130
|
|
128
131
|
has_one :part_object_field, as: :fieldable
|
129
132
|
belongs_to :field_template
|
@@ -131,14 +134,14 @@ module Field
|
|
131
134
|
delegate :title, to: :field_template, allow_nil: true
|
132
135
|
delegate :is_required, to: :field_template, allow_nil: true
|
133
136
|
|
134
|
-
validates :
|
137
|
+
validates :textarea, presence: { if: :is_required }
|
135
138
|
|
136
139
|
end
|
137
140
|
end
|
138
141
|
```
|
139
142
|
|
140
143
|
```
|
141
|
-
<%# views/admin/field_inputs/
|
144
|
+
<%# views/admin/field_inputs/_textarea.html.erb %>
|
142
145
|
<%= builder.input field_template.field_type, label: field_template.title, required: field_template.is_required, input_html: {name: form_prefix + builder.object_name.sub('part[', '[') + "[#{field_template.field_type}]" } %>
|
143
146
|
```
|
144
147
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activeadmin-magicfields
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Silvain Toromanoff
|
@@ -88,14 +88,11 @@ files:
|
|
88
88
|
- lib/app/models/repeater_part_object.rb
|
89
89
|
- lib/app/views/admin/field_inputs/_checkbox.html.erb
|
90
90
|
- lib/app/views/admin/field_inputs/_image.html.erb
|
91
|
-
- lib/app/views/admin/field_inputs/_product.html.erb
|
92
91
|
- lib/app/views/admin/field_inputs/_repeater.html.erb
|
93
|
-
- lib/app/views/admin/field_inputs/_site_page.html.erb
|
94
92
|
- lib/app/views/admin/field_inputs/_text.html.erb
|
95
93
|
- lib/app/views/admin/field_inputs/_textarea.html.erb
|
96
94
|
- lib/app/views/admin/part_objects/_part_object.html.erb
|
97
95
|
- lib/app/views/admin/parts/_part.html.erb
|
98
|
-
- lib/app/views/admin/parts/_part_old.arb
|
99
96
|
- lib/generators/activeadmin-magicfields/install/install_generator.rb
|
100
97
|
- lib/generators/activeadmin-magicfields/install/templates/create_field_checkbox.rb
|
101
98
|
- lib/generators/activeadmin-magicfields/install/templates/create_field_image.rb
|
@@ -1 +0,0 @@
|
|
1
|
-
<%= builder.input :product_id, as: :select, multiselect: false, collection: Spree::Product.all, label: field_template.title, required: field_template.is_required, input_html: {name: form_prefix + builder.object_name.sub('part[', '[') + "[product_id]" } %>
|
@@ -1 +0,0 @@
|
|
1
|
-
<%= builder.input :site_page_id, as: :select, multiselect: false, collection: SitePage.all, label: field_template.title, required: field_template.is_required, input_html: {name: form_prefix + builder.object_name.sub('part[', '[') + "[site_page_id]" } %>
|
@@ -1,32 +0,0 @@
|
|
1
|
-
# Define the Part Object
|
2
|
-
part_objects = resource.part_objects.build
|
3
|
-
|
4
|
-
# parents_array = params[:form_name].split("[").map{|n| n.chomp(']')}
|
5
|
-
|
6
|
-
# raise
|
7
|
-
|
8
|
-
# Build the form
|
9
|
-
active_admin_form_for part, url: "to_be_stripped" do |f|
|
10
|
-
f.semantic_fields_for :part_objects do |part_object|
|
11
|
-
|
12
|
-
part_object.input :part_id, as: :hidden, input_html: {value: part.id}
|
13
|
-
|
14
|
-
resource.field_templates.each_with_index do |field_template, ix|
|
15
|
-
part_object.semantic_fields_for "part_object_fields_attributes[#{ix}]", part_objects.part_object_fields.build do |part_object_field|
|
16
|
-
|
17
|
-
|
18
|
-
field_object = Field.const_get(field_template.field_type.classify).new
|
19
|
-
|
20
|
-
part_object_field.semantic_fields_for "fieldable_attributes", field_object do |field|
|
21
|
-
part_object.inputs do
|
22
|
-
field.input field_template.field_type, label: field_template.title, required: field_template.is_required
|
23
|
-
field.input :fieldable_type, as: :hidden, input_html: {value: field_template.field_type.classify}
|
24
|
-
field.input :title, as: :hidden, input_html: {value: field_template.title}
|
25
|
-
end
|
26
|
-
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|