rails_admin_extended_fields 0.1.0 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +33 -6
- data/app/views/rails_admin/main/_nested_accordion.html.haml +45 -0
- data/app/views/rails_admin/main/_nested_list.html.haml +10 -0
- data/app/views/rails_admin/main/_nested_one.html.haml +8 -0
- data/lib/rails_admin_extended_fields.rb +67 -11
- data/lib/rails_admin_extended_fields/version.rb +1 -1
- metadata +4 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ad603b539fdc7c10228f295d2569719c278c7957
|
4
|
+
data.tar.gz: 789311fcb9586347d1c20704ed004592d528f235
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 45f21ab1906fd9699d8415409f2b115494032dc4b7a04aefc16e575fe97bf127e5dce234192b8073bcca9b000d859912d4ca2533fb6f95fc60261ccc51b46edb
|
7
|
+
data.tar.gz: e627486169c7a510573984cbb6406bbc50a87317650d0a71ef1b52e2e128d94f91bbcb093639f680923cf0e1d8c5b4bae6981dc4417e05b9dd7d64dd954c2115
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# rails_admin_extended_fields
|
1
|
+
# rails_admin_extended_fields [![Gem Version](https://badge.fury.io/rb/rails_admin_extended_fields.svg)](https://badge.fury.io/rb/rails_admin_extended_fields)
|
2
2
|
|
3
3
|
A [rails_admin](https://github.com/sferik/rails_admin) plugin to add more options to fields.
|
4
4
|
|
@@ -8,6 +8,14 @@ Features:
|
|
8
8
|
|
9
9
|
- load fields css classes from model
|
10
10
|
|
11
|
+
- nested_list: has_many associations alternative view (list and accordion)
|
12
|
+
|
13
|
+
- nested_one: has_one associations alternative view
|
14
|
+
|
15
|
+
Notes:
|
16
|
+
|
17
|
+
- nested_list and nested_one don't support creating new records and deleting existing ones
|
18
|
+
|
11
19
|
## Install
|
12
20
|
|
13
21
|
- Add to the Gemfile:
|
@@ -22,7 +30,7 @@ Features:
|
|
22
30
|
|
23
31
|
#### nested sortable tabs
|
24
32
|
|
25
|
-
Example
|
33
|
+
Example: a parent model *Page* and a nested model *Block* (page has many blocks)
|
26
34
|
|
27
35
|
- Add a position field to your nested model (ex. an integer or float column):
|
28
36
|
|
@@ -58,9 +66,7 @@ Example with a parent model *Page* and a nested model *Block*
|
|
58
66
|
|
59
67
|
#### load fields css classes from model
|
60
68
|
|
61
|
-
It can be useful to add specific classes to some fields using Single Table Inheritance models
|
62
|
-
|
63
|
-
- Add to a model:
|
69
|
+
It can be useful to add specific classes to some fields using Single Table Inheritance models:
|
64
70
|
|
65
71
|
```ruby
|
66
72
|
class Block < ApplicationRecord
|
@@ -79,7 +85,28 @@ class BlockImage < Block
|
|
79
85
|
end
|
80
86
|
```
|
81
87
|
|
82
|
-
|
88
|
+
Class 'hide' is added to *abstract* and *name* fields of *BlockImage* only.
|
89
|
+
|
90
|
+
#### nested_list
|
91
|
+
|
92
|
+
- Present an has_many association as a list:
|
93
|
+
|
94
|
+
`field :page_options, :nested_list`
|
95
|
+
|
96
|
+
- Present an has_many association as an accordion with drag and drop reordering:
|
97
|
+
|
98
|
+
```ruby
|
99
|
+
field :page_options, :nested_list do
|
100
|
+
accordion true
|
101
|
+
sortable true
|
102
|
+
end
|
103
|
+
```
|
104
|
+
|
105
|
+
#### nested_one
|
106
|
+
|
107
|
+
- Present an has_one association:
|
108
|
+
|
109
|
+
`field :page_info, :nested_one`
|
83
110
|
|
84
111
|
## Contributors
|
85
112
|
|
@@ -0,0 +1,45 @@
|
|
1
|
+
.controls.col-sm-10{data: { nestedmany: true }}
|
2
|
+
-# .btn-group
|
3
|
+
-# - unless field.nested_form[:update_only] || !field.inline_add
|
4
|
+
-# = form.link_to_add "<i class=\"icon-plus icon-white\"></i> #{wording_for(:link, :new, field.associated_model_config.abstract_model)}".html_safe, field.name, { class: 'btn btn-info', onclick: 'this.style.display="none"' }
|
5
|
+
= form.errors_for(field)
|
6
|
+
= form.help_for(field)
|
7
|
+
.clearfix
|
8
|
+
|
9
|
+
- fld = field.name ? field.name.to_s : field.to_s
|
10
|
+
- accordion = 'acc_' + fld
|
11
|
+
-# .tab-content
|
12
|
+
.fields.nested_accordion.panel-group{ id: accordion, role: 'tablist', 'aria-multiselectable': 'true' }
|
13
|
+
- cnt = 0
|
14
|
+
= form.fields_for field.name, nil, wrapper: false do |nested_form|
|
15
|
+
- cnt += 1
|
16
|
+
.panel.panel-default{ id: "pan_#{fld}_#{cnt}" }
|
17
|
+
.panel-heading{ id: "head_#{fld}_#{cnt}", role: 'tab' }
|
18
|
+
%span.panel-icon
|
19
|
+
%h4.panel-title
|
20
|
+
%a.collapsed{ href: "#coll_#{fld}_#{cnt}", role: 'button', data: {toggle: 'collapse', parent: "##{accordion}"}, 'aria-expanded': 'false', 'aria-controls': "coll_#{fld}_#{cnt}" }
|
21
|
+
= ( defined?( nested_form.object.name ) && !nested_form.object.name.empty? ) ? nested_form.object.name : nested_form.object.class.to_s.underscore
|
22
|
+
.panel-collapse.collapse{ id: "coll_#{fld}_#{cnt}", role: 'tabpanel', 'aria-labelledby': "heading#{cnt}" }
|
23
|
+
.panel-body
|
24
|
+
-# - if field.nested_form[:allow_destroy] || nested_form.options[:child_index] == "new_#{field.name}"
|
25
|
+
-# = link_to '<span class="btn btn-small btn-danger"><i class="icon-trash icon-white"></i></span>'.html_safe, '#', onclick: "event.preventDefault();document.getElementById('pan_#{fld}_#{cnt}').removeChild(document.getElementById('coll_#{fld}_#{cnt}'))"
|
26
|
+
-# = nested_form.link_to_remove '<span class="btn btn-small btn-danger"><i class="icon-trash icon-white"></i></span>'.html_safe
|
27
|
+
= nested_form.generate({action: :nested, model_config: field.associated_model_config, nested_in: field })
|
28
|
+
|
29
|
+
-# :javascript
|
30
|
+
-# $(document).on('rails_admin.dom_ready', function(){
|
31
|
+
-# $('.tab-content.nested_accordion').show();
|
32
|
+
-# });
|
33
|
+
|
34
|
+
- if field.sortable
|
35
|
+
- position = field.sortable.is_a?( String ) ? field.sortable : 'position'
|
36
|
+
:javascript
|
37
|
+
$('##{accordion} .#{position}_field').hide();
|
38
|
+
$('##{accordion}').sortable({
|
39
|
+
update: function( event, ui ) {
|
40
|
+
var len = $('##{accordion} .#{position}_field input').length;
|
41
|
+
$('##{accordion} .#{position}_field input').each( function( i ) {
|
42
|
+
$(this).val( len-- );
|
43
|
+
});
|
44
|
+
}
|
45
|
+
});
|
@@ -0,0 +1,10 @@
|
|
1
|
+
.controls.col-sm-10{data: { nestedmany: true }}
|
2
|
+
= form.errors_for(field)
|
3
|
+
= form.help_for(field)
|
4
|
+
.clearfix
|
5
|
+
|
6
|
+
%hr
|
7
|
+
.nested_list{ style: 'padding-left: 12px' }
|
8
|
+
= form.fields_for field.name do |nested_form|
|
9
|
+
= nested_form.generate({action: :nested, model_config: field.associated_model_config, nested_in: field })
|
10
|
+
%hr
|
@@ -0,0 +1,8 @@
|
|
1
|
+
.controls.col-sm-10{data: { nestedone: true }}
|
2
|
+
= form.errors_for(field)
|
3
|
+
= form.help_for(field)
|
4
|
+
.clearfix
|
5
|
+
|
6
|
+
.nested_one{ style: 'padding-left: 12px' }
|
7
|
+
= form.fields_for field.name do |nested_form|
|
8
|
+
= nested_form.generate({action: :nested, model_config: field.associated_model_config, nested_in: field })
|
@@ -18,17 +18,73 @@ RailsAdmin::Config::Fields::Base.class_eval do
|
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
21
|
+
module RailsAdmin::Config::Fields::Types
|
22
|
+
class NestedList < RailsAdmin::Config::Fields::Association
|
23
|
+
RailsAdmin::Config::Fields::Types::register(self)
|
24
|
+
|
25
|
+
register_instance_option :partial do
|
26
|
+
nested_form ? ( accordion ? :nested_accordion : :nested_list ) : :form_filtering_multiselect
|
27
|
+
end
|
28
|
+
|
29
|
+
register_instance_option :accordion do
|
30
|
+
false
|
31
|
+
end
|
32
|
+
|
33
|
+
register_instance_option :sortable do
|
34
|
+
false
|
35
|
+
end
|
36
|
+
|
37
|
+
register_instance_option :inline_add do
|
38
|
+
true
|
39
|
+
end
|
40
|
+
|
41
|
+
def method_name
|
42
|
+
nested_form ? "#{super}_attributes".to_sym : "#{super.to_s.singularize}_ids".to_sym # name_ids
|
43
|
+
end
|
44
|
+
|
45
|
+
# Reader for validation errors of the bound object
|
46
|
+
def errors
|
47
|
+
bindings[:object].errors[name]
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
class NestedOne < RailsAdmin::Config::Fields::Association
|
52
|
+
RailsAdmin::Config::Fields::Types::register(self)
|
53
|
+
|
54
|
+
register_instance_option :partial do
|
55
|
+
nested_form ? :nested_one : :form_filtering_select
|
56
|
+
end
|
57
|
+
|
58
|
+
# Accessor for field's formatted value
|
59
|
+
register_instance_option :formatted_value do
|
60
|
+
(o = value) && o.send(associated_model_config.object_label_method)
|
61
|
+
end
|
62
|
+
|
63
|
+
register_instance_option :inline_add do
|
64
|
+
true
|
65
|
+
end
|
66
|
+
|
67
|
+
register_instance_option :inline_edit do
|
68
|
+
true
|
69
|
+
end
|
70
|
+
|
71
|
+
def editable?
|
72
|
+
(nested_form || abstract_model.model.new.respond_to?("#{name}_id=")) && super
|
73
|
+
end
|
74
|
+
|
75
|
+
def selected_id
|
76
|
+
value.try :id
|
77
|
+
end
|
78
|
+
|
79
|
+
def method_name
|
80
|
+
nested_form ? "#{name}_attributes".to_sym : "#{name}_id".to_sym
|
81
|
+
end
|
82
|
+
|
83
|
+
def multiple?
|
84
|
+
false
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
32
88
|
|
33
89
|
# RailsAdmin::Config::Fields.register_factory do |parent, properties, fields|
|
34
90
|
# if properties[:name] == :extended_fields
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_admin_extended_fields
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mattia Roccoberton
|
@@ -20,6 +20,9 @@ files:
|
|
20
20
|
- MIT-LICENSE
|
21
21
|
- README.md
|
22
22
|
- Rakefile
|
23
|
+
- app/views/rails_admin/main/_nested_accordion.html.haml
|
24
|
+
- app/views/rails_admin/main/_nested_list.html.haml
|
25
|
+
- app/views/rails_admin/main/_nested_one.html.haml
|
23
26
|
- lib/rails_admin_extended_fields.rb
|
24
27
|
- lib/rails_admin_extended_fields/engine.rb
|
25
28
|
- lib/rails_admin_extended_fields/version.rb
|