diff --git a/application/views/jssnippets/tabulatorcolumns/stv.js b/application/views/jssnippets/tabulatorcolumns/stv.js index 6aa395071..fb2049beb 100644 --- a/application/views/jssnippets/tabulatorcolumns/stv.js +++ b/application/views/jssnippets/tabulatorcolumns/stv.js @@ -65,19 +65,15 @@ return [ title: "Geburtsdatum", titlePhrase: 'person/geburtsdatum', field: "gebdatum", - formatter: 'dateFormatter', - headerFilter: true, - headerFilterFunc(headerValue, rowValue) { - const matches = headerValue.match(/^(([0-9]{2})\.)?([0-9]{2})\.([0-9]{4})?$/); - let comparestr = headerValue; - if(matches !== null) { - const year = (matches[4] !== undefined) ? matches[4] : ''; - const month = matches[3]; - const day = (matches[2] !== undefined) ? matches[2] : ''; - comparestr = year + '-' + month + '-' + day; - } - return rowValue.match(comparestr); - } + formatter: 'datetime', + formatterParams: { + inputFormat: "iso", + outputFormat: "dd.MM.yyyy", + invalidPlaceholder: " ", + timezone: FHC_JS_DATA_STORAGE_OBJECT.timezone + }, + headerFilter: 'input', + headerFilterFunc: 'dateinput' }, { title: "Geschlecht", @@ -179,15 +175,28 @@ return [ titlePhrase: 'profilUpdate/statusDate', field: "status_datum", visible: false, - formatter: 'dateFormatter' + formatter: 'datetime', + formatterParams: { + inputFormat: "iso", + outputFormat: "dd.MM.yyyy", + invalidPlaceholder: " ", + timezone: FHC_JS_DATA_STORAGE_OBJECT.timezone + } }, { title: "Status Bestaetigung", titlePhrase: 'global/status_bestaetigung', field: "status_bestaetigung", visible: false, - formatter: 'dateFormatter', - headerFilter: true + formatter: 'datetime', + formatterParams: { + inputFormat: "iso", + outputFormat: "dd.MM.yyyy", + invalidPlaceholder: " ", + timezone: FHC_JS_DATA_STORAGE_OBJECT.timezone + }, + headerFilter: 'input', + headerFilterFunc: 'dateinput' }, { title: "EMail (Privat)", diff --git a/public/js/components/Stv/Studentenverwaltung/List.js b/public/js/components/Stv/Studentenverwaltung/List.js index ea9803223..c9229b657 100644 --- a/public/js/components/Stv/Studentenverwaltung/List.js +++ b/public/js/components/Stv/Studentenverwaltung/List.js @@ -14,6 +14,9 @@ import draggable from '../../../directives/draggable.js'; import StvColumns from '../../../../../index.ci.php/js/tabulatorcolumns/stv'; +import ModuleFilterFilters from '../../../tabulator/filter/filters.js'; +Tabulator.extendModule("filter", "filters", ModuleFilterFilters); + export default { name: "ListPrestudents", components: { @@ -53,20 +56,6 @@ export default { 'filterActive' ], data() { - Tabulator.extendModule("format", "formatters", { - dateFormatter(cell) { - let val = cell.getValue(); - if (!val) - return ' '; - let date = new Date(val); - return date.toLocaleDateString('de-AT', { - "day": "2-digit", - "month": "2-digit", - "year": "numeric" - }); - } - }); - return { tabulatorOptions: { columns: StvColumns, @@ -226,7 +215,7 @@ export default { return "StudentList_" + today + ".csv"; }, }, - created: function() { + created() { if(this.tagsEnabled) { const coltags = { title: 'Tags', diff --git a/public/js/tabulator/filter/filters.js b/public/js/tabulator/filter/filters.js new file mode 100644 index 000000000..36d48cc8f --- /dev/null +++ b/public/js/tabulator/filter/filters.js @@ -0,0 +1,54 @@ +function dateinput(headerValue, rowValue, rowData, config) { + if (!luxon) + return this.like(headerValue, rowValue, rowData, config); + + let inputFormat = config.inputFormat || 'iso'; + let outputFormat = config.outputFormat || 'dd.MM.yyyy'; + + let value; + if (inputFormat == 'iso') + value = luxon.DateTime.fromISO(rowValue); + else + value = luxon.DateTime.fromFormat(rowValue, inputFormat); + + let range = []; + range = headerValue.split(' - '); + if (range.length == 1) { + range = headerValue.split('-'); + } + if (range.length == 2) { + range = range.map(r => { + r = r.trim(); + if (r) { + let d = luxon.DateTime.fromFormat(r, outputFormat); + if (!d.isValid && inputFormat != 'iso' && inputFormat != outputFormat) + d = luxon.DateTime.fromFormat(r, inputFormat); + if (!d.isValid) + d = luxon.DateTime.fromISO(r); + if (d.isValid) + return d; + } + return null; + }); + if (!range[0] && !range[1]) + return true; + else if (!range[0]) + return this['<='](range[1], value, rowData, config); + else if (!range[1]) + return this['>='](range[0], value, rowData, config); + + let smaller = this['<='](range[1], value, rowData, config); + let bigger = this['>='](range[0], value, rowData, config); + return smaller && bigger; + } + + // fallback + return this.like(headerValue, value.toFormat(outputFormat), rowData, config); +} + +export { + dateinput +}; +export default { + dateinput +};