| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- <template>
- <main>
- <v-form
- ref="form"
- v-model="valid"
- lazy-validation
- >
- <v-row>
- <slot></slot>
- </v-row>
- <v-btn
- class="mr-4 submitBtn"
- @click="submit"
- >
- submit
- </v-btn>
- </v-form>
- <AlertComponent type="success" v-if="saveOk">Sauvegarde Effectuée</AlertComponent>
- <AlertComponent type="error" v-if="saveKo">Sauvegarde Echouée</AlertComponent>
- </main>
- </template>
- <script lang="ts">
- import {defineComponent, ref, toRef} from '@vue/composition-api'
- import {Repository} from "@vuex-orm/core";
- export default defineComponent({
- props: {
- repository:{
- type: Object as () => Repository,
- required: true
- }
- },
- setup(){
- const valid = true
- const saveOk = ref(false)
- const saveKo = ref(false)
- return {
- valid,
- saveOk,
- saveKo
- }
- },
- methods:{
- async submit(){
- if(this.$refs.form.validate()){
- const model = await this.repository.find(parseInt(this.$route.params.id));
- const playload = model.$toJson();
- this.$http.$put(`https://local.new.api.opentalent.fr/api/${model.$entity}/${this.$route.params.id}`, playload)
- .then(()=>{
- this.saveOk=true
- }, () =>{
- this.saveKo=true
- })
- setTimeout(()=>{
- this.saveOk=false
- this.saveKo=false
- },2000)
- }
- }
- }
- })
- </script>
- <style scoped>
- .submitBtn{
- margin-top: 20px;
- }
- </style>
|