mirror of
https://github.com/ilyakooo0/urbit.git
synced 2024-12-18 20:31:40 +03:00
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
|
||
|
}
|
||
|
}
|