NewScreen - use bbui input
- use input error message - screen name no longer needs to be unique
This commit is contained in:
parent
ec7f9da9d1
commit
92ef492bd1
|
@ -29,8 +29,9 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
const ok = () => {
|
const ok = () => {
|
||||||
|
const result = onOk()
|
||||||
|
if (result === false) return
|
||||||
hide()
|
hide()
|
||||||
onOk()
|
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
|
@ -22,11 +22,8 @@
|
||||||
let layoutComponent
|
let layoutComponent
|
||||||
let screens
|
let screens
|
||||||
let name = ""
|
let name = ""
|
||||||
let nameError = ""
|
|
||||||
let routeError
|
let routeError
|
||||||
|
|
||||||
let saveAttempted = false
|
|
||||||
|
|
||||||
$: layoutComponents = Object.values($store.components).filter(
|
$: layoutComponents = Object.values($store.components).filter(
|
||||||
componentDefinition => componentDefinition.container
|
componentDefinition => componentDefinition.container
|
||||||
)
|
)
|
||||||
|
@ -40,33 +37,21 @@
|
||||||
$: route = !route && $store.screens.length === 0 ? "*" : route
|
$: route = !route && $store.screens.length === 0 ? "*" : route
|
||||||
|
|
||||||
const save = () => {
|
const save = () => {
|
||||||
saveAttempted = true
|
if (!route) {
|
||||||
|
|
||||||
if (name.length === 0) {
|
|
||||||
nameError = "Name is required"
|
|
||||||
} else {
|
|
||||||
if (screenNameExists(name)) {
|
|
||||||
nameError = "This name is already taken"
|
|
||||||
} else {
|
|
||||||
nameError = ""
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (route.length === 0) {
|
|
||||||
routeError = "Url is required"
|
routeError = "Url is required"
|
||||||
} else {
|
} else {
|
||||||
if (routeNameExists(name)) {
|
if (routeNameExists(route)) {
|
||||||
routeError = "This url is already taken"
|
routeError = "This url is already taken"
|
||||||
} else {
|
} else {
|
||||||
routeError = ""
|
routeError = ""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const isValid = !routeError && !nameError
|
if (routeError) return false
|
||||||
|
|
||||||
if (!isValid) return
|
|
||||||
|
|
||||||
store.createScreen(name, route, layoutComponent._component)
|
store.createScreen(name, route, layoutComponent._component)
|
||||||
|
name = ""
|
||||||
|
route = ""
|
||||||
dialog.hide()
|
dialog.hide()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -74,12 +59,6 @@
|
||||||
dialog.hide()
|
dialog.hide()
|
||||||
}
|
}
|
||||||
|
|
||||||
const screenNameExists = name => {
|
|
||||||
return $store.screens.some(
|
|
||||||
screen => screen.name.toLowerCase() === name.toLowerCase()
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
const routeNameExists = route => {
|
const routeNameExists = route => {
|
||||||
return $store.screens.some(
|
return $store.screens.some(
|
||||||
screen => screen.route.toLowerCase() === route.toLowerCase()
|
screen => screen.route.toLowerCase() === route.toLowerCase()
|
||||||
|
@ -102,7 +81,7 @@
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<div class="uk-margin">
|
<div class="uk-margin">
|
||||||
<Input label="Name" error={nameError} bind:value={name} />
|
<Input label="Name" bind:value={name} />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="uk-margin">
|
<div class="uk-margin">
|
||||||
|
@ -115,7 +94,7 @@
|
||||||
|
|
||||||
<div class="uk-margin">
|
<div class="uk-margin">
|
||||||
<label>Layout Component</label>
|
<label>Layout Component</label>
|
||||||
<Select bind:value={layoutComponent}>
|
<Select bind:value={layoutComponent} secondary>
|
||||||
{#each layoutComponents as { _component, name }}
|
{#each layoutComponents as { _component, name }}
|
||||||
<option value={_component}>{name}</option>
|
<option value={_component}>{name}</option>
|
||||||
{/each}
|
{/each}
|
||||||
|
|
Loading…
Reference in New Issue