diff --git a/assets/js/common.ts b/assets/js/common.ts index 9d4b0bc..da9097c 100644 --- a/assets/js/common.ts +++ b/assets/js/common.ts @@ -17,12 +17,13 @@ type Config = { export function config (api, polling): Config { const pu = polling ? `${api.path}/${polling.msgbase.join('/')}` : '' - const urlparams = new URL(location.href).searchParams + //const urlparams = new URL(location.href).searchParams return { apiurl: api.path, pollurl: pu, domain: domain, - itemid: urlparams.get('id'), + //itemid: urlparams.get('id'), + itemid: location.hash.substring(1), sid: getSid(), iid: createRandString(1), nopoll: nopoll @@ -61,7 +62,7 @@ function handle(msg) { return } if (comp) { - comp.handle(domain, action, class_, item, msg.payload) + comp.handle(this, domain, action, class_, item, msg.payload) } } diff --git a/assets/js/comp-data.ts b/assets/js/comp-data.ts index 34dca93..c92f575 100644 --- a/assets/js/comp-data.ts +++ b/assets/js/comp-data.ts @@ -31,10 +31,19 @@ export function Data(name: string, conf: any): object { // Data methods -function handle(domain, action, class_, item, payload: string) { +function handle(parent: any, domain, action, class_, item, payload: string) { if (action == 'data') { const data = JSON.parse(payload) Object.assign(this.data, data) + this.id = item + this.mode = 'view' + this.data_bak = {} + } else if (action == 'response') { + this.id = item + this.mode = 'view' + this.data_bak = {} + window.location.hash = item + sendMsg(parent.conf, [this.domain, 'query', this.name, item], {}) } } @@ -48,7 +57,11 @@ function exec(action: string) { } this.output += '\n' + value console.log('exec:', value) - sendMsg(conf, [this.domain, action, this.name, data.id], data) + const msgbase = [this.domain, action, this.name] + if (this.mode != 'new') { + msgbase.push(this.id) + } + sendMsg(conf, msgbase, data) } function initField(name: string, meta: any) { @@ -81,7 +94,6 @@ function chmode(action: string) { function copynew(action: string) { Object.assign(this.data, this.data_bak) - this.data.id = '' this.mode = 'new' } @@ -101,6 +113,5 @@ function setNew(obj) { obj.data[key] = meta.default || '' } } - obj.data.id = '' } diff --git a/assets/js/comp-list.ts b/assets/js/comp-list.ts index 33d216b..a886b13 100644 --- a/assets/js/comp-list.ts +++ b/assets/js/comp-list.ts @@ -24,7 +24,7 @@ export function List(name: string, conf: any): object { // Data methods -function handle(domain, action, class_, item: string, payload) { +function handle(parent: any, domain, action, class_, item: string, payload) { if (action == 'list') { const rows = payload.split('\n') this.data.length = 0 diff --git a/exampleSite/content/app/person.md b/exampleSite/content/app/person.md index a96a96f..1bac950 100644 --- a/exampleSite/content/app/person.md +++ b/exampleSite/content/app/person.md @@ -17,19 +17,17 @@ cyberscopes example site - view / edit person (user) data. {{< pv/tabs-mode >}} - Id: {{< pv/input-textline name="id" defexpr="this.conf.itemid" >}} First Name: {{< pv/input-textline name="firstname" attrs="autofocus" >}} Last Name: {{< pv/input-textline name="lastname" >}} Email: {{< pv/input-textline name="email" default="hm@cy55.de" >}} - {{< pv/button mode="query" action="query" label="Execute Query" >}} {{< pv/button mode="edit" label="Save Changes" >}} {{< pv/button mode="edit" exec="copynew" label="Copy Data" >}} {{< pv/button mode="edit" action="delete" label="Delete Item" >}} {{< pv/button mode="new" label="Create Item" >}}
- {{< pv/display linkto="data.id" + {{< pv/display linkto="id" expr="`${data.firstname} ${data.lastname}`.trim() || '???'" >}}
{{< pv/link >}} diff --git a/layouts/shortcodes/pv/display.html b/layouts/shortcodes/pv/display.html index f8fa6b8..3051095 100644 --- a/layouts/shortcodes/pv/display.html +++ b/layouts/shortcodes/pv/display.html @@ -1,6 +1,6 @@ {{- $name := .Get "name" | default "textline" -}} {{- $expr := .Get "expr" | default (printf "data.%s" $name) -}} {{- $linkto := .Get "linkto" -}} -{{- if $linkto }}{{ end -}} +{{- if $linkto }}{{ end -}} {{- if $linkto }}{{ end -}} diff --git a/layouts/shortcodes/pv/input-textline.html b/layouts/shortcodes/pv/input-textline.html index 7ab5e86..c97a502 100644 --- a/layouts/shortcodes/pv/input-textline.html +++ b/layouts/shortcodes/pv/input-textline.html @@ -4,7 +4,7 @@
diff --git a/layouts/shortcodes/pv/link.html b/layouts/shortcodes/pv/link.html index d30d9ad..9f987d0 100644 --- a/layouts/shortcodes/pv/link.html +++ b/layouts/shortcodes/pv/link.html @@ -1,3 +1,6 @@ -{{- $target := .Get "target" | default "data.id" -}} -{{- $prefix := .Get "prefix" | default "?id=" -}} +{{- $target := .Get "target" | default "id" -}} +{{- $prefix := .Get "prefix" | default "#" -}} + this.id = item + this.mode = 'view' + this.data_bak = {} {{ .Inner }} diff --git a/layouts/shortcodes/pv/list.html b/layouts/shortcodes/pv/list.html index 286adc5..51b1599 100644 --- a/layouts/shortcodes/pv/list.html +++ b/layouts/shortcodes/pv/list.html @@ -9,7 +9,7 @@ {{- .Inner -}} - {| item[fname] |} + {| item[fname] |} diff --git a/layouts/shortcodes/pv/table.html b/layouts/shortcodes/pv/table.html deleted file mode 100644 index 4b6a3f7..0000000 --- a/layouts/shortcodes/pv/table.html +++ /dev/null @@ -1,11 +0,0 @@ -{{- $name := .Get "name" | default "table" -}} -{{- $tcells := true -}} - - - -
-
-
- diff --git a/layouts/shortcodes/pv/tabs-mode.md b/layouts/shortcodes/pv/tabs-mode.md index 01de21d..f2bd3f2 100644 --- a/layouts/shortcodes/pv/tabs-mode.md +++ b/layouts/shortcodes/pv/tabs-mode.md @@ -3,10 +3,6 @@ View -