feat: refs #8304 add saveUrl prop to VnNotes and implement confirm update functionality
gitea/salix-front/pipeline/pr-dev There was a failure building this commit Details

This commit is contained in:
Jose Antonio Tubau 2025-01-21 14:44:07 +01:00
parent f1b1163611
commit 83064c3813
2 changed files with 28 additions and 12 deletions

View File

@ -16,8 +16,11 @@ import VnSelect from 'components/common/VnSelect.vue';
import FetchData from 'components/FetchData.vue';
import VnInput from 'components/common/VnInput.vue';
const emit = defineEmits(['onFetch']);
const $props = defineProps({
url: { type: String, default: null },
saveUrl: {type: String, default: null},
filter: { type: Object, default: () => {} },
body: { type: Object, default: () => {} },
addNote: { type: Boolean, default: false },
@ -34,7 +37,7 @@ let originalText;
function handleClick(e) {
if (e.shiftKey && e.key === 'Enter') return;
if ($props.justInput) update();
if ($props.justInput) confirmAndUpdate();
else insert();
}
@ -51,7 +54,7 @@ async function insert() {
}
async function update() {
function confirmAndUpdate() {
if(!newNote.text && originalText)
quasar
.dialog({
@ -61,21 +64,21 @@ async function update() {
message: t('Are you sure remove this note?'),
},
})
.onOk(() => save())
.onOk(() => update())
.onCancel(() => {
newNote.text = originalText;
});
else save();
else update();
}
async function save() {
async function update() {
originalText = newNote.text;
const body = $props.body;
const newBody = {
...body,
...{ notes: newNote.text },
};
await axios.patch(`${$props.url}/${$props.body.workerFk}`, newBody);
await axios.patch(`${$props.saveUrl ?? `${$props.url}/${$props.body.workerFk}`}`, newBody);
}
onBeforeRouteLeave((to, from, next) => {
@ -101,9 +104,9 @@ onBeforeRouteLeave((to, from, next) => {
/>
<FetchData
v-if="justInput"
url="Businesses"
:url="url"
:filter="filter"
@on-fetch="(data) => (newNote.text = data[0]?.notes, originalText = data[0]?.notes)"
@on-fetch="(data) => (newNote.text = data[0]?.notes, originalText = data[0]?.notes, emit('onFetch', data))"
auto-load
/>
<QCard

View File

@ -1,8 +1,9 @@
<script setup>
import { nextTick, ref, watch } from 'vue';
import { nextTick, ref, watch, computed } from 'vue';
import { useI18n } from 'vue-i18n';
import { useRoute } from 'vue-router';
import { useRouter } from 'vue-router';
import { useAcl } from 'src/composables/useAcl';
import WorkerCalendarFilter from 'pages/Worker/Card/WorkerCalendarFilter.vue';
import FetchData from 'components/FetchData.vue';
@ -16,6 +17,12 @@ const router = useRouter();
const stateStore = useStateStore();
const route = useRoute();
const { t } = useI18n();
const acl = useAcl();
const canSeeNotes = computed(() =>
acl.hasAny([
{ model: 'Worker', props: '__get__business', accessType: 'READ' },
])
);
const workerIsFreelance = ref();
const WorkerFreelanceRef = ref();
const workerCalendarFilterRef = ref(null);
@ -29,6 +36,7 @@ const contractHolidays = ref(null);
const yearHolidays = ref(null);
const eventsMap = ref({});
const festiveEventsMap = ref({});
const saveUrl = ref();
const body = {
workerFk: route.params.id,
};
@ -187,11 +195,16 @@ watch([year, businessFk], () => refreshData());
</Teleport>
<div>
<VnNotes
v-if="canSeeNotes"
:just-input="true"
:url="`businesses`"
:url="`Workers/${route.params.id}/business`"
:filter="{fields: ['id', 'notes', 'workerFk']}"
:save-url="saveUrl"
@on-fetch="(data) => {
console.log(data);
saveUrl = `Businesses/${data[0].id}`
}"
:body="body"
:maxlength=10
:filter="{ fields: ['id', 'notes'], where: { workerFk: route.params.id }, order: 'started DESC' }"
/>
</div>
<QPage class="column items-center">