stubbed out all Food GenericModalForms

This commit is contained in:
smilerz
2021-08-30 15:05:54 -05:00
parent a1d1cbac5d
commit 52abba1f16
21 changed files with 155595 additions and 385 deletions

View File

@@ -1,13 +1,15 @@
<template>
<div>
<b-modal class="modal" id="modal" >
<template v-slot:modal-title><h4>{{model}} {{action}}</h4></template>
<div v-for="(f, i) in fields" v-bind:key=i>
<template v-slot:modal-title><h4>{{form.title}}</h4></template>
<div v-for="(f, i) in form.fields" v-bind:key=i>
<p v-if="f.type=='instruction'">{{f.label}}</p>
<lookup-input v-if="f.type=='lookup'"
:label="f.label"
:value="f.value"
:field="f.field"
:model="listModel(f.list)"
:sticky_options="f.sticky_options || undefined"
@change="changeValue"/> <!-- TODO add ability to create new items associated with lookup -->
<checkbox-input v-if="f.type=='checkbox'"
:label="f.label"
@@ -22,7 +24,7 @@
<template v-slot:modal-footer>
<b-button class="float-right mx-1" variant="secondary" v-on:click="$bvModal.hide('modal')">{{$t('Cancel')}}</b-button>
<b-button class="float-right mx-1" variant="primary" v-on:click="doAction">{{buttonLabel}}</b-button>
<b-button class="float-right mx-1" variant="primary" v-on:click="doAction">{{form.ok_label}}</b-button>
</template>
</b-modal>
<b-button v-on:click="Button">ok</b-button>
@@ -32,7 +34,10 @@
<script>
import Vue from 'vue'
import {BootstrapVue} from 'bootstrap-vue'
import {getForm} from "@/utils/utils";
Vue.use(BootstrapVue)
import {Models} from "@/utils/models";
import CheckboxInput from "@/components/Modals/CheckboxInput";
import LookupInput from "@/components/Modals/LookupInput";
import TextInput from "@/components/Modals/TextInput";
@@ -41,46 +46,17 @@ export default {
name: 'GenericModalForm',
components: {CheckboxInput, LookupInput, TextInput},
props: {
model: {type: String, default: ''},
model: {type: Object, default: function() {}},
action: {type: Object, default: function() {}},
item1: {type: Object, default: function() {}},
item2: {type: Object, default: function() {}},
// action: {type: String, default: ''},
show: {type: Boolean, default: false},
},
data() {
return {
new_item: {},
action: '',
fields: [
{'label': 'This is a long set of instructions that tell you to be careful with what you do next or really bad things are likely to happen.',
'type': 'instruction',
'value': undefined},
{'field': 'name',
'label': 'first',
'type': 'text',
'value': undefined,
'placeholder': 'do the thing'},
{'field': 'shopping',
'label': 'second',
'type': 'lookup',
'value': undefined},
{'field': 'isreal',
'label': 'third',
'type': 'checkbox',
'value': undefined},
{'field': 'ignore',
'label': 'fourth',
'type': 'checkbox',
'value': undefined},
{'field': 'another_category',
'label': 'fifth',
'type': 'lookup',
'value': undefined},
{'field': 'description',
'label': 'sixth',
'type': 'text',
'value': undefined,
'placeholder': 'also, do the thing'
}
],
form: {},
buttons: {
'new':{'label': this.$t('Save')},
'delete':{'label': this.$t('Delete')},
@@ -101,20 +77,20 @@ export default {
watch: {
'show': function () {
if (this.show) {
this.form = getForm(this.model, this.action, this.item1, this.item2)
this.$bvModal.show('modal')
}
},
},
methods: {
Button: function(e) {
console.log(typeof({}), typeof([]), typeof('this'), typeof(1))
this.action='new'
this.form = getForm(this.model, this.action, this.item1, this.item2)
console.log(this.form)
this.$bvModal.show('modal')
},
doAction: function(){
console.log(this.new_item)
let alert_text = ''
for (const [k, v] of Object.entries(this.fields)) {
for (const [k, v] of Object.entries(this.form.fields)) {
if (v.type !== 'instruction'){
alert_text = alert_text + v.field + ": " + this.new_item[v.field] + "\n"
}
@@ -122,11 +98,17 @@ export default {
this.$nextTick(function() {this.$bvModal.hide('modal')})
setTimeout(() => {}, 0) // confirm that the
alert(alert_text)
console.log(this.model_values)
},
changeValue: function(field, value) {
// console.log('catch change', field, value)
this.new_item[field] = value
console.log('catch value', field, value)
},
listModel: function(m) {
if (m === 'self') {
return this.model
} else {
return Models[m]
}
}
}
}