|
| 1 | +<svelte:options immutable={true} /> |
| 2 | + |
| 3 | +<script lang="ts"> |
| 4 | + import { createEventDispatcher } from 'svelte'; |
| 5 | + import { parcels } from '../../stores/sequencing'; |
| 6 | + import Modal from './Modal.svelte'; |
| 7 | + import ModalContent from './ModalContent.svelte'; |
| 8 | + import ModalFooter from './ModalFooter.svelte'; |
| 9 | + import ModalHeader from './ModalHeader.svelte'; |
| 10 | +
|
| 11 | + export let height: number = 200; |
| 12 | + export let width: number = 380; |
| 13 | +
|
| 14 | + const dispatch = createEventDispatcher<{ |
| 15 | + close: void; |
| 16 | + save: { library: FileList; parcel: number }; |
| 17 | + }>(); |
| 18 | +
|
| 19 | + let saveButtonDisabled: boolean = true; |
| 20 | + let modalTitle: string; |
| 21 | + let libraryName: FileList; |
| 22 | + let parcelId: number; |
| 23 | +
|
| 24 | + $: saveButtonDisabled = parcelId === null || libraryName === undefined; |
| 25 | + $: modalTitle = 'Import Library'; |
| 26 | +
|
| 27 | + function save() { |
| 28 | + if (!saveButtonDisabled) { |
| 29 | + dispatch('save', { library: libraryName, parcel: parcelId }); |
| 30 | + } |
| 31 | + } |
| 32 | +
|
| 33 | + function onKeydown(event: KeyboardEvent) { |
| 34 | + const { key } = event; |
| 35 | + if (key === 'Enter') { |
| 36 | + event.preventDefault(); |
| 37 | + save(); |
| 38 | + } |
| 39 | + } |
| 40 | +</script> |
| 41 | + |
| 42 | +<svelte:window on:keydown={onKeydown} /> |
| 43 | + |
| 44 | +<Modal {height} {width}> |
| 45 | + <ModalHeader on:close>{modalTitle}</ModalHeader> |
| 46 | + |
| 47 | + <ModalContent> |
| 48 | + <div class="st-typography-body">Parcel (required)</div> |
| 49 | + <select bind:value={parcelId} class="st-select w-100" name="parcel"> |
| 50 | + <option value={null} /> |
| 51 | + {#each $parcels as parcel} |
| 52 | + <option value={parcel.id}> |
| 53 | + {parcel.name} |
| 54 | + </option> |
| 55 | + {/each} |
| 56 | + </select> |
| 57 | + <fieldset> |
| 58 | + <label for="name">Imported Library</label> |
| 59 | + <input bind:files={libraryName} class="w-100" name="libraryFile" type="file" accept=".satf" /> |
| 60 | + </fieldset> |
| 61 | + </ModalContent> |
| 62 | + |
| 63 | + <ModalFooter> |
| 64 | + <button class="st-button secondary" on:click={() => dispatch('close')}> Cancel </button> |
| 65 | + <button class="st-button" disabled={saveButtonDisabled} on:click={save}> Import </button> |
| 66 | + </ModalFooter> |
| 67 | +</Modal> |
0 commit comments