implemented new features for warehouseorderrequest

This commit is contained in:
Luca Haid
2025-01-07 16:49:20 +01:00
parent e20af3eca5
commit f622204aa0
12 changed files with 253 additions and 87 deletions
@@ -77,6 +77,7 @@ Vue.component('tt-autocomplete', {
items: {type: Array, default: () => []},
sm: {type: Boolean, default: true},
row: {type: Boolean, default: false},
returnText: {type: Boolean, default: false},
}, data() {
return {
displayingItems: [],
@@ -107,6 +108,10 @@ Vue.component('tt-autocomplete', {
if (this.value && this.apiUrl) {
if (this.returnText && isNaN(this.value)) {
this.displayValue = this.value;
return;
}
const response = await axios.get(`${this.apiUrl}${this.apiUrl.includes('?') ? '&' : '?'}autocomplete=1&searchedID=${this.value}`);
this.displayValue = response.data[0].text;
} else if (this.value) {
@@ -120,6 +125,7 @@ Vue.component('tt-autocomplete', {
onInput(event) {
this.displayValue = event.target.value;
this.$emit('input', '');
this.$emit('input', this.returnText ? this.displayValue : '');
this.fetchSuggestions();
}, onFocus() {
this.showSuggestions = true;
@@ -1,104 +1,146 @@
Vue.component('tt-date-picker', {
props: {
label: String,
disabled: Boolean,
placeholder: String,
required: Boolean,
row: Boolean,
value: [Object, Number],
hint: String,
additionalProps: Object,
sm: { type: Boolean, default: false },
dateRange: { type: Boolean, default: true },
},
template: `
<input type="text" class="form-control form-control-sm" ref="input"
style="cursor: pointer;background-color: #ffffff">
`, props: ['value'],
<div class="form-group" :class="{'row': row}">
<slot name="prepend"></slot>
<label
:class="{'col-form-label': row, 'col-sm-4': row, 'col-form-label-sm': sm && row}"
v-if="label"
:for="label">{{ label }}</label>
<input type="text"
:id="label"
:name="label"
class="form-control"
:class="{'form-control-sm': sm, 'col-sm-8': row}"
:placeholder="placeholder"
:required="required"
:disabled="disabled"
v-bind="additionalProps"
ref="input"
style="cursor: pointer; background-color: #ffffff;"
>
<small v-if="hint" class="form-text text-muted">{{ hint }}</small>
</div>
`,
data() {
return {
inputValue: '',
isInitialized: false,
moment: window.moment,
locale: {
"format": "DD.MM.YYYY HH:mm",
"separator": " - ",
"applyLabel": "Übernehmen",
"cancelLabel": "Löschen",
"fromLabel": "Von",
"toLabel": "Bis",
"customRangeLabel": "Benutzerdefiniert",
"weekLabel": "W",
"daysOfWeek": [
"So",
"Mo",
"Di",
"Mi",
"Do",
"Fr",
"Sa"
],
"monthNames": [
"Januar",
"Februar",
"März",
"April",
"Mai",
"Juni",
"Juli",
"August",
"September",
"Oktober",
"November",
"Dezember"
],
"firstDay": 1
// ... (keep your existing locale object)
},
}
},
mounted() {
this.isInitialized = true;
$(this.$refs.input).daterangepicker({
const datePickerOptions = {
autoUpdateInput: true,
startDate: this.value?.from ? this.moment.unix(this.value.from) : undefined,
endDate: this.value?.to ? this.moment.unix(this.value.to) : undefined,
singleDatePicker: !this.dateRange,
timePicker: true,
timePicker24Hour: true,
locale: this.locale,
});
};
if (this.dateRange) {
datePickerOptions.startDate = this.value?.from ? this.moment.unix(this.value.from) : undefined;
datePickerOptions.endDate = this.value?.to ? this.moment.unix(this.value.to) : undefined;
} else {
datePickerOptions.startDate = this.value ? this.moment.unix(this.value) : undefined;
}
$(this.$refs.input).daterangepicker(datePickerOptions);
const _this = this;
$(this.$refs.input).on('apply.daterangepicker', function (ev, picker) {
_this.$emit('input', {
if (_this.dateRange) {
_this.$emit('input', {
from: picker.startDate.unix(),
to: picker.endDate.unix()
}
);
$(_this.$refs.input).val(picker.startDate.format(_this.locale.format) + _this.locale.separator + picker.endDate.format(_this.locale.format));
});
$(_this.$refs.input).val(picker.startDate.format(_this.locale.format) + _this.locale.separator + picker.endDate.format(_this.locale.format));
} else {
_this.$emit('input', picker.startDate.unix());
$(_this.$refs.input).val(picker.startDate.format(_this.locale.format));
}
});
function checkIfAppliedElseClear() {
if (this.value && this.value.from && this.value.to) return;
if (_this.dateRange) {
if (_this.value && _this.value.from && _this.value.to) return;
} else {
if (_this.value) return;
}
$(_this.$refs.input).val('');
}
function clearIfCancelled() {
_this.$emit('input', {from: null, to: null});
_this.$emit('input', _this.dateRange ? {from: null, to: null} : null);
$(_this.$refs.input).val('');
}
$(this.$refs.input).on('cancel.daterangepicker', clearIfCancelled);
$(this.$refs.input).on('hide.daterangepicker', checkIfAppliedElseClear.bind(this));
// if value from or to is undefined then clear the input field
if (!this.value || this.value.from === null || this.value.to === null) {
$(_this.$refs.input).val('');
// Clear input field if value is not set
if (_this.dateRange) {
if (!this.value || this.value.from === null || this.value.to === null) {
$(_this.$refs.input).val('');
}
} else {
if (!this.value) {
$(_this.$refs.input).val('');
}
}
// Add click event listener to the document
document.addEventListener('click', this.handleOutsideClick);
},
methods: {
handleOutsideClick(event) {
const datepicker = document.querySelector('.daterangepicker');
const input = this.$refs.input;
if (datepicker && !datepicker.contains(event.target) && event.target !== input) {
$(this.$refs.input).data('daterangepicker').hide();
}
}
},
watch: {
value: function (newVal) {
if (!this.isInitialized) return;
const datePicker = $(this.$refs.input).data('daterangepicker');
if (!newVal || newVal.from === null || newVal.to === null) {
$(this.$refs.input).val('');
if (this.dateRange) {
if (!newVal || newVal.from === null || newVal.to === null) {
$(this.$refs.input).val('');
} else {
datePicker.setStartDate(this.moment.unix(newVal.from));
datePicker.setEndDate(this.moment.unix(newVal.to));
}
} else {
datePicker.setStartDate(this.moment.unix(newVal.from));
datePicker.setEndDate(this.moment.unix(newVal.to));
if (!newVal) {
$(this.$refs.input).val('');
} else {
datePicker.setStartDate(this.moment.unix(newVal));
datePicker.setEndDate(this.moment.unix(newVal));
}
}
}
},
beforeDestroy() {
$(this.$refs.input).off('apply.daterangepicker');
$('.daterangepicker').remove();
document.removeEventListener('click', this.handleOutsideClick);
},
})
@@ -21,7 +21,7 @@ Vue.component('tt-table-crud', {
</slot>
<span v-else-if="column.modal?.type === 'select' && column.modal.items.find(item => item.value + '' === row[column.key] + '')">{{column.modal.items.find(item => item.value == row[column.key]).text}}</span>
<span v-else-if="column.modal?.type === 'select'"
<span v-else-if="column.modal?.type === 'select' && row[column.key] !== null && row[column.key] !== undefined"
:data-all-items="JSON.stringify(column.modal.items)"
>Select not found for column {{column.key}} and value {{row[column.key]}}</span>
</template>
@@ -64,8 +64,8 @@ Vue.component('tt-table-crud', {
<tt-input v-show="crudModalColumnVisibility[column.key]" v-else-if="column.type === 'number'" v-model="crudModalData[column.key]" :label="column.text" type="number" sm row/>
<tt-textarea v-show="crudModalColumnVisibility[column.key]" v-else-if="column.type === 'textarea'" v-model="crudModalData[column.key]" :label="column.text" sm row/>
<tt-select v-show="crudModalColumnVisibility[column.key]" v-else-if="column.type === 'select'" v-model="crudModalData[column.key]" :label="column.text" :options="column.items" sm row/>
<tt-autocomplete v-show="crudModalColumnVisibility[column.key]" v-else-if="column.type === 'autocomplete'" v-model="crudModalData[column.key]" :label="column.text" :api-url="column.apiUrl" :items="column.items" sm row/>
<tt-date-picker v-show="crudModalColumnVisibility[column.key]" v-else-if="column.type === 'datepicker'" v-model="crudModalData[column.key]" :label="column.text" sm row/>
<tt-autocomplete v-show="crudModalColumnVisibility[column.key]" v-else-if="column.type === 'autocomplete'" v-model="crudModalData[column.key]" :label="column.text" :api-url="column.apiUrl" :items="column.items" sm row :return-text="column.returnText" />
<tt-date-picker v-show="crudModalColumnVisibility[column.key]" v-else-if="column.type === 'datepicker'" v-model="crudModalData[column.key]" :label="column.text" sm row :date-range="false"/>
<tt-icon-select v-show="crudModalColumnVisibility[column.key]" v-else-if="column.type === 'icon-select'" v-model="crudModalData[column.key]" :label="column.text" sm row/>
<tt-checkbox v-show="crudModalColumnVisibility[column.key]" v-else-if="column.type === 'checkbox'" v-model="crudModalData[column.key]" :label="column.text" sm row/>
</slot>
@@ -94,6 +94,12 @@ Vue.component('tt-table-crud', {
this.crudModal = false;
}, async submitCrudModal() {
delete this.crudModalData.isTrusted;
for (const column of this.modalConfig.headers) {
if (column.type === 'autocomplete' && this.crudModalData[column.key] === '') {
delete this.crudModalData[column.key];
}
}
const response = await axios.post(this.crudModalData.id ? window['TT_CONFIG']['UPDATE_URL'] : window['TT_CONFIG']['CREATE_URL'],
this.crudModalData);
if (response.data.success) {
+7 -6
View File
@@ -135,7 +135,8 @@ Vue.component('tt-table', {
<!-- Table -->
<table
ref="table"
:class="['table','tt-table','table-condensed',{ 'loading': loading },{ 'table-striped': striped },{ 'table-bordered': bordered },{ 'table-hover': hover },{ 'table-sm': small }]">
:class="['table','tt-table','table-condensed',{ 'loading': loading },{ 'table-striped': striped },{ 'table-bordered': bordered },{ 'table-hover': hover },{ 'table-sm': small },
config.key + '-table']">
<thead style="border-width: 2px">
<tr>
<th scope="col" v-for="column in columns"
@@ -159,7 +160,7 @@ Vue.component('tt-table', {
<tt-number-range v-else-if="column.filter === 'numberRange' && !disableFiltering" :returnText="!ssr" v-model="filters[column.key]" sm/>
<tt-select v-else-if="column.filter === 'select' && !disableFiltering" :options="[{text: 'Alle', value: undefined}, ...column.filterOptions]" v-model="filters[column.key]" sm/>
<tt-autocomplete v-else-if="column.filter === 'autocomplete' && !disableFiltering" :api-url="column.filterOptions" v-model="filters[column.key]" sm/>
<tt-date-picker v-else-if="column.filter === 'date' && !disableFiltering" v-model="filters[column.key]"/>
<tt-date-picker v-else-if="(column.filter === 'date' || column.filter === 'datepicker') && !disableFiltering" v-model="filters[column.key]" sm/>
<!-- @formatter:on -->
</th>
</tr>
@@ -191,7 +192,7 @@ Vue.component('tt-table', {
style="cursor: pointer;font-size: 14px;padding-right: 8px;user-select: none"></i>
<slot :name="key.toLowerCase()" :value="row[key]" :row="row">
<span
v-if="column.filter === 'date'">{{
v-if="(column.filter === 'date' || column.filter === 'datepicker')">{{
row[key] ? (moment.unix(row[key])
.isValid() ? moment.unix(row[key]).format('DD.MM.YYYY HH:mm') : moment(row[key])
.format('DD.MM.YYYY HH:mm')) : ''
@@ -223,7 +224,7 @@ Vue.component('tt-table', {
<slot :name="key.toLowerCase()" :value="row[key]" :row="row">
<span
v-if="column.filter === 'date'">{{
v-if="(column.filter === 'date' || column.filter === 'datepicker')">{{
row[key] ? (moment.unix(row[key])
.isValid() ? moment.unix(row[key]).format('DD.MM.YYYY HH:mm') : moment(row[key])
.format('DD.MM.YYYY HH:mm')) : ''
@@ -805,12 +806,12 @@ Vue.component('tt-table', {
// use header#topnav as top to stick to but if window is resized then check if header#topnav height is changed
const headerHeight = document.querySelector('header#topnav')?.offsetHeight || 0;
style.innerHTML = `table.tt-table thead th { position: sticky; top: ${headerHeight}px; z-index: 1; background-color: white; }`;
style.innerHTML = `table.tt-table.${this.config.key}-table thead th { position: sticky; top: ${headerHeight}px; z-index: 1; background-color: white; }`;
style.id = 'tt-table-sticky-header';
window.addEventListener('resize', () => {
const headerHeight = document.querySelector('header#topnav')?.offsetHeight || 0;
style.innerHTML = `table.tt-table thead th { position: sticky; top: ${headerHeight}px; z-index: 1; background-color: white; }`;
style.innerHTML = `table.tt-table.${this.config.key}-table thead th { position: sticky; top: ${headerHeight}px; z-index: 1; background-color: white; }`;
})
document.head.appendChild(style);