Skip to content

Commit

Permalink
confirm dialog on saving data when data has changed on server
Browse files Browse the repository at this point in the history
  • Loading branch information
wulff007 committed Sep 2, 2024
1 parent 3fc8c90 commit b1a842b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -184,5 +184,6 @@
"open": "Open",
"openRevision": "Open from revision",
"confirmOpenRevision": "Data is changed! Do you confirm opening data from the revision?",
"revisions": "Changes history"
"revisions": "Changes history",
"confirmSaveOnServerDataChanged": "Data is changed on server! Do you confirm save current data?"
}
3 changes: 2 additions & 1 deletion src/locales/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -183,5 +183,6 @@
"open": "Открыть",
"openRevision": "Открыть из истории",
"confirmOpenRevision": "Данные изменены! Открыть запись из истории?",
"revisions": "История изменений"
"revisions": "История изменений",
"confirmSaveOnServerDataChanged": "Данные на сервере изменены! Вы точно хотите сохранить данные?"
}
19 changes: 19 additions & 0 deletions src/pages/PageView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ let revisionBtn = ref(null)
let editEntity = ref<EntityInterface>(null)
let editEntityRevisionId = -1
let serverRevision = null
let isSaving = false
let editDataSource: DataSourceInterface = null
let isNew = ref(false)
Expand Down Expand Up @@ -230,6 +231,19 @@ async function save() {
.then(async () => {
await saveData()
})
} else if (!isNew.value && serverRevision !== editEntityRevisionId) {
ElMessageBox.confirm(
t('confirmSaveOnServerDataChanged'),
t('save'),
{
confirmButtonText: t('save'),
cancelButtonText: t('cancel'),
type: 'warning',
}
)
.then(async () => {
await saveData()
})
} else {
await saveData()
}
Expand All @@ -250,6 +264,7 @@ async function save() {
id: editEntityRevisionId
}
isChanged.value = false
serverRevision = editEntityRevisionId
await setViewed()
ElMessage.success(t('saved'))
Expand Down Expand Up @@ -445,11 +460,13 @@ async function init() {
currentRevision.value = {
id: editEntityRevisionId
}
serverRevision = editEntityRevisionId
setViewed()
} else {
editEntity.value = await generateEntityWithDefault(editDataSource.fields)
isNew.value = true
editEntityRevisionId = -1
serverRevision = null
}
scriptContext.value.item = editEntity.value
Expand Down Expand Up @@ -627,12 +644,14 @@ async function onUpdates(msg: any) {
if (msg.entity.id === editEntity.value.id
&& editEntityRevisionId !== msg.entity.rev) {
serverRevision = msg.entity.rev
ElMessage.warning({
message: t('entityUpdated'),
duration: 0,
showClose: true,
grouping: true
})
}
}
Expand Down

0 comments on commit b1a842b

Please sign in to comment.