Skip to content

Commit 08d16b3

Browse files
author
Mattia Roccoberton
committed
Minor improvements
1 parent c9b99b9 commit 08d16b3

4 files changed

Lines changed: 21 additions & 29 deletions

File tree

README.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,14 @@ Features:
66

77
- set conditional checks on fields
88
- trigger some actions on other fields
9-
- create links to load some content in a dialogs
9+
- create links to load some content in a dialog
1010

11-
The easiest way to show how this plugin works is looking the examples (below).
11+
The easiest way to show how this plugin works is looking the examples [below](#examples-of-dynamic-fields).
1212

1313
## Install
1414

1515
- Add to your Gemfile: `gem 'activeadmin_dynamic_fields'`
1616
- Execute bundle
17-
- Add at the end of your ActiveAdmin styles (_app/assets/stylesheets/active_admin.scss_):
18-
`@import 'activeadmin/dynamic_fields';`
1917
- Add at the end of your ActiveAdmin javascripts (_app/assets/javascripts/active_admin.js_):
2018
`//= require activeadmin/dynamic_fields`
2119

@@ -106,7 +104,7 @@ Prepare the content dialog - in Active Admin Author config:
106104
ActiveAdmin.register Author do
107105
# ...
108106
member_action :dialog do
109-
content = '<dl>'
107+
content = '<dl style="margin: 12px">'
110108
[:name, :age, :created_at].each do |field|
111109
content += "<dt>#{Author.human_attribute_name(field)}:</dt><dd>#{resource[field]}</dd>"
112110
end

app/assets/javascripts/activeadmin/dynamic_fields.js

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
1+
// Evaluate a condition
22
function dfEvalCondition( el, args ) {
33
if( args.fn ) {
44
if( args.fn && window[args.fn] ) return !window[args.fn]( el );
@@ -25,6 +25,7 @@ function dfEvalCondition( el, args ) {
2525
return undefined;
2626
}
2727

28+
// Prepare a field
2829
function dfSetupField( el ) {
2930
var action = el.data( 'action' );
3031
var target, args = {};
@@ -82,13 +83,26 @@ function dfSetupField( el ) {
8283
}
8384
}
8485

86+
// Set the value of an element
8587
function dfSetValue( el, val ) {
8688
if( el.attr('type') != 'checkbox' ) el.val( val );
8789
else el.prop('checked', val == '1');
8890
el.trigger( 'change' );
8991
}
9092

93+
// Init
9194
$(document).ready( function() {
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
92106
$('.active_admin [data-df-dialog]').on( 'click', function( event ) {
93107
event.preventDefault();
94108
if( $('#df-dialog').length == 0 ) $('body').append( '<div id="df-dialog"></div>' );
@@ -101,14 +115,7 @@ $(document).ready( function() {
101115
$('#df-dialog').dialog({ modal: true });
102116
});
103117
});
104-
105-
$('.active_admin .input [data-if], .active_admin .input [data-function], .active_admin .input [data-eq], .active_admin .input [data-not]').each( function() {
106-
dfSetupField( $(this) );
107-
});
108-
109-
$('.active_admin .has_many_container').on( 'has_many_add:after', function( e, fieldset, container ) {
110-
$('.active_admin .input [data-if], .active_admin .input [data-function], .active_admin .input [data-eq], .active_admin .input [data-not]').each( function() {
111-
dfSetupField( $(this) );
112-
});
118+
$('.active_admin [data-df-icon]').each( function() {
119+
$(this).append( ' &raquo;' ); // ' &bullet;'
113120
});
114121
});

app/assets/stylesheets/activeadmin/_dynamic_fields.sass

Lines changed: 0 additions & 13 deletions
This file was deleted.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module ActiveAdmin
22
module DynamicFields
3-
VERSION = '0.1.0'
3+
VERSION = '0.1.2'
44
end
55
end

0 commit comments

Comments
 (0)