2021-04-12 06:18:30 +02:00
|
|
|
<!--
|
|
|
|
Copyright: Ankitects Pty Ltd and contributors
|
|
|
|
License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|
|
|
-->
|
2021-04-16 15:29:21 +02:00
|
|
|
<script lang="ts">
|
2021-04-18 03:56:41 +02:00
|
|
|
import * as tr from "anki/i18n";
|
2021-04-16 15:29:21 +02:00
|
|
|
import { textInputModal } from "./textInputModal";
|
|
|
|
import type { DeckConfigState } from "./lib";
|
|
|
|
|
|
|
|
export let state: DeckConfigState;
|
|
|
|
|
|
|
|
function addConfig(): void {
|
|
|
|
textInputModal({
|
|
|
|
title: "Add Config",
|
|
|
|
prompt: "Name:",
|
|
|
|
onOk: (text: string) => {
|
|
|
|
const trimmed = text.trim();
|
|
|
|
if (trimmed.length) {
|
|
|
|
state.addConfig(trimmed);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function renameConfig(): void {
|
|
|
|
textInputModal({
|
|
|
|
title: "Rename Config",
|
|
|
|
prompt: "Name:",
|
|
|
|
startingValue: state.getCurrentName(),
|
|
|
|
onOk: (text: string) => {
|
|
|
|
state.setCurrentName(text);
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function removeConfig(): void {
|
2021-04-18 03:56:41 +02:00
|
|
|
// show pop-up after dropdown has gone away
|
2021-04-16 15:29:21 +02:00
|
|
|
setTimeout(() => {
|
2021-04-18 03:56:41 +02:00
|
|
|
if (state.defaultConfigSelected()) {
|
|
|
|
alert(tr.schedulingTheDefaultConfigurationCantBeRemoved());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// fixme: move tr.qt_misc schema mod msg into core
|
|
|
|
// fixme: include name of deck in msg
|
|
|
|
const msg = state.removalWilLForceFullSync()
|
|
|
|
? "This will require a one-way sync. Are you sure?"
|
|
|
|
: "Are you sure?";
|
|
|
|
if (confirm(msg)) {
|
2021-04-16 15:29:21 +02:00
|
|
|
try {
|
|
|
|
state.removeCurrentConfig();
|
|
|
|
} catch (err) {
|
|
|
|
alert(err);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}, 100);
|
|
|
|
}
|
2021-04-20 11:50:05 +02:00
|
|
|
|
|
|
|
function save(applyToChildDecks: boolean): void {
|
|
|
|
state.save(applyToChildDecks);
|
|
|
|
}
|
2021-04-16 15:29:21 +02:00
|
|
|
</script>
|
|
|
|
|
2021-04-12 06:18:30 +02:00
|
|
|
<style>
|
|
|
|
:global(svg) {
|
|
|
|
vertical-align: text-bottom;
|
|
|
|
}
|
|
|
|
</style>
|
|
|
|
|
2021-04-22 09:45:16 +02:00
|
|
|
<div class="btn-group" dir="ltr">
|
2021-04-20 11:50:05 +02:00
|
|
|
<button
|
|
|
|
type="button"
|
|
|
|
class="btn btn-primary"
|
|
|
|
on:click={() => save(false)}>Save</button>
|
2021-04-12 06:18:30 +02:00
|
|
|
<button
|
|
|
|
type="button"
|
2021-04-22 03:33:27 +02:00
|
|
|
class="btn btn-secondary dropdown-toggle dropdown-toggle-split"
|
2021-04-12 06:18:30 +02:00
|
|
|
data-bs-toggle="dropdown"
|
|
|
|
aria-expanded="false">
|
|
|
|
<span class="visually-hidden">Toggle Dropdown</span>
|
|
|
|
</button>
|
|
|
|
<ul class="dropdown-menu">
|
2021-04-16 15:29:21 +02:00
|
|
|
<li><a class="dropdown-item" href={'#'} on:click={addConfig}>Add Config</a></li>
|
|
|
|
<li>
|
|
|
|
<a class="dropdown-item" href={'#'} on:click={renameConfig}>Rename Config</a>
|
|
|
|
</li>
|
|
|
|
<li>
|
|
|
|
<a class="dropdown-item" href={'#'} on:click={removeConfig}>Remove Config</a>
|
|
|
|
</li>
|
2021-04-12 06:18:30 +02:00
|
|
|
<li>
|
|
|
|
<hr class="dropdown-divider" />
|
|
|
|
</li>
|
2021-04-20 11:50:05 +02:00
|
|
|
<li>
|
|
|
|
<a class="dropdown-item" href={'#'} on:click={() => save(true)}>Save to All
|
|
|
|
Children</a>
|
|
|
|
</li>
|
2021-04-12 06:18:30 +02:00
|
|
|
</ul>
|
|
|
|
</div>
|