Add support for "Create Row" button when viewing parent CRUD object

plus misc. other tweaks, for polish
This commit is contained in:
Lance Edgar 2020-03-27 11:48:30 -05:00
parent bc148f910a
commit d1db1c54c4
2 changed files with 78 additions and 13 deletions

View file

@ -42,14 +42,8 @@
@click="save()"> @click="save()">
{{ getSaveButtonText() }} {{ getSaveButtonText() }}
</b-button> </b-button>
<b-button v-if="mode == 'creating'" <b-button tag="router-link"
tag="router-link" :to="getCancelURL()">
:to="getModelPathPrefix() + '/'">
Cancel
</b-button>
<b-button v-if="mode == 'editing' || mode == 'deleting'"
tag="router-link"
:to="getViewURL()">
Cancel Cancel
</b-button> </b-button>
</div> </div>
@ -63,7 +57,7 @@
icon-left="edit" icon-left="edit"
tag="router-link" tag="router-link"
:to="getEditURL()"> :to="getEditURL()">
Edit This Edit this {{ getModelTitle() }}
</b-button> </b-button>
<b-button v-if="shouldAllowDelete() && !quickDelete" <b-button v-if="shouldAllowDelete() && !quickDelete"
@ -71,20 +65,44 @@
icon-left="trash" icon-left="trash"
tag="router-link" tag="router-link"
:to="getDeleteURL()"> :to="getDeleteURL()">
Delete This Delete this {{ getModelTitle() }}
</b-button> </b-button>
<b-button v-if="shouldAllowDelete() && quickDelete" <b-button v-if="shouldAllowDelete() && quickDelete"
type="is-danger" type="is-danger"
icon-left="trash" icon-left="trash"
@click="$emit('delete')"> @click="$emit('delete')">
Delete This Delete this {{ getModelTitle() }}
</b-button> </b-button>
</div> </div>
<slot name="quick-entry"></slot> <slot name="quick-entry"></slot>
<div v-if="hasRows && mode == 'viewing'"> <div v-if="hasRows && mode == 'viewing'">
<h2 v-if="rowsTitle">{{ rowsTitle }}</h2> <br />
<div v-if="rowsTitle && shouldAllowCreateRow()"
style="display: flex;">
<h2 style="flex-grow: 1;">{{ rowsTitle }}</h2>
<b-button type="is-primary"
tag="router-link"
:to="getCreateRowButtonUrl()"
icon-left="plus">
{{ createRowButtonText }}
</b-button>
</div>
<h2 v-if="rowsTitle && !shouldAllowCreateRow()">
{{ rowsTitle }}
</h2>
<b-button v-if="shouldAllowCreateRow() && !rowsTitle"
type="is-primary"
tag="router-link"
:to="getCreateRowButtonUrl()"
icon-left="plus">
{{ createRowButtonText }}
</b-button>
<slot name="row-filters"></slot> <slot name="row-filters"></slot>
<b-menu> <b-menu>
<b-menu-list> <b-menu-list>
@ -137,6 +155,18 @@ export default {
type: String, type: String,
default: null, default: null,
}, },
allowCreateRow: {
type: Boolean,
default: false,
},
createRowButtonText: {
type: String,
default: "Create New Row",
},
createRowButtonUrl: {
type: String,
default: null,
},
rowsPaginated: { rowsPaginated: {
type: Boolean, type: Boolean,
default: true, default: true,
@ -194,6 +224,10 @@ export default {
type: String, type: String,
default: null, default: null,
}, },
cancelUrl: {
type: String,
default: null,
},
}, },
data: function() { data: function() {
return { return {
@ -548,6 +582,16 @@ export default {
return true return true
}, },
getCancelURL() {
if (this.cancelUrl) {
return this.cancelUrl
}
if (this.mode == 'creating') {
return this.getIndexURL()
}
return this.getViewURL()
},
save() { save() {
if (this.mode == 'deleting') { if (this.mode == 'deleting') {
this.confirmDelete() this.confirmDelete()
@ -586,6 +630,26 @@ export default {
}) })
}) })
}, },
shouldAllowCreateRow() {
if (!this.allowCreateRow) {
return false
}
if (this.mode != 'viewing') {
return false
}
if (!this.hasModelPerm('create_row')) {
return false
}
return true
},
getCreateRowButtonUrl() {
if (this.createRowButtonUrl) {
return this.createRowButtonUrl
}
return this.getApiRowsUrl()
},
}, },
} }
</script> </script>

View file

@ -12,7 +12,8 @@
<b-button class="new-object" <b-button class="new-object"
type="is-primary" type="is-primary"
tag="router-link" tag="router-link"
:to="getModelPathPrefix() + '/new'"> :to="getModelPathPrefix() + '/new'"
icon-left="plus">
New {{ getModelTitle() }} New {{ getModelTitle() }}
</b-button> </b-button>
</div> </div>