Misc. tweaks for model-crud, customer-field

This commit is contained in:
Lance Edgar 2022-08-11 00:17:34 -05:00
parent 4189bdf919
commit 2a1f5764a1
2 changed files with 26 additions and 15 deletions

View file

@ -4,6 +4,7 @@
<byjove-autocomplete v-if="!readonly && !useDropdown" <byjove-autocomplete v-if="!readonly && !useDropdown"
v-model="customerUUID" v-model="customerUUID"
ref="autocomplete"
:service-url="autocompleteUrl" :service-url="autocompleteUrl"
@input="customerChanged"> @input="customerChanged">
</byjove-autocomplete> </byjove-autocomplete>
@ -148,6 +149,13 @@ export default {
this.$emit('input', value) this.$emit('input', value)
}, },
setCustomer(customer) {
this.$refs.autocomplete.selectionMade({
value: customer.uuid,
label: customer._str,
})
},
}, },
} }

View file

@ -37,6 +37,7 @@
<div v-if="showButtons" <div v-if="showButtons"
class="buttons" style="margin-top: 1rem;"> class="buttons" style="margin-top: 1rem;">
<b-button :type="getSaveButtonType()" <b-button :type="getSaveButtonType()"
v-if="!hideSaveButton"
:icon-left="getSaveButtonIcon()" :icon-left="getSaveButtonIcon()"
:disabled="saveDisabled" :disabled="saveDisabled"
@click="save()"> @click="save()">
@ -158,6 +159,10 @@ export default {
type: Boolean, type: Boolean,
default: false, default: false,
}, },
createRowPermission: {
type: String,
default: null,
},
createRowButtonText: { createRowButtonText: {
type: String, type: String,
default: "Create New Row", default: "Create New Row",
@ -214,6 +219,10 @@ export default {
type: Boolean, type: Boolean,
default: false, default: false,
}, },
hideSaveButton: {
type: Boolean,
default: false,
},
saveDisabled: { saveDisabled: {
type: Boolean, type: Boolean,
default: false, default: false,
@ -427,23 +436,11 @@ export default {
return this.getModelSlug() return this.getModelSlug()
}, },
// TODO: should use this.$hasPerm()
hasPerm(perm) {
// if user is root then assume permission
if (this.$store.state.user && this.$store.state.user.is_root) {
return true
}
// otherwise do true perm check for user
return this.$store.state.permissions.includes(perm)
},
hasModelPerm(perm) { hasModelPerm(perm) {
// do normal check, but first add prefix // do normal check, but first add prefix
let prefix = this.getModelPermissionPrefix() let prefix = this.getModelPermissionPrefix()
return this.hasPerm(prefix + '.' + perm) return this.$byjoveHasPerm(prefix + '.' + perm)
}, },
renderLabel(obj) { renderLabel(obj) {
@ -665,8 +662,14 @@ export default {
if (this.mode != 'viewing') { if (this.mode != 'viewing') {
return false return false
} }
if (!this.hasModelPerm('create_row')) { if (this.createRowPermission) {
return false if (!this.$byjoveHasPerm(this.createRowPermission)) {
return false
}
} else {
if (!this.hasModelPerm('create_row')) {
return false
}
} }
return true return true
}, },