@ -15,6 +15,7 @@ import {
ReloadRowDataHookInj ,
computedInject ,
createEventHook ,
iconMap ,
inject ,
message ,
provide ,
@ -66,6 +67,9 @@ const router = useRouter()
const isPublic = inject ( IsPublicInj , ref ( false ) )
/ / t o c h e c k i f a e x p a n d e d f o r m w h i c h i s n o t y e t s a v e d e x i s t o r n o t
const isUnsavedFormExist = ref ( false )
const { isUIAllowed } = useRoles ( )
const reloadTrigger = inject ( ReloadRowDataHookInj , createEventHook ( ) )
@ -151,6 +155,7 @@ const onClose = () => {
const onDuplicateRow = ( ) => {
duplicatingRowInProgress . value = true
isUnsavedFormExist . value = true
const oldRow = { ... row . value . row }
delete oldRow . ncRecordId
const newRow = Object . assign (
@ -168,25 +173,38 @@ const onDuplicateRow = () => {
} , 500 )
}
const save = async ( ) => {
if ( isNew . value ) {
const data = await _save ( rowState . value )
await syncLTARRefs ( data )
reloadTrigger ? . trigger ( )
} else {
await _save ( )
reloadTrigger ? . trigger ( )
}
isUnsavedFormExist . value = false
}
const isPreventChangeModalOpen = ref ( false )
const discardPreventModal = ( ) => {
emits ( 'next' )
isPreventChangeModalOpen . value = false
}
const onNext = async ( ) => {
if ( changedColumns . value . size > 0 ) {
await Modal . confirm ( {
title : 'Do you want to save the changes?' ,
okText : 'Save' ,
cancelText : 'Discard' ,
onOk : async ( ) => {
await save ( )
emits ( 'next' )
} ,
onCancel : ( ) => {
emits ( 'next' )
} ,
} )
isPreventChangeModalOpen . value = true
} else {
emits ( 'next' )
}
}
const saveChanges = async ( ) => {
isUnsavedFormExist . value = false
await save ( )
emits ( 'next' )
}
const reloadParentRowHook = inject ( ReloadRowDataHookInj , createEventHook ( ) )
/ / o v e r r i d e r e l o a d t r i g g e r a n d u s e i t t o r e l o a d g r i d a n d t h e f o r m i t s e l f
@ -208,6 +226,10 @@ if (isKanban.value) {
}
}
watch ( isUnsavedFormExist , ( ) => {
console . log ( isUnsavedFormExist . value , 'HEHEH' )
} )
provide ( IsExpandedFormOpenInj , isExpanded )
const cellWrapperEl = ref ( )
@ -230,18 +252,6 @@ const addNewRow = () => {
isExpanded . value = true
} , 500 )
}
const save = async ( ) => {
if ( isNew . value ) {
const data = await _save ( rowState . value )
await syncLTARRefs ( data )
reloadTrigger ? . trigger ( )
} else {
await _save ( )
reloadTrigger ? . trigger ( )
}
}
/ / a t t a c h k e y b o a r d l i s t e n e r s t o s w i t c h b e t w e e n r o w s
/ / u s i n g a l t + l e f t / r i g h t a r r o w k e y s
useActiveKeyupListener (
@ -325,14 +335,9 @@ const onConfirmDeleteRowClick = async () => {
showDeleteRowModal . value = false
await deleteRowById ( primaryKey . value )
message . success ( 'Row deleted' )
/ / i f ( ! p r o p s . l a s t R o w ) {
/ / a w a i t o n N e x t ( )
/ / } e l s e i f ( ! p r o p s . f i r s t R o w ) {
/ / e m i t s ( ' p r e v ' )
/ / } e l s e {
/ / }
reloadTrigger . trigger ( )
onClose ( )
showDeleteRowModal . value = false
}
watch (
@ -378,7 +383,7 @@ export default {
< div class = "h-[85vh] xs:(max-h-full) max-h-215 flex flex-col p-6" >
< div class = "flex h-8 flex-shrink-0 w-full items-center nc-expanded-form-header relative mb-4 justify-between" >
< template v-if ="!isMobileMode" >
< div class = "flex gap-3" >
< div class = "flex gap-3 w-100 " >
< div class = "flex gap-2" >
< NcButton
v - if = "props.showNextPrevIcons"
@ -399,7 +404,7 @@ export default {
< MdiChevronDown class = "text-md" / >
< / NcButton >
< / div >
< div v-if ="displayValue" class="flex items-center truncate max-w-32 font-bold text-gray-800 text-xl" >
< div v-if ="displayValue" class="flex items-center truncate font-bold text-gray-800 text-xl" >
{ { displayValue } }
< / div >
< div class = "bg-gray-100 px-2 gap-1 flex my-1 items-center rounded-lg text-gray-800 font-medium" >
@ -438,7 +443,7 @@ export default {
< NcMenuItem
v - if = "isUIAllowed('dataEdit') && !isNew"
v - e = "['c:row-expand:delete']"
class = "!text-red-500"
class = "!text-red-500 !hover:bg-red-50 "
@ click = "!isNew && onDeleteRowClick()"
>
< component :is ="iconMap.delete" data -testid = " nc -expanded -form -delete " class = "cursor-pointer nc-delete-row" / >
@ -595,7 +600,7 @@ export default {
< NcMenuItem
v - if = "isUIAllowed('dataEdit') && !isNew"
v - e = "['c:row-expand:delete']"
class = "!text-red-500"
class = "!text-red-500 !hover:bg-red-50 "
@ click = "!isNew && onDeleteRowClick()"
>
< div data -testid = " nc -expanded -form -delete " >
@ -624,6 +629,7 @@ export default {
type = "primary"
size = "medium"
class = "nc-expand-form-save-btn !xs:(text-base)"
: disabled = "changedColumns.size === 0 && !isUnsavedFormExist"
@ click = "save"
>
< div class = "xs:px-1" > Save < / div >
@ -642,16 +648,32 @@ export default {
< / div >
< / NcModal >
< NcModal v -model :visible ="showDeleteRowModal" class = "!w-[25rem] !xs-" >
< div class = "" >
< div class = "prose-xl font-bold self-center" > Delete row ? < / div >
< div class = "mt-4" > Are you sure you want to delete this row ? < / div >
< GeneralDeleteModal v -model :visible ="showDeleteRowModal" entity -name = " Record " : on -delete = " ( ) = > onConfirmDeleteRowClick ( ) " >
< template # entity -preview >
< span >
< div class = "flex flex-row items-center py-2.25 px-2.5 bg-gray-50 rounded-lg text-gray-700 mb-4" >
< component :is ="iconMap.table" class = "nc-view-icon" / >
< div class = "capitalize text-ellipsis overflow-hidden select-none w-full pl-1.75 break-keep whitespace-nowrap" >
{ { meta . title } }
< / div >
< div class = "flex flex-row gap-x-2 mt-4 pt-1.5 justify-end pt-4 gap-x-3" >
< NcButton v-if ="isMobileMode" type="secondary" @click="showDeleteRowModal = false" > {{ $ t ( ' general.cancel ' ) }} < / NcButton >
< / div >
< / span >
< / template >
< / GeneralDeleteModal >
<!-- Prevent unsaved change modal -- >
< NcModal v -model :visible ="isPreventChangeModalOpen" size = "small" >
< template # header >
< div class = "flex flex-row items-center gap-x-2" > Do you want to save the changes ? < / div >
< / template >
< div class = "mt-2" >
< div class = "flex flex-row justify-end gap-x-2 mt-6" >
< NcButton type = "secondary" @click ="discardPreventModal" > {{ $ t ( ' general.quit ' ) }} < / NcButton >
< NcButton v-e ="['a:row-expand:delete']" @click="onConfirmDeleteRowClick" > {{ $ t ( ' general.confirm ' ) }} < / NcButton >
< NcButton key = "submit" type = "primary" label = "Rename Table" loading -label = " Renaming Table " @click ="saveChanges" >
{ { $t ( 'activity.saveAndQuit' ) } }
< / NcButton >
< / div >
< / div >
< / NcModal >
< / template >