preparing to manage weights in poll

Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
2026-02-25 09:17:25 +01:00
parent cbc6ce188d
commit 4a2c49c42c
6 changed files with 86 additions and 14 deletions

View File

@@ -12,6 +12,7 @@
let { id } = $props();
let new_option = $state({name:'',description:{'source':'',rendered:''}});
let new_weight = $state({description:'',weight:0});
let poll = $state(null);
async function load(){
@@ -51,7 +52,23 @@
if (field == 'name' && newVal == ''){
poll.options = poll.options.filter(o => o.id !== option.id);
} else poll.options = json.options;
} else error(res);
return true;
}
error(res);
return false;
}
async function patch_weight(data){
let url = api(`poll/${id}/weight`);
let res = await patch(url,data);
if (res.ok) {
yikes();
const json = await res.json();
console.log(json);
return true;
}
error(res);
return false;
}
@@ -66,6 +83,12 @@
} else error(res);
}
function save_new_weight(e){
const data = {};
data[new_weight.weight] = new_weight.description;
patch_weight(data);
}
onMount(load);
</script>
@@ -130,10 +153,19 @@
<input type="number" value={weight} />
</td>
<td>
<input type="text" value={descr} />
<LineEditor value={descr} onSet={desc => patch_weight({weight: desc})} />
</td>
</tr>
{/each}
<tr>
<td>
<input type="number" bind:value={new_weight.weight} />
</td>
<td>
<input type="text" bind:value={new_weight.description} />
<button onclick={save_new_weight}>{t('save')}</button>
</td>
</tr>
</tbody>
</table>
</fieldset>