get current collection out of url

This commit is contained in:
Anton Dyudin 2017-12-18 16:30:45 -08:00
parent 55de688f3d
commit 88aba74503
2 changed files with 25 additions and 12 deletions

View File

@ -11,7 +11,9 @@
;p: updated {<mod.conf.col>}
::TODO public, visible
::
;h2: Topics:
;* ?~ tops.col ~
;= ;h2: Topics:
==
;ul
;* %+ turn (sort ~(tap by tops.col) dor)
|= [top=@da topicful]
@ -27,9 +29,7 @@
;form(onsubmit "return easy_form.submit(this)")
;input(type "hidden", name "easy_form:mark", value "collections-action");
;input(type "hidden", name "easy_form:tag", value "submit");
::
::FIXME we really want the filename here
;input(type "hidden", name "col", value "{<mod.conf.col>}");
;input(type "hidden", name "easy_form:url_end", value "collections/:col");
::
;input(name "tit", placeholder "Title");
;br;
@ -43,11 +43,9 @@
;form(onsubmit "return easy_form.submit(this)")
;input(type "hidden", name "easy_form:mark", value "collections-action");
;input(type "hidden", name "easy_form:tag", value "delete");
;input(type "hidden", name "easy_form:url_end", value "collections/:col");
;input(type "hidden", name "easy_form:confirm");
::
::FIXME we really want the filename here
;input(type "hidden", name "col", value "{<mod.conf.col>}");
::
;input.red(type "submit", value "Archive this collection");
==
==

View File

@ -1,19 +1,34 @@
//REVIEW this feels too complicated
let match_url_end = (pattern,out={})=> {
if(!pattern) return out
let here = document.location.pathname.split("/").reverse()
while(!here[0]) here.shift()
for(let segment of pattern.split("/").reverse()){
let val = here.shift()
if(segment[0] != ":") continue //REVIEW check for match?
out[segment.slice(1)] = val
}
return out
}
//
window.easy_form = {
submit: (form)=> {
const param = (key)=> {
var x = form.elements[`easy_form:${key}`]
return x && x.value
}
var mark = param("mark")
let mark = param("mark")
if(!mark) throw new TypeError("Need a mark")
var appl = param("appl") || mark.match(/^[^-]*/)[0]
var tag = param("tag")
let appl = param("appl") || mark.match(/^[^-]*/)[0]
let tag = param("tag")
//
if(param("confirm") != null && !confirm("Are you sure?"))
return false
//
var req = {}
for (var [k,v] of new FormData(form)){
let req = {}
req = match_url_end(param("url_end"),req)
//
for (let [k,v] of new FormData(form)){
if(!/^easy_form:/.test(k)) {
req[k] = v
}