nfp_sites/filadelfia_web/app/input.js

73 lines
2 KiB
JavaScript
Raw Normal View History

2023-11-14 07:27:04 +00:00
const m = require('mithril')
2023-11-15 04:43:05 +00:00
const popper = require('@popperjs/core')
const tempus = require('@eonasdan/tempus-dominus')
2023-11-14 07:27:04 +00:00
const Input = {
oninit: function(vnode) {
2023-11-15 04:43:05 +00:00
this.tempus = null
this.subscription = null
},
onremove: function(vnode) {
if (!this.tempus) return
this.tempus.dispose()
this.tempus = null
},
getInput: function(vnode) {
switch (vnode.attrs.utility) {
case 'datetime':
return m('input', {
type: 'text',
oncreate: (e) => {
this.tempus = new tempus.TempusDominus(e.dom, {
defaultDate: vnode.attrs.form[vnode.attrs.formKey],
viewDate: vnode.attrs.form[vnode.attrs.formKey],
localization: {
locale: 'is',
startOfTheWeek: 0,
hourCycle: 'h23',
dateFormats: {
LTS: 'H:mm:ss',
LT: 'H:mm',
L: 'dd.MM.yyyy',
LL: 'd [de] MMMM [de] yyyy',
LLL: 'd [de] MMMM [de] yyyy H:mm',
LLLL: 'dddd, d [de] MMMM [de] yyyy H:mm',
},
},
})
this.subscription = this.tempus.subscribe(tempus.Namespace.events.change, (e) => {
console.log(e);
});
},
})
default:
return m('input', {
type: vnode.attrs.type || 'text',
value: vnode.attrs.form[vnode.attrs.formKey],
oninput: (e) => { vnode.attrs.form[vnode.attrs.formKey] = e.currentTarget.value },
})
}
2023-11-14 07:27:04 +00:00
},
view: function(vnode) {
2023-11-15 04:43:05 +00:00
let input = m('input', {
type: vnode.attrs.type || 'text',
value: vnode.attrs.form[vnode.attrs.formKey],
oninput: (e) => { vnode.attrs.form[vnode.attrs.formKey] = e.currentTarget.value },
})
if (vnode.attrs.utility === 'datetime') {
}
2023-11-14 07:27:04 +00:00
return [
m('label', vnode.attrs.label),
2023-11-15 04:43:05 +00:00
this.getInput(vnode),
2023-11-14 07:27:04 +00:00
]
},
}
module.exports = Input