activeadmin_dynamic_fields 0.5.0 → 0.5.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '019f2b81ed1552f13f57b73141860957f4869b10de1f018a289aa8724cc23ec1'
4
- data.tar.gz: 4ed1bb60f5b1ddef1a3d870296d8548faa18cc36db5adadb8271f0c655c769f6
3
+ metadata.gz: 64bede8d2c37bae18d72078be390d20e182035f02496f797a30acf02bf025329
4
+ data.tar.gz: 5629d5a20bc6e9f36f1873127971d01cbaf979159fac4e81c62b7e60f4eb5c7c
5
5
  SHA512:
6
- metadata.gz: b07cc4e73b801ef79ee52b52a6c82117d7e966a2f1eadb0e415e00c608456c02f2c14694c2fc41037ad381c9c0c3bfbf1c0ed96c0c6d13bd0ce3335c38dc1e11
7
- data.tar.gz: c0aa33df12ef6ed16927a49bb9b93d0fcffeffc6f20b661f11edb350544f12e550f90fd5fa5870a43154c0097995bbb02f2f80f24e1ff821eddc2d0fa60e613d
6
+ metadata.gz: f9e4f26043ed9970de78044eda0ab671b005b92b612efcc6912604cefb46078dcac839f75f004982e501bd079167caf58ecf35be7a68cbdf2968a7e98fd9907a
7
+ data.tar.gz: 62888b36a03b0945c7fb7e9defae7ea429570158c6cc70b2e171ccf5de65bd85301838ff88c864ba5faad1cfc5f6e1d32e00541f18a8ee3f77d369151fb75198
data/README.md CHANGED
@@ -208,9 +208,9 @@ end
208
208
  The link url is loaded via AJAX before opening the dialog.
209
209
 
210
210
  ## Do you like it? Star it!
211
- If you use this component just star it. A developer is more motivated to improve a project when there is some interest.
211
+ If you use this component just star it. A developer is more motivated to improve a project when there is some interest. My other [Active Admin components](https://github.com/blocknotes?utf8=✓&tab=repositories&q=activeadmin&type=source).
212
212
 
213
- Take a look at [other ActiveAdmin components](https://github.com/blocknotes?utf8=✓&tab=repositories&q=activeadmin&type=source) that I made if you are curious.
213
+ Or consider offering me a coffee, it's a small thing but it is greatly appreciated: [about me](https://www.blocknot.es/about-me).
214
214
 
215
215
  ## Contributors
216
216
  - [Mattia Roccoberton](http://blocknot.es): author
data/Rakefile CHANGED
@@ -1,3 +1,16 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "bundler/gem_tasks"
3
+ require 'bundler/gem_tasks'
4
+
5
+ begin
6
+ require 'rspec/core/rake_task'
7
+
8
+ RSpec::Core::RakeTask.new(:spec) do |t|
9
+ # t.ruby_opts = %w[-w]
10
+ t.rspec_opts = ['--color', '--format documentation']
11
+ end
12
+
13
+ task default: :spec
14
+ rescue LoadError
15
+ puts '! LoadError: no RSpec available'
16
+ end
@@ -1,6 +1,7 @@
1
1
  (function () {
2
2
  'use strict'
3
3
 
4
+ // noinspection JSUnusedGlobalSymbols
4
5
  const ACTIONS = {
5
6
  addClass: (el, name) => el.addClass(name),
6
7
  addStyle: (el, extra_style) => {
@@ -11,7 +12,8 @@
11
12
  }
12
13
  },
13
14
  callback: (el, name) => {
14
- if (window[name]) window[name](el.data('args'))
15
+ const cb_function = window.hasOwnProperty(name) ? window[name] : null
16
+ if (typeof cb_function === 'function') cb_function(el.data('args'))
15
17
  else {
16
18
  el.attr('data-df-errors', 'callback function not found')
17
19
  console.warn(`activeadmin_dynamic_fields callback function not found: ${name}`)
@@ -21,13 +23,14 @@
21
23
  hide: el => el.hide(),
22
24
  setText: (el, text) => el.text(text),
23
25
  setValue: (el, value) => {
24
- if (el.attr('type') == 'checkbox') el.prop('checked', value == '1')
26
+ if (el.attr('type') === 'checkbox') el.prop('checked', value === '1')
25
27
  else el.val(value)
26
28
  el.trigger('change')
27
29
  },
28
30
  slide: el => el.slideUp()
29
31
  }
30
32
 
33
+ // noinspection EqualityComparisonWithCoercionJS, JSUnusedGlobalSymbols
31
34
  const CONDITIONS = {
32
35
  blank: el => el.val().length === 0 || !el.val().trim(),
33
36
  changed: _el => true,
@@ -90,10 +93,18 @@
90
93
  evaluateCondition() {
91
94
  let value = CONDITIONS[this.el.data('if')?.trim()]
92
95
  if (value) return { condition: value }
93
- if (value = this.el.data('eq')) return { condition: CONDITIONS['eq'], condition_arg: value }
94
- if (value = this.el.data('not')) return { condition: CONDITIONS['not'], condition_arg: value }
95
- if (value = this.el.data('match')) return { condition: CONDITIONS['match'], condition_arg: new RegExp(value) }
96
- if (value = this.el.data('mismatch')) return { condition: CONDITIONS['mismatch'], condition_arg: new RegExp(value) }
96
+
97
+ value = this.el.data('eq')
98
+ if (value) return { condition: CONDITIONS['eq'], condition_arg: value }
99
+
100
+ value = this.el.data('not')
101
+ if (value) return { condition: CONDITIONS['not'], condition_arg: value }
102
+
103
+ value = this.el.data('match')
104
+ if (value) return { condition: CONDITIONS['match'], condition_arg: new RegExp(value) }
105
+
106
+ value = this.el.data('mismatch')
107
+ if (value) return { condition: CONDITIONS['mismatch'], condition_arg: new RegExp(value) }
97
108
 
98
109
  this.custom_function = this.el.data('function')
99
110
  if (this.custom_function) {
@@ -112,32 +123,30 @@
112
123
  // closest find for has many associations
113
124
  if (this.el.data('target')) this.target = this.el.closest('fieldset').find(this.el.data('target'))
114
125
  else if (this.el.data('gtarget')) this.target = $(this.el.data('gtarget'))
115
- if (action_name == 'callback') this.target = this.el
126
+ if (action_name === 'callback') this.target = this.el
116
127
  }
117
128
 
118
129
  isValid() {
119
130
  if (!this.condition) return false
120
- if (!this.action && !this.custom_function) return false
121
-
122
- return true
131
+ return (this.action || this.custom_function)
123
132
  }
124
133
 
125
134
  setup() {
126
135
  if (!this.isValid()) return
127
- if (this.el.data('if') != 'changed') this.apply()
136
+ if (this.el.data('if') !== 'changed') this.apply()
128
137
  this.el.on('change', () => this.apply())
129
138
  }
130
139
  }
131
140
 
132
- // Inline update - must be called binded on the editing element
141
+ // Inline update - must be called bound on the editing element
133
142
  function dfUpdateField() {
134
- if ($(this).data('loading') != '1') {
143
+ if ($(this).data('loading') !== '1') {
135
144
  $(this).data('loading', '1');
136
145
  let _this = $(this);
137
146
  let type = $(this).data('field-type');
138
147
  let new_value;
139
- if (type == 'boolean') new_value = !$(this).data('field-value');
140
- else if (type == 'select') new_value = $(this).val();
148
+ if (type === 'boolean') new_value = !$(this).data('field-value');
149
+ else if (type === 'select') new_value = $(this).val();
141
150
  else new_value = $(this).text();
142
151
  let data = {};
143
152
  data[$(this).data('field')] = new_value;
@@ -146,16 +155,16 @@
146
155
  data: { data: data },
147
156
  method: 'POST',
148
157
  url: $(this).data('save-url'),
149
- complete: function (req, status) {
158
+ complete: function (_req, _status) {
150
159
  $(this).data('loading', '0');
151
160
  },
152
- success: function (data, status, req) {
153
- if (data.status == 'error') {
161
+ success: function (data, _status, _req) {
162
+ if (data.status === 'error') {
154
163
  if ($(this).data('show-errors')) {
155
164
  let result = '';
156
165
  let message = data.message;
157
166
  for (let key in message) {
158
- if (typeof (message[key]) === 'object') {
167
+ if (message.hasOwnProperty(key) && typeof (message[key]) === 'object') {
159
168
  if (result) result += ' - ';
160
169
  result += key + ': ' + message[key].join('; ');
161
170
  }
@@ -181,8 +190,7 @@
181
190
  }
182
191
  }
183
192
 
184
- // Init
185
- $(document).ready(function () {
193
+ function dfInit() {
186
194
  // Setup dynamic fields
187
195
  const selectors = '.active_admin .input [data-if], .active_admin .input [data-eq], .active_admin .input [data-not], .active_admin .input [data-match], .active_admin .input [data-mismatch], .active_admin .input [data-function]'
188
196
  $(selectors).each(function () {
@@ -205,20 +213,23 @@
205
213
  $('.active_admin [data-df-dialog]').on('click', function (event) {
206
214
  event.preventDefault()
207
215
  $(this).blur()
208
- if ($('#df-dialog').data('loading') != '1') {
209
- $('#df-dialog').data('loading', '1')
210
- if ($('#df-dialog').length == 0) $('body').append('<div id="df-dialog"></div>')
216
+ const df_dialog = $('#df-dialog')
217
+
218
+ if (df_dialog.data('loading') !== '1') {
219
+ df_dialog.data('loading', '1')
220
+ if (df_dialog.length === 0) $('body').append('<div id="df-dialog"></div>')
211
221
  let title = $(this).attr('title')
212
222
  $.ajax({
213
223
  url: $(this).attr('href'),
214
- complete: function (req, status) {
224
+ complete: function (_req, _status) {
215
225
  $('#df-dialog').data('loading', '0')
216
226
  },
217
- success: function (data, status, req) {
218
- if (title) $('#df-dialog').attr('title', title)
219
- $('#df-dialog').html(data)
220
- $('#df-dialog').dialog({ modal: true })
221
- },
227
+ success: function (data, _status, _req) {
228
+ const dialog = $('#df-dialog')
229
+ if (title) dialog.attr('title', title)
230
+ dialog.html(data)
231
+ dialog.dialog({ modal: true })
232
+ }
222
233
  })
223
234
  }
224
235
  })
@@ -231,11 +242,14 @@
231
242
  $(this).data('field-value', $(this).text())
232
243
  let fnUpdate = $.proxy(dfUpdateField, $(this))
233
244
  $(this).on('blur', function () {
234
- if ($(this).data('field-value') != $(this).text()) fnUpdate()
245
+ if ($(this).data('field-value') !== $(this).text()) fnUpdate()
235
246
  })
236
247
  })
237
248
  $('[data-field][data-field-type="select"][data-save-url]').each(function () {
238
249
  $(this).on('change', $.proxy(dfUpdateField, $(this)))
239
250
  })
240
- })
251
+ }
252
+
253
+ $(document).ready(dfInit)
254
+ $(document).on('turbolinks:load', dfInit)
241
255
  })()
@@ -2,6 +2,6 @@
2
2
 
3
3
  module ActiveAdmin
4
4
  module DynamicFields
5
- VERSION = '0.5.0'
5
+ VERSION = '0.5.2'
6
6
  end
7
7
  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.5.0
4
+ version: 0.5.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: 2020-10-04 00:00:00.000000000 Z
11
+ date: 2021-03-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activeadmin
@@ -30,126 +30,154 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 6.0.3.2
33
+ version: '6.0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 6.0.3.2
40
+ version: '6.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: capybara
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 3.33.0
47
+ version: '3.33'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: 3.33.0
54
+ version: '3.33'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: pry
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: 0.13.1
61
+ version: '0.13'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: 0.13.1
68
+ version: '0.13'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: puma
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: 4.3.5
75
+ version: '4.3'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: 4.3.5
82
+ version: '4.3'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: rspec_junit_formatter
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: 0.4.1
89
+ version: '0.4'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: 0.4.1
96
+ version: '0.4'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: rspec-rails
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
101
  - - "~>"
102
102
  - !ruby/object:Gem::Version
103
- version: 4.0.1
103
+ version: '4.0'
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
108
  - - "~>"
109
109
  - !ruby/object:Gem::Version
110
- version: 4.0.1
110
+ version: '4.0'
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: rubocop
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
115
  - - "~>"
116
116
  - !ruby/object:Gem::Version
117
- version: 0.90.0
117
+ version: '0.90'
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
122
  - - "~>"
123
123
  - !ruby/object:Gem::Version
124
- version: 0.90.0
124
+ version: '0.90'
125
+ - !ruby/object:Gem::Dependency
126
+ name: sassc
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '2.4'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '2.4'
125
139
  - !ruby/object:Gem::Dependency
126
140
  name: selenium-webdriver
127
141
  requirement: !ruby/object:Gem::Requirement
128
142
  requirements:
129
143
  - - "~>"
130
144
  - !ruby/object:Gem::Version
131
- version: 3.142.7
145
+ version: '3.142'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: '3.142'
153
+ - !ruby/object:Gem::Dependency
154
+ name: sprockets-rails
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - "~>"
158
+ - !ruby/object:Gem::Version
159
+ version: '3.2'
132
160
  type: :development
133
161
  prerelease: false
134
162
  version_requirements: !ruby/object:Gem::Requirement
135
163
  requirements:
136
164
  - - "~>"
137
165
  - !ruby/object:Gem::Version
138
- version: 3.142.7
166
+ version: '3.2'
139
167
  - !ruby/object:Gem::Dependency
140
168
  name: sqlite3
141
169
  requirement: !ruby/object:Gem::Requirement
142
170
  requirements:
143
171
  - - "~>"
144
172
  - !ruby/object:Gem::Version
145
- version: 1.4.2
173
+ version: '1.4'
146
174
  type: :development
147
175
  prerelease: false
148
176
  version_requirements: !ruby/object:Gem::Requirement
149
177
  requirements:
150
178
  - - "~>"
151
179
  - !ruby/object:Gem::Version
152
- version: 1.4.2
180
+ version: '1.4'
153
181
  description: An Active Admin plugin to add dynamic behaviors to fields
154
182
  email: mat@blocknot.es
155
183
  executables: []
@@ -183,7 +211,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
183
211
  - !ruby/object:Gem::Version
184
212
  version: '0'
185
213
  requirements: []
186
- rubygems_version: 3.0.3
214
+ rubygems_version: 3.1.4
187
215
  signing_key:
188
216
  specification_version: 4
189
217
  summary: Dynamic fields for ActiveAdmin