formatic 0.1.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 +7 -0
- data/CHANGELOG.md +5 -0
- data/LICENSE.txt +21 -0
- data/README.md +32 -0
- data/app/assets/javascript/formatic/components/date.ts +54 -0
- data/app/assets/javascript/formatic/components/select.ts +109 -0
- data/app/assets/javascript/formatic/components/stepper.ts +89 -0
- data/app/assets/javascript/formatic/components/textarea.ts +108 -0
- data/app/assets/javascript/formatic/components/toggle.ts +81 -0
- data/app/assets/javascript/formatic.js +350 -0
- data/app/assets/javascript/formatic.js.map +1 -0
- data/app/assets/stylesheets/formatic/components/checklist.sass +3 -0
- data/app/assets/stylesheets/formatic/components/date.sass +70 -0
- data/app/assets/stylesheets/formatic/components/select.sass +24 -0
- data/app/assets/stylesheets/formatic/components/stepper.sass +43 -0
- data/app/assets/stylesheets/formatic/components/string.sass +13 -0
- data/app/assets/stylesheets/formatic/components/textarea.sass +22 -0
- data/app/assets/stylesheets/formatic/components/toggle.sass +93 -0
- data/app/assets/stylesheets/formatic/components/wrapper.sass +51 -0
- data/app/assets/stylesheets/formatic/generics/flip.sass +3 -0
- data/app/assets/stylesheets/formatic/index.sass +16 -0
- data/app/assets/stylesheets/formatic/package.json +5 -0
- data/app/assets/stylesheets/formatic/scopes/form.sass +45 -0
- data/app/assets/stylesheets/formatic/settings/_colors.sass +13 -0
- data/app/assets/stylesheets/formatic/tools/terminal.sass +3 -0
- data/app/assets/stylesheets/formatic/utilities/container.sass +2 -0
- data/app/components/formatic/application_component.rb +39 -0
- data/app/components/formatic/base.rb +72 -0
- data/app/components/formatic/checklist.rb +65 -0
- data/app/components/formatic/date.rb +110 -0
- data/app/components/formatic/select.rb +49 -0
- data/app/components/formatic/stepper.rb +35 -0
- data/app/components/formatic/string.rb +57 -0
- data/app/components/formatic/textarea.rb +48 -0
- data/app/components/formatic/toggle.rb +57 -0
- data/app/components/formatic/wrapper.rb +122 -0
- data/config/locales/formatic.de.yml +5 -0
- data/config/locales/formatic.en.yml +5 -0
- data/lib/formatic/choices/countries.rb +14 -0
- data/lib/formatic/choices/keys.rb +27 -0
- data/lib/formatic/choices/options.rb +39 -0
- data/lib/formatic/choices/records.rb +47 -0
- data/lib/formatic/choices.rb +62 -0
- data/lib/formatic/css.rb +10 -0
- data/lib/formatic/engine.rb +40 -0
- data/lib/formatic/safe_join.rb +20 -0
- data/lib/formatic/templates/date.rb +76 -0
- data/lib/formatic/templates/select.rb +35 -0
- data/lib/formatic/templates/wrapper.rb +52 -0
- data/lib/formatic/version.rb +5 -0
- data/lib/formatic/wrappers/alternative_attribute_name.rb +18 -0
- data/lib/formatic/wrappers/error_messages.rb +39 -0
- data/lib/formatic/wrappers/required.rb +29 -0
- data/lib/formatic/wrappers/translate.rb +41 -0
- data/lib/formatic/wrappers/validators.rb +39 -0
- data/lib/formatic.rb +29 -0
- metadata +186 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 141f3404812472271ac7282970a7b86b5c25075760629d5c40ecacc959b39d59
|
4
|
+
data.tar.gz: 8eb7224e10e771fb2970a26e199fcf34d3da05b65ca957ee40d35990c367b625
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 217d2ff02fe3b2c0ec7c8ff9c8c5169e0c0896ac34912688ac4c512f8c9a2a53ad771ca92ae20b5362651ac36ecdf96ef6960863b0618c627972b04a05a97aca
|
7
|
+
data.tar.gz: c044f04c04f9b0dc206f4c4066849dad6ea13d0f1feba6f463e91c35198e471b3a7d91f45b21b9b96ba22ff2c4814371b128e8474377415431fc85bc715091a7
|
data/CHANGELOG.md
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) halo
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# Formatic
|
2
|
+
|
3
|
+
Opinionated ViewComponents for building forms.
|
4
|
+
|
5
|
+
## Usage
|
6
|
+
|
7
|
+
```ruby
|
8
|
+
# In Rails view
|
9
|
+
= render Formatic::String.new(f:, attribute_name: :first_name)
|
10
|
+
```
|
11
|
+
|
12
|
+
## Installation
|
13
|
+
|
14
|
+
Install the gem and add to the application's Gemfile by executing:
|
15
|
+
|
16
|
+
$ bundle add formatic
|
17
|
+
|
18
|
+
If bundler is not being used to manage dependencies, install the gem by executing:
|
19
|
+
|
20
|
+
$ gem install formatic
|
21
|
+
|
22
|
+
## Development
|
23
|
+
|
24
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/ci` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
25
|
+
|
26
|
+
## Contributing
|
27
|
+
|
28
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/halo/formatic.
|
29
|
+
|
30
|
+
## License
|
31
|
+
|
32
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
@@ -0,0 +1,54 @@
|
|
1
|
+
namespace Formatic {
|
2
|
+
export class Date {
|
3
|
+
private el: HTMLElement
|
4
|
+
|
5
|
+
constructor(el: HTMLElement) {
|
6
|
+
this.el = el
|
7
|
+
this.setupBindings()
|
8
|
+
}
|
9
|
+
|
10
|
+
private setupBindings() {
|
11
|
+
this.shortcutButtons.forEach((el) => {
|
12
|
+
el.addEventListener('click', (event) => {
|
13
|
+
event.preventDefault()
|
14
|
+
const shortcut = <HTMLInputElement>event.currentTarget
|
15
|
+
|
16
|
+
this.dayInput.value = shortcut.dataset.day
|
17
|
+
this.monthInput.value = shortcut.dataset.month
|
18
|
+
this.yearInput.value = shortcut.dataset.year
|
19
|
+
})
|
20
|
+
})
|
21
|
+
}
|
22
|
+
|
23
|
+
// ------------
|
24
|
+
// DOM Elements
|
25
|
+
// ------------
|
26
|
+
|
27
|
+
private get dayInput() {
|
28
|
+
return this.el.querySelector<HTMLSelectElement>('.js-formatic-date__day')
|
29
|
+
}
|
30
|
+
|
31
|
+
private get monthInput() {
|
32
|
+
return this.el.querySelector<HTMLSelectElement>('.js-formatic-date__month')
|
33
|
+
}
|
34
|
+
|
35
|
+
private get yearInput() {
|
36
|
+
return this.el.querySelector<HTMLSelectElement>('.js-formatic-date__year')
|
37
|
+
}
|
38
|
+
|
39
|
+
private get shortcutButtons() {
|
40
|
+
return this.el.querySelectorAll<HTMLElement>('.js-formatic-date__shortcut')
|
41
|
+
}
|
42
|
+
}
|
43
|
+
}
|
44
|
+
|
45
|
+
// --------------
|
46
|
+
// Initialization
|
47
|
+
// --------------
|
48
|
+
|
49
|
+
document.addEventListener('DOMContentLoaded', () => {
|
50
|
+
document.querySelectorAll<HTMLElement>('.js-formatic-date').forEach((el) => {
|
51
|
+
console.debug('Instantiating Formatic.Date...')
|
52
|
+
new Formatic.Date(el)
|
53
|
+
})
|
54
|
+
})
|
@@ -0,0 +1,109 @@
|
|
1
|
+
namespace Formatic {
|
2
|
+
export class Select {
|
3
|
+
private el: HTMLElement
|
4
|
+
private timeoutId: ReturnType<typeof setTimeout>
|
5
|
+
|
6
|
+
constructor(el: HTMLElement) {
|
7
|
+
this.el = el
|
8
|
+
this.setupBindings()
|
9
|
+
}
|
10
|
+
|
11
|
+
private setupBindings() {
|
12
|
+
this.autosize()
|
13
|
+
|
14
|
+
this.el.addEventListener('input', (event) => {
|
15
|
+
event.preventDefault()
|
16
|
+
if (this.autoSubmit) this.actionSave()
|
17
|
+
})
|
18
|
+
}
|
19
|
+
|
20
|
+
// ACTIONS
|
21
|
+
|
22
|
+
private actionSave() {
|
23
|
+
this.guiWaitingForSave()
|
24
|
+
this.debounce(this.actionSaveNow.bind(this))()
|
25
|
+
}
|
26
|
+
|
27
|
+
private actionSaveNow() {
|
28
|
+
console.debug("Saving select...")
|
29
|
+
this.el.classList.remove('is-loading')
|
30
|
+
this.el.classList.add('is-saved')
|
31
|
+
this.save()
|
32
|
+
}
|
33
|
+
|
34
|
+
// GUI
|
35
|
+
|
36
|
+
private guiWaitingForSave() {
|
37
|
+
this.el.classList.add('is-loading')
|
38
|
+
this.el.classList.remove('is-saved')
|
39
|
+
this.el.classList.remove('is-failed')
|
40
|
+
}
|
41
|
+
|
42
|
+
private guiSaved() {
|
43
|
+
this.el.classList.remove('is-loading')
|
44
|
+
this.el.classList.add('is-saved')
|
45
|
+
this.el.classList.remove('is-failed')
|
46
|
+
}
|
47
|
+
|
48
|
+
private guiFailed() {
|
49
|
+
this.el.classList.remove('is-loading')
|
50
|
+
this.el.classList.remove('is-saved')
|
51
|
+
this.el.classList.add('is-failed')
|
52
|
+
}
|
53
|
+
|
54
|
+
// Attributes
|
55
|
+
|
56
|
+
private get autoSubmit() {
|
57
|
+
return this.el.classList.contains('is-autosubmit')
|
58
|
+
}
|
59
|
+
|
60
|
+
// Helpers
|
61
|
+
|
62
|
+
private save() {
|
63
|
+
const form = this.el.closest<HTMLFormElement>('form')
|
64
|
+
const data = new FormData(form)
|
65
|
+
data.set('_method', 'patch')
|
66
|
+
|
67
|
+
fetch(form.action, { method: 'POST', body: data })
|
68
|
+
.then(response => {
|
69
|
+
if (response.status == 201) {
|
70
|
+
console.debug('Select content saved')
|
71
|
+
this.guiSaved()
|
72
|
+
} else {
|
73
|
+
console.debug('Select content not saved')
|
74
|
+
this.guiFailed()
|
75
|
+
}
|
76
|
+
}).catch(err => {
|
77
|
+
console.warn(err)
|
78
|
+
console.debug('Failed badly to save')
|
79
|
+
})
|
80
|
+
}
|
81
|
+
|
82
|
+
private debounce(fn: Function) {
|
83
|
+
return () => {
|
84
|
+
clearTimeout(this.timeoutId)
|
85
|
+
this.timeoutId = setTimeout(() => fn(), 1000)
|
86
|
+
}
|
87
|
+
}
|
88
|
+
|
89
|
+
private autosize() {
|
90
|
+
try {
|
91
|
+
autosize(this.el) // External library.
|
92
|
+
} catch (error) {
|
93
|
+
console.warn(`Formatic is missing the autosize library`)
|
94
|
+
}
|
95
|
+
}
|
96
|
+
}
|
97
|
+
}
|
98
|
+
|
99
|
+
// --------------
|
100
|
+
// Initialization
|
101
|
+
// --------------
|
102
|
+
|
103
|
+
document.addEventListener('DOMContentLoaded', () => {
|
104
|
+
document.querySelectorAll<HTMLElement>('.js-formatic-select').forEach((el) => {
|
105
|
+
console.debug('Instantiating Formatic.Select...')
|
106
|
+
new Formatic.Select(el)
|
107
|
+
})
|
108
|
+
})
|
109
|
+
|
@@ -0,0 +1,89 @@
|
|
1
|
+
namespace Formatic {
|
2
|
+
export class Stepper {
|
3
|
+
private el: HTMLElement
|
4
|
+
|
5
|
+
constructor(el: HTMLElement) {
|
6
|
+
this.el = el
|
7
|
+
this.setupBindings()
|
8
|
+
}
|
9
|
+
|
10
|
+
private setupBindings() {
|
11
|
+
this.incrementButtons.forEach((el) => {
|
12
|
+
el.addEventListener('click', (event) => {
|
13
|
+
event.preventDefault()
|
14
|
+
this.increment()
|
15
|
+
})
|
16
|
+
})
|
17
|
+
|
18
|
+
this.decrementButtons.forEach((el) => {
|
19
|
+
el.addEventListener('click', (event) => {
|
20
|
+
event.preventDefault()
|
21
|
+
this.decrement()
|
22
|
+
})
|
23
|
+
})
|
24
|
+
|
25
|
+
this.numberInput.addEventListener('click', (event) => {
|
26
|
+
this.numberInput.select()
|
27
|
+
})
|
28
|
+
}
|
29
|
+
|
30
|
+
private increment() {
|
31
|
+
if (!this.number && this.number != 0) {
|
32
|
+
// Incrementing leads to `0` (it's common to quickly want to achieve the number zero).
|
33
|
+
// But if the minimum is e.g. `1` then it should be that instead.
|
34
|
+
this.numberInput.value = Math.max(...[0, this.minimum]).toString()
|
35
|
+
} else if (isNaN(this.number)) {
|
36
|
+
// Do nothing on weird stuff.
|
37
|
+
return
|
38
|
+
} else if (this.number < this.minimum) {
|
39
|
+
this.numberInput.value = this.minimum.toString()
|
40
|
+
} else {
|
41
|
+
this.numberInput.value = (this.number + 1).toString()
|
42
|
+
}
|
43
|
+
}
|
44
|
+
|
45
|
+
private decrement() {
|
46
|
+
if (!this.number && this.number != 0) {
|
47
|
+
// Decementing empty leads to `-1`.
|
48
|
+
// But if the minimum is e.g. `0` then it should be that instead.
|
49
|
+
this.numberInput.value = Math.max(...[-1, this.minimum]).toString()
|
50
|
+
} else if (isNaN(this.number)) {
|
51
|
+
// Do nothing on weird stuff.
|
52
|
+
return
|
53
|
+
} else if (this.number <= this.minimum) {
|
54
|
+
// Do nothing if at the minimum already
|
55
|
+
return
|
56
|
+
} else {
|
57
|
+
// Normal decrement.
|
58
|
+
this.numberInput.value = (this.number - 1).toString()
|
59
|
+
}
|
60
|
+
}
|
61
|
+
|
62
|
+
private get minimum() {
|
63
|
+
return parseInt(this.numberInput.min)
|
64
|
+
}
|
65
|
+
|
66
|
+
private get number() {
|
67
|
+
return parseInt(this.numberInput.value)
|
68
|
+
}
|
69
|
+
|
70
|
+
private get incrementButtons() {
|
71
|
+
return this.el.querySelectorAll<HTMLLinkElement>('.js-formatic-stepper__increment')
|
72
|
+
}
|
73
|
+
|
74
|
+
private get decrementButtons() {
|
75
|
+
return this.el.querySelectorAll<HTMLLinkElement>('.js-formatic-stepper__decrement')
|
76
|
+
}
|
77
|
+
|
78
|
+
private get numberInput() {
|
79
|
+
return this.el.querySelector<HTMLInputElement>('.js-formatic-stepper__number')
|
80
|
+
}
|
81
|
+
}
|
82
|
+
}
|
83
|
+
|
84
|
+
document.addEventListener('DOMContentLoaded', () => {
|
85
|
+
document.querySelectorAll<HTMLElement>('.js-formatic-stepper').forEach((el) => {
|
86
|
+
console.debug('Instantiating Formatic.Stepper...')
|
87
|
+
new Formatic.Stepper(el)
|
88
|
+
})
|
89
|
+
})
|
@@ -0,0 +1,108 @@
|
|
1
|
+
namespace Formatic {
|
2
|
+
export class Textarea {
|
3
|
+
private el: HTMLElement
|
4
|
+
private timeoutId: ReturnType<typeof setTimeout>
|
5
|
+
|
6
|
+
constructor(el: HTMLElement) {
|
7
|
+
this.el = el
|
8
|
+
this.setupBindings()
|
9
|
+
}
|
10
|
+
|
11
|
+
private setupBindings() {
|
12
|
+
this.autosize()
|
13
|
+
|
14
|
+
this.el.addEventListener('input', (event) => {
|
15
|
+
event.preventDefault()
|
16
|
+
if (this.autoSubmit) this.actionSave()
|
17
|
+
})
|
18
|
+
}
|
19
|
+
|
20
|
+
// ACTIONS
|
21
|
+
|
22
|
+
private actionSave() {
|
23
|
+
this.guiWaitingForSave()
|
24
|
+
this.debounce(this.actionSaveNow.bind(this))()
|
25
|
+
}
|
26
|
+
|
27
|
+
private actionSaveNow() {
|
28
|
+
console.debug("Saving textarea...")
|
29
|
+
this.el.classList.remove('is-loading')
|
30
|
+
this.el.classList.add('is-saved')
|
31
|
+
this.save()
|
32
|
+
}
|
33
|
+
|
34
|
+
// GUI
|
35
|
+
|
36
|
+
private guiWaitingForSave() {
|
37
|
+
this.el.classList.add('is-loading')
|
38
|
+
this.el.classList.remove('is-saved')
|
39
|
+
this.el.classList.remove('is-failed')
|
40
|
+
}
|
41
|
+
|
42
|
+
private guiSaved() {
|
43
|
+
this.el.classList.remove('is-loading')
|
44
|
+
this.el.classList.add('is-saved')
|
45
|
+
this.el.classList.remove('is-failed')
|
46
|
+
}
|
47
|
+
|
48
|
+
private guiFailed() {
|
49
|
+
this.el.classList.remove('is-loading')
|
50
|
+
this.el.classList.remove('is-saved')
|
51
|
+
this.el.classList.add('is-failed')
|
52
|
+
}
|
53
|
+
|
54
|
+
// Attributes
|
55
|
+
|
56
|
+
private get autoSubmit() {
|
57
|
+
return this.el.classList.contains('is-autosubmit')
|
58
|
+
}
|
59
|
+
|
60
|
+
// Helpers
|
61
|
+
|
62
|
+
private save() {
|
63
|
+
const form = this.el.closest<HTMLFormElement>('form')
|
64
|
+
const data = new FormData(form)
|
65
|
+
data.set('_method', 'patch')
|
66
|
+
|
67
|
+
fetch(form.action, { method: 'POST', body: data })
|
68
|
+
.then(response => {
|
69
|
+
if (response.status == 201) {
|
70
|
+
console.debug('Textarea content saved')
|
71
|
+
this.guiSaved()
|
72
|
+
} else {
|
73
|
+
console.debug('Textarea content not saved')
|
74
|
+
this.guiFailed()
|
75
|
+
}
|
76
|
+
}).catch(err => {
|
77
|
+
console.warn(err)
|
78
|
+
console.debug('Failed badly to save')
|
79
|
+
})
|
80
|
+
}
|
81
|
+
|
82
|
+
private debounce(fn: Function) {
|
83
|
+
return () => {
|
84
|
+
clearTimeout(this.timeoutId)
|
85
|
+
this.timeoutId = setTimeout(() => fn(), 1000)
|
86
|
+
}
|
87
|
+
}
|
88
|
+
|
89
|
+
private autosize() {
|
90
|
+
try {
|
91
|
+
autosize(this.el) // External library.
|
92
|
+
} catch (error) {
|
93
|
+
console.warn(`Formatic is missing the autosize library`)
|
94
|
+
}
|
95
|
+
}
|
96
|
+
}
|
97
|
+
|
98
|
+
// --------------
|
99
|
+
// Initialization
|
100
|
+
// --------------
|
101
|
+
|
102
|
+
document.addEventListener('DOMContentLoaded', () => {
|
103
|
+
document.querySelectorAll<HTMLElement>('.js-formatic-textarea').forEach((el) => {
|
104
|
+
console.debug('Instantiating Formatic.Textarea...')
|
105
|
+
new Formatic.Textarea(el)
|
106
|
+
})
|
107
|
+
})
|
108
|
+
}
|
@@ -0,0 +1,81 @@
|
|
1
|
+
namespace Formatic {
|
2
|
+
export class Toggle {
|
3
|
+
|
4
|
+
private el: HTMLElement
|
5
|
+
|
6
|
+
constructor(el: HTMLElement) {
|
7
|
+
this.el = el
|
8
|
+
this.setupBindings()
|
9
|
+
}
|
10
|
+
|
11
|
+
private setupBindings() {
|
12
|
+
this.checkbox.addEventListener('click', (event) => {
|
13
|
+
event.preventDefault()
|
14
|
+
const box = <HTMLInputElement>event.target
|
15
|
+
box.checked ? this.activate(box) : this.deactivate(box)
|
16
|
+
})
|
17
|
+
}
|
18
|
+
|
19
|
+
private activate(box: HTMLInputElement) {
|
20
|
+
const form = box.closest<HTMLFormElement>('form')
|
21
|
+
const data = new FormData(form)
|
22
|
+
data.set('_method', 'patch')
|
23
|
+
|
24
|
+
fetch(form.action, { method: 'POST', body: data })
|
25
|
+
.then(response => {
|
26
|
+
// For accurate user feedback, we make sure this is not an accidental 200.
|
27
|
+
// Your controller needs to respond with 201 on create/update.
|
28
|
+
if (response.status == 201) {
|
29
|
+
console.debug('Activation confirmed')
|
30
|
+
box.checked = true
|
31
|
+
} else {
|
32
|
+
console.debug('Activation not confirmed')
|
33
|
+
console.log("Activation denied")
|
34
|
+
}
|
35
|
+
}).catch(err => {
|
36
|
+
console.warn(err)
|
37
|
+
console.debug('Failed badly to activate')
|
38
|
+
})
|
39
|
+
}
|
40
|
+
|
41
|
+
private deactivate(box: HTMLInputElement) {
|
42
|
+
const form = box.closest<HTMLFormElement>('form')
|
43
|
+
const data = new FormData(form)
|
44
|
+
data.set('_method', 'delete')
|
45
|
+
|
46
|
+
fetch(form.action, { method: 'POST', body: data })
|
47
|
+
.then(response => {
|
48
|
+
// Your controller needs to respond with 204 on destroy.
|
49
|
+
if (response.status == 204) {
|
50
|
+
console.debug('Deactivation confirmed')
|
51
|
+
box.checked = false
|
52
|
+
} else {
|
53
|
+
console.debug('Deactivation not confirmed')
|
54
|
+
console.log("Deactivation denied")
|
55
|
+
}
|
56
|
+
}).catch(err => {
|
57
|
+
console.warn(err)
|
58
|
+
console.debug('Failed badly to deactivate')
|
59
|
+
})
|
60
|
+
}
|
61
|
+
|
62
|
+
// ------------
|
63
|
+
// DOM Elements
|
64
|
+
// ------------
|
65
|
+
|
66
|
+
private get checkbox() {
|
67
|
+
return this.el.querySelector<HTMLInputElement>('input[type="checkbox"]')
|
68
|
+
}
|
69
|
+
}
|
70
|
+
}
|
71
|
+
|
72
|
+
// --------------
|
73
|
+
// Initialization
|
74
|
+
// --------------
|
75
|
+
|
76
|
+
document.addEventListener('DOMContentLoaded', () => {
|
77
|
+
document.querySelectorAll<HTMLElement>('.js-formatic-toggle').forEach((el) => {
|
78
|
+
console.debug('Instantiating Formatic::Toggle...')
|
79
|
+
new Formatic.Toggle(el)
|
80
|
+
})
|
81
|
+
})
|