put all mode changes in buttons
This commit is contained in:
parent
4cd5021a63
commit
e47d90cde9
5 changed files with 41 additions and 20 deletions
|
@ -29,14 +29,14 @@ const store_prefix = 'api.storage'
|
||||||
async function sendMsg(basemsg: string[], data: any) {
|
async function sendMsg(basemsg: string[], data: any) {
|
||||||
const [ domain, action, class_, item ] = basemsg
|
const [ domain, action, class_, item ] = basemsg
|
||||||
switch (action) {
|
switch (action) {
|
||||||
case 'data':
|
case 'query':
|
||||||
handle(this, store(domain, class_, item, data))
|
handle(this, query(domain, class_, item))
|
||||||
break
|
break
|
||||||
case 'delete':
|
case 'delete':
|
||||||
handle(this, remove(domain, class_, item))
|
handle(this, remove(domain, class_, item))
|
||||||
break
|
break
|
||||||
case 'query':
|
default:
|
||||||
handle(this, query(domain, class_, item))
|
handle(this, store(domain, class_, item, data))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,7 @@ export function Data(name: string, conf: any): object {
|
||||||
exec, // default function to execute upon button click
|
exec, // default function to execute upon button click
|
||||||
initField, // initialize field (= @mounted), collect metadata
|
initField, // initialize field (= @mounted), collect metadata
|
||||||
chmode,
|
chmode,
|
||||||
|
hasmode,
|
||||||
copynew
|
copynew
|
||||||
}
|
}
|
||||||
//this.components[name] = comp
|
//this.components[name] = comp
|
||||||
|
@ -26,9 +27,7 @@ export function Data(name: string, conf: any): object {
|
||||||
// Data methods
|
// Data methods
|
||||||
|
|
||||||
function initialize() {
|
function initialize() {
|
||||||
if (this.state.id) {
|
loadData(this)
|
||||||
this.sendMsg([this.domain, 'query', this.name, this.state.id], {})
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function handle(domain, action, class_, item, payload: string) {
|
function handle(domain, action, class_, item, payload: string) {
|
||||||
|
@ -45,7 +44,15 @@ function handle(domain, action, class_, item, payload: string) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function exec(action: string) {
|
function initField(name: string, meta: any): void {
|
||||||
|
if (meta.defexpr) {
|
||||||
|
meta.default = eval(meta.defexpr)
|
||||||
|
}
|
||||||
|
this.data[name] = meta.default || ""
|
||||||
|
this.meta[name] = meta
|
||||||
|
}
|
||||||
|
|
||||||
|
function exec(action: string): void {
|
||||||
action = action || this.action
|
action = action || this.action
|
||||||
const data = this.data
|
const data = this.data
|
||||||
let value = ''
|
let value = ''
|
||||||
|
@ -60,19 +67,15 @@ function exec(action: string) {
|
||||||
this.sendMsg(msgbase, data)
|
this.sendMsg(msgbase, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
function initField(name: string, meta: any) {
|
function chmode(action: string): void {
|
||||||
if (meta.defexpr) {
|
|
||||||
meta.default = eval(meta.defexpr)
|
|
||||||
}
|
|
||||||
this.data[name] = meta.default || ""
|
|
||||||
this.meta[name] = meta
|
|
||||||
}
|
|
||||||
|
|
||||||
function chmode(action: string) {
|
|
||||||
if (this.state.mode == action) {
|
if (this.state.mode == action) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
switch(action) {
|
switch(action) {
|
||||||
|
case 'view':
|
||||||
|
case 'edit':
|
||||||
|
loadData(this)
|
||||||
|
break
|
||||||
case 'query':
|
case 'query':
|
||||||
setQuery(this)
|
setQuery(this)
|
||||||
break
|
break
|
||||||
|
@ -83,12 +86,27 @@ function chmode(action: string) {
|
||||||
this.state.mode = action
|
this.state.mode = action
|
||||||
}
|
}
|
||||||
|
|
||||||
function copynew(action: string) {
|
function hasmode(mode: string): boolean {
|
||||||
|
for (const m of mode.split(' ')) {
|
||||||
|
if (this.state.mode === m) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
function copynew(action: string): void {
|
||||||
this.state.mode = 'new'
|
this.state.mode = 'new'
|
||||||
}
|
}
|
||||||
|
|
||||||
// helper functions for data manipulation (used by Data component)
|
// helper functions for data manipulation (used by Data component)
|
||||||
|
|
||||||
|
function loadData(obj) {
|
||||||
|
if (obj.state.id) {
|
||||||
|
obj.sendMsg([obj.domain, 'query', obj.name, obj.state.id], {})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function setQuery(obj) {
|
function setQuery(obj) {
|
||||||
for (const key in obj.data) {
|
for (const key in obj.data) {
|
||||||
obj.data[key] = ''
|
obj.data[key] = ''
|
||||||
|
|
|
@ -28,6 +28,7 @@ params:
|
||||||
api:
|
api:
|
||||||
domain: demo
|
domain: demo
|
||||||
module: main-demo.ts
|
module: main-demo.ts
|
||||||
|
#module: main-ig.ts
|
||||||
|
|
||||||
taxonomies:
|
taxonomies:
|
||||||
domain: domains
|
domain: domains
|
||||||
|
|
|
@ -20,6 +20,9 @@ cyberscopes example site - view / edit person (user) data.
|
||||||
Last Name: {{< pv/data-field-line name="lastname" >}}
|
Last Name: {{< pv/data-field-line name="lastname" >}}
|
||||||
Email: {{< pv/data-field-line name="email" default="hm@cy55.de" >}}
|
Email: {{< pv/data-field-line name="email" default="hm@cy55.de" >}}
|
||||||
|
|
||||||
|
{{< pv/button mode="view" exec="chmode" action="edit" label="Edit" >}}
|
||||||
|
{{< pv/button mode="view" exec="chmode" action="new" label="New" >}}
|
||||||
|
{{< pv/button mode="edit new" exec="chmode" action="view" label="Cancel" >}}
|
||||||
{{< pv/button mode="edit" label="Save Changes" >}}
|
{{< pv/button mode="edit" label="Save Changes" >}}
|
||||||
{{< pv/button mode="edit" exec="copynew" label="Copy Data" >}}
|
{{< pv/button mode="edit" exec="copynew" label="Copy Data" >}}
|
||||||
{{< pv/button mode="edit" action="delete" label="Delete Item" >}}
|
{{< pv/button mode="edit" action="delete" label="Delete Item" >}}
|
||||||
|
@ -38,4 +41,3 @@ cyberscopes example site - view / edit person (user) data.
|
||||||
|
|
||||||
{{< pv/debug >}}
|
{{< pv/debug >}}
|
||||||
|
|
||||||
[click here](?id=10127-180017)
|
|
||||||
|
|
|
@ -5,6 +5,6 @@
|
||||||
{{- $action := .Get "action" | default "" -}}
|
{{- $action := .Get "action" | default "" -}}
|
||||||
{{- $mode := .Get "mode" -}}
|
{{- $mode := .Get "mode" -}}
|
||||||
<button type="{{ $type }}" name="{{ $name }}"
|
<button type="{{ $type }}" name="{{ $name }}"
|
||||||
{{- with $mode }}v-show="state.mode == '{{ . }}'"{{ end -}}
|
{{- with $mode }}v-show="hasmode('{{ . }}')"{{ end -}}
|
||||||
@click="{{ $exec }}('{{ $action }}')">{{$label}}</button>
|
@click="{{ $exec }}('{{ $action }}')">{{$label}}</button>
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue