activeadmin_dynamic_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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4ee6e7b7330564161d89fc27dca1c94c33c17e24
4
- data.tar.gz: 95dd1da212342bd8531f270426e5666403f691de
3
+ metadata.gz: 35c4dfd1640b8577278714cdbd2b4680e01f79e2
4
+ data.tar.gz: 6c157e9f6d829dadba72fa2ad4dcd8c85d62199c
5
5
  SHA512:
6
- metadata.gz: b3c5c278abee8e3ce1befd06ddf91236a02467ee3a80e905942718ddd0f58896ad592ba098cf876def36b2f12b529e38fab13ea4e3ccb8b69a3e63644ebf1af3
7
- data.tar.gz: 6c929053ca401f09a8901f97f81f23b0cfbfe93a8fe74933b5270054de7081e4757fd2d67f63d185de534996018a6cddce3cdad7a4e216bcbc4df8f038ae5be0
6
+ metadata.gz: 1ee9565520e9e58036782be7e297d438c90bba3adb96877caa49f4ca64224041a480d9d29b85d5fec80a7822e654925059b719705bd0a120ef59f59322a57c9e
7
+ data.tar.gz: f4122e8d584dc2a42d4fd1eec7b2ec68be46171aa33113759b40cdad3ef9d6de4bd6cb77f4cdf75424afdbb2f66d4bb67475c47e3c22307d040c23e81d129a75
data/README.md CHANGED
@@ -6,7 +6,7 @@ Features:
6
6
 
7
7
  - set conditional checks on fields
8
8
  - trigger some actions on other fields
9
- - create links to load some content in a dialog
9
+ - create links to load some content in a dialogs
10
10
 
11
11
  The easiest way to show how this plugin works is looking the examples (below).
12
12
 
@@ -14,8 +14,6 @@ The easiest way to show how this plugin works is looking the examples (below).
14
14
 
15
15
  - Add to your Gemfile: `gem 'activeadmin_dynamic_fields'`
16
16
  - Execute bundle
17
- - Add at the end of your ActiveAdmin styles (_app/assets/stylesheets/active_admin.scss_):
18
- `@import 'activeadmin/dynamic_fields';`
19
17
  - Add at the end of your ActiveAdmin javascripts (_app/assets/javascripts/active_admin.js_):
20
18
  `//= require activeadmin/dynamic_fields`
21
19
 
@@ -106,7 +104,7 @@ Prepare the content dialog - in Active Admin Author config:
106
104
  ActiveAdmin.register Author do
107
105
  # ...
108
106
  member_action :dialog do
109
- content = '<dl>'
107
+ content = '<dl style="margin: 12px">'
110
108
  [:name, :age, :created_at].each do |field|
111
109
  content += "<dt>#{Author.human_attribute_name(field)}:</dt><dd>#{resource[field]}</dd>"
112
110
  end
@@ -1,4 +1,4 @@
1
-
1
+ // Evaluate a condition
2
2
  function dfEvalCondition( el, args ) {
3
3
  if( args.fn ) {
4
4
  if( args.fn && window[args.fn] ) return !window[args.fn]( el );
@@ -25,6 +25,7 @@ function dfEvalCondition( el, args ) {
25
25
  return undefined;
26
26
  }
27
27
 
28
+ // Prepare a field
28
29
  function dfSetupField( el ) {
29
30
  var action = el.data( 'action' );
30
31
  var target, args = {};
@@ -82,14 +83,27 @@ function dfSetupField( el ) {
82
83
  }
83
84
  }
84
85
 
86
+ // Set the value of an element
85
87
  function dfSetValue( el, val ) {
86
88
  if( el.attr('type') != 'checkbox' ) el.val( val );
87
89
  else el.prop('checked', val == '1');
88
90
  el.trigger( 'change' );
89
91
  }
90
92
 
93
+ // Init
91
94
  $(document).ready( function() {
92
- $('[data-df-dialog]').on( 'click', function( event ) {
95
+ // Setup dynamic fields
96
+ $('.active_admin .input [data-if], .active_admin .input [data-function], .active_admin .input [data-eq], .active_admin .input [data-not]').each( function() {
97
+ dfSetupField( $(this) );
98
+ });
99
+ // Setup dynamic fields for has many associations
100
+ $('.active_admin .has_many_container').on( 'has_many_add:after', function( e, fieldset, container ) {
101
+ $('.active_admin .input [data-if], .active_admin .input [data-function], .active_admin .input [data-eq], .active_admin .input [data-not]').each( function() {
102
+ dfSetupField( $(this) );
103
+ });
104
+ });
105
+ // Open content in dialog
106
+ $('.active_admin [data-df-dialog]').on( 'click', function( event ) {
93
107
  event.preventDefault();
94
108
  if( $('#df-dialog').length == 0 ) $('body').append( '<div id="df-dialog"></div>' );
95
109
  var title = $(this).attr( 'title' );
@@ -101,14 +115,7 @@ $(document).ready( function() {
101
115
  $('#df-dialog').dialog({ modal: true });
102
116
  });
103
117
  });
104
-
105
- $('[data-if], [data-function], [data-eq], [data-not]').each( function() {
106
- dfSetupField( $(this) );
107
- });
108
-
109
- $('.has_many_container').on( 'has_many_add:after', function( e, fieldset, container ) {
110
- $('[data-if], [data-function], [data-eq], [data-not]').each( function() {
111
- dfSetupField( $(this) );
112
- });
118
+ $('.active_admin [data-df-icon]').each( function() {
119
+ $(this).append( ' &raquo;' ); // ' &bullet;'
113
120
  });
114
121
  });
@@ -1,5 +1,5 @@
1
1
  module ActiveAdmin
2
2
  module DynamicFields
3
- VERSION = '0.1.0'
3
+ VERSION = '0.1.2'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activeadmin_dynamic_fields
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mattia Roccoberton
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-09-09 00:00:00.000000000 Z
11
+ date: 2017-09-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activeadmin
@@ -37,7 +37,6 @@ files:
37
37
  - Rakefile
38
38
  - activeadmin_dynamic_fields.gemspec
39
39
  - app/assets/javascripts/activeadmin/dynamic_fields.js
40
- - app/assets/stylesheets/activeadmin/_dynamic_fields.sass
41
40
  - lib/activeadmin/dynamic_fields.rb
42
41
  - lib/activeadmin/dynamic_fields/engine.rb
43
42
  - lib/activeadmin/dynamic_fields/version.rb
@@ -1,13 +0,0 @@
1
- body.active_admin
2
- a[data-df-icon]::after
3
- content: ' •'
4
- // .ui-dialog
5
- // .ui-dialog-titlebar
6
- // display: flex
7
- // justify-content: space-between
8
- // > *
9
- // align-self: center
10
- // // .ui-dialog-buttonset
11
- // // text-align: right
12
- #df-dialog
13
- padding: 10px 15px 5px 15px