preparing to save options
Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
@@ -5,12 +5,13 @@
|
||||
import LineEditor from '../../Components/LineEditor.svelte';
|
||||
import MarkdownEditor from '../../Components/MarkdownEditor.svelte';
|
||||
|
||||
import { api, get } from '../../urls.svelte';
|
||||
import { api, get, post } from '../../urls.svelte';
|
||||
import { error, yikes } from '../../warn.svelte';
|
||||
import { t } from '../../translations.svelte';
|
||||
import { user } from '../../user.svelte.js';
|
||||
|
||||
let { id } = $props();
|
||||
let new_option = $state({name:'',description:{'source':'',rendered:''}});
|
||||
let poll = $state(null);
|
||||
|
||||
async function load(){
|
||||
@@ -22,6 +23,14 @@
|
||||
} else error(res);
|
||||
}
|
||||
|
||||
async function save_new_option(){
|
||||
let url = api('poll/'+id+'/option');
|
||||
let res = await post(url,new_option);
|
||||
if (res.ok){
|
||||
yikes();
|
||||
} else error(res);
|
||||
}
|
||||
|
||||
|
||||
onMount(load);
|
||||
|
||||
@@ -48,7 +57,7 @@
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{#each poll.options as option}
|
||||
{#each poll.options as option}
|
||||
<tr>
|
||||
<td>
|
||||
<input type="text" value={option.name} />
|
||||
@@ -57,7 +66,17 @@
|
||||
<MarkdownEditor bind:value={option.description} />
|
||||
</td>
|
||||
</tr>
|
||||
{/each}
|
||||
{/each}
|
||||
<tr>
|
||||
<td class="new_option">
|
||||
{t('add element',{element:t('options')})}
|
||||
<input type="text" bind:value={new_option.name} />
|
||||
</td>
|
||||
<td>
|
||||
<MarkdownEditor simple={true} bind:value={new_option.description} />
|
||||
<button onclick={save_new_option}>{t('save')}</button>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</fieldset>
|
||||
|
||||
Reference in New Issue
Block a user