Add basic support for editing field help info

This commit is contained in:
Lance Edgar 2022-12-24 21:46:02 -06:00
parent 9fe9983bf9
commit 3befdc09e3
6 changed files with 218 additions and 7 deletions

View file

@ -66,6 +66,47 @@
% if not form.readonly:
${h.end_form()}
% endif
% if can_edit_help:
<b-modal has-modal-card
:active.sync="configureFieldShowDialog">
<div class="modal-card">
<header class="modal-card-head">
<p class="modal-card-title">Field: {{ configureFieldName }}</p>
</header>
<section class="modal-card-body">
<b-field label="Label">
<b-input v-model="configureFieldLabel" disabled></b-input>
</b-field>
<b-field label="Help Text (Markdown)">
<b-input v-model="configureFieldMarkdown"
type="textarea" rows="8"
ref="configureFieldMarkdown">
</b-input>
</b-field>
</section>
<footer class="modal-card-foot">
<b-button @click="configureFieldShowDialog = false">
Cancel
</b-button>
<b-button type="is-primary"
@click="configureFieldSave()"
:disabled="configureFieldSaving"
icon-pack="fas"
icon-left="save">
{{ configureFieldSaving ? "Working, please wait..." : "Save" }}
</b-button>
</footer>
</div>
</b-modal>
% endif
</div>
</script>
@ -85,7 +126,29 @@
submit${form.component_studly}() {
this.${form.component_studly}Submitting = true
this.${form.component_studly}ButtonText = "Working, please wait..."
}
},
% endif
% if can_edit_help:
configureFieldSave() {
this.configureFieldSaving = true
let url = '${edit_help_url}'
let params = {
field_name: this.configureFieldName,
markdown_text: this.configureFieldMarkdown,
}
this.submitForm(url, params, response => {
this.configureFieldShowDialog = false
this.$buefy.toast.open({
message: "Info was saved; please refresh page to see changes.",
type: 'is-info',
duration: 4000, // 4 seconds
})
this.configureFieldSaving = false
}, response => {
this.configureFieldSaving = false
})
},
% endif
}
}
@ -95,6 +158,16 @@
## TODO: should find a better way to handle CSRF token
csrftoken: ${json.dumps(request.session.get_csrf_token() or request.session.new_csrf_token())|n},
% if can_edit_help:
fieldLabels: ${json.dumps(field_labels)|n},
fieldMarkdowns: ${json.dumps(field_markdowns)|n},
configureFieldShowDialog: false,
configureFieldSaving: false,
configureFieldName: null,
configureFieldLabel: null,
configureFieldMarkdown: null,
% endif
## TODO: ugh, this seems pretty hacky. need to declare some data models
## for various field components to bind to...
% if not form.readonly: