Implemented bulk creation

ref #94
This commit is contained in:
Nicolai Ort 2021-03-23 19:55:55 +01:00
parent 3cd0468b19
commit 7ad6b73574
3 changed files with 32 additions and 38 deletions

View File

@ -2,9 +2,7 @@
import { _ } from "svelte-i18n"; import { _ } from "svelte-i18n";
import { clickOutside } from "../base/outsideclick"; import { clickOutside } from "../base/outsideclick";
import { focusTrap } from "svelte-focus-trap"; import { focusTrap } from "svelte-focus-trap";
import { import { RunnerCardService } from "@odit/lfk-client-js";
RunnerCardService
} from "@odit/lfk-client-js";
import Toastify from "toastify-js"; import Toastify from "toastify-js";
export let bulk_modal_open; export let bulk_modal_open;
export let current_cards; export let current_cards;
@ -12,7 +10,7 @@
el.focus(); el.focus();
} }
$: card_count = 0; $: card_count = 0;
$: is_card_count_valid= card_count>0; $: is_card_count_valid = card_count > 0;
$: processed_last_submit = true; $: processed_last_submit = true;
$: createbtnenabled = is_card_count_valid; $: createbtnenabled = is_card_count_valid;
(() => { (() => {
@ -29,30 +27,22 @@
} }
}; };
})(); })();
//TODO: Creation logic
function submit() { function submit() {
if (processed_last_submit === true) { if (processed_last_submit === true) {
processed_last_submit = false; processed_last_submit = false;
const toast = Toastify({ const toast = Toastify({
text: $_("adding-card"), text: $_("creating-blanco-cards"),
duration: -1, duration: -1,
}).showToast(); }).showToast();
let postdata = { RunnerCardService.runnerCardControllerPostBlancoBulk(card_count)
runner,
enabled,
};
RunnerCardService.runnerCardControllerPost(postdata)
.then((result) => { .then((result) => {
runner = 0;
bulk_modal_open = false; bulk_modal_open = false;
// //
Toastify({ Toastify({
text: $_("card-added"), text: $_("created-blanco-cards"),
duration: 500, duration: 500,
backgroundColor: "linear-gradient(to right, #00b09b, #96c93d)", backgroundColor: "linear-gradient(to right, #00b09b, #96c93d)",
}).showToast(); }).showToast();
current_cards.push(result);
current_cards = current_cards;
}) })
.catch((err) => { .catch((err) => {
// //
@ -118,27 +108,27 @@
<label <label
for="amount" for="amount"
class="block text-sm font-medium text-gray-700">{$_('amount')}</label> class="block text-sm font-medium text-gray-700">{$_('amount')}</label>
<div class="mt-1 flex rounded-md shadow-sm"> <div class="mt-1 flex rounded-md shadow-sm">
<input <input
autocomplete="off" autocomplete="off"
class:border-red-500={!is_card_count_valid} class:border-red-500={!is_card_count_valid}
class:focus:border-red-500={!is_card_count_valid} class:focus:border-red-500={!is_card_count_valid}
class:focus:ring-red-500={!is_card_count_valid} class:focus:ring-red-500={!is_card_count_valid}
bind:value={card_count} bind:value={card_count}
type="number" type="number"
step="1" step="1"
name="amount" name="amount"
class="focus:ring-indigo-500 focus:border-indigo-500 flex-1 block w-full rounded-none rounded-l-md sm:text-sm border-gray-300 border bg-gray-50 text-gray-500 p-2" class="focus:ring-indigo-500 focus:border-indigo-500 flex-1 block w-full rounded-none rounded-l-md sm:text-sm border-gray-300 border bg-gray-50 text-gray-500 p-2"
placeholder="400" /> placeholder="400" />
<span <span
class="inline-flex items-center px-3 rounded-r-md border border-gray-300 bg-gray-50 text-gray-500 text-sm">{$_('cards')}</span> class="inline-flex items-center px-3 rounded-r-md border border-gray-300 bg-gray-50 text-gray-500 text-sm">{$_('cards')}</span>
</div> </div>
{#if !is_card_count_valid} {#if !is_card_count_valid}
<span <span
class="flex items-center font-medium tracking-wide text-red-500 text-xs mt-1 ml-1"> class="flex items-center font-medium tracking-wide text-red-500 text-xs mt-1 ml-1">
{$_('you-must-create-at-least-one-card-or-cancel')} {$_('you-must-create-at-least-one-card-or-cancel')}
</span> </span>
{/if} {/if}
</div> </div>
</div> </div>
</div> </div>

View File

@ -396,5 +396,7 @@
"just-enter-how-many-you-want-and-the-system-will-create-them": "Geb einfach ein, wie viele Blankokarten das System erstellen soll.", "just-enter-how-many-you-want-and-the-system-will-create-them": "Geb einfach ein, wie viele Blankokarten das System erstellen soll.",
"amount": "Anzahl", "amount": "Anzahl",
"you-must-create-at-least-one-card-or-cancel": "Du musst mindestens eine Blankokarte erstellen (oder abbrechen).", "you-must-create-at-least-one-card-or-cancel": "Du musst mindestens eine Blankokarte erstellen (oder abbrechen).",
"create-bulk-cards": "Blankokarten erstellen" "create-bulk-cards": "Blankokarten erstellen",
"creating-blanco-cards": "Erstelle Blankokarten",
"created-blanco-cards": "Blankokarten wurden erstellt"
} }

View File

@ -396,5 +396,7 @@
"just-enter-how-many-you-want-and-the-system-will-create-them": "Just enter how many you want and the system will create them", "just-enter-how-many-you-want-and-the-system-will-create-them": "Just enter how many you want and the system will create them",
"amount": "Amount", "amount": "Amount",
"you-must-create-at-least-one-card-or-cancel": "You must create at least one card (or cancel).", "you-must-create-at-least-one-card-or-cancel": "You must create at least one card (or cancel).",
"create-bulk-cards": "Add blanco cards" "create-bulk-cards": "Add blanco cards",
"creating-blanco-cards": "Creating blanco cards",
"created-blanco-cards": "Created blanco cards"
} }