3
0

Make user record field values clearable

This commit is contained in:
Jože Fortun 2024-07-08 15:51:53 +02:00
parent ee2e678bf6
commit c06d9d28bf
5 changed files with 28 additions and 54 deletions

View File

@ -47,7 +47,6 @@
:options="options"
:get-option-label="getOptionLabel"
:get-option-key="getOptionKey"
:clearable="false"
:filterable="false"
:selectable="option => option.selectable"
:loading="processing"
@ -96,7 +95,6 @@
:get-option-label="getOptionLabel"
:get-option-key="getOptionKey"
:value="getUserIDByIndex(ctx.index)"
:clearable="false"
:filterable="false"
:selectable="option => option.selectable"
:loading="processing"
@ -116,16 +114,13 @@
</template>
</multi>
<template
v-else
>
<template v-else>
<c-input-select
:placeholder="$t('kind.user.suggestionPlaceholder')"
:options="options"
:get-option-label="getOptionLabel"
:get-option-key="getOptionKey"
:value="getUserIDByIndex()"
:clearable="field.name !== 'ownedBy'"
:filterable="false"
:selectable="option => option.selectable"
:loading="processing"

View File

@ -74,7 +74,7 @@
</div>
<i
v-else
class="text-primary"
class="text-muted"
>
{{ $t('field.noPermission') }}
</i>
@ -299,28 +299,6 @@ export default {
this.inlineEdit.query = ''
},
isFieldEditable (field) {
if (!field) return false
const { canCreateOwnedRecord } = this.fieldModule || {}
const { createdAt, canManageOwnerOnRecord } = this.record || {}
const { name, canUpdateRecordValue, isSystem, expressions = {} } = field || {}
if (!canUpdateRecordValue) return false
if (isSystem) {
// Make ownedBy field editable if correct permissions
if (name === 'ownedBy') {
// If not created we check module permissions, otherwise the canManageOwnerOnRecord
return createdAt ? canManageOwnerOnRecord : canCreateOwnedRecord
}
return false
}
return !expressions.value
},
setDefaultValues () {
this.referenceRecord = undefined
this.referenceModule = undefined

View File

@ -65,11 +65,12 @@
value-only
/>
</div>
<div
v-else
>
<i
class="text-primary"
class="text-muted"
>
{{ $t('field.noPermission') }}
</i>
@ -198,29 +199,6 @@ export default {
.filterByMeta('id', this.errorID)
},
isFieldEditable (field) {
if (!field) return false
const { canCreateRecord, canCreateOwnedRecord } = this.module || {}
const { createdAt, canManageOwnerOnRecord } = this.record || {}
const { name, canUpdateRecordValue, isSystem, expressions = {} } = field || {}
// If new record check canCreateRecord module permissions, otherwise canUpdateRecordValue on the record
if (this.isNew ? !canCreateRecord : !canUpdateRecordValue) return false
if (isSystem) {
// Make ownedBy field editable if correct permissions
if (name === 'ownedBy') {
// If not created we check module permissions, otherwise the canManageOwnerOnRecord
return createdAt ? canManageOwnerOnRecord : canCreateOwnedRecord
}
return false
}
return !expressions.value
},
onFieldChange: debounce(function (field) {
this.evaluateExpressions()

View File

@ -4,7 +4,7 @@ import { NoID } from '@cortezaproject/corteza-js'
export default {
data () {
return {
conditions: [],
conditions: [], // Array of fieldIDs that should be hidden
evaluating: false,
}
},

View File

@ -38,5 +38,28 @@ export default {
}
}))
},
isFieldEditable (field) {
if (!field) return false
const { canCreateRecord, canCreateOwnedRecord } = this.module || {}
const { canManageOwnerOnRecord, canUpdateRecord } = this.record || {}
const { name, canReadRecordValue, canUpdateRecordValue, isSystem, expressions = {} } = field || {}
// If new record check canCreateRecord module permissions, otherwise check canUpdateRecord and only then canUpdateRecordValue
if (this.isNew ? !canCreateRecord : !(canUpdateRecord && canReadRecordValue && canUpdateRecordValue)) return false
if (isSystem) {
// Make ownedBy field editable if correct permissions
if (name === 'ownedBy') {
// If created we check module permissions, otherwise the canManageOwnerOnRecord
return this.isNew ? canCreateOwnedRecord : canManageOwnerOnRecord
}
return false
}
return !expressions.value
},
},
}