#6911 save on enter #207

Merged
jsegarra merged 50 commits from 6911-saveOnEnter into dev 2024-06-07 07:20:48 +00:00
12 changed files with 276 additions and 239 deletions

View File

@ -1,21 +1,48 @@
import { getCurrentInstance } from 'vue';
const filterAvailableInput = element => element.classList.contains('q-field__native') && !element.disabled
const filterAvailableText = element => element.__vueParentComponent.type.name === 'QInput' && element.__vueParentComponent?.attrs?.class !== 'vn-input-date';
const filterAvailableInput = (element) => {
return element.classList.contains('q-field__native') && !element.disabled;
};
const filterAvailableText = (element) => {
return (
element.__vueParentComponent.type.name === 'QInput' &&
element.__vueParentComponent?.attrs?.class !== 'vn-input-date'
);
};
export default {
mounted: function () {
const vm = getCurrentInstance();
if (vm.type.name === 'QForm')
if (!['searchbarForm','filterPanelForm'].includes(this.$el?.id)) {
if (vm.type.name === 'QForm') {
if (!['searchbarForm', 'filterPanelForm'].includes(this.$el?.id)) {
// AUTOFOCUS
const elementsArray = Array.from(this.$el.elements);
const firstInputElement = elementsArray.filter(filterAvailableInput).find(filterAvailableText);
const availableInputs = elementsArray.filter(filterAvailableInput);
const firstInputElement = availableInputs.find(filterAvailableText);
if (firstInputElement) {
firstInputElement.focus();
}
const that = this;
this.$el.addEventListener('keyup', function (evt) {
if (evt.key === 'Enter') {
const input = evt.target;
console.log('input', input);
if (input.type == 'textarea' && evt.shiftKey) {
evt.preventDefault();
let { selectionStart, selectionEnd } = input;
input.value =
input.value.substring(0, selectionStart) +
'\n' +
input.value.substring(selectionEnd);
selectionStart = selectionEnd = selectionStart + 1;
return;
}
evt.preventDefault();
that.onSubmit();
}
});
}
}
},
};

View File

@ -155,7 +155,7 @@ const rotateRight = () => {
editor.value.rotate(-90);
};
const onUploadAccept = () => {
const onSubmit = () => {
try {
if (!newPhoto.files && !newPhoto.url) {
notify(t('Select an image'), 'negative');
@ -206,7 +206,7 @@ const makeRequest = async () => {
@on-fetch="(data) => (allowedContentTypes = data.join(', '))"
auto-load
/>
<QForm @submit="onUploadAccept()" class="all-pointer-events">
<QForm @submit="onSubmit()" class="all-pointer-events">
<QCard class="q-pa-lg">
<span ref="closeButton" class="close-icon" v-close-popup>
Outdated
Review

Esto ya no hace falta

Esto ya no hace falta
https://gitea.verdnatura.es/verdnatura/salix-front/commit/d8bf95008a20c791714ac6e3beea18d8aefa5132
<QIcon name="close" size="sm" />

View File

@ -50,7 +50,7 @@ const onDataSaved = () => {
closeForm();
};
const submitData = async () => {
const onSubmit = async () => {
try {
isLoading.value = true;
const rowsToEdit = $props.rows.map((row) => ({ id: row.id, itemFk: row.itemFk }));
@ -74,7 +74,7 @@ const closeForm = () => {
</script>
<template>
<QForm @submit="submitData()" class="all-pointer-events">
<QForm @submit="onSubmit()" class="all-pointer-events">
<QCard class="q-pa-lg">
<span ref="closeButton" class="close-icon" v-close-popup>
<QIcon name="close" size="sm" />

View File

@ -83,7 +83,7 @@ const tableColumns = computed(() => [
},
]);
const fetchResults = async () => {
const onSubmit = async () => {
try {
let filter = itemFilter;
const params = itemFilterParams;
@ -145,7 +145,7 @@ const selectItem = ({ id }) => {
@on-fetch="(data) => (InksOptions = data)"
auto-load
/>
<QForm @submit="fetchResults()" class="all-pointer-events">
<QForm @submit="onSubmit()" class="all-pointer-events">
<QCard class="column" style="padding: 32px; z-index: 100">
<span ref="closeButton" class="close-icon" v-close-popup>
<QIcon name="close" size="sm" />

View File

@ -85,7 +85,7 @@ const tableColumns = computed(() => [
},
]);
const fetchResults = async () => {
const onSubmit = async () => {
try {
let filter = travelFilter;
const params = travelFilterParams;
@ -138,7 +138,7 @@ const selectTravel = ({ id }) => {
@on-fetch="(data) => (warehousesOptions = data)"
auto-load
/>
<QForm @submit="fetchResults()" class="all-pointer-events">
<QForm @submit="onSubmit()" class="all-pointer-events">
<QCard class="column" style="padding: 32px; z-index: 100">
<span ref="closeButton" class="close-icon" v-close-popup>

veo muchos @keyup.enter=
si todos los QForm los vamos a querer así.. @jsegarra no hay forma de hacerlo por defecto así?

veo muchos @keyup.enter= si todos los QForm los vamos a querer así.. @jsegarra no hay forma de hacerlo por defecto así?

Propone sustituir en todos los sitios donde haya QForm por FormModel. Lo hago en esta tarea?

Propone sustituir en todos los sitios donde haya QForm por FormModel. Lo hago en esta tarea?
<QIcon name="close" size="sm" />

View File

@ -20,7 +20,12 @@ const state = useState();
const currentUser = ref(state.getUser());
const newNote = ref('');
const vnPaginateRef = ref();
function handleKeyUp(event) {
jsegarra marked this conversation as resolved
Review
    if (event.key === 'Enter') {
        event.preventDefault();
        if (!event.shiftKey) insert();
    }
``` if (event.key === 'Enter') { event.preventDefault(); if (!event.shiftKey) insert(); } ```
if (event.key === 'Enter') {
event.preventDefault();
if (!event.shiftKey) insert();
}
}
async function insert() {
const body = $props.body;
Object.assign(body, { text: newNote.value });
@ -48,12 +53,12 @@ async function insert() {
size="lg"
autogrow
autofocus
@keyup.ctrl.enter.stop="insert"
@keyup="handleKeyUp"
Outdated
Review

Cambiar traduccion

Cambiar traduccion
https://gitea.verdnatura.es/verdnatura/salix-front/commit/492e333d2fdb4aaa1d903f5b1f21d78e6641889f
clearable
>
<template #append
><QBtn
:title="t('Save (ctrl + Enter)')"
<template #append>
<QBtn
:title="t('Save (Enter)')"
icon="save"
color="primary"
flat
@ -130,6 +135,6 @@ async function insert() {
es:
Add note here...: Añadir nota aquí...
New note: Nueva nota
Save (ctrl + Enter): Guardar (Ctrl + Intro)
Save (Enter): Guardar (Intro)
</i18n>

View File

@ -158,8 +158,7 @@ const statesFilter = {
map-options
use-input
:input-debounce="0"
>
</QSelect>
/>
</VnRow>
</template>
</FormModel>

View File

@ -174,7 +174,7 @@ const redirectToBuysView = () => {
@on-fetch="(data) => (packagingsOptions = data)"
auto-load
/>
<QForm>
<QForm @submit="onSubmit()">
Outdated
Review

Esto tampoco hace falta no?
Seria poner lo del @submit?

Esto tampoco hace falta no? Seria poner lo del @submit?
https://gitea.verdnatura.es/verdnatura/salix-front/commit/25d5887a577e8b721a047eac7f67da8eef7633cc
<Teleport to="#st-actions" v-if="stateStore?.isSubToolbarShown()">
<div>
<QBtnGroup push class="q-gutter-x-sm">
@ -222,7 +222,7 @@ const redirectToBuysView = () => {
<VnRow class="row q-gutter-md q-mb-md">
<VnInput
:label="t('entry.buys.reference')"
v-model="importData.ref"
v-model="importData.ref"
/>
</VnRow>
<VnRow class="row q-gutter-md q-mb-md">

View File

@ -81,7 +81,7 @@ async function setCreateDms() {
createDmsRef.value.show();
}
async function upsert() {
async function onSubmit() {
try {
const isEdit = !!dms.value.id;
const errors = {
@ -318,224 +318,236 @@ async function upsert() {
</template>
</FormModel>
<QDialog ref="editDmsRef">
<QCard>
<QCardSection class="q-pb-none">
<QItem class="q-px-none">
<span class="text-primary text-h6 full-width">
<QForm @submit="onSubmit()" class="all-pointer-events">
<QCard class="q-pa-sm">
<QCardSection class="row items-center q-pb-none">
<span class="text-primary text-h6">
<QIcon name="edit" class="q-mr-xs" />
{{ t('Edit document') }}
</span>
<QSpace />
<QBtn icon="close" flat round dense v-close-popup />
</QItem>
</QCardSection>
<QCardSection class="q-py-none">
<QItem>
<VnInput
class="full-width q-pa-xs"
:label="t('Reference')"
v-model="dms.reference"
clearable
clear-icon="close"
</QCardSection>
<QCardSection class="q-py-none">
<QItem>
<VnInput
class="full-width q-pa-xs"
:label="t('Reference')"
v-model="dms.reference"
clearable
clear-icon="close"
/>
<VnSelect
class="full-width q-pa-xs"
:label="t('Company')"
v-model="dms.companyId"
:options="companies"
option-value="id"
option-label="code"
:required="true"
/>
</QItem>
<QItem>
<VnSelect
class="full-width q-pa-xs"
:label="t('Warehouse')"
v-model="dms.warehouseId"
:options="warehouses"
option-value="id"
option-label="name"
:required="true"
/>
<VnSelect
class="full-width q-pa-xs"
:label="t('Type')"
v-model="dms.dmsTypeId"
:options="dmsTypes"
option-value="id"
option-label="name"
:required="true"
/>
</QItem>
<QItem>
<VnInput
:label="t('Description')"
v-model="dms.description"
:required="true"
type="textarea"
class="full-width q-pa-xs"
size="lg"
autogrow
clearable
clear-icon="close"
/>
</QItem>
<QItem>
<QFile
ref="inputFileRef"
class="full-width q-pa-xs"
:label="t('File')"
v-model="dms.files"
multiple
:accept="allowedContentTypes.join(',')"
clearable
clear-icon="close"
>
<template #append>
<QBtn
icon="attach_file_add"
flat
round
padding="xs"
@click="inputFileRef.pickFiles()"
>
<QTooltip>
{{ t('globals.selectFile') }}
</QTooltip>
</QBtn>
<QBtn icon="info" flat round padding="xs">
<QTooltip max-width="30rem">
{{
`${t(
'Allowed content types'
)}: ${allowedContentTypes.join(', ')}`
}}
</QTooltip>
https://gitea.verdnatura.es/verdnatura/salix-front/commit/59f9cf411186d3512b3af5f5f01690222f430f3c
</QBtn>
</template>
</QFile>
</QItem>
<QItem>
<QCheckbox
:label="t('Generate identifier for original file')"
v-model="dms.hasFile"
/>
</QItem>
</QCardSection>
<QCardActions class="justify-end">
<QBtn
flat
:label="t('globals.close')"
color="primary"
v-close-popup
/>
<VnSelect
class="full-width q-pa-xs"
:label="t('Company')"
v-model="dms.companyId"
:options="companies"
option-value="id"
option-label="code"
:required="true"
/>
</QItem>
<QItem>
<VnSelect
class="full-width q-pa-xs"
:label="t('Warehouse')"
v-model="dms.warehouseId"
:options="warehouses"
option-value="id"
option-label="name"
:required="true"
/>
<VnSelect
class="full-width q-pa-xs"
:label="t('Type')"
v-model="dms.dmsTypeId"
:options="dmsTypes"
option-value="id"
option-label="name"
:required="true"
/>
</QItem>
<QItem>
<VnInput
:label="t('Description')"
v-model="dms.description"
:required="true"
type="textarea"
class="full-width q-pa-xs"
size="lg"
autogrow
clearable
clear-icon="close"
/>
</QItem>
<QItem>
<QFile
ref="inputFileRef"
class="full-width q-pa-xs"
:label="t('File')"
v-model="dms.files"
multiple
:accept="allowedContentTypes.join(',')"
clearable
clear-icon="close"
>
<template #append>
<QBtn
icon="attach_file_add"
flat
round
padding="xs"
@click="inputFileRef.pickFiles()"
>
<QTooltip>
{{ t('globals.selectFile') }}
</QTooltip>
</QBtn>
<QBtn icon="info" flat round padding="xs">
<QTooltip max-width="30rem">
{{
`${t(
'Allowed content types'
)}: ${allowedContentTypes.join(', ')}`
}}
</QTooltip>
</QBtn>
</template>
</QFile>
</QItem>
<QItem>
<QCheckbox
:label="t('Generate identifier for original file')"
v-model="dms.hasFile"
/>
</QItem>
</QCardSection>
<QCardActions class="justify-end">
<QBtn flat :label="t('globals.close')" color="primary" v-close-popup />
<QBtn :label="t('globals.save')" color="primary" @click="upsert" />
</QCardActions>
</QCard>
<QBtn :label="t('globals.save')" color="primary" @click="onSubmit" />
</QCardActions>
</QCard>
</QForm>
</QDialog>
<QDialog ref="createDmsRef">
<QCard>
<QCardSection class="q-pb-none">
<QItem>
<span class="text-primary text-h6 full-width">
<QForm @submit="onSubmit()" class="all-pointer-events">
<QCard class="q-pa-sm">
<QCardSection class="row items-center q-pb-none">
<span class="text-primary text-h6">
<QIcon name="edit" class="q-mr-xs" />
{{ t('Create document') }}
</span>
<QBtn icon="close" flat round dense v-close-popup align="right" />
</QItem>
</QCardSection>
<QCardSection class="q-pb-none">
<QItem>
<VnInput
class="full-width q-pa-xs"
:label="t('Reference')"
v-model="dms.reference"
<QSpace />
<QBtn icon="close" flat round dense v-close-popup />
</QCardSection>
<QCardSection class="q-pb-none">
<QItem>
<VnInput
class="full-width q-pa-xs"
:label="t('Reference')"
v-model="dms.reference"
/>
<VnSelect
class="full-width q-pa-xs"
:label="`${t('Company')}*`"
v-model="dms.companyId"
:options="companies"
option-value="id"
option-label="code"
:required="true"
/>
</QItem>
<QItem>
<VnSelect
class="full-width q-pa-xs"
:label="`${t('Warehouse')}*`"
v-model="dms.warehouseId"
:options="warehouses"
option-value="id"
option-label="name"
:required="true"
/>
<VnSelect
class="full-width q-pa-xs"
:label="`${t('Type')}*`"
v-model="dms.dmsTypeId"
:options="dmsTypes"
option-value="id"
option-label="name"
:required="true"
/>
</QItem>
<QItem>
<VnInput
class="full-width q-pa-xs"
type="textarea"
size="lg"
autogrow
:label="`${t('Description')}*`"
v-model="dms.description"
clearable
clear-icon="close"
:rules="[(val) => val.length || t('Required field')]"
/>
</QItem>
<QItem>
<QFile
ref="inputFileRef"
class="full-width q-pa-xs"
:label="t('File')"
v-model="dms.files"
multiple
:accept="allowedContentTypes.join(',')"
clearable
clear-icon="close"
>
<template #append>
<QBtn
icon="attach_file_add"
flat
round
padding="xs"
@click="inputFileRef.pickFiles()"
>
<QTooltip>
{{ t('globals.selectFile') }}
</QTooltip>
</QBtn>
<QBtn icon="info" flat round padding="xs">
<QTooltip max-width="30rem">
{{
`${t(
'Allowed content types'
)}: ${allowedContentTypes.join(', ')}`
}}
</QTooltip>
</QBtn>
</template>
</QFile>
</QItem>
<QItem>
<QCheckbox
:label="t('Generate identifier for original file')"
v-model="dms.hasFile"
/>
</QItem>
</QCardSection>
<QCardActions align="right">
<QBtn
flat
:label="t('globals.close')"
color="primary"
v-close-popup
/>
<VnSelect
class="full-width q-pa-xs"
:label="`${t('Company')}*`"
v-model="dms.companyId"
:options="companies"
option-value="id"
option-label="code"
:required="true"
/>
</QItem>
<QItem>
<VnSelect
class="full-width q-pa-xs"
:label="`${t('Warehouse')}*`"
v-model="dms.warehouseId"
:options="warehouses"
option-value="id"
option-label="name"
:required="true"
/>
<VnSelect
class="full-width q-pa-xs"
:label="`${t('Type')}*`"
v-model="dms.dmsTypeId"
:options="dmsTypes"
option-value="id"
option-label="name"
:required="true"
/>
</QItem>
<QItem>
<VnInput
class="full-width q-pa-xs"
type="textarea"
size="lg"
autogrow
:label="`${t('Description')}*`"
v-model="dms.description"
clearable
clear-icon="close"
:rules="[(val) => val.length || t('Required field')]"
/>
</QItem>
<QItem>
<QFile
ref="inputFileRef"
class="full-width q-pa-xs"
:label="t('File')"
v-model="dms.files"
multiple
:accept="allowedContentTypes.join(',')"
clearable
clear-icon="close"
>
<template #append>
<QBtn
icon="attach_file_add"
flat
round
padding="xs"
@click="inputFileRef.pickFiles()"
>
<QTooltip>
{{ t('globals.selectFile') }}
</QTooltip>
</QBtn>
<QBtn icon="info" flat round padding="xs">
<QTooltip max-width="30rem">
{{
`${t(
'Allowed content types'
)}: ${allowedContentTypes.join(', ')}`
}}
</QTooltip>
</QBtn>
</template>
</QFile>
</QItem>
<QItem>
<QCheckbox
:label="t('Generate identifier for original file')"
v-model="dms.hasFile"
/>
</QItem>
</QCardSection>
<QCardActions align="right">
<QBtn flat :label="t('globals.close')" color="primary" v-close-popup />
<QBtn :label="t('globals.save')" color="primary" @click="upsert" />
</QCardActions>
</QCard>
<QBtn :label="t('globals.save')" color="primary" @click="onSubmit" />
</QCardActions>
</QCard>
</QForm>
</QDialog>
</template>
<style lang="scss" scoped>

View File

@ -487,9 +487,6 @@ const createInvoiceInCorrection = async () => {
.q-dialog {
.q-card {
max-width: 45em;
.q-item__section > .q-input {
padding-bottom: 1.4em;
}
}
}

View File

@ -33,7 +33,7 @@ const addToOrder = async () => {
<template>
<div class="container order-catalog-item q-pb-md">
<QForm @submit.prevent="addToOrder">
<QForm @submit="addToOrder">
Outdated
Review

Esto tampoco hace falta no?

Esto tampoco hace falta no?
https://gitea.verdnatura.es/verdnatura/salix-front/commit/0ad839dfc655dee059a1c32da599ffc6aadb2115
<QMarkupTable class="shadow-0">
<tbody>
<tr v-for="item in fields" :key="item.warehouse">

View File

@ -13,7 +13,6 @@ describe('AgencyWorkCenter', () => {
cy.get(
'.vn-row > .q-field > .q-field__inner > .q-field__control > .q-field__control-container'
).type('workCenterOne{enter}');
cy.get('.q-btn--standard > .q-btn__content > .block').click();
cy.get('.q-notification__message').should('have.text', 'Data created');
});
@ -35,13 +34,11 @@ describe('AgencyWorkCenter', () => {
cy.get(
'.vn-row > .q-field > .q-field__inner > .q-field__control > .q-field__control-container'
).type('workCenterOne{enter}');
cy.get('.q-btn--standard > .q-btn__content > .block').click();
cy.get('.q-notification__message').should('have.text', 'Data created');
cy.get('.q-page-sticky > div > .q-btn > .q-btn__content > .q-icon').click();
cy.get(
'.vn-row > .q-field > .q-field__inner > .q-field__control > .q-field__control-container'
).type('workCenterOne{enter}');
cy.get('.q-btn--standard > .q-btn__content > .block').click();
cy.get(
':nth-child(2) > .q-notification__wrapper > .q-notification__content > .q-notification__message'