Merge branch 'TagItemDisplay' into dev
This commit is contained in:
37
frontend/src/routes/stock/display.svelte
Normal file
37
frontend/src/routes/stock/display.svelte
Normal file
@@ -0,0 +1,37 @@
|
||||
<script>
|
||||
import { onMount } from 'svelte';
|
||||
import { useTinyRouter } from 'svelte-tiny-router';
|
||||
|
||||
import { api, get } from '../../urls.svelte';
|
||||
import { error, yikes } from '../../warn.svelte';
|
||||
import { t } from '../../translations.svelte';
|
||||
|
||||
let {module, id} = $props();
|
||||
let item = $state(null);
|
||||
let router = useTinyRouter();
|
||||
|
||||
function onclick(e){
|
||||
e.preventDefault();
|
||||
var target = e.target;
|
||||
while (target && !target.href) target=target.parentNode;
|
||||
let href = target.getAttribute('href');
|
||||
if (href) router.navigate(href);
|
||||
return false;
|
||||
}
|
||||
|
||||
async function loadItem(){
|
||||
let url = api(`stock/item/${id}`);
|
||||
let res = await get(url);
|
||||
if (res.ok) {
|
||||
yikes();
|
||||
item = await res.json();
|
||||
} else error();
|
||||
}
|
||||
|
||||
|
||||
onMount(loadItem);
|
||||
</script>
|
||||
|
||||
{#if item}
|
||||
<a href="/stock/{id}/view" {onclick} >({item.code}) {item.name}</a>
|
||||
{/if}
|
||||
Reference in New Issue
Block a user