import { Component , Prop } from "vue-property-decorator" ; import WithRender from "./manage-types.vue" ; import Vue from "vue" ; import { ID , Type } from "facilmap-types" ; import { Client , InjectClient , InjectContext } from "../../utils/decorators" ; import { showErrorToast } from "../../utils/toasts" ; import EditType from "../edit-type/edit-type" ; import { Context } from "../facilmap/facilmap" ; @ WithRender @ Component ( { components : { EditType } } ) export default class ManageTypes extends Vue { @ InjectContext ( ) context ! : Context ; @ InjectClient ( ) client ! : Client ; @ Prop ( { type : String , required : true } ) id ! : string ; isDeleting : Record < ID , boolean > = { } ; showEditDialog = false ; editDialogTypeId : ID | null = null ; isBusy ( ) { return Object . values ( this . isDeleting ) . some ( ( v ) => v ) ; } openEditDialog ( type ) { this . editDialogTypeId = type && type . id ; this . showEditDialog = true ; setTimeout ( ( ) => { this . $bvModal . show ( `fm${ this . context . id }-manage-types-edit-type` ) ; } , 0 ) ; } openCreateDialog ( ) { this . openEditDialog ( null ) ; } async deleteType ( type ) { this . $bvToast . hide ( `fm${ this . context . id }-manage-types-delete-${ type . id }` ) ; Vue . set ( this . isDeleting , type . id , true ) ; try { if ( ! await this . $bvModal . msgBoxConfirm ( `Do you really want to delete the type “${ type . name }”?` ) ) return ; await this . client . deleteType ( { id : type . id } ) ; } catch ( err ) { showErrorToast ( this , `fm${ this . context . id }-manage-types-delete-${ type . id }` , `Error deleting type “${ type . name }”` , err ) ; } finally { Vue . delete ( this . isDeleting , type . id ) ; } } }