headmin 0.2.5 → 0.2.6
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/Gemfile.lock +2 -2
- data/app/helpers/headmin/admin_helper.rb +3 -59
- data/app/helpers/headmin/bootstrap_helper.rb +9 -0
- data/app/helpers/headmin/filter_helper.rb +7 -3
- data/app/helpers/headmin/form_helper.rb +36 -0
- data/app/helpers/headmin/request_helper.rb +39 -0
- data/app/models/concerns/headmin/fieldable.rb +3 -1
- data/app/services/block_service.rb +8 -4
- data/app/views/headmin/_filters.html.erb +1 -1
- data/app/views/headmin/_pagination.html.erb +4 -1
- data/app/views/headmin/dropdown/_devise.html.erb +20 -10
- data/app/views/headmin/dropdown/_list.html.erb +17 -7
- data/app/views/headmin/forms/_blocks.html.erb +11 -4
- data/app/views/headmin/forms/_date.html.erb +1 -1
- data/app/views/headmin/forms/_label.html.erb +2 -2
- data/app/views/headmin/forms/_repeater.html.erb +5 -8
- data/app/views/headmin/table/_actions.html.erb +37 -11
- data/app/views/headmin/views/devise/confirmations/_new.html.erb +1 -1
- data/app/views/headmin/views/devise/passwords/_edit.html.erb +2 -2
- data/app/views/headmin/views/devise/passwords/_new.html.erb +1 -1
- data/app/views/headmin/views/devise/registrations/_edit.html.erb +4 -4
- data/app/views/headmin/views/devise/registrations/_new.html.erb +3 -3
- data/app/views/headmin/views/devise/shared/_links.html.erb +7 -7
- data/app/views/headmin/views/devise/unlocks/_new.html.erb +1 -1
- data/config/locales/activerecord/en.yml +9 -0
- data/config/locales/activerecord/nl.yml +9 -0
- data/config/locales/headmin/table/en.yml +5 -1
- data/config/locales/headmin/table/nl.yml +5 -1
- data/config/locales/headmin/views/en.yml +1 -1
- data/config/locales/headmin/views/nl.yml +14 -14
- data/dist/css/headmin.css +54 -13
- data/dist/js/headmin.js +45 -513
- data/docs/blocks.md +0 -7
- data/lib/generators/headmin/blocks_generator.rb +4 -1
- data/lib/generators/headmin/devise_generator.rb +5 -1
- data/lib/generators/headmin/fields_generator.rb +4 -1
- data/lib/generators/templates/controllers/auth/confirmations_controller.rb +31 -0
- data/lib/generators/templates/controllers/auth/omniauth_callbacks_controller.rb +31 -0
- data/lib/generators/templates/controllers/auth/passwords_controller.rb +35 -0
- data/lib/generators/templates/controllers/auth/registrations_controller.rb +63 -0
- data/lib/generators/templates/controllers/auth/sessions_controller.rb +28 -0
- data/lib/generators/templates/controllers/auth/unlocks_controller.rb +31 -0
- data/lib/headmin/version.rb +1 -1
- data/package.json +2 -1
- data/src/js/headmin/controllers/blocks_controller.js +1 -1
- data/src/js/headmin/controllers/filter_controller.js +1 -1
- data/src/js/headmin/controllers/filters_controller.js +1 -1
- data/src/js/headmin/controllers/popup_controller.js +1 -1
- data/src/js/headmin/controllers/repeater_controller.js +9 -9
- data/src/js/headmin/controllers/table_actions_controller.js +104 -9
- data/src/js/headmin/controllers/table_controller.js +28 -57
- data/src/js/headmin/headmin.js +2 -2
- data/src/scss/headmin/table.scss +1 -0
- data/yarn.lock +940 -1058
- metadata +13 -2
data/docs/blocks.md
CHANGED
@@ -30,13 +30,6 @@ A hidden template form will be rendered for all types defined in `allow:`
|
|
30
30
|
```
|
31
31
|
|
32
32
|
For each type of block you want to include, create a template in `views/admin/blocks`.
|
33
|
-
Make sure to include a hidden field to store the name of the block.
|
34
|
-
|
35
|
-
```erb
|
36
|
-
# app/views/admin/blocks/_contact.html.erb
|
37
|
-
<%= form.hidden_field :name, value: :contact %>
|
38
|
-
...
|
39
|
-
```
|
40
33
|
|
41
34
|
### Usage in frontend
|
42
35
|
|
@@ -4,8 +4,11 @@ module Headmin
|
|
4
4
|
|
5
5
|
source_root File.expand_path('../../templates', __FILE__)
|
6
6
|
|
7
|
-
def
|
7
|
+
def copy_models
|
8
8
|
template 'models/block.rb', 'app/models/block.rb'
|
9
|
+
end
|
10
|
+
|
11
|
+
def copy_migrations
|
9
12
|
migration_template 'migrations/create_blocks.rb', 'db/migrate/create_blocks.rb'
|
10
13
|
end
|
11
14
|
|
@@ -4,7 +4,11 @@ module Headmin
|
|
4
4
|
|
5
5
|
source_root File.expand_path('../../templates', __FILE__)
|
6
6
|
|
7
|
-
def
|
7
|
+
def copy_controllers
|
8
|
+
directory 'controllers/auth', 'app/controllers/auth'
|
9
|
+
end
|
10
|
+
|
11
|
+
def copy_views
|
8
12
|
directory 'views/auth', 'app/views/auth'
|
9
13
|
copy_file 'views/layouts/auth.html.erb', 'app/views/layouts/auth.html.erb'
|
10
14
|
end
|
@@ -4,8 +4,11 @@ module Headmin
|
|
4
4
|
|
5
5
|
source_root File.expand_path('../../templates', __FILE__)
|
6
6
|
|
7
|
-
def
|
7
|
+
def copy_models
|
8
8
|
template 'models/field.rb', 'app/models/field.rb'
|
9
|
+
end
|
10
|
+
|
11
|
+
def copy_migrations
|
9
12
|
migration_template 'migrations/create_fields.rb', 'db/migrate/create_fields.rb'
|
10
13
|
migration_template 'migrations/create_field_hierarchies.rb', 'db/migrate/create_field_hierarchies.rb'
|
11
14
|
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class Auth::ConfirmationsController < Devise::ConfirmationsController
|
4
|
+
layout 'auth'
|
5
|
+
# GET /resource/confirmation/new
|
6
|
+
# def new
|
7
|
+
# super
|
8
|
+
# end
|
9
|
+
|
10
|
+
# POST /resource/confirmation
|
11
|
+
# def create
|
12
|
+
# super
|
13
|
+
# end
|
14
|
+
|
15
|
+
# GET /resource/confirmation?confirmation_token=abcdef
|
16
|
+
# def show
|
17
|
+
# super
|
18
|
+
# end
|
19
|
+
|
20
|
+
# protected
|
21
|
+
|
22
|
+
# The path used after resending confirmation instructions.
|
23
|
+
# def after_resending_confirmation_instructions_path_for(resource_name)
|
24
|
+
# super(resource_name)
|
25
|
+
# end
|
26
|
+
|
27
|
+
# The path used after confirmation.
|
28
|
+
# def after_confirmation_path_for(resource_name, resource)
|
29
|
+
# super(resource_name, resource)
|
30
|
+
# end
|
31
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class Auth::OmniauthCallbacksController < Devise::OmniauthCallbacksController
|
4
|
+
layout 'auth'
|
5
|
+
# You should configure your model like this:
|
6
|
+
# devise :omniauthable, omniauth_providers: [:twitter]
|
7
|
+
|
8
|
+
# You should also create an action method in this controller like this:
|
9
|
+
# def twitter
|
10
|
+
# end
|
11
|
+
|
12
|
+
# More info at:
|
13
|
+
# https://github.com/heartcombo/devise#omniauth
|
14
|
+
|
15
|
+
# GET|POST /resource/auth/twitter
|
16
|
+
# def passthru
|
17
|
+
# super
|
18
|
+
# end
|
19
|
+
|
20
|
+
# GET|POST /users/auth/twitter/callback
|
21
|
+
# def failure
|
22
|
+
# super
|
23
|
+
# end
|
24
|
+
|
25
|
+
# protected
|
26
|
+
|
27
|
+
# The path used when OmniAuth fails
|
28
|
+
# def after_omniauth_failure_path_for(scope)
|
29
|
+
# super(scope)
|
30
|
+
# end
|
31
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class Auth::PasswordsController < Devise::PasswordsController
|
4
|
+
layout 'auth'
|
5
|
+
# GET /resource/password/new
|
6
|
+
# def new
|
7
|
+
# super
|
8
|
+
# end
|
9
|
+
|
10
|
+
# POST /resource/password
|
11
|
+
# def create
|
12
|
+
# super
|
13
|
+
# end
|
14
|
+
|
15
|
+
# GET /resource/password/edit?reset_password_token=abcdef
|
16
|
+
# def edit
|
17
|
+
# super
|
18
|
+
# end
|
19
|
+
|
20
|
+
# PUT /resource/password
|
21
|
+
# def update
|
22
|
+
# super
|
23
|
+
# end
|
24
|
+
|
25
|
+
# protected
|
26
|
+
|
27
|
+
# def after_resetting_password_path_for(resource)
|
28
|
+
# super(resource)
|
29
|
+
# end
|
30
|
+
|
31
|
+
# The path used after sending reset password instructions
|
32
|
+
# def after_sending_reset_password_instructions_path_for(resource_name)
|
33
|
+
# super(resource_name)
|
34
|
+
# end
|
35
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class Auth::RegistrationsController < Devise::RegistrationsController
|
4
|
+
layout 'auth'
|
5
|
+
# before_action :configure_sign_up_params, only: [:create]
|
6
|
+
# before_action :configure_account_update_params, only: [:update]
|
7
|
+
|
8
|
+
# GET /resource/sign_up
|
9
|
+
# def new
|
10
|
+
# super
|
11
|
+
# end
|
12
|
+
|
13
|
+
# POST /resource
|
14
|
+
# def create
|
15
|
+
# super
|
16
|
+
# end
|
17
|
+
|
18
|
+
# GET /resource/edit
|
19
|
+
# def edit
|
20
|
+
# super
|
21
|
+
# end
|
22
|
+
|
23
|
+
# PUT /resource
|
24
|
+
# def update
|
25
|
+
# super
|
26
|
+
# end
|
27
|
+
|
28
|
+
# DELETE /resource
|
29
|
+
# def destroy
|
30
|
+
# super
|
31
|
+
# end
|
32
|
+
|
33
|
+
# GET /resource/cancel
|
34
|
+
# Forces the session data which is usually expired after sign
|
35
|
+
# in to be expired now. This is useful if the user wants to
|
36
|
+
# cancel oauth signing in/up in the middle of the process,
|
37
|
+
# removing all OAuth session data.
|
38
|
+
# def cancel
|
39
|
+
# super
|
40
|
+
# end
|
41
|
+
|
42
|
+
# protected
|
43
|
+
|
44
|
+
# If you have extra params to permit, append them to the sanitizer.
|
45
|
+
# def configure_sign_up_params
|
46
|
+
# devise_parameter_sanitizer.permit(:sign_up, keys: [:attribute])
|
47
|
+
# end
|
48
|
+
|
49
|
+
# If you have extra params to permit, append them to the sanitizer.
|
50
|
+
# def configure_account_update_params
|
51
|
+
# devise_parameter_sanitizer.permit(:account_update, keys: [:attribute])
|
52
|
+
# end
|
53
|
+
|
54
|
+
# The path used after sign up.
|
55
|
+
# def after_sign_up_path_for(resource)
|
56
|
+
# super(resource)
|
57
|
+
# end
|
58
|
+
|
59
|
+
# The path used after sign up for inactive accounts.
|
60
|
+
# def after_inactive_sign_up_path_for(resource)
|
61
|
+
# super(resource)
|
62
|
+
# end
|
63
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class Auth::SessionsController < Devise::SessionsController
|
4
|
+
layout 'auth'
|
5
|
+
# before_action :configure_sign_in_params, only: [:create]
|
6
|
+
|
7
|
+
# GET /resource/sign_in
|
8
|
+
# def new
|
9
|
+
# super
|
10
|
+
# end
|
11
|
+
|
12
|
+
# POST /resource/sign_in
|
13
|
+
# def create
|
14
|
+
# super
|
15
|
+
# end
|
16
|
+
|
17
|
+
# DELETE /resource/sign_out
|
18
|
+
# def destroy
|
19
|
+
# super
|
20
|
+
# end
|
21
|
+
|
22
|
+
# protected
|
23
|
+
|
24
|
+
# If you have extra params to permit, append them to the sanitizer.
|
25
|
+
# def configure_sign_in_params
|
26
|
+
# devise_parameter_sanitizer.permit(:sign_in, keys: [:attribute])
|
27
|
+
# end
|
28
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class Auth::UnlocksController < Devise::UnlocksController
|
4
|
+
layout 'auth'
|
5
|
+
# GET /resource/unlock/new
|
6
|
+
# def new
|
7
|
+
# super
|
8
|
+
# end
|
9
|
+
|
10
|
+
# POST /resource/unlock
|
11
|
+
# def create
|
12
|
+
# super
|
13
|
+
# end
|
14
|
+
|
15
|
+
# GET /resource/unlock?unlock_token=abcdef
|
16
|
+
# def show
|
17
|
+
# super
|
18
|
+
# end
|
19
|
+
|
20
|
+
# protected
|
21
|
+
|
22
|
+
# The path used after sending unlock password instructions
|
23
|
+
# def after_sending_unlock_instructions_path_for(resource)
|
24
|
+
# super(resource)
|
25
|
+
# end
|
26
|
+
|
27
|
+
# The path used after unlocking the resource
|
28
|
+
# def after_unlock_path_for(resource)
|
29
|
+
# super(resource)
|
30
|
+
# end
|
31
|
+
end
|
data/lib/headmin/version.rb
CHANGED
data/package.json
CHANGED
@@ -20,13 +20,14 @@
|
|
20
20
|
},
|
21
21
|
"homepage": "https://github.com/insiting/headmin#readme",
|
22
22
|
"dependencies": {
|
23
|
+
"@hotwired/stimulus": "^3.0",
|
24
|
+
"@hotwired/stimulus-webpack-helpers": "^1.0",
|
23
25
|
"@popperjs/core": "^2.9.3",
|
24
26
|
"@rails/ujs": "^6.0.0",
|
25
27
|
"bootstrap": "^5.1.1",
|
26
28
|
"ckeditor5-build-classic-simple-upload-adapter-image-resize": "^1.0.4",
|
27
29
|
"flatpickr": "^4.6.9",
|
28
30
|
"sortablejs": "^1.13.0",
|
29
|
-
"stimulus": "^2.0.0",
|
30
31
|
"tom-select": "^2.0.0-rc.4"
|
31
32
|
},
|
32
33
|
"devDependencies": {
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import {Controller} from "stimulus"
|
1
|
+
import {Controller} from "@hotwired/stimulus"
|
2
2
|
import Sortable from "sortablejs";
|
3
3
|
|
4
4
|
export default class extends Controller {
|
@@ -52,8 +52,8 @@ export default class extends Controller {
|
|
52
52
|
let rowIndex = button.dataset.rowIndex
|
53
53
|
|
54
54
|
// Prepare html from template
|
55
|
-
|
56
|
-
html = this.replaceIdsWithTimestamps(
|
55
|
+
const template = this.getTemplate(templateName)
|
56
|
+
const html = this.replaceIdsWithTimestamps(template)
|
57
57
|
|
58
58
|
// Fallback to last row if no index is set
|
59
59
|
if (rowIndex) {
|
@@ -92,16 +92,16 @@ export default class extends Controller {
|
|
92
92
|
this.toggleEmpty()
|
93
93
|
}
|
94
94
|
|
95
|
-
|
96
|
-
|
95
|
+
getTemplate(name) {
|
96
|
+
return this.templateTargets.filter((template) => {
|
97
97
|
return template.dataset.templateName === name
|
98
98
|
})[0]
|
99
|
-
return template.innerHTML
|
100
99
|
}
|
101
100
|
|
102
|
-
replaceIdsWithTimestamps(
|
103
|
-
|
104
|
-
|
101
|
+
replaceIdsWithTimestamps(template) {
|
102
|
+
console.log(template)
|
103
|
+
const regex = new RegExp(template.dataset.templateIdRegex, "g")
|
104
|
+
return template.innerHTML.replace(regex, new Date().getTime())
|
105
105
|
}
|
106
106
|
|
107
107
|
visibleRowsCount() {
|
@@ -1,33 +1,128 @@
|
|
1
|
-
import {Controller} from "stimulus"
|
1
|
+
import {Controller} from "@hotwired/stimulus"
|
2
2
|
|
3
3
|
export default class extends Controller {
|
4
|
+
static get values() {
|
5
|
+
return {
|
6
|
+
count: {type: Number, default: 0}
|
7
|
+
}
|
8
|
+
}
|
9
|
+
|
4
10
|
static get targets() {
|
5
|
-
return ["form", "select", "method", "button"]
|
11
|
+
return ["wrapper", "form", "select", "method", "button", "idInputTemplate", "id", "counter"]
|
6
12
|
}
|
7
13
|
|
8
14
|
connect() {
|
9
|
-
this.
|
15
|
+
this.wrapperTarget.addEventListener('idSelectionChanged', (event) => {
|
16
|
+
const ids = event.detail.ids
|
17
|
+
this.updateIdFields(ids)
|
18
|
+
this.updateCountValueWithIds(ids)
|
19
|
+
})
|
20
|
+
|
10
21
|
}
|
11
22
|
|
12
23
|
update(event) {
|
13
24
|
event.preventDefault()
|
14
|
-
|
25
|
+
this.updateFormAction()
|
26
|
+
this.updateFormMethod()
|
27
|
+
this.updateButton()
|
28
|
+
}
|
29
|
+
|
30
|
+
updateIdFields(ids) {
|
31
|
+
this.removeIds()
|
32
|
+
if (ids instanceof Array) {
|
33
|
+
this.countValue = ids.length
|
34
|
+
ids.forEach((id) => {
|
35
|
+
this.addId(id)
|
36
|
+
})
|
37
|
+
} else {
|
38
|
+
this.countValue = Infinity
|
39
|
+
this.addId('')
|
40
|
+
}
|
41
|
+
}
|
15
42
|
|
16
|
-
|
43
|
+
updateCounter() {
|
44
|
+
let htmlString = ''
|
45
|
+
switch (this.countValue) {
|
46
|
+
case 0:
|
47
|
+
htmlString = this.counterTarget.getAttribute('data-items-zero')
|
48
|
+
break;
|
49
|
+
case 1:
|
50
|
+
htmlString = this.counterTarget.getAttribute('data-items-one')
|
51
|
+
break;
|
52
|
+
case Infinity:
|
53
|
+
htmlString = this.counterTarget.getAttribute('data-items-other')
|
54
|
+
htmlString = htmlString.replace(/<b>[\s\S]*?<\/b>/, '<b>' + this.totalCount() + '<\/b>');
|
55
|
+
break;
|
56
|
+
default:
|
57
|
+
htmlString = this.counterTarget.getAttribute('data-items-other')
|
58
|
+
let count = this.countValue === Infinity ? this.totalCount() : this.countValue
|
59
|
+
htmlString = htmlString.replace(/<b>[\s\S]*?<\/b>/, `<b>${count}<\/b>`);
|
60
|
+
}
|
61
|
+
this.counterTarget.innerHTML = htmlString;
|
62
|
+
}
|
63
|
+
|
64
|
+
totalCount() {
|
65
|
+
return this.counterTarget.getAttribute('data-total-count')
|
66
|
+
}
|
67
|
+
|
68
|
+
updateCountValueWithIds(ids) {
|
69
|
+
if (ids instanceof Array) {
|
70
|
+
this.countValue = ids.length
|
71
|
+
} else {
|
72
|
+
this.countValue = Infinity
|
73
|
+
}
|
74
|
+
}
|
75
|
+
|
76
|
+
countValueChanged() {
|
77
|
+
this.updateCounter()
|
78
|
+
this.toggle()
|
79
|
+
}
|
80
|
+
|
81
|
+
toggle() {
|
82
|
+
if (this.countValue > 0) {
|
83
|
+
this.wrapperTarget.classList.remove('d-none')
|
84
|
+
} else {
|
85
|
+
this.wrapperTarget.classList.add('d-none')
|
86
|
+
}
|
87
|
+
}
|
88
|
+
|
89
|
+
updateFormAction() {
|
17
90
|
this.formTarget.action = this.selectTarget.value
|
91
|
+
}
|
18
92
|
|
19
|
-
|
93
|
+
updateFormMethod() {
|
94
|
+
const option = this.selectedOption()
|
20
95
|
this.methodTarget.value = option.dataset.method
|
96
|
+
}
|
21
97
|
|
22
|
-
|
98
|
+
updateButton() {
|
99
|
+
const option = this.selectedOption()
|
23
100
|
const confirm = option.dataset.confirm
|
24
|
-
if(confirm) {
|
101
|
+
if (confirm) {
|
25
102
|
this.buttonTarget.dataset.confirm = confirm
|
26
103
|
} else {
|
27
104
|
this.buttonTarget.removeAttribute('data-confirm')
|
28
105
|
}
|
106
|
+
this.enableButton()
|
107
|
+
}
|
108
|
+
|
109
|
+
selectedOption() {
|
110
|
+
return this.selectTarget.options[this.selectTarget.selectedIndex]
|
111
|
+
}
|
29
112
|
|
30
|
-
|
113
|
+
enableButton() {
|
31
114
|
this.buttonTarget.removeAttribute('disabled')
|
32
115
|
}
|
116
|
+
|
117
|
+
addId(id) {
|
118
|
+
const template = this.idInputTemplateTarget
|
119
|
+
const input = template.innerHTML.replace(/ID/g, id)
|
120
|
+
this.formTarget.insertAdjacentHTML('afterbegin', input)
|
121
|
+
}
|
122
|
+
|
123
|
+
removeIds() {
|
124
|
+
this.idTargets.forEach((input) => {
|
125
|
+
this.formTarget.removeChild(input)
|
126
|
+
});
|
127
|
+
}
|
33
128
|
}
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import {Controller} from "stimulus"
|
1
|
+
import {Controller} from "@hotwired/stimulus"
|
2
2
|
import Sortable from "sortablejs";
|
3
3
|
import Rails from "@rails/ujs";
|
4
4
|
|
@@ -38,25 +38,43 @@ export default class extends Controller {
|
|
38
38
|
const checkbox = event.target
|
39
39
|
this.toggleIdsCheckboxes(checkbox.checked)
|
40
40
|
this.toggleIdCheckboxes(checkbox.checked)
|
41
|
-
this.
|
42
|
-
this.toggleActions()
|
41
|
+
this.updateActions()
|
43
42
|
}
|
44
43
|
|
45
44
|
toggleId(event) {
|
46
45
|
this.toggleIdsCheckboxes(false)
|
47
|
-
this.
|
48
|
-
this.toggleActions()
|
46
|
+
this.updateActions()
|
49
47
|
}
|
50
48
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
49
|
+
updateActions() {
|
50
|
+
this.actionsTarget.dispatchEvent(
|
51
|
+
new CustomEvent(
|
52
|
+
'idSelectionChanged',
|
53
|
+
{
|
54
|
+
detail: {
|
55
|
+
ids: this.ids()
|
56
|
+
}
|
57
|
+
}
|
58
|
+
)
|
59
|
+
)
|
60
|
+
}
|
61
|
+
|
62
|
+
ids() {
|
63
|
+
if (this.idsCheckboxTarget.checked) {
|
64
|
+
return null
|
55
65
|
} else {
|
56
|
-
this.
|
66
|
+
return this.selectedIdCheckboxes().map((checkbox) => {
|
67
|
+
return checkbox.value
|
68
|
+
})
|
57
69
|
}
|
58
70
|
}
|
59
71
|
|
72
|
+
selectedIdCheckboxes() {
|
73
|
+
return this.idCheckboxTargets.filter((checkbox) => {
|
74
|
+
return checkbox.checked
|
75
|
+
})
|
76
|
+
}
|
77
|
+
|
60
78
|
toggleIdsCheckboxes(checked) {
|
61
79
|
this.idsCheckboxTargets.forEach((checkbox) => {
|
62
80
|
checkbox.checked = checked
|
@@ -69,51 +87,4 @@ export default class extends Controller {
|
|
69
87
|
});
|
70
88
|
}
|
71
89
|
|
72
|
-
syncFields() {
|
73
|
-
this.removeIds()
|
74
|
-
if(this.idsCheckboxTarget.checked) {
|
75
|
-
this.addId('')
|
76
|
-
} else {
|
77
|
-
this.idCheckboxTargets.forEach((checkbox) => {
|
78
|
-
if(checkbox.checked) {
|
79
|
-
this.addId(checkbox.value)
|
80
|
-
}
|
81
|
-
});
|
82
|
-
}
|
83
|
-
}
|
84
|
-
|
85
|
-
addId(id) {
|
86
|
-
let field = this.getIdField(id)
|
87
|
-
if (!field) {
|
88
|
-
field = this.newIdField(id)
|
89
|
-
this.actionsTarget.querySelector('form').insertAdjacentHTML('afterbegin', field)
|
90
|
-
}
|
91
|
-
}
|
92
|
-
|
93
|
-
removeIds() {
|
94
|
-
const fields = this.getIdFields()
|
95
|
-
fields.forEach((field) => {
|
96
|
-
this.actionsTarget.querySelector('form').removeChild(field)
|
97
|
-
});
|
98
|
-
}
|
99
|
-
|
100
|
-
removeId(id) {
|
101
|
-
const field = this.getIdField(id)
|
102
|
-
if (field) {
|
103
|
-
this.actionsTarget.querySelector('form').removeChild(field)
|
104
|
-
}
|
105
|
-
}
|
106
|
-
|
107
|
-
newIdField(id) {
|
108
|
-
const template = this.actionsTarget.querySelector('[data-table-target="idFieldTemplate"]')
|
109
|
-
return template.innerHTML.replace(/ID/g, id)
|
110
|
-
}
|
111
|
-
|
112
|
-
getIdFields() {
|
113
|
-
return this.actionsTarget.querySelectorAll(`input[name="ids[]"]`);
|
114
|
-
}
|
115
|
-
|
116
|
-
getIdField(id) {
|
117
|
-
return this.actionsTarget.querySelector(`input[name="ids[]"][value="${id}"]`);
|
118
|
-
}
|
119
90
|
}
|
data/src/js/headmin/headmin.js
CHANGED
@@ -4,8 +4,8 @@ import flatpickr from "flatpickr";
|
|
4
4
|
import bootstrap from "bootstrap/dist/js/bootstrap.bundle";
|
5
5
|
import Rails from "@rails/ujs";
|
6
6
|
|
7
|
-
import {Application} from "stimulus"
|
8
|
-
import {definitionsFromContext} from "stimulus
|
7
|
+
import {Application} from "@hotwired/stimulus"
|
8
|
+
import {definitionsFromContext} from "@hotwired/stimulus-webpack-helpers"
|
9
9
|
|
10
10
|
export class Headmin {
|
11
11
|
static start() {
|