Add custom tailbone-datepicker
component for Buefy
for easier reuse, outside of main CRUD forms
This commit is contained in:
parent
dfe0f49655
commit
3c8d16a368
47
tailbone/static/js/tailbone.buefy.datepicker.js
Normal file
47
tailbone/static/js/tailbone.buefy.datepicker.js
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
|
||||||
|
const TailboneDatepicker = {
|
||||||
|
|
||||||
|
template: [
|
||||||
|
'<b-datepicker',
|
||||||
|
'placeholder="Click to select ..."',
|
||||||
|
`:name="name"`,
|
||||||
|
`:id="id"`,
|
||||||
|
'editable',
|
||||||
|
'icon-pack="fas"',
|
||||||
|
'icon="calendar-alt"',
|
||||||
|
':date-formatter="formatDate"',
|
||||||
|
':date-parser="parseDate"',
|
||||||
|
':value="rawValue ? parseDate(rawValue) : null"',
|
||||||
|
'>',
|
||||||
|
'</b-datepicker>'
|
||||||
|
].join(' '),
|
||||||
|
|
||||||
|
props: {
|
||||||
|
name: String,
|
||||||
|
id: String,
|
||||||
|
rawValue: String
|
||||||
|
},
|
||||||
|
|
||||||
|
methods: {
|
||||||
|
|
||||||
|
formatDate(date) {
|
||||||
|
// just need to convert to simple ISO date format here, seems
|
||||||
|
// like there should be a more obvious way to do that?
|
||||||
|
var year = date.getFullYear()
|
||||||
|
var month = date.getMonth() + 1
|
||||||
|
var day = date.getDate()
|
||||||
|
month = month < 10 ? '0' + month : month
|
||||||
|
day = day < 10 ? '0' + day : day
|
||||||
|
return year + '-' + month + '-' + day
|
||||||
|
},
|
||||||
|
|
||||||
|
parseDate(date) {
|
||||||
|
// note, this assumes classic YYYY-MM-DD (i.e. ISO?) format
|
||||||
|
var parts = date.split('-')
|
||||||
|
return new Date(parts[0], parseInt(parts[1]) - 1, parts[2])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
Vue.component('tailbone-datepicker', TailboneDatepicker)
|
|
@ -89,6 +89,21 @@ header .level .theme-picker {
|
||||||
margin-top: 1em;
|
margin-top: 1em;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/******************************
|
||||||
|
* fix datepicker within modals
|
||||||
|
* TODO: someday this may not be necessary? cf.
|
||||||
|
* https://github.com/buefy/buefy/issues/292#issuecomment-347365637
|
||||||
|
******************************/
|
||||||
|
|
||||||
|
.modal .animation-content .modal-card {
|
||||||
|
overflow: visible !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.modal-card-body {
|
||||||
|
overflow: visible !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/******************************
|
/******************************
|
||||||
* feedback
|
* feedback
|
||||||
******************************/
|
******************************/
|
||||||
|
|
|
@ -37,16 +37,10 @@
|
||||||
|
|
||||||
<div tal:condition="use_buefy">
|
<div tal:condition="use_buefy">
|
||||||
${field.start_mapping()}
|
${field.start_mapping()}
|
||||||
<b-datepicker placeholder="Click to select..."
|
<tailbone-datepicker name="date"
|
||||||
name="date"
|
|
||||||
id="${oid}"
|
id="${oid}"
|
||||||
editable
|
raw-value="${cstruct}">
|
||||||
icon-pack="fas"
|
</tailbone-datepicker>
|
||||||
icon="calendar-alt"
|
|
||||||
tal:attributes=":date-formatter 'formatDate';
|
|
||||||
:date-parser 'parseDate';
|
|
||||||
:value ('parseDate(\'' + cstruct + '\')') if cstruct else 'null'">
|
|
||||||
</b-datepicker>
|
|
||||||
${field.end_mapping()}
|
${field.end_mapping()}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
@ -57,25 +57,6 @@
|
||||||
|
|
||||||
const BuefyForm = {
|
const BuefyForm = {
|
||||||
template: '#buefy-form-template',
|
template: '#buefy-form-template',
|
||||||
methods: {
|
|
||||||
|
|
||||||
formatDate(date) {
|
|
||||||
// just need to convert to simple ISO date format here, seems
|
|
||||||
// like there should be a more obvious way to do that?
|
|
||||||
var year = date.getFullYear()
|
|
||||||
var month = date.getMonth() + 1
|
|
||||||
var day = date.getDate()
|
|
||||||
month = month < 10 ? '0' + month : month
|
|
||||||
day = day < 10 ? '0' + day : day
|
|
||||||
return year + '-' + month + '-' + day
|
|
||||||
},
|
|
||||||
|
|
||||||
parseDate(date) {
|
|
||||||
// note, this assumes classic YYYY-MM-DD (i.e. ISO?) format
|
|
||||||
var parts = date.split('-')
|
|
||||||
return new Date(parts[0], parseInt(parts[1]) - 1, parts[2])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Vue.component('buefy-form', BuefyForm)
|
Vue.component('buefy-form', BuefyForm)
|
||||||
|
|
|
@ -297,6 +297,9 @@
|
||||||
## FontAwesome 5.3.1
|
## FontAwesome 5.3.1
|
||||||
<script defer src="https://use.fontawesome.com/releases/v5.3.1/js/all.js"></script>
|
<script defer src="https://use.fontawesome.com/releases/v5.3.1/js/all.js"></script>
|
||||||
|
|
||||||
|
## Tailbone / Buefy stuff
|
||||||
|
${h.javascript_link(request.static_url('tailbone:static/js/tailbone.buefy.datepicker.js') + '?ver={}'.format(tailbone.__version__))}
|
||||||
|
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
var session_timeout = ${request.get_session_timeout() or 'null'};
|
var session_timeout = ${request.get_session_timeout() or 'null'};
|
||||||
var logout_url = '${request.route_url('logout')}';
|
var logout_url = '${request.route_url('logout')}';
|
||||||
|
|
Loading…
Reference in a new issue