implemented creating new poll and managing poll options

Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
2026-02-23 23:46:52 +01:00
parent e5ab655787
commit cbc6ce188d
7 changed files with 182 additions and 24 deletions

View File

@@ -23,7 +23,24 @@
} else error(res);
}
async function patchOption(option, field, newVal){
async function patch_poll(field, newVal){
let url = api(`poll/${id}`);
let data = {}
data[field] = newVal;
let res = await patch(url,data);
if (res.ok) {
yikes();
const json = await res.json();
poll = { ...poll, ...json };
return true;
}
error(res);
return false;
}
async function patch_option(option, field, newVal){
let url = api(`poll/${id}/option/${option.id}`);
let data = {}
data[field] = newVal;
@@ -31,11 +48,15 @@
if (res.ok) {
yikes();
const json = await res.json();
if (field == 'name' && newVal == ''){
poll.options = poll.options.filter(o => o.id !== option.id);
} else poll.options = json.options;
} else error(res);
}
async function save_new_option(){
if (!new_option.name) return;
let url = api('poll/'+id+'/option');
let res = await post(url,new_option);
if (res.ok){
@@ -54,11 +75,11 @@
{#if poll && poll.name}
<fieldset>
<legend>{t('name')}</legend>
<LineEditor bind:value={poll.name} editable={true} />
<LineEditor bind:value={poll.name} editable={true} onSet={name => patch_poll('name',name)} />
</fieldset>
<fieldset>
<legend>{t('description')}</legend>
<MarkdownEditor bind:value={poll.description} />
<MarkdownEditor bind:value={poll.description} onSet={desc => patch_poll('description',desc)} />
</fieldset>
<fieldset>
<legend>{t('options')}</legend>
@@ -70,13 +91,13 @@
</tr>
</thead>
<tbody>
{#each poll.options as option}
{#each poll.options as option (option.id)}
<tr>
<td>
<LineEditor editable={true} value={option.name} onSet={name => patchOption(option,'name',name)} />
<LineEditor editable={true} value={option.name} onSet={name => patch_option(option,'name',name)} title={t('clear to remove')} />
</td>
<td>
<MarkdownEditor bind:value={option.description} />
<MarkdownEditor bind:value={option.description} onSet={desc => patch_option(option,'description',desc)} />
</td>
</tr>
{/each}