headmin 0.3.4 → 0.4.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 +4 -4
- data/.github/workflows/ci.yml +27 -0
- data/.gitignore +14 -0
- data/.lock-487e157d270f3062a98b7b2a012753708-1272821827 +0 -0
- data/.nvmrc +1 -0
- data/CHANGELOG.md +31 -0
- data/Gemfile +7 -4
- data/Gemfile.lock +191 -25
- data/README.md +7 -0
- data/Rakefile +1 -7
- data/app/assets/javascripts/headmin/config/i18n.js +9 -9
- data/app/assets/javascripts/headmin/controllers/autocomplete_controller.js +318 -0
- data/app/assets/javascripts/headmin/controllers/blocks_controller.js +74 -79
- data/app/assets/javascripts/headmin/controllers/date_range_controller.js +24 -24
- data/app/assets/javascripts/headmin/controllers/dropzone_controller.js +23 -25
- data/app/assets/javascripts/headmin/controllers/file_preview_controller.js +237 -237
- data/app/assets/javascripts/headmin/controllers/filter_controller.js +44 -44
- data/app/assets/javascripts/headmin/controllers/filters_controller.js +57 -61
- data/app/assets/javascripts/headmin/controllers/flatpickr_controller.js +29 -29
- data/app/assets/javascripts/headmin/controllers/hello_controller.js +3 -3
- data/app/assets/javascripts/headmin/controllers/notification_controller.js +7 -6
- data/app/assets/javascripts/headmin/controllers/popup_controller.js +57 -51
- data/app/assets/javascripts/headmin/controllers/redactorx_controller.js +36 -9
- data/app/assets/javascripts/headmin/controllers/repeater_controller.js +122 -125
- data/app/assets/javascripts/headmin/controllers/select_controller.js +40 -39
- data/app/assets/javascripts/headmin/controllers/table_actions_controller.js +100 -101
- data/app/assets/javascripts/headmin/controllers/table_controller.js +115 -115
- data/app/assets/javascripts/headmin/index.js +38 -35
- data/app/assets/javascripts/headmin.js +295 -37
- data/app/assets/stylesheets/headmin/forms/autocomplete.scss +21 -0
- data/app/assets/stylesheets/headmin/forms/file.scss +46 -0
- data/app/assets/stylesheets/headmin/forms/repeater.scss +62 -0
- data/app/assets/stylesheets/headmin/forms/search.scss +12 -0
- data/app/assets/stylesheets/headmin/forms.scss +11 -0
- data/app/assets/stylesheets/headmin/general.scss +14 -0
- data/app/assets/stylesheets/headmin/overrides/bootstrap.scss +5 -3
- data/app/assets/stylesheets/headmin/overrides/redactorx.scss +74 -0
- data/app/assets/stylesheets/headmin/popup.scss +1 -0
- data/app/assets/stylesheets/headmin/syntax.scss +36 -349
- data/app/assets/stylesheets/headmin/table.scss +1 -1
- data/app/assets/stylesheets/headmin/utilities/buttons.scss +19 -0
- data/app/assets/stylesheets/headmin/utilities/dropzone.scss +72 -0
- data/app/assets/stylesheets/headmin/utilities.scss +2 -68
- data/app/assets/stylesheets/headmin.css +209 -205
- data/app/assets/stylesheets/headmin.scss +1 -1
- data/app/helpers/headmin/admin_helper.rb +0 -1
- data/app/helpers/headmin/form_helper.rb +2 -8
- data/app/models/concerns/headmin/blockable.rb +1 -1
- data/app/models/concerns/headmin/field.rb +4 -1
- data/app/models/concerns/headmin/fieldable.rb +138 -44
- data/app/models/concerns/headmin/form/autocompletable.rb +38 -0
- data/app/models/concerns/headmin/form/hintable.rb +19 -0
- data/app/models/concerns/headmin/form/input_groupable.rb +23 -0
- data/app/models/concerns/headmin/form/labelable.rb +33 -0
- data/app/models/concerns/headmin/form/listable.rb +28 -0
- data/app/models/concerns/headmin/form/placeholderable.rb +13 -0
- data/app/models/concerns/headmin/form/validatable.rb +40 -0
- data/app/models/concerns/headmin/form/wrappable.rb +21 -0
- data/app/models/headmin/.DS_Store +0 -0
- data/app/models/headmin/blocks_view.rb +15 -0
- data/app/models/headmin/form/blocks_view.rb +29 -0
- data/app/models/headmin/form/checkbox_view.rb +52 -0
- data/app/models/headmin/form/date_range_view.rb +25 -0
- data/app/models/headmin/form/date_view.rb +45 -0
- data/app/models/headmin/form/email_view.rb +48 -0
- data/app/models/headmin/form/file_view.rb +116 -0
- data/app/models/headmin/form/flatpickr_range_view.rb +102 -0
- data/app/models/headmin/form/flatpickr_view.rb +37 -0
- data/app/models/headmin/form/hidden_view.rb +10 -0
- data/app/models/headmin/form/hint_view.rb +6 -0
- data/app/models/headmin/form/input_group_view.rb +19 -0
- data/app/models/headmin/form/label_view.rb +24 -0
- data/app/models/headmin/form/number_view.rb +49 -0
- data/app/models/headmin/form/password_view.rb +44 -0
- data/app/models/headmin/form/redactorx_view.rb +59 -0
- data/app/models/headmin/form/search_view.rb +48 -0
- data/app/models/headmin/form/select_view.rb +62 -0
- data/app/models/headmin/form/switch_view.rb +23 -0
- data/app/models/headmin/form/text_view.rb +48 -0
- data/app/models/headmin/form/textarea_view.rb +44 -0
- data/app/models/headmin/form/url_view.rb +48 -0
- data/app/models/headmin/form/wrapper_view.rb +19 -0
- data/app/models/headmin/form/wysiwyg_view.rb +17 -0
- data/app/models/headmin/{thumbnail.rb → thumbnail_view.rb} +6 -1
- data/app/models/view_model.rb +58 -0
- data/app/views/headmin/_blocks.html.erb +13 -9
- data/app/views/headmin/_heading.html.erb +7 -1
- data/app/views/headmin/_thumbnail.html.erb +1 -37
- data/app/views/headmin/forms/_autocomplete.html.erb +11 -0
- data/app/views/headmin/forms/_blocks.html.erb +16 -17
- data/app/views/headmin/forms/_checkbox.html.erb +24 -29
- data/app/views/headmin/forms/_datalist.html.erb +3 -0
- data/app/views/headmin/forms/_date.html.erb +24 -24
- data/app/views/headmin/forms/_date_range.html.erb +19 -21
- data/app/views/headmin/forms/_email.html.erb +27 -32
- data/app/views/headmin/forms/_errors.html.erb +2 -3
- data/app/views/headmin/forms/_file.html.erb +84 -181
- data/app/views/headmin/forms/_flatpickr.html.erb +19 -20
- data/app/views/headmin/forms/_flatpickr_range.html.erb +28 -37
- data/app/views/headmin/forms/_hidden.html.erb +9 -10
- data/app/views/headmin/forms/_hint.html.erb +16 -0
- data/app/views/headmin/forms/_input_group.html.erb +21 -0
- data/app/views/headmin/forms/_label.html.erb +5 -13
- data/app/views/headmin/forms/_number.html.erb +23 -35
- data/app/views/headmin/forms/_password.html.erb +21 -30
- data/app/views/headmin/forms/_redactorx.html.erb +21 -40
- data/app/views/headmin/forms/_repeater.html.erb +55 -60
- data/app/views/headmin/forms/_search.html.erb +43 -0
- data/app/views/headmin/forms/_select.html.erb +24 -49
- data/app/views/headmin/forms/_switch.html.erb +29 -0
- data/app/views/headmin/forms/_text.html.erb +42 -96
- data/app/views/headmin/forms/_textarea.html.erb +21 -32
- data/app/views/headmin/forms/_url.html.erb +26 -31
- data/app/views/headmin/forms/_validation.html.erb +10 -13
- data/app/views/headmin/forms/_wrapper.html.erb +9 -0
- data/app/views/headmin/forms/_wysiwyg.html.erb +28 -0
- data/app/views/headmin/forms/autocomplete/_item.html.erb +3 -0
- data/app/views/headmin/forms/autocomplete/_list.html.erb +3 -0
- data/app/views/headmin/forms/fields/_file.html.erb +1 -1
- data/app/views/headmin/forms/fields/_files.html.erb +17 -0
- data/app/views/headmin/forms/fields/_group.html.erb +9 -2
- data/app/views/headmin/forms/repeater/_row.html.erb +4 -4
- data/bin/console +0 -1
- data/config/locales/headmin/forms/en.yml +1 -12
- data/config/locales/headmin/forms/nl.yml +1 -12
- data/esbuild-css.js +18 -18
- data/esbuild-js.js +8 -8
- data/headmin.gemspec +1 -3
- data/lib/generators/templates/controllers/auth/confirmations_controller.rb +0 -2
- data/lib/generators/templates/controllers/auth/omniauth_callbacks_controller.rb +0 -2
- data/lib/generators/templates/controllers/auth/passwords_controller.rb +0 -2
- data/lib/generators/templates/controllers/auth/registrations_controller.rb +0 -2
- data/lib/generators/templates/controllers/auth/sessions_controller.rb +0 -2
- data/lib/generators/templates/controllers/auth/unlocks_controller.rb +0 -2
- data/lib/headmin/version.rb +1 -3
- data/lib/headmin.rb +0 -2
- data/package-lock.json +5359 -0
- data/package.json +12 -4
- data/view_model_benchmark.rb +74 -0
- data/yarn-error.log +17 -12
- data/yarn.lock +1575 -31
- metadata +64 -25
- data/app/assets/stylesheets/headmin/form.scss +0 -132
- data/app/assets/stylesheets/headmin/overrides/redactorx.css +0 -3
- data/app/helpers/headmin/documentation_helper.rb +0 -35
- data/app/models/headmin/documentation_renderer.rb +0 -32
- data/app/models/headmin/form/base.rb +0 -78
- data/app/models/headmin/form/text.rb +0 -51
- data/app/services/block_service.rb +0 -72
- data/app/views/headmin/_card.html.erb +0 -52
- data/app/views/headmin/forms/_actions.html.erb +0 -28
- data/app/views/headmin/forms/_base.html.erb +0 -114
- data/app/views/headmin/forms/_image.html.erb +0 -21
- data/app/views/headmin/forms/_video.html.erb +0 -21
- data/app/views/headmin/forms/actions/_destroy.html.erb +0 -13
- data/app/views/headmin/forms/actions/_save.html.erb +0 -12
- data/app/views/headmin/forms/actions/_view.html.erb +0 -15
- data/app/views/headmin/forms/fields/_image.html.erb +0 -17
- data/docs/blocks-and-fields.md +0 -54
- data/docs/blocks.md +0 -48
- data/docs/devise.md +0 -41
- data/docs/fields.md +0 -79
@@ -1,48 +1,49 @@
|
|
1
|
-
import {Controller} from
|
2
|
-
import TomSelect from
|
3
|
-
import I18n from
|
1
|
+
import { Controller } from '@hotwired/stimulus'
|
2
|
+
import TomSelect from 'tom-select'
|
3
|
+
import I18n from '../config/i18n'
|
4
4
|
|
5
5
|
export default class extends Controller {
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
}
|
6
|
+
connect () {
|
7
|
+
if (this.element.hasAttribute('multiple')) {
|
8
|
+
this.initTomSelect()
|
10
9
|
}
|
10
|
+
}
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
}
|
33
|
-
}
|
12
|
+
defaultOptions (locale) {
|
13
|
+
const defaultOptions = {
|
14
|
+
en: {
|
15
|
+
render: {
|
16
|
+
option_create: function (data, escape) {
|
17
|
+
return '<div class="create">Add <strong>' + escape(data.input) + '</strong>…</div>'
|
18
|
+
},
|
19
|
+
no_results: function (data, escape) {
|
20
|
+
return '<div class="no-results">No results found</div>'
|
21
|
+
}
|
22
|
+
}
|
23
|
+
},
|
24
|
+
nl: {
|
25
|
+
render: {
|
26
|
+
option_create: function (data, escape) {
|
27
|
+
return '<div class="create">Voeg <strong>' + escape(data.input) + '</strong> toe …</div>'
|
28
|
+
},
|
29
|
+
no_results: function (data, escape) {
|
30
|
+
return '<div class="no-results">Geen resultaten gevonden</div>'
|
31
|
+
}
|
34
32
|
}
|
35
|
-
|
33
|
+
}
|
36
34
|
}
|
35
|
+
return defaultOptions[locale]
|
36
|
+
}
|
37
37
|
|
38
|
-
|
39
|
-
|
40
|
-
|
38
|
+
hasTags () {
|
39
|
+
return this.element.dataset.tags === 'true'
|
40
|
+
}
|
41
41
|
|
42
|
-
|
43
|
-
|
44
|
-
|
42
|
+
initTomSelect () {
|
43
|
+
const defaultOptions = this.defaultOptions(I18n.locale)
|
44
|
+
const options = { create: this.hasTags() }
|
45
45
|
|
46
|
-
|
47
|
-
}
|
48
|
-
}
|
46
|
+
/* eslint-disable no-new */
|
47
|
+
new TomSelect(this.element, { ...defaultOptions, ...options })
|
48
|
+
}
|
49
|
+
}
|
@@ -1,110 +1,109 @@
|
|
1
|
-
import {Controller} from
|
1
|
+
import { Controller } from '@hotwired/stimulus'
|
2
2
|
|
3
3
|
export default class extends Controller {
|
4
|
-
|
5
|
-
|
4
|
+
static get targets () {
|
5
|
+
return ['wrapper', 'form', 'select', 'method', 'button', 'idInputTemplate', 'id', 'counter']
|
6
|
+
}
|
7
|
+
|
8
|
+
connect () {
|
9
|
+
this.wrapperTarget.addEventListener('idSelectionChanged', (event) => {
|
10
|
+
this.updateIdFields(event.detail.ids)
|
11
|
+
this.updateCounter(event.detail.count)
|
12
|
+
this.toggleCounter(event.detail.count)
|
13
|
+
})
|
14
|
+
}
|
15
|
+
|
16
|
+
update (event) {
|
17
|
+
event.preventDefault()
|
18
|
+
this.updateFormAction()
|
19
|
+
this.updateFormMethod()
|
20
|
+
this.updateFormDataAttributes()
|
21
|
+
this.enableButton()
|
22
|
+
}
|
23
|
+
|
24
|
+
updateIdFields (ids) {
|
25
|
+
this.removeIds()
|
26
|
+
if (ids instanceof Array) {
|
27
|
+
ids.forEach((id) => {
|
28
|
+
this.addId(id)
|
29
|
+
})
|
30
|
+
} else {
|
31
|
+
this.addId('')
|
6
32
|
}
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
this.
|
20
|
-
|
21
|
-
this.updateFormDataAttributes()
|
22
|
-
this.enableButton()
|
23
|
-
}
|
24
|
-
|
25
|
-
updateIdFields(ids) {
|
26
|
-
this.removeIds()
|
27
|
-
if (ids instanceof Array) {
|
28
|
-
ids.forEach((id) => {
|
29
|
-
this.addId(id)
|
30
|
-
})
|
31
|
-
} else {
|
32
|
-
this.addId('')
|
33
|
-
}
|
34
|
-
}
|
35
|
-
|
36
|
-
updateCounter(count) {
|
37
|
-
let htmlString = ''
|
38
|
-
switch (count) {
|
39
|
-
case 0:
|
40
|
-
htmlString = this.counterTarget.getAttribute('data-items-zero')
|
41
|
-
break;
|
42
|
-
case 1:
|
43
|
-
htmlString = this.counterTarget.getAttribute('data-items-one')
|
44
|
-
break;
|
45
|
-
default:
|
46
|
-
htmlString = this.counterTarget.getAttribute('data-items-other')
|
47
|
-
htmlString = htmlString.replace(/<b>[\s\S]*?<\/b>/, `<b>${count}<\/b>`);
|
48
|
-
}
|
49
|
-
this.counterTarget.innerHTML = htmlString;
|
50
|
-
}
|
51
|
-
|
52
|
-
toggleCounter(count) {
|
53
|
-
if (count > 0) {
|
54
|
-
this.wrapperTarget.classList.remove('d-none')
|
55
|
-
} else {
|
56
|
-
this.wrapperTarget.classList.add('d-none')
|
57
|
-
}
|
58
|
-
}
|
59
|
-
|
60
|
-
updateFormAction() {
|
61
|
-
this.formTarget.action = this.selectTarget.value
|
33
|
+
}
|
34
|
+
|
35
|
+
updateCounter (count) {
|
36
|
+
let htmlString = ''
|
37
|
+
switch (count) {
|
38
|
+
case 0:
|
39
|
+
htmlString = this.counterTarget.getAttribute('data-items-zero')
|
40
|
+
break
|
41
|
+
case 1:
|
42
|
+
htmlString = this.counterTarget.getAttribute('data-items-one')
|
43
|
+
break
|
44
|
+
default:
|
45
|
+
htmlString = this.counterTarget.getAttribute('data-items-other')
|
46
|
+
htmlString = htmlString.replace(/<b>[\s\S]*?<\/b>/, `<b>${count}</b>`)
|
62
47
|
}
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
this.updateFormDataConfirm(option.dataset.turboConfirm)
|
72
|
-
this.updateFormDataTurbo(option.dataset.turbo)
|
73
|
-
}
|
74
|
-
|
75
|
-
updateFormDataConfirm(confirm) {
|
76
|
-
if (confirm) {
|
77
|
-
this.formTarget.dataset.turboConfirm = confirm
|
78
|
-
} else {
|
79
|
-
this.formTarget.removeAttribute('data-turbo-confirm')
|
80
|
-
}
|
81
|
-
}
|
82
|
-
|
83
|
-
updateFormDataTurbo(turbo) {
|
84
|
-
if (turbo) {
|
85
|
-
this.formTarget.dataset.turbo = turbo
|
86
|
-
} else {
|
87
|
-
this.formTarget.removeAttribute('data-turbo')
|
88
|
-
}
|
89
|
-
}
|
90
|
-
|
91
|
-
selectedOption() {
|
92
|
-
return this.selectTarget.options[this.selectTarget.selectedIndex]
|
48
|
+
this.counterTarget.innerHTML = htmlString
|
49
|
+
}
|
50
|
+
|
51
|
+
toggleCounter (count) {
|
52
|
+
if (count > 0) {
|
53
|
+
this.wrapperTarget.classList.remove('d-none')
|
54
|
+
} else {
|
55
|
+
this.wrapperTarget.classList.add('d-none')
|
93
56
|
}
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
57
|
+
}
|
58
|
+
|
59
|
+
updateFormAction () {
|
60
|
+
this.formTarget.action = this.selectTarget.value
|
61
|
+
}
|
62
|
+
|
63
|
+
updateFormMethod () {
|
64
|
+
const option = this.selectedOption()
|
65
|
+
this.methodTarget.value = option.dataset.method
|
66
|
+
}
|
67
|
+
|
68
|
+
updateFormDataAttributes () {
|
69
|
+
const option = this.selectedOption()
|
70
|
+
this.updateFormDataConfirm(option.dataset.turboConfirm)
|
71
|
+
this.updateFormDataTurbo(option.dataset.turbo)
|
72
|
+
}
|
73
|
+
|
74
|
+
updateFormDataConfirm (confirm) {
|
75
|
+
if (confirm) {
|
76
|
+
this.formTarget.dataset.turboConfirm = confirm
|
77
|
+
} else {
|
78
|
+
this.formTarget.removeAttribute('data-turbo-confirm')
|
103
79
|
}
|
80
|
+
}
|
104
81
|
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
82
|
+
updateFormDataTurbo (turbo) {
|
83
|
+
if (turbo) {
|
84
|
+
this.formTarget.dataset.turbo = turbo
|
85
|
+
} else {
|
86
|
+
this.formTarget.removeAttribute('data-turbo')
|
109
87
|
}
|
88
|
+
}
|
89
|
+
|
90
|
+
selectedOption () {
|
91
|
+
return this.selectTarget.options[this.selectTarget.selectedIndex]
|
92
|
+
}
|
93
|
+
|
94
|
+
enableButton () {
|
95
|
+
this.buttonTarget.removeAttribute('disabled')
|
96
|
+
}
|
97
|
+
|
98
|
+
addId (id) {
|
99
|
+
const template = this.idInputTemplateTarget
|
100
|
+
const input = template.innerHTML.replace(/ID/g, id)
|
101
|
+
this.formTarget.insertAdjacentHTML('afterbegin', input)
|
102
|
+
}
|
103
|
+
|
104
|
+
removeIds () {
|
105
|
+
this.idTargets.forEach((input) => {
|
106
|
+
this.formTarget.removeChild(input)
|
107
|
+
})
|
108
|
+
}
|
110
109
|
}
|
@@ -1,124 +1,124 @@
|
|
1
|
-
|
2
|
-
import
|
1
|
+
/* global CustomEvent, fetch, FormData */
|
2
|
+
import { Controller } from '@hotwired/stimulus'
|
3
|
+
import Sortable from 'sortablejs'
|
3
4
|
|
4
5
|
export default class extends Controller {
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
}
|
10
|
-
}
|
11
|
-
|
12
|
-
static get targets() {
|
13
|
-
return ["table", "body", "actions", "idCheckbox", "idsCheckbox", "row"]
|
14
|
-
}
|
15
|
-
|
16
|
-
connect() {
|
17
|
-
new Sortable(this.bodyTarget, {
|
18
|
-
handle: '.table-drag-sort-handle',
|
19
|
-
onEnd: (event) => {
|
20
|
-
this.submitPositions()
|
21
|
-
}
|
22
|
-
})
|
23
|
-
}
|
24
|
-
|
25
|
-
submitPositions() {
|
26
|
-
fetch(this.urlValue, {
|
27
|
-
method: 'PATCH',
|
28
|
-
body: this.idsFormData(),
|
29
|
-
headers: {
|
30
|
-
'X-CSRF-Token': document.querySelector('meta[name="csrf-token"]').content
|
31
|
-
},
|
32
|
-
}).then((response) => {
|
33
|
-
return response.text()
|
34
|
-
}).catch((err) => {
|
35
|
-
console.warn('Fetch went wrong', err)
|
36
|
-
})
|
37
|
-
}
|
38
|
-
|
39
|
-
positions() {
|
40
|
-
const handles = [...this.tableTarget.querySelectorAll(".table-drag-sort-handle")]
|
41
|
-
return handles.map((handle) => {
|
42
|
-
return handle.dataset.id
|
43
|
-
})
|
44
|
-
}
|
45
|
-
|
46
|
-
idsFormData() {
|
47
|
-
let formData = new FormData()
|
48
|
-
this.positions().forEach(id => {
|
49
|
-
formData.append('ids[]', id)
|
50
|
-
})
|
51
|
-
return formData
|
52
|
-
}
|
53
|
-
|
54
|
-
toggleIds(event) {
|
55
|
-
const checkbox = event.target
|
56
|
-
this.toggleIdsCheckboxes(checkbox.checked)
|
57
|
-
this.toggleIdCheckboxes(checkbox.checked)
|
58
|
-
this.updateActions()
|
59
|
-
}
|
60
|
-
|
61
|
-
toggleId(event) {
|
62
|
-
this.toggleIdsCheckboxes(false)
|
63
|
-
this.updateActions()
|
64
|
-
}
|
65
|
-
|
66
|
-
updateActions() {
|
67
|
-
this.actionsTarget.dispatchEvent(
|
68
|
-
new CustomEvent(
|
69
|
-
'idSelectionChanged',
|
70
|
-
{
|
71
|
-
detail: {
|
72
|
-
ids: this.ids(),
|
73
|
-
count: this.selectedIdsCount()
|
74
|
-
}
|
75
|
-
}
|
76
|
-
)
|
77
|
-
)
|
78
|
-
}
|
79
|
-
|
80
|
-
selectedIdsCount() {
|
81
|
-
if (this.ids() instanceof Array) {
|
82
|
-
return this.ids().length
|
83
|
-
} else {
|
84
|
-
return this.totalCount()
|
85
|
-
}
|
86
|
-
}
|
87
|
-
|
88
|
-
totalCount() {
|
89
|
-
if (this.countValue === 0) {
|
90
|
-
return this.rowTargets.length
|
91
|
-
} else {
|
92
|
-
return this.countValue
|
93
|
-
}
|
6
|
+
static get values () {
|
7
|
+
return {
|
8
|
+
url: String,
|
9
|
+
count: Number
|
94
10
|
}
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
11
|
+
}
|
12
|
+
|
13
|
+
static get targets () {
|
14
|
+
return ['table', 'body', 'actions', 'idCheckbox', 'idsCheckbox', 'row']
|
15
|
+
}
|
16
|
+
|
17
|
+
connect () {
|
18
|
+
Sortable.create(this.bodyTarget, {
|
19
|
+
handle: '.table-drag-sort-handle',
|
20
|
+
onEnd: (event) => {
|
21
|
+
this.submitPositions()
|
22
|
+
}
|
23
|
+
})
|
24
|
+
}
|
25
|
+
|
26
|
+
submitPositions () {
|
27
|
+
fetch(this.urlValue, {
|
28
|
+
method: 'PATCH',
|
29
|
+
body: this.idsFormData(),
|
30
|
+
headers: {
|
31
|
+
'X-CSRF-Token': document.querySelector('meta[name="csrf-token"]').content
|
32
|
+
}
|
33
|
+
}).then((response) => {
|
34
|
+
return response.text()
|
35
|
+
}).catch((err) => {
|
36
|
+
console.warn('Fetch went wrong', err)
|
37
|
+
})
|
38
|
+
}
|
39
|
+
|
40
|
+
positions () {
|
41
|
+
const handles = [...this.tableTarget.querySelectorAll('.table-drag-sort-handle')]
|
42
|
+
return handles.map((handle) => {
|
43
|
+
return handle.dataset.id
|
44
|
+
})
|
45
|
+
}
|
46
|
+
|
47
|
+
idsFormData () {
|
48
|
+
const formData = new FormData()
|
49
|
+
this.positions().forEach(id => {
|
50
|
+
formData.append('ids[]', id)
|
51
|
+
})
|
52
|
+
return formData
|
53
|
+
}
|
54
|
+
|
55
|
+
toggleIds (event) {
|
56
|
+
const checkbox = event.target
|
57
|
+
this.toggleIdsCheckboxes(checkbox.checked)
|
58
|
+
this.toggleIdCheckboxes(checkbox.checked)
|
59
|
+
this.updateActions()
|
60
|
+
}
|
61
|
+
|
62
|
+
toggleId (event) {
|
63
|
+
this.toggleIdsCheckboxes(false)
|
64
|
+
this.updateActions()
|
65
|
+
}
|
66
|
+
|
67
|
+
updateActions () {
|
68
|
+
this.actionsTarget.dispatchEvent(
|
69
|
+
new CustomEvent(
|
70
|
+
'idSelectionChanged',
|
71
|
+
{
|
72
|
+
detail: {
|
73
|
+
ids: this.ids(),
|
74
|
+
count: this.selectedIdsCount()
|
75
|
+
}
|
103
76
|
}
|
77
|
+
)
|
78
|
+
)
|
79
|
+
}
|
80
|
+
|
81
|
+
selectedIdsCount () {
|
82
|
+
if (this.ids() instanceof Array) {
|
83
|
+
return this.ids().length
|
84
|
+
} else {
|
85
|
+
return this.totalCount()
|
104
86
|
}
|
87
|
+
}
|
105
88
|
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
89
|
+
totalCount () {
|
90
|
+
if (this.countValue === 0) {
|
91
|
+
return this.rowTargets.length
|
92
|
+
} else {
|
93
|
+
return this.countValue
|
110
94
|
}
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
95
|
+
}
|
96
|
+
|
97
|
+
ids () {
|
98
|
+
if (this.idsCheckboxTarget.checked) {
|
99
|
+
return null
|
100
|
+
} else {
|
101
|
+
return this.selectedIdCheckboxes().map((checkbox) => {
|
102
|
+
return checkbox.value
|
103
|
+
})
|
116
104
|
}
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
}
|
123
|
-
|
105
|
+
}
|
106
|
+
|
107
|
+
selectedIdCheckboxes () {
|
108
|
+
return this.idCheckboxTargets.filter((checkbox) => {
|
109
|
+
return checkbox.checked
|
110
|
+
})
|
111
|
+
}
|
112
|
+
|
113
|
+
toggleIdsCheckboxes (checked) {
|
114
|
+
this.idsCheckboxTargets.forEach((checkbox) => {
|
115
|
+
checkbox.checked = checked
|
116
|
+
})
|
117
|
+
}
|
118
|
+
|
119
|
+
toggleIdCheckboxes (checked) {
|
120
|
+
this.idCheckboxTargets.forEach((checkbox) => {
|
121
|
+
checkbox.checked = checked
|
122
|
+
})
|
123
|
+
}
|
124
124
|
}
|
@@ -1,37 +1,40 @@
|
|
1
|
-
|
2
|
-
import
|
3
|
-
import
|
4
|
-
import
|
5
|
-
import
|
6
|
-
import
|
7
|
-
import
|
8
|
-
import
|
9
|
-
import
|
10
|
-
import
|
11
|
-
import
|
12
|
-
import
|
13
|
-
import
|
14
|
-
import
|
15
|
-
import
|
16
|
-
import
|
1
|
+
/* global Stimulus */
|
2
|
+
import { Application } from '@hotwired/stimulus'
|
3
|
+
import AutocompleteController from './controllers/autocomplete_controller'
|
4
|
+
import BlocksController from './controllers/blocks_controller'
|
5
|
+
import DateRangeController from './controllers/date_range_controller'
|
6
|
+
import DropzoneController from './controllers/dropzone_controller'
|
7
|
+
import FilePreviewController from './controllers/file_preview_controller'
|
8
|
+
import FilterController from './controllers/filter_controller'
|
9
|
+
import FiltersController from './controllers/filters_controller'
|
10
|
+
import FlatpickrController from './controllers/flatpickr_controller'
|
11
|
+
import HelloController from './controllers/hello_controller'
|
12
|
+
import NotificationController from './controllers/notification_controller'
|
13
|
+
import PopupController from './controllers/popup_controller'
|
14
|
+
import RedactorxController from './controllers/redactorx_controller'
|
15
|
+
import RepeaterController from './controllers/repeater_controller'
|
16
|
+
import SelectController from './controllers/select_controller'
|
17
|
+
import TableActionsController from './controllers/table_actions_controller'
|
18
|
+
import TableController from './controllers/table_controller'
|
17
19
|
|
18
20
|
export class Headmin {
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
}
|
21
|
+
static start () {
|
22
|
+
window.Stimulus = window.Stimulus || Application.start()
|
23
|
+
Stimulus.register('autocomplete', AutocompleteController)
|
24
|
+
Stimulus.register('blocks', BlocksController)
|
25
|
+
Stimulus.register('date-range', DateRangeController)
|
26
|
+
Stimulus.register('dropzone', DropzoneController)
|
27
|
+
Stimulus.register('file-preview', FilePreviewController)
|
28
|
+
Stimulus.register('filter', FilterController)
|
29
|
+
Stimulus.register('filters', FiltersController)
|
30
|
+
Stimulus.register('flatpickr', FlatpickrController)
|
31
|
+
Stimulus.register('hello', HelloController)
|
32
|
+
Stimulus.register('notification', NotificationController)
|
33
|
+
Stimulus.register('popup', PopupController)
|
34
|
+
Stimulus.register('redactorx', RedactorxController)
|
35
|
+
Stimulus.register('repeater', RepeaterController)
|
36
|
+
Stimulus.register('select', SelectController)
|
37
|
+
Stimulus.register('table', TableController)
|
38
|
+
Stimulus.register('table-actions', TableActionsController)
|
39
|
+
}
|
40
|
+
}
|