|
1 |
| -/* eslint-disable no-undef */ |
| 1 | +/* global $ */ |
2 | 2 | (function () {
|
3 | 3 | 'use strict'
|
4 | 4 |
|
|
13 | 13 | }
|
14 | 14 | },
|
15 | 15 | callback: (el, name) => {
|
16 |
| - const cb_function = window.hasOwnProperty(name) ? window[name] : null |
17 |
| - if (typeof cb_function === 'function') cb_function(el.data('args')) |
| 16 | + const callbackDefined = Object.prototype.hasOwnProperty.call(window, name) |
| 17 | + const callbackFunction = callbackDefined ? window[name] : null |
| 18 | + if (typeof callbackFunction === 'function') callbackFunction(el.data('args')) |
18 | 19 | else {
|
19 | 20 | el.attr('data-df-errors', 'callback function not found')
|
20 | 21 | console.warn(`activeadmin_dynamic_fields callback function not found: ${name}`)
|
|
34 | 35 | // noinspection EqualityComparisonWithCoercionJS, JSUnusedGlobalSymbols
|
35 | 36 | const CONDITIONS = {
|
36 | 37 | blank: el => el.val().length === 0 || !el.val().trim(),
|
37 |
| - changed: _el => true, |
| 38 | + changed: () => true, |
38 | 39 | checked: el => el.is(':checked'),
|
39 | 40 | eq: (el, value) => el.val() == value,
|
40 | 41 | match: (el, regexp) => regexp.test(el.val()),
|
|
102 | 103 | }
|
103 | 104 |
|
104 | 105 | evaluateCondition() {
|
105 |
| - let value |
106 |
| - if (value = this.el.data('if')) { |
| 106 | + let value = this.el.data('if') |
| 107 | + if (value) { |
107 | 108 | if (REGEXP_NOT.test(value)) value = 'not_' + value.replace(REGEXP_NOT, '')
|
| 109 | + |
108 | 110 | return { condition: CONDITIONS[value] }
|
109 | 111 | }
|
110 |
| - if (value = this.el.data('eq')) { |
| 112 | + |
| 113 | + value = this.el.data('eq') |
| 114 | + if (value) { |
111 | 115 | if (REGEXP_NOT.test(value)) {
|
112 | 116 | return { condition: CONDITIONS['not'], condition_arg: value.replace(REGEXP_NOT, '') }
|
113 | 117 | }
|
| 118 | + |
114 | 119 | return { condition: CONDITIONS['eq'], condition_arg: value }
|
115 | 120 | }
|
116 |
| - if (value = this.el.data('not')) { |
| 121 | + |
| 122 | + value = this.el.data('not') |
| 123 | + if (value) { |
117 | 124 | if (REGEXP_NOT.test(value)) {
|
118 | 125 | return { condition: CONDITIONS['eq'], condition_arg: value.replace(REGEXP_NOT, '') }
|
119 | 126 | }
|
| 127 | + |
120 | 128 | return { condition: CONDITIONS['not'], condition_arg: value }
|
121 | 129 | }
|
122 |
| - if (value = this.el.data('match')) { |
| 130 | + |
| 131 | + value = this.el.data('match') |
| 132 | + if (value) { |
123 | 133 | return { condition: CONDITIONS['match'], condition_arg: new RegExp(value) }
|
124 | 134 | }
|
125 |
| - if (value = this.el.data('mismatch')) { |
| 135 | + |
| 136 | + value = this.el.data('mismatch') |
| 137 | + if (value) { |
126 | 138 | return { condition: CONDITIONS['mismatch'], condition_arg: new RegExp(value) }
|
127 | 139 | }
|
128 | 140 |
|
129 | 141 | this.custom_function = this.el.data('function')
|
130 | 142 | if (this.custom_function) {
|
131 | 143 | value = window[this.custom_function]
|
132 |
| - if (value) return { condition: value } |
| 144 | + if (value) { |
| 145 | + return { condition: value } |
| 146 | + } |
133 | 147 | else {
|
134 | 148 | this.el.attr('data-df-errors', 'custom function not found')
|
135 | 149 | console.warn(`activeadmin_dynamic_fields custom function not found: ${this.custom_function}`)
|
|
175 | 189 | data: { data: data },
|
176 | 190 | method: 'POST',
|
177 | 191 | url: $(this).data('save-url'),
|
178 |
| - complete: function (_req, _status) { |
| 192 | + complete: function () { |
179 | 193 | $(this).data('loading', '0');
|
180 | 194 | },
|
181 |
| - success: function (data, _status, _req) { |
| 195 | + success: function (data) { |
182 | 196 | if (data.status === 'error') {
|
183 | 197 | if ($(this).data('show-errors')) {
|
184 | 198 | let result = '';
|
185 | 199 | let message = data.message;
|
186 | 200 | for (let key in message) {
|
187 |
| - if (message.hasOwnProperty(key) && typeof (message[key]) === 'object') { |
| 201 | + const keyAvailable = Object.prototype.hasOwnProperty.call(message, key) |
| 202 | + if (keyAvailable && typeof (message[key]) === 'object') { |
188 | 203 | if (result) result += ' - ';
|
189 | 204 | result += key + ': ' + message[key].join('; ');
|
190 | 205 | }
|
|
241 | 256 | let title = $(this).attr('title')
|
242 | 257 | $.ajax({
|
243 | 258 | url: $(this).attr('href'),
|
244 |
| - complete: function (_req, _status) { |
| 259 | + complete: function () { |
245 | 260 | $('#df-dialog').data('loading', '0')
|
246 | 261 | },
|
247 |
| - success: function (data, _status, _req) { |
| 262 | + success: function (data) { |
248 | 263 | const dialog = $('#df-dialog')
|
249 | 264 | if (title) dialog.attr('title', title)
|
250 | 265 | dialog.html(data)
|
|
0 commit comments