mirror of
https://github.com/ilyakooo0/urbit.git
synced 2024-12-18 12:22:10 +03:00
3d2640da26
with corresponding &collections-action tweak to use less canonical urbit json format
30 lines
781 B
JavaScript
30 lines
781 B
JavaScript
window.easy_form = {
|
|
submit: (form,req={})=> {
|
|
var mark, appl, tag;
|
|
var req = {}
|
|
for (var [k,v] of new FormData(form)){
|
|
switch(k){
|
|
case "easy_form:tag":
|
|
tag = v
|
|
break; case "easy_form:appl":
|
|
appl = v
|
|
break; case "easy_form:mark":
|
|
mark = v
|
|
appl = appl || v.match(/^[^-]*/)[0]
|
|
break; default:
|
|
req[k] = v
|
|
}
|
|
}
|
|
if(!mark) throw new TypeError("Need a mark")
|
|
if(tag) req = {[tag]:req}
|
|
fetch("/~/auth.json", {credentials: "same-origin"})
|
|
.then((res)=>res.json())
|
|
.then(({oryx})=> fetch(`/~/to/${appl}/${mark}`,{
|
|
method: "POST",
|
|
body:JSON.stringify({oryx,wire:"/",xyro:req}),
|
|
credentials: "same-origin"
|
|
}))
|
|
return false
|
|
}
|
|
}
|