diff --git a/src/components/ui/VnNotes.vue b/src/components/ui/VnNotes.vue index 1690a94ba..54dc61c5a 100644 --- a/src/components/ui/VnNotes.vue +++ b/src/components/ui/VnNotes.vue @@ -22,6 +22,7 @@ const $props = defineProps({ body: { type: Object, default: () => {} }, addNote: { type: Boolean, default: false }, selectType: { type: Boolean, default: false }, + justInput: { type: Boolean, default: false }, }); const { t } = useI18n(); @@ -29,6 +30,13 @@ const quasar = useQuasar(); const newNote = reactive({ text: null, observationTypeFk: null }); const observationTypes = ref([]); const vnPaginateRef = ref(); +let originalText; + +function handleClick(e) { + if (e.shiftKey && e.key === 'Enter') return; + if ($props.justInput) update(); + else insert(); +} async function insert() { if (!newNote.text || ($props.selectType && !newNote.observationTypeFk)) return; @@ -41,8 +49,37 @@ async function insert() { await axios.post($props.url, newBody); await vnPaginateRef.value.fetch(); } + + +async function update() { + if(!newNote.text && originalText) + quasar + .dialog({ + component: VnConfirm, + componentProps: { + title: t('New note is empty'), + message: t('Are you sure remove this note?'), + }, + }) + .onOk(() => save()) + .onCancel(() => { + newNote.text = originalText; + }); + else save(); +} + +async function save() { + originalText = newNote.text; + const body = $props.body; + const newBody = { + ...body, + ...{ notes: newNote.text }, + }; + await axios.patch(`${$props.url}/${$props.body.workerFk}`, newBody); +} + onBeforeRouteLeave((to, from, next) => { - if (newNote.text) + if ((newNote.text && !$props.justInput) || (newNote.text !== originalText) && $props.justInput ) quasar.dialog({ component: VnConfirm, componentProps: { @@ -61,9 +98,20 @@ onBeforeRouteLeave((to, from, next) => { :filter="{ fields: ['id', 'description'] }" auto-load @on-fetch="(data) => (observationTypes = data)" + /> + - - + + {{ t('New note') }} @@ -85,7 +133,7 @@ onBeforeRouteLeave((to, from, next) => { filled size="lg" autogrow - @keyup.enter.stop="insert" + @keyup.enter.stop="handleClick" clearable :required="true" > @@ -95,7 +143,7 @@ onBeforeRouteLeave((to, from, next) => { icon="save" color="primary" flat - @click="insert" + @click="handleClick" class="q-mb-xs" dense data-cy="saveNote" @@ -106,6 +154,7 @@ onBeforeRouteLeave((to, from, next) => { { if (!data) return; @@ -181,6 +185,15 @@ watch([year, businessFk], () => refreshData()); :year-holidays="yearHolidays" /> +
+ +
@@ -229,6 +242,7 @@ watch([year, businessFk], () => refreshData()); } + en: addAbsencesText: To start adding absences, click an absence type from the right menu and then on the day you want to add an absence