2017-12-16 09:04:09 +03:00
|
|
|
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")
|
|
|
|
//
|
2017-12-16 09:04:09 +03:00
|
|
|
var req = {}
|
|
|
|
for (var [k,v] of new FormData(form)){
|
2017-12-19 01:33:20 +03:00
|
|
|
if(!/^easy_form:/.test(k)) {
|
2017-12-16 09:04:09 +03:00
|
|
|
req[k] = v
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(tag) req = {[tag]:req}
|
2017-12-19 01:33:20 +03:00
|
|
|
|
2017-12-16 09:04:09 +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
|
|
|
|
}
|
|
|
|
}
|