active_admin_scoped_collection_actions 2.1.0 → 2.2.0
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 +4 -4
- data/CHANGELOG.md +6 -0
- data/README.md +59 -0
- data/app/javascript/active_admin_scoped_collection_actions/dialog.js +282 -0
- data/config/importmap.rb +5 -0
- data/lib/active_admin_scoped_collection_actions/engine.rb +31 -1
- data/lib/active_admin_scoped_collection_actions/resource_extension.rb +20 -3
- data/lib/active_admin_scoped_collection_actions/version.rb +1 -1
- data/lib/active_admin_scoped_collection_actions.rb +9 -0
- metadata +6 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 42b89c377c3731b575446f6e1f81f476933cc6eb81f8ecede26029acb82430c2
|
|
4
|
+
data.tar.gz: 72fbb62b5ccd5ee2ee3a137c35aa858a0563a1ec9809aa456ae50cdc7504ee72
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 1e65c11a26b58d814bbac206865f9b7142ad6cd84855d0df983482435bb2f089b044972a735e8337a27a4cf491f499e87f05d292bf0fab921296f3f33ad79057
|
|
7
|
+
data.tar.gz: 7969a98d345001dc589ee738c8d26ddd442b31b71b903e1fe88da45ac448fc975c92c4e4e051d5c9677bd9aaef9bd2f17031ab43dff5be35fb3599ab5aa919c2
|
data/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
## ActiveAdmin Scoped Collection Actions 2.2.0 (November 27, 2026) ##
|
|
2
|
+
|
|
3
|
+
* ActiveAdmin 4 support: the dialog is a Flowbite modal in an ES module pinned into `ActiveAdmin.importmap`;
|
|
4
|
+
ActiveAdmin 3 keeps the jQuery UI dialog
|
|
5
|
+
* `data-scoped-collection-action` on the sidebar buttons
|
|
6
|
+
|
|
1
7
|
## ActiveAdmin Scoped Collection Actions 2.1.0 (October 02, 2026) ##
|
|
2
8
|
|
|
3
9
|
* New action option `:confirm_submit` - turns the fields dialog into two steps, the second one replaces the
|
data/README.md
CHANGED
|
@@ -13,6 +13,8 @@ Plugin for ActiveAdmin. Provides batch Update and Delete for scoped_collection (
|
|
|
13
13
|
|
|
14
14
|
- [Description](#description)
|
|
15
15
|
- [Installation](#installation)
|
|
16
|
+
- [ActiveAdmin 3](#activeadmin-3)
|
|
17
|
+
- [ActiveAdmin 4](#activeadmin-4)
|
|
16
18
|
- [Usage](#usage)
|
|
17
19
|
- [Update action](#update-action)
|
|
18
20
|
- [Custom actions](#custom-actions)
|
|
@@ -51,6 +53,8 @@ And then execute:
|
|
|
51
53
|
bundle
|
|
52
54
|
```
|
|
53
55
|
|
|
56
|
+
### ActiveAdmin 3
|
|
57
|
+
|
|
54
58
|
Add the following line at the end of `app/assets/javascript/active_admin.js`:
|
|
55
59
|
|
|
56
60
|
```javascript
|
|
@@ -63,6 +67,49 @@ Also include the CSS in `app/assets/stylesheets/active_admin.css.scss`:
|
|
|
63
67
|
@import "active_admin_scoped_collection_actions";
|
|
64
68
|
```
|
|
65
69
|
|
|
70
|
+
### ActiveAdmin 4
|
|
71
|
+
|
|
72
|
+
The gem pins its dialog module, `active_admin_scoped_collection_actions`, into `ActiveAdmin.importmap`. The dialog is
|
|
73
|
+
a Flowbite modal, the one ActiveAdmin 4 ships with.
|
|
74
|
+
|
|
75
|
+
Import the module on ActiveAdmin pages:
|
|
76
|
+
|
|
77
|
+
- With an ActiveAdmin that has the `javascript_modules` setting
|
|
78
|
+
([activeadmin/activeadmin#9148](https://github.com/activeadmin/activeadmin/pull/9148)), the gem adds it there and
|
|
79
|
+
there is nothing to do.
|
|
80
|
+
- With active_admin_theme 4, add it to the theme's list in `config/initializers/active_admin.rb`:
|
|
81
|
+
|
|
82
|
+
```ruby
|
|
83
|
+
ActiveAdminTheme.javascripts += %w[active_admin_scoped_collection_actions]
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
- Otherwise copy `app/views/active_admin/_html_head.html.erb` from ActiveAdmin into your app and add at its end:
|
|
87
|
+
|
|
88
|
+
```erb
|
|
89
|
+
<%= javascript_import_module_tag "active_admin_scoped_collection_actions" %>
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
The sidebar and the modal are styled with Tailwind classes, so Tailwind has to scan the gem. Add it to `content` in
|
|
93
|
+
`tailwind-active_admin.config.js`:
|
|
94
|
+
|
|
95
|
+
```javascript
|
|
96
|
+
const scopedCollectionActionsPath = execSync('bundle show active_admin_scoped_collection_actions', { encoding: 'utf-8' }).trim().split(/\r?\n/).pop();
|
|
97
|
+
|
|
98
|
+
export default {
|
|
99
|
+
content: [
|
|
100
|
+
// ...
|
|
101
|
+
`${scopedCollectionActionsPath}/app/javascript/**/*.js`,
|
|
102
|
+
`${scopedCollectionActionsPath}/lib/**/*.rb`
|
|
103
|
+
],
|
|
104
|
+
// ...
|
|
105
|
+
}
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
Differences from ActiveAdmin 3:
|
|
109
|
+
|
|
110
|
+
- `datepicker` fields are native date inputs, as everywhere in ActiveAdmin 4.
|
|
111
|
+
- The sidebar section has no titled panel, because ActiveAdmin 4 renders sidebar sections without one.
|
|
112
|
+
|
|
66
113
|
## Usage
|
|
67
114
|
|
|
68
115
|
Usually you need two standard actions: Delete and Update.
|
|
@@ -129,6 +176,18 @@ $(document).on('mass_update_modal_dialog:after_open', function (event, form) {
|
|
|
129
176
|
});
|
|
130
177
|
```
|
|
131
178
|
|
|
179
|
+
On ActiveAdmin 4 the same event is a bubbling DOM `CustomEvent` with the form in `event.detail.form`.
|
|
180
|
+
`mass_update_modal_dialog:before_open` is dispatched the same way, before the modal is shown:
|
|
181
|
+
|
|
182
|
+
```javascript
|
|
183
|
+
document.addEventListener('mass_update_modal_dialog:after_open', (event) => {
|
|
184
|
+
event.detail.form.querySelectorAll('input.my-widget').forEach((input) => myWidget(input));
|
|
185
|
+
});
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
The button, the modal and its form carry `data-scoped-collection-action`, `data-scoped-collection-action-modal`
|
|
189
|
+
and `data-scoped-collection-action-form`, each set to the action name.
|
|
190
|
+
|
|
132
191
|
## Custom actions
|
|
133
192
|
|
|
134
193
|
Example: we have a Phone resource with a `manufactured_at` column. We need an action which will erase this date.
|
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
// ActiveAdmin 4 dialog; ActiveAdmin 3 keeps the jQuery UI one in vendor/assets.
|
|
2
|
+
// Posts the same params as that one: changes[name], collection_selection[],
|
|
3
|
+
// authenticity_token and batch_action.
|
|
4
|
+
import "flowbite"
|
|
5
|
+
|
|
6
|
+
const BUTTON = ".scoped_collection_action_button"
|
|
7
|
+
const COUNT_ACTION = "scoped_collection_records_count"
|
|
8
|
+
|
|
9
|
+
const PRIMARY_BUTTON = "text-white bg-blue-700 hover:bg-blue-800 focus:ring-4 focus:outline-hidden focus:ring-blue-300 font-medium rounded-lg text-sm px-5 py-2.5 cursor-pointer disabled:opacity-50 disabled:cursor-default dark:bg-blue-600 dark:hover:bg-blue-700 dark:focus:ring-blue-800"
|
|
10
|
+
const SECONDARY_BUTTON = "action-item-button cursor-pointer"
|
|
11
|
+
const INPUT = "block w-full mt-1 rounded-md border border-gray-300 bg-white text-sm text-gray-900 disabled:opacity-50 dark:border-gray-600 dark:bg-gray-700 dark:text-white"
|
|
12
|
+
const CHECKBOX = "rounded-sm border-gray-300 dark:border-gray-600 dark:bg-gray-700"
|
|
13
|
+
|
|
14
|
+
const element = (tag, attributes = {}, text = null) => {
|
|
15
|
+
const el = document.createElement(tag)
|
|
16
|
+
for (const [name, value] of Object.entries(attributes)) {
|
|
17
|
+
if (value !== null && value !== undefined) el.setAttribute(name, value)
|
|
18
|
+
}
|
|
19
|
+
if (text !== null) el.textContent = text
|
|
20
|
+
return el
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const batchActionUrl = () => window.location.pathname + "/batch_action" + window.location.search
|
|
24
|
+
|
|
25
|
+
const selection = () =>
|
|
26
|
+
Array.from(document.querySelectorAll('input[name="collection_selection[]"]:checked'), (input) => input.value)
|
|
27
|
+
|
|
28
|
+
const post = (token, batchAction, changes = {}) => {
|
|
29
|
+
const body = new URLSearchParams()
|
|
30
|
+
for (const [name, value] of Object.entries(changes)) body.append(`changes[${name}]`, value)
|
|
31
|
+
for (const id of selection()) body.append("collection_selection[]", id)
|
|
32
|
+
body.append("authenticity_token", token)
|
|
33
|
+
body.append("batch_action", batchAction)
|
|
34
|
+
|
|
35
|
+
return fetch(batchActionUrl(), {
|
|
36
|
+
method: "POST",
|
|
37
|
+
body,
|
|
38
|
+
credentials: "same-origin",
|
|
39
|
+
headers: { "X-Requested-With": "XMLHttpRequest" }
|
|
40
|
+
})
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const recordsCount = (token) =>
|
|
44
|
+
post(token, COUNT_ACTION).then((response) => (response.ok ? response.json() : Promise.reject(response)))
|
|
45
|
+
|
|
46
|
+
// "You are going to delete {count} record(s).", hidden behind a spinner until
|
|
47
|
+
// the count is known, so nobody reads half a message.
|
|
48
|
+
const recordsSummary = (template, token) => {
|
|
49
|
+
const summary = element("p", { class: "dialog_records_summary mb-2 text-gray-900 dark:text-gray-100", "data-scoped-collection-action-summary": "" })
|
|
50
|
+
const spinner = element("div", { class: "dialog_spinner mx-auto my-4 size-6 animate-spin rounded-full border-3 border-current border-r-transparent text-gray-500 dark:text-gray-400", "data-scoped-collection-action-spinner": "" })
|
|
51
|
+
const show = (count) => { summary.textContent = template.replace("{count}", count) }
|
|
52
|
+
|
|
53
|
+
summary.hidden = true
|
|
54
|
+
const request = recordsCount(token)
|
|
55
|
+
.then((data) => show(data.count))
|
|
56
|
+
.catch(() => show("?"))
|
|
57
|
+
.finally(() => {
|
|
58
|
+
spinner.remove()
|
|
59
|
+
summary.hidden = false
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
return { summary, spinner, request }
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// One field of the `form:` option: a checkbox that enables it, a label and
|
|
66
|
+
// the input. Unchecked fields stay disabled and are not submitted.
|
|
67
|
+
const field = (name, type) => {
|
|
68
|
+
const id = `mass_update_dialog_${name}`
|
|
69
|
+
const item = element("li", { class: "mt-3", "data-scoped-collection-action-field": name })
|
|
70
|
+
const toggle = element("input", { type: "checkbox", class: `mass_update_protect_fild_flag ${CHECKBOX}`, value: "Y", id })
|
|
71
|
+
const label = element("label", { for: id, id: `${id}_label`, class: "ms-2 text-sm font-medium text-gray-900 dark:text-white" }, name.charAt(0).toUpperCase() + name.slice(1))
|
|
72
|
+
let input
|
|
73
|
+
|
|
74
|
+
if (Array.isArray(type)) {
|
|
75
|
+
input = element("select", { name, class: INPUT })
|
|
76
|
+
for (const option of type) {
|
|
77
|
+
const [text, value] = Array.isArray(option) ? option : [option, option]
|
|
78
|
+
// ['None', nil]: without a value attribute the browser would submit the label
|
|
79
|
+
input.append(element("option", { value: value ?? "" }, text))
|
|
80
|
+
}
|
|
81
|
+
} else if (type !== null && typeof type === "object") {
|
|
82
|
+
// {type: 'text', class: 'my-widget'}: a plain input carrying the host's
|
|
83
|
+
// class, so its own JavaScript can turn it into any widget.
|
|
84
|
+
input = element("input", { name, type: type.type || "text", class: `${type.class || ""} ${INPUT}` })
|
|
85
|
+
} else if (type === "text") {
|
|
86
|
+
input = element("input", { name, type: "text", class: INPUT })
|
|
87
|
+
} else if (type === "checkbox") {
|
|
88
|
+
input = element("input", { name, type: "checkbox", class: `ms-2 ${CHECKBOX}` })
|
|
89
|
+
} else if (type === "datepicker") {
|
|
90
|
+
// ActiveAdmin 4 uses the native date input instead of a datepicker widget.
|
|
91
|
+
input = element("input", { name, type: "date", class: `datepicker ${INPUT}` })
|
|
92
|
+
} else {
|
|
93
|
+
throw new Error(`Unsupported input type: {${name}: ${type}}`)
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// The label's `for` names the checkbox, so the value control needs its own link
|
|
97
|
+
input.setAttribute("aria-labelledby", label.id)
|
|
98
|
+
input.disabled = true
|
|
99
|
+
toggle.addEventListener("change", () => { input.disabled = !toggle.checked })
|
|
100
|
+
item.append(toggle, label, input)
|
|
101
|
+
return item
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// The checked fields as the dialog shows them: [{label: 'Name', value: 'test'}]
|
|
105
|
+
const checkedChanges = (form) =>
|
|
106
|
+
Array.from(form.querySelectorAll(".mass_update_protect_fild_flag:checked"), (toggle) => {
|
|
107
|
+
const item = toggle.closest("[data-scoped-collection-action-field]")
|
|
108
|
+
const input = item.querySelector("[name]")
|
|
109
|
+
let value
|
|
110
|
+
if (input.tagName === "SELECT") {
|
|
111
|
+
value = Array.from(input.selectedOptions, (option) => option.text.trim()).join(", ")
|
|
112
|
+
} else if (input.type === "checkbox") {
|
|
113
|
+
value = input.checked
|
|
114
|
+
} else {
|
|
115
|
+
value = input.value
|
|
116
|
+
}
|
|
117
|
+
return { label: item.querySelector("label").textContent.trim(), value }
|
|
118
|
+
})
|
|
119
|
+
|
|
120
|
+
const formChanges = (form) => {
|
|
121
|
+
const changes = {}
|
|
122
|
+
for (const [name, value] of new FormData(form)) changes[name] = value
|
|
123
|
+
// FormData skips an unchecked box, but the confirm step shows it as false
|
|
124
|
+
for (const input of form.querySelectorAll('input[type="checkbox"][name]:not(:disabled):not(:checked)')) {
|
|
125
|
+
changes[input.name] = "off"
|
|
126
|
+
}
|
|
127
|
+
return changes
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
const openDialog = (button) => {
|
|
131
|
+
const data = JSON.parse(button.getAttribute("data"))
|
|
132
|
+
const token = data.auth_token
|
|
133
|
+
const batchAction = data.batch_action
|
|
134
|
+
// confirm_submit adds a second step, and confirm_summary then only words it
|
|
135
|
+
const confirmSubmit = data.confirm_submit
|
|
136
|
+
? { title: data.confirm_submit, summary: data.confirm_summary || data.confirm_submit_summary }
|
|
137
|
+
: null
|
|
138
|
+
const summaryText = confirmSubmit ? null : data.confirm_summary
|
|
139
|
+
|
|
140
|
+
const modalEl = element("div", {
|
|
141
|
+
id: "scoped-collection-action-modal",
|
|
142
|
+
tabindex: "-1",
|
|
143
|
+
"aria-hidden": "true",
|
|
144
|
+
"aria-labelledby": "scoped-collection-action-modal-title",
|
|
145
|
+
class: "fixed inset-0 z-50 hidden w-full p-4 overflow-x-hidden overflow-y-auto h-full max-h-full",
|
|
146
|
+
"data-scoped-collection-action-modal": batchAction,
|
|
147
|
+
"data-step": "fields"
|
|
148
|
+
})
|
|
149
|
+
const dialog = element("div", { class: "relative w-full max-w-md max-h-full" })
|
|
150
|
+
const content = element("div", { class: "relative bg-white rounded-lg shadow dark:bg-gray-800 dark:border dark:border-white/10 px-6 py-6 lg:px-8" })
|
|
151
|
+
const title = element("h3", { id: "scoped-collection-action-modal-title", class: "mb-4 text-xl font-medium text-gray-900 dark:text-white", "data-scoped-collection-action-title": "" }, data.confirm)
|
|
152
|
+
const form = element("form", { "data-scoped-collection-action-form": batchAction })
|
|
153
|
+
const fields = element("ul", { "data-scoped-collection-action-fields": "" })
|
|
154
|
+
const footer = element("div", { class: "mt-6 flex justify-end gap-2" })
|
|
155
|
+
const ok = element("button", { type: "submit", class: PRIMARY_BUTTON, "data-scoped-collection-action-ok": "" }, "OK")
|
|
156
|
+
const cancel = element("button", { type: "button", class: SECONDARY_BUTTON, "data-scoped-collection-action-cancel": "" }, "Cancel")
|
|
157
|
+
|
|
158
|
+
for (const [name, type] of Object.entries(data.inputs || {})) fields.append(field(name, type))
|
|
159
|
+
footer.append(ok, cancel)
|
|
160
|
+
form.append(fields, footer)
|
|
161
|
+
content.append(title, form)
|
|
162
|
+
dialog.append(content)
|
|
163
|
+
modalEl.append(dialog)
|
|
164
|
+
document.body.append(modalEl)
|
|
165
|
+
|
|
166
|
+
// OK stays disabled while the count is pending, so nothing is confirmed
|
|
167
|
+
// before the user sees what they confirm.
|
|
168
|
+
let waiting = null
|
|
169
|
+
const waitFor = (request) => {
|
|
170
|
+
waiting = request
|
|
171
|
+
ok.disabled = true
|
|
172
|
+
request.finally(() => {
|
|
173
|
+
if (waiting !== request) return
|
|
174
|
+
waiting = null
|
|
175
|
+
ok.disabled = false
|
|
176
|
+
})
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
if (summaryText) {
|
|
180
|
+
const { summary, spinner, request } = recordsSummary(summaryText, token)
|
|
181
|
+
form.prepend(spinner, summary)
|
|
182
|
+
waitFor(request)
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
const modal = new window.Modal(modalEl, {
|
|
186
|
+
backdrop: "dynamic",
|
|
187
|
+
closable: true,
|
|
188
|
+
onHide: () => {
|
|
189
|
+
setTimeout(() => {
|
|
190
|
+
modal.destroyAndRemoveInstance()
|
|
191
|
+
modalEl.remove()
|
|
192
|
+
button.focus()
|
|
193
|
+
})
|
|
194
|
+
}
|
|
195
|
+
}, { id: modalEl.id, override: true })
|
|
196
|
+
|
|
197
|
+
cancel.addEventListener("click", () => modal.hide())
|
|
198
|
+
|
|
199
|
+
const focusFirstControl = () =>
|
|
200
|
+
form.querySelector("input:not(:disabled), select:not(:disabled), button:not(:disabled)")?.focus()
|
|
201
|
+
|
|
202
|
+
// Escape and the backdrop call hide() too; once the action is sent the modal
|
|
203
|
+
// stays until the page reloads.
|
|
204
|
+
let submitted = false
|
|
205
|
+
const hide = modal.hide.bind(modal)
|
|
206
|
+
modal.hide = () => { if (!submitted) hide() }
|
|
207
|
+
const submit = () => {
|
|
208
|
+
submitted = true
|
|
209
|
+
const changes = formChanges(form)
|
|
210
|
+
footer.replaceChildren(element("span", { class: "text-sm text-gray-700 dark:text-gray-300" }, "Processing. Please wait..."))
|
|
211
|
+
post(token, batchAction, changes)
|
|
212
|
+
.then((response) => {
|
|
213
|
+
const location = response.headers.get("Location")
|
|
214
|
+
if (location) window.location.assign(location)
|
|
215
|
+
else window.location.reload()
|
|
216
|
+
})
|
|
217
|
+
.catch(() => window.location.reload())
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
// Second step: the fields give way to what is going to change and on how
|
|
221
|
+
// many records. Back returns to the filled-in fields.
|
|
222
|
+
const showConfirmStep = (changes) => {
|
|
223
|
+
const step = element("div", { class: "dialog_confirm_submit", "data-scoped-collection-action-confirm": "" })
|
|
224
|
+
const list = element("ul", { class: "dialog_confirm_submit_changes mt-1 text-sm text-gray-900 dark:text-gray-100" })
|
|
225
|
+
for (const change of changes) {
|
|
226
|
+
const item = element("li", { class: "mt-1" })
|
|
227
|
+
item.append(element("b", {}, change.label), document.createTextNode(`: ${change.value}`))
|
|
228
|
+
list.append(item)
|
|
229
|
+
}
|
|
230
|
+
const { summary, spinner, request } = recordsSummary(confirmSubmit.summary, token)
|
|
231
|
+
list.hidden = true
|
|
232
|
+
request.finally(() => { list.hidden = false })
|
|
233
|
+
step.append(spinner, summary, list)
|
|
234
|
+
|
|
235
|
+
const back = element("button", { type: "button", class: SECONDARY_BUTTON, "data-scoped-collection-action-back": "" }, "Back")
|
|
236
|
+
const fieldsTitle = title.textContent
|
|
237
|
+
back.addEventListener("click", () => {
|
|
238
|
+
waiting = null
|
|
239
|
+
ok.disabled = false
|
|
240
|
+
step.remove()
|
|
241
|
+
back.replaceWith(cancel)
|
|
242
|
+
fields.hidden = false
|
|
243
|
+
title.textContent = fieldsTitle
|
|
244
|
+
modalEl.dataset.step = "fields"
|
|
245
|
+
focusFirstControl()
|
|
246
|
+
})
|
|
247
|
+
|
|
248
|
+
fields.hidden = true
|
|
249
|
+
fields.after(step)
|
|
250
|
+
cancel.replaceWith(back)
|
|
251
|
+
title.textContent = confirmSubmit.title
|
|
252
|
+
modalEl.dataset.step = "confirm"
|
|
253
|
+
waitFor(request)
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
form.addEventListener("submit", (event) => {
|
|
257
|
+
event.preventDefault()
|
|
258
|
+
if (waiting || submitted) return
|
|
259
|
+
|
|
260
|
+
if (modalEl.dataset.step === "confirm") return submit()
|
|
261
|
+
|
|
262
|
+
const changes = checkedChanges(form)
|
|
263
|
+
// nothing is checked, so there is nothing to confirm
|
|
264
|
+
if (!confirmSubmit || !changes.length) return submit()
|
|
265
|
+
showConfirmStep(changes)
|
|
266
|
+
})
|
|
267
|
+
|
|
268
|
+
document.body.dispatchEvent(new CustomEvent("mass_update_modal_dialog:before_open", { bubbles: true, detail: { form } }))
|
|
269
|
+
modal.show()
|
|
270
|
+
focusFirstControl()
|
|
271
|
+
document.body.dispatchEvent(new CustomEvent("mass_update_modal_dialog:after_open", { bubbles: true, detail: { form } }))
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
document.addEventListener("click", (event) => {
|
|
275
|
+
const button = event.target.closest(BUTTON)
|
|
276
|
+
if (!button) return
|
|
277
|
+
|
|
278
|
+
event.preventDefault()
|
|
279
|
+
// Enter on the still-focused button would stack a second modal with the same ids
|
|
280
|
+
if (document.getElementById("scoped-collection-action-modal")) return
|
|
281
|
+
openDialog(button)
|
|
282
|
+
})
|
data/config/importmap.rb
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
# Drawn into ActiveAdmin.importmap by the engine on ActiveAdmin 4. Not
|
|
2
|
+
# preloaded, so a host that does not import the module does not fetch it.
|
|
3
|
+
# The file is not named after the gem: that name is the Sprockets bundle in
|
|
4
|
+
# vendor/assets, which Propshaft would serve instead.
|
|
5
|
+
pin 'active_admin_scoped_collection_actions', to: 'active_admin_scoped_collection_actions/dialog.js', preload: false
|
|
@@ -4,6 +4,36 @@ module ActiveAdminScopedCollectionActions
|
|
|
4
4
|
config.after_initialize do
|
|
5
5
|
ActiveAdmin::ResourceController.send :include, ActiveAdminScopedCollectionActions::Controller
|
|
6
6
|
end
|
|
7
|
+
|
|
8
|
+
# ActiveAdmin 4 renders its own import map, ActiveAdmin.importmap, so the
|
|
9
|
+
# dialog module is pinned there rather than in the host's importmap.
|
|
10
|
+
initializer 'active_admin_scoped_collection_actions.importmap', after: 'active_admin.importmap' do |app|
|
|
11
|
+
next unless ActiveAdmin.respond_to?(:importmap) && app.config.respond_to?(:importmap)
|
|
12
|
+
|
|
13
|
+
ActiveAdmin.importmap.draw(root.join('config', 'importmap.rb'))
|
|
14
|
+
if app.config.respond_to?(:assets)
|
|
15
|
+
app.config.assets.paths << root.join('app/javascript')
|
|
16
|
+
# Sprockets raises AssetNotPrecompiledError for modules outside its precompile list.
|
|
17
|
+
app.config.assets.precompile += %w[active_admin_scoped_collection_actions/dialog.js]
|
|
18
|
+
end
|
|
19
|
+
if ActiveAdmin.application.respond_to?(:importmap_watches)
|
|
20
|
+
ActiveAdmin.application.importmap_watches << root.join('app/javascript')
|
|
21
|
+
elsif app.config.importmap.sweep_cache
|
|
22
|
+
# Without importmap_watches (activeadmin/activeadmin#9153) each
|
|
23
|
+
# cache_sweeper(watches:) call replaces the watcher, so rebuild
|
|
24
|
+
# ActiveAdmin's with both directories.
|
|
25
|
+
watches = [ActiveAdmin::Engine.root.join('app/javascript'), root.join('app/javascript')].map(&:to_s)
|
|
26
|
+
app.config.after_initialize { ActiveAdmin.importmap.cache_sweeper(watches: watches) }
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
# javascript_modules is pending upstream (activeadmin/activeadmin#9148).
|
|
31
|
+
# Without it the host imports the module itself, see the README.
|
|
32
|
+
config.after_initialize do
|
|
33
|
+
if ActiveAdmin.application.respond_to?(:javascript_modules)
|
|
34
|
+
ActiveAdmin.application.javascript_modules |= %w[active_admin_scoped_collection_actions]
|
|
35
|
+
end
|
|
36
|
+
end
|
|
7
37
|
end
|
|
8
38
|
end
|
|
9
|
-
end
|
|
39
|
+
end
|
|
@@ -51,10 +51,18 @@ module ActiveAdminScopedCollectionActions
|
|
|
51
51
|
|
|
52
52
|
def scoped_collection_actions_sidebar_section
|
|
53
53
|
ActiveAdmin::SidebarSection.new :collection_actions, only: :index, if: scoped_collection_sidebar_condition do
|
|
54
|
+
aa_v4 = ActiveAdminScopedCollectionActions.aa_v4?
|
|
54
55
|
|
|
55
|
-
|
|
56
|
+
if aa_v4
|
|
57
|
+
# ActiveAdmin 4 no longer wraps sidebar sections in a panel.
|
|
58
|
+
div I18n.t('active_admin_scoped_collection_actions.sidebar_msg'), class: 'mb-3 text-sm text-gray-700 dark:text-gray-300'
|
|
59
|
+
else
|
|
60
|
+
div I18n.t('active_admin_scoped_collection_actions.sidebar_msg')
|
|
61
|
+
end
|
|
56
62
|
|
|
57
|
-
|
|
63
|
+
buttons = div(class: 'flex flex-wrap gap-2', 'data-scoped-collection-actions': '') if aa_v4
|
|
64
|
+
|
|
65
|
+
actions = active_admin_config.scoped_collection_actions.each do |key, options={}|
|
|
58
66
|
next if options.key?(:if) && !call_method_or_exec_proc(options[:if])
|
|
59
67
|
|
|
60
68
|
b_title = options.fetch(:title, ::ActiveSupport::Inflector.humanize(key))
|
|
@@ -62,6 +70,9 @@ module ActiveAdminScopedCollectionActions
|
|
|
62
70
|
b_options[:class] = options[:class] if options[:class].present?
|
|
63
71
|
# Important: If user did not specify html_class, then use default
|
|
64
72
|
b_options[:class] = 'scoped_collection_action_button' unless b_options[:class]
|
|
73
|
+
b_options[:class] += ' action-item-button cursor-pointer' if aa_v4 && options[:class].blank?
|
|
74
|
+
b_options[:type] = 'button'
|
|
75
|
+
b_options['data-scoped-collection-action'] = key.to_s
|
|
65
76
|
b_data = { auth_token: form_authenticity_token.to_s }
|
|
66
77
|
b_data[:batch_action] = key.to_s
|
|
67
78
|
if options[:form].present?
|
|
@@ -82,8 +93,14 @@ module ActiveAdminScopedCollectionActions
|
|
|
82
93
|
b_data[:confirm_summary] = confirm_summary.is_a?(String) ? confirm_summary : I18n.t("active_admin_scoped_collection_actions.#{default_key}")
|
|
83
94
|
end
|
|
84
95
|
b_options[:data] = b_data.to_json
|
|
85
|
-
|
|
96
|
+
if aa_v4
|
|
97
|
+
within(buttons) { button b_title, b_options }
|
|
98
|
+
else
|
|
99
|
+
button b_title, b_options
|
|
100
|
+
end
|
|
86
101
|
end
|
|
102
|
+
# ActiveAdmin 4 prints a block result that is not an Arbre element.
|
|
103
|
+
aa_v4 ? buttons : actions
|
|
87
104
|
end
|
|
88
105
|
end
|
|
89
106
|
|
|
@@ -1,4 +1,13 @@
|
|
|
1
1
|
require 'activeadmin'
|
|
2
|
+
|
|
3
|
+
module ActiveAdminScopedCollectionActions
|
|
4
|
+
# ActiveAdmin 4 replaced jQuery UI and Sprockets with Flowbite, Tailwind and
|
|
5
|
+
# importmaps, so the sidebar markup and the dialog script differ per version.
|
|
6
|
+
def self.aa_v4?
|
|
7
|
+
Gem::Version.new(ActiveAdmin::VERSION) >= Gem::Version.new('4.0.0.beta1')
|
|
8
|
+
end
|
|
9
|
+
end
|
|
10
|
+
|
|
2
11
|
require 'active_admin_scoped_collection_actions/engine'
|
|
3
12
|
require 'active_admin_scoped_collection_actions/version'
|
|
4
13
|
require 'active_admin_scoped_collection_actions/dsl'
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: active_admin_scoped_collection_actions
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.
|
|
4
|
+
version: 2.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Gena M.
|
|
@@ -18,7 +18,7 @@ dependencies:
|
|
|
18
18
|
version: '3.0'
|
|
19
19
|
- - "<"
|
|
20
20
|
- !ruby/object:Gem::Version
|
|
21
|
-
version:
|
|
21
|
+
version: 5.0.0.a
|
|
22
22
|
type: :runtime
|
|
23
23
|
prerelease: false
|
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
|
@@ -28,7 +28,7 @@ dependencies:
|
|
|
28
28
|
version: '3.0'
|
|
29
29
|
- - "<"
|
|
30
30
|
- !ruby/object:Gem::Version
|
|
31
|
-
version:
|
|
31
|
+
version: 5.0.0.a
|
|
32
32
|
description: Plugin for ActiveAdmin. Provides batch Update and Delete for scoped_collection
|
|
33
33
|
(Filters + Scope) across all pages.
|
|
34
34
|
email:
|
|
@@ -40,6 +40,8 @@ files:
|
|
|
40
40
|
- CHANGELOG.md
|
|
41
41
|
- LICENSE.txt
|
|
42
42
|
- README.md
|
|
43
|
+
- app/javascript/active_admin_scoped_collection_actions/dialog.js
|
|
44
|
+
- config/importmap.rb
|
|
43
45
|
- config/locales/de.yml
|
|
44
46
|
- config/locales/en.yml
|
|
45
47
|
- config/locales/es.yml
|
|
@@ -74,7 +76,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
74
76
|
- !ruby/object:Gem::Version
|
|
75
77
|
version: '0'
|
|
76
78
|
requirements: []
|
|
77
|
-
rubygems_version: 3.
|
|
79
|
+
rubygems_version: 3.6.9
|
|
78
80
|
specification_version: 4
|
|
79
81
|
summary: scoped_collection actions extension for ActiveAdmin
|
|
80
82
|
test_files: []
|