Merge pull request #317 from trheyi/main
[add] syntactic sugar action.hide
This commit is contained in:
commit
e8e96bb4f1
2 changed files with 27 additions and 0 deletions
|
|
@ -23,6 +23,31 @@ func (action *ActionDSL) UnmarshalJSON(data []byte) error {
|
|||
return err
|
||||
}
|
||||
|
||||
// Syntactic sugar { "hide": ["add", "edit", "view"] }
|
||||
// ["add", "edit", "view"]
|
||||
if action.Hide != nil {
|
||||
|
||||
// set default value
|
||||
action.ShowWhenAdd = true // shown in add form
|
||||
action.ShowWhenView = true // shown in view form
|
||||
action.HideWhenEdit = false // shown in edit form
|
||||
|
||||
for _, kind := range action.Hide {
|
||||
kind = strings.ToLower(kind)
|
||||
switch kind {
|
||||
case "add":
|
||||
action.ShowWhenAdd = false
|
||||
break
|
||||
case "view":
|
||||
action.ShowWhenView = false
|
||||
break
|
||||
case "edit":
|
||||
action.HideWhenEdit = true
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if action.Action == nil {
|
||||
action.Action = ActionNodes{}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -40,8 +40,10 @@ type ActionDSL struct {
|
|||
Style string `json:"style,omitempty"`
|
||||
Xpath string `json:"xpath,omitempty"`
|
||||
DivideLine bool `json:"divideLine,omitempty"`
|
||||
Hide []string `json:"hide,omitempty"` // Syntactic sugar ["add", "edit", "view"]
|
||||
ShowWhenAdd bool `json:"showWhenAdd,omitempty"`
|
||||
ShowWhenView bool `json:"showWhenView,omitempty"`
|
||||
HideWhenEdit bool `json:"hideWhenEdit,omitempty"`
|
||||
Props PropsDSL `json:"props,omitempty"`
|
||||
Confirm *ConfirmActionDSL `json:"confirm,omitempty"`
|
||||
Action ActionNodes `json:"action,omitempty"`
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue