urbit/web/lib/js/easy-form.js

30 lines
760 B
JavaScript
Raw Normal View History

window.easy_form = {
2017-12-19 01:33:20 +03:00
submit: (form)=> {
const param = (key)=> {
var x = form.elements[`easy_form:${key}`]
return x && x.value
}
var mark = param("mark")
if(!mark) throw new TypeError("Need a mark")
var appl = param("appl") || mark.match(/^[^-]*/)[0]
var tag = param("tag")
//
var req = {}
for (var [k,v] of new FormData(form)){
2017-12-19 01:33:20 +03:00
if(!/^easy_form:/.test(k)) {
req[k] = v
}
}
if(tag) req = {[tag]:req}
2017-12-19 01:33:20 +03:00
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
}
}