From 88aba7450369b571c7e2d26a61b871d5597fdc36 Mon Sep 17 00:00:00 2001 From: Anton Dyudin Date: Mon, 18 Dec 2017 16:30:45 -0800 Subject: [PATCH] get current collection out of url --- mar/collections/collection.hoon | 12 +++++------- web/lib/js/easy-form.js | 25 ++++++++++++++++++++----- 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/mar/collections/collection.hoon b/mar/collections/collection.hoon index 9b0638d7c..59108794b 100644 --- a/mar/collections/collection.hoon +++ b/mar/collections/collection.hoon @@ -11,7 +11,9 @@ ;p: updated {} ::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 "{}"); + ;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 "{}"); - :: ;input.red(type "submit", value "Archive this collection"); == == diff --git a/web/lib/js/easy-form.js b/web/lib/js/easy-form.js index 0530e6eba..b7360673e 100644 --- a/web/lib/js/easy-form.js +++ b/web/lib/js/easy-form.js @@ -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 }