diff --git a/README.md b/README.md index 4b8c704..9b5db97 100644 --- a/README.md +++ b/README.md @@ -20,27 +20,31 @@ TO DO: Version Changes Control ======================= -v0.0.10 - 2020-03-08 +v0.0.11 - 2020-04-13 +------------------------ +- Added parameters to creation of containers, zones, dataset and elements + +v0.0.10 - 2020-04-08 ------------------------ - Added know child "code" to event -v0.0.9 - 2020-03-08 +v0.0.9 - 2020-04-08 ------------------------ - Correction of event node so code is into code node. -v0.0.8 - 2020-03-08 +v0.0.8 - 2020-04-08 ------------------------ - Correction of all the Types of containers and elements to put correct js library name (nameContainer and nameElement syntax) -v0.0.7 - 2020-03-08 +v0.0.7 - 2020-04-08 ------------------------ - Added MarshalXML on Node to build XML code from nodes -v0.0.6 - 2020-03-08 +v0.0.6 - 2020-04-08 ------------------------ - Correction on assigning the node data (concatened, only if some info into it: will ignore spaces and line formatting characters) -v0.0.5 - 2020-03-07 +v0.0.5 - 2020-04-07 ----------------------- - Added UnmarshalXML - Added MarshalJSON @@ -48,7 +52,7 @@ v0.0.5 - 2020-03-07 - Removed messages, events, help attributes of Node - Added AddZone() to SeparatorContainer as a new struct extended from DomDef interface to build upon specific functions for specific nodes (it works) -v0.0.4 - 2020-03-06 +v0.0.4 - 2020-04-06 ----------------------- - All structures and Application tree implemented in GO - Full wajaf JS available in js directory diff --git a/accordioncontainer.go b/accordioncontainer.go index 7151fdb..09abbc9 100644 --- a/accordioncontainer.go +++ b/accordioncontainer.go @@ -1,27 +1,37 @@ package wajaf -type AccordionContainer NodeDef +type AccordionContainer struct { + NodeDef +} -func NewAccordionContainer(id string) AccordionContainer { +func NewAccordionContainer(id string) *AccordionContainer { - c := NewNode("container", "accordionContainer") + c := &AccordionContainer{ + NodeDef: NewNode("container", "accordionContainer"), + } c.SetID(id) c.RegisterKnownAttributes([]string{"display", "style", "classname", "classnamezone", "left", "width", "right", "top", "height", "bottom", "haslistener"}) - c.RegisterKnownChildren([]string{"zone", "event", "help", "message"}) + c.RegisterKnownChildren([]string{"zone", "event", "help"}) return c } +func (c *AccordionContainer) NewZone(ztype string, id string) NodeDef { + z := NewAccordionZone(ztype, id) + c.AddChild(z) + return z +} + type AccordionZone NodeDef -func NewAccordionZone(id string) AccordionZone { +func NewAccordionZone(ztype string, id string) AccordionZone { - z := NewNode("zone", "") + z := NewNode("zone", ztype) z.SetID(id) z.RegisterKnownAttributes([]string{"style", "classname", "application", "params"}) - z.RegisterKnownChildren([]string{"container", "element"}) + z.RegisterKnownChildren([]string{"container", "element", "event", "help"}) return z } diff --git a/application.go b/application.go index 28aeed9..06559b4 100644 --- a/application.go +++ b/application.go @@ -8,7 +8,7 @@ func NewApplication(id string) Application { app.SetID(id) app.RegisterKnownAttributes([]string{"id", "enforce", "style"}) - app.RegisterKnownChildren([]string{"container", "element"}) + app.RegisterKnownChildren([]string{"container", "element", "event"}) return app } diff --git a/barcontainer.go b/barcontainer.go index eed7d47..2176953 100644 --- a/barcontainer.go +++ b/barcontainer.go @@ -1,27 +1,37 @@ package wajaf -type BarContainer NodeDef +type BarContainer struct { + NodeDef +} -func NewBarContainer(id string) BarContainer { +func NewBarContainer(id string) *BarContainer { - c := NewNode("container", "barContainer") + c := &BarContainer{ + NodeDef: NewNode("container", "barContainer"), + } c.SetID(id) c.RegisterKnownAttributes([]string{"display", "style", "classname", "classnamezone", "left", "width", "right", "top", "height", "bottom", "haslistener"}) - c.RegisterKnownChildren([]string{"zone"}) + c.RegisterKnownChildren([]string{"zone", "event", "help"}) return c } +func (c *BarContainer) NewZone(ztype string, id string) NodeDef { + z := NewBarZone(ztype, id) + c.AddChild(z) + return z +} + type BarZone NodeDef -func NewBarZone(id string) BarZone { +func NewBarZone(ztype string, id string) BarZone { - z := NewNode("zone", "") + z := NewNode("zone", ztype) z.SetID(id) z.RegisterKnownAttributes([]string{"style", "classname", "application", "params"}) - z.RegisterKnownChildren([]string{"container", "element"}) + z.RegisterKnownChildren([]string{"container", "element", "event", "help"}) return z } diff --git a/buttonelement.go b/buttonelement.go index 2f27a4f..19bc188 100644 --- a/buttonelement.go +++ b/buttonelement.go @@ -2,7 +2,7 @@ package wajaf type ButtonElement NodeDef -func NewButtonElement(id string) ButtonElement { +func NewButtonElement(id string, action string) ButtonElement { e := NewNode("element", "buttonElement") e.SetID(id) @@ -11,5 +11,7 @@ func NewButtonElement(id string) ButtonElement { "visible", "action", "status", "extra"}) // e.RegisterKnownMessages([]string{"titleinsert", "titleupdate", "titledelete", "titleview"}) + e.SetAttribute("action", action) + return e } diff --git a/codeelement.go b/codeelement.go index 5c0e771..83bbfac 100644 --- a/codeelement.go +++ b/codeelement.go @@ -2,10 +2,11 @@ package wajaf type CodeElement NodeDef -func NewCodeElement(id string) CodeElement { +func NewCodeElement(id string, code string) CodeElement { e := NewNode("element", "codeElement") e.SetID(id) + e.SetData(code) e.RegisterKnownAttributes([]string{"display", "style", "classname", "left", "width", "right", "top", "height", "bottom"}) diff --git a/dblistcontainer.go b/dblistcontainer.go index 5901110..6380478 100644 --- a/dblistcontainer.go +++ b/dblistcontainer.go @@ -1,36 +1,52 @@ package wajaf -type DBListContainer NodeDef +type DBListContainer struct { + NodeDef +} -func NewDBListContainer(id string) DBListContainer { +func NewDBListContainer(id string) *DBListContainer { - c := NewNode("container", "dblistContainer") + c := &DBListContainer{ + NodeDef: NewNode("container", "dblistContainer"), + } c.SetID(id) c.RegisterKnownAttributes([]string{"display", "style", "classname", "classnamezone", "left", "width", "right", "top", "height", "bottom", "haslistener"}) - c.RegisterKnownChildren([]string{"zone", "template", "dataset"}) + c.RegisterKnownChildren([]string{"zone", "template", "dataset", "event", "help"}) return c } +func (c *DBListContainer) NewZone(ztype string, id string) NodeDef { + z := NewDBListZone(ztype, id) + c.AddChild(z) + return z +} + type DBListZone NodeDef -func NewDBListZone(id string) DBListZone { +func NewDBListZone(id string, ztype string) DBListZone { - z := NewNode("zone", "") + z := NewNode("zone", ztype) z.SetID(id) z.RegisterKnownAttributes([]string{"style", "classname", "application", "params"}) - z.RegisterKnownChildren([]string{"container", "element"}) + z.RegisterKnownChildren([]string{"container", "element", "event", "help"}) + + return z +} +func (c *DBListContainer) NewTemplate(ttype string, name string) NodeDef { + z := NewDBListTemplate(ttype, name) + c.AddChild(z) return z } type DBListTemplate NodeDef -func NewDBListTemplate(name string) DBListTemplate { +func NewDBListTemplate(ttype string, name string) DBListTemplate { - t := NewNode("template", "") + t := NewNode("template", ttype) t.RegisterKnownAttributes([]string{"name"}) t.RegisterKnownChildren([]string{"container", "element"}) @@ -40,11 +56,17 @@ func NewDBListTemplate(name string) DBListTemplate { return t } +func (c *DBListContainer) NewDataset(dtype string, data string) NodeDef { + z := NewDBListDataset(dtype, data) + c.AddChild(z) + return z +} + type DBListDataset NodeDef -func NewDBListDataset(data string) DBListDataset { +func NewDBListDataset(dtype string, data string) DBListDataset { - d := NewNode("dataset", "") + d := NewNode("dataset", dtype) d.SetData(data) return d diff --git a/decoder.go b/decoder.go deleted file mode 100644 index bbd1060..0000000 --- a/decoder.go +++ /dev/null @@ -1,14 +0,0 @@ -package wajaf - -type Decoder struct { - Containers map[string]NodeDef - Elements map[string]NodeDef -} - -func NewDecoder() *Decoder { - d := &Decoder{} - - // Adds all known container and elements and events - - return d -} diff --git a/dockcontainer.go b/dockcontainer.go index 58efbda..0c75435 100644 --- a/dockcontainer.go +++ b/dockcontainer.go @@ -1,27 +1,37 @@ package wajaf -type DockContainer NodeDef +type DockContainer struct { + NodeDef +} -func NewDockContainer(id string) DockContainer { +func NewDockContainer(id string) *DockContainer { - c := NewNode("container", "dockContainer") + c := &DockContainer{ + NodeDef: NewNode("container", "dockContainer"), + } c.SetID(id) c.RegisterKnownAttributes([]string{"display", "style", "classname", "classnamezone", "left", "width", "right", "top", "height", "bottom", "haslistener"}) - c.RegisterKnownChildren([]string{"zone"}) + c.RegisterKnownChildren([]string{"zone", "event", "help"}) return c } +func (c *DockContainer) NewZone(ztype string, id string) NodeDef { + z := NewDockZone(ztype, id) + c.AddChild(z) + return z +} + type DockZone NodeDef -func NewDockZone(id string) DockZone { +func NewDockZone(ztype string, id string) DockZone { - z := NewNode("zone", "") + z := NewNode("zone", ztype) z.SetID(id) z.RegisterKnownAttributes([]string{"style", "classname", "application", "params"}) - z.RegisterKnownChildren([]string{"container", "element"}) + z.RegisterKnownChildren([]string{"container", "element", "event", "help"}) return z } diff --git a/expandablecontainer.go b/expandablecontainer.go index e1e1d17..df0168f 100644 --- a/expandablecontainer.go +++ b/expandablecontainer.go @@ -1,28 +1,38 @@ package wajaf -type ExpandableContainer NodeDef +type ExpandableContainer struct { + NodeDef +} -func NewExpandableContainer(id string) ExpandableContainer { +func NewExpandableContainer(id string) *ExpandableContainer { - c := NewNode("container", "expandableContainer") + c := &ExpandableContainer{ + NodeDef: NewNode("container", "expandableContainer"), + } c.SetID(id) c.RegisterKnownAttributes([]string{"display", "style", "classname", "classnamezone", "left", "width", "right", "top", "height", "bottom", "haslistener"}) - c.RegisterKnownChildren([]string{"zone"}) + c.RegisterKnownChildren([]string{"zone", "event", "help"}) return c } +func (c *ExpandableContainer) NewZone(ztype string, id string) NodeDef { + z := NewExpandableZone(ztype, id) + c.AddChild(z) + return z +} + type ExpandableZone NodeDef -func NewExpandableZone(id string) ExpandableZone { +func NewExpandableZone(ztype string, id string) ExpandableZone { - z := NewNode("zone", "") + z := NewNode("zone", ztype) z.SetID(id) z.RegisterKnownAttributes([]string{"style", "classname", "application", "params", "title", "closed", "classnameselectoropen", "classnameselectorclose", "display"}) - z.RegisterKnownChildren([]string{"container", "element"}) + z.RegisterKnownChildren([]string{"container", "element", "event", "help"}) return z } diff --git a/floatingcontainer.go b/floatingcontainer.go index 3bacb33..8f83189 100644 --- a/floatingcontainer.go +++ b/floatingcontainer.go @@ -1,27 +1,37 @@ package wajaf -type FloatingContainer NodeDef +type FloatingContainer struct { + NodeDef +} -func NewFloatingContainer(id string) FloatingContainer { +func NewFloatingContainer(id string) *FloatingContainer { - c := NewNode("container", "floatingContainer") + c := &FloatingContainer{ + NodeDef: NewNode("container", "floatingContainer"), + } c.SetID(id) c.RegisterKnownAttributes([]string{"display", "style", "classname", "classnamezone", "left", "width", "right", "top", "height", "bottom", "haslistener"}) - c.RegisterKnownChildren([]string{"zone"}) + c.RegisterKnownChildren([]string{"zone", "event", "help"}) return c } +func (c *FloatingContainer) NewZone(ztype string, id string) NodeDef { + z := NewFloatingZone(ztype, id) + c.AddChild(z) + return z +} + type FloatingZone NodeDef -func NewFloatingZone(id string) FloatingZone { +func NewFloatingZone(ztype string, id string) FloatingZone { - z := NewNode("zone", "") + z := NewNode("zone", ztype) z.SetID(id) z.RegisterKnownAttributes([]string{"style", "classname", "application", "params"}) - z.RegisterKnownChildren([]string{"container", "element"}) + z.RegisterKnownChildren([]string{"container", "element", "event", "help"}) return z } diff --git a/gridcontainer.go b/gridcontainer.go index b973471..93eb2ca 100644 --- a/gridcontainer.go +++ b/gridcontainer.go @@ -1,38 +1,54 @@ package wajaf -type GridContainer NodeDef +type GridContainer struct { + NodeDef +} -func NewGridContainer(id string) GridContainer { +func NewGridContainer(id string) *GridContainer { - c := NewNode("container", "gridContainer") + c := &GridContainer{ + NodeDef: NewNode("container", "gridContainer"), + } c.SetID(id) c.RegisterKnownAttributes([]string{"display", "style", "classname", "classnamezone", "left", "width", "right", "top", "height", "bottom", "haslistener", "pagination", "maxperpage", "mode", "selectable", "insertable", "deletable", "change", "params"}) - c.RegisterKnownChildren([]string{"zone", "template", "dataset"}) + c.RegisterKnownChildren([]string{"zone", "template", "dataset", "event", "help"}) return c } +func (c *GridContainer) NewZone(ztype string, id string) NodeDef { + z := NewGridZone(ztype, id) + c.AddChild(z) + return z +} + type GridZone NodeDef -func NewGridZone(id string) GridZone { +func NewGridZone(ztype string, id string) GridZone { - z := NewNode("zone", "") + z := NewNode("zone", ztype) z.SetID(id) z.RegisterKnownAttributes([]string{"style", "classname", "application", "params", "title", "application", "size", "sizemin", "sizemax", "selectable", "sortable", "sizeable", "maskable", "editable", "type", "editor", "render", "format", "align"}) - z.RegisterKnownChildren([]string{"container", "element"}) + z.RegisterKnownChildren([]string{"container", "element", "event", "help"}) + + return z +} +func (c *GridContainer) NewTemplate(ttype string, name string) NodeDef { + z := NewGridTemplate(ttype, name) + c.AddChild(z) return z } type GridTemplate NodeDef -func NewGridTemplate(name string) GridTemplate { +func NewGridTemplate(ttype string, name string) GridTemplate { - t := NewNode("template", "") + t := NewNode("template", ttype) t.RegisterKnownAttributes([]string{"name"}) t.RegisterKnownChildren([]string{"container", "element"}) @@ -42,11 +58,17 @@ func NewGridTemplate(name string) GridTemplate { return t } +func (c *GridContainer) NewDataset(dtype string, data string) NodeDef { + z := NewGridDataset(dtype, data) + c.AddChild(z) + return z +} + type GridDataset NodeDef -func NewGridDataset(data string) GridDataset { +func NewGridDataset(dtype string, data string) GridDataset { - d := NewNode("dataset", "") + d := NewNode("dataset", dtype) d.SetData(data) return d diff --git a/groupcontainer.go b/groupcontainer.go index 27efcf1..9c8d514 100644 --- a/groupcontainer.go +++ b/groupcontainer.go @@ -1,38 +1,56 @@ package wajaf -type GroupContainer NodeDef +type GroupContainer struct { + NodeDef +} -func NewGroupContainer(id string) GroupContainer { +func NewGroupContainer(id string) *GroupContainer { - c := NewNode("container", "groupContainer") + c := &GroupContainer{ + NodeDef: NewNode("container", "groupContainer"), + } c.SetID(id) - c.RegisterKnownAttributes([]string{"display", "style", "classname", "classnamezone", "left", "width", "right", "top", "height", "bottom", "haslistener", - "mode", "authmodes", "varkey", "key", "varorder", "varmode"}) + c.RegisterKnownAttributes([]string{"display", "style", "classname", "classnamezone", + "left", "width", "right", "top", "height", "bottom", "haslistener", + "varmode", "varorder", "varkey", + "mode", "authmodes", "key"}) // c.RegisterKnownMessages([]string{"alertmessage", "servermessage", "titleinsert", "titleupdate", "titledelete", "titleview", "insertok", "updateok", "deleteok"}) - c.RegisterKnownChildren([]string{"zone", "dataset"}) + c.RegisterKnownChildren([]string{"zone", "dataset", "event", "help"}) return c } +func (c *GroupContainer) NewZone(ztype string, id string) NodeDef { + z := NewGroupZone(ztype, id) + c.AddChild(z) + return z +} + type GroupZone NodeDef -func NewGroupZone(id string) GroupZone { +func NewGroupZone(ztype string, id string) GroupZone { - z := NewNode("zone", "") + z := NewNode("zone", ztype) z.SetID(id) z.RegisterKnownAttributes([]string{"style", "classname", "application", "params"}) - z.RegisterKnownChildren([]string{"container", "element"}) + z.RegisterKnownChildren([]string{"container", "element", "event", "help"}) + + return z +} +func (c *GroupContainer) NewDataset(dtype string, data string) NodeDef { + z := NewGroupDataset(dtype, data) + c.AddChild(z) return z } type GroupDataset NodeDef -func NewGroupDataset(data string) GroupDataset { +func NewGroupDataset(dtype string, data string) GroupDataset { - d := NewNode("dataset", "") + d := NewNode("dataset", dtype) d.SetData(data) return d diff --git a/hiddenelement.go b/hiddenelement.go index beeb02d..2dd2de3 100644 --- a/hiddenelement.go +++ b/hiddenelement.go @@ -2,10 +2,11 @@ package wajaf type HiddenElement NodeDef -func NewHiddenElement(id string) HiddenElement { +func NewHiddenElement(id string, data string) HiddenElement { e := NewNode("element", "hiddenElement") e.SetID(id) + e.SetData(data) return e } diff --git a/hiddenfieldelement.go b/hiddenfieldelement.go index 8e27154..bdc2869 100644 --- a/hiddenfieldelement.go +++ b/hiddenfieldelement.go @@ -2,11 +2,10 @@ package wajaf type HiddenFieldElement NodeDef -func NewHiddenFieldElement(id string, data string) HiddenFieldElement { +func NewHiddenFieldElement(id string) HiddenFieldElement { e := NewNode("element", "hiddenfieldElement") e.SetID(id) - e.SetData(data) e.RegisterKnownAttributes([]string{"display", "style", "classname", "left", "width", "right", "top", "height", "bottom"}) diff --git a/listcontainer.go b/listcontainer.go index 9ccc7ac..c1ce24d 100644 --- a/listcontainer.go +++ b/listcontainer.go @@ -1,10 +1,14 @@ package wajaf -type ListContainer NodeDef +type ListContainer struct { + NodeDef +} -func NewListContainer(id string) ListContainer { +func NewListContainer(id string) *ListContainer { - c := NewNode("container", "listContainer") + c := &ListContainer{ + NodeDef: NewNode("container", "listContainer"), + } c.SetID(id) c.RegisterKnownAttributes([]string{"display", "style", "classname", "classnamezone", "left", "width", "right", "top", "height", "bottom", "haslistener"}) @@ -13,11 +17,17 @@ func NewListContainer(id string) ListContainer { return c } +func (c *ListContainer) NewZone(ztype string, id string) NodeDef { + z := NewListZone(ztype, id) + c.AddChild(z) + return z +} + type ListZone NodeDef -func NewListZone(id string) ListZone { +func NewListZone(ztype string, id string) ListZone { - z := NewNode("zone", "") + z := NewNode("zone", ztype) z.SetID(id) z.RegisterKnownAttributes([]string{"style", "classname", "application", "params"}) @@ -26,11 +36,17 @@ func NewListZone(id string) ListZone { return z } +func (c *ListContainer) NewTemplate(ttype string, name string) NodeDef { + z := NewListTemplate(ttype, name) + c.AddChild(z) + return z +} + type ListTemplate NodeDef -func NewListTemplate(name string) ListTemplate { +func NewListTemplate(ttype string, name string) ListTemplate { - t := NewNode("template", "") + t := NewNode("template", ttype) t.RegisterKnownAttributes([]string{"name"}) t.RegisterKnownChildren([]string{"container", "element"}) @@ -40,11 +56,17 @@ func NewListTemplate(name string) ListTemplate { return t } +func (c *ListContainer) NewDataset(dtype string, data string) NodeDef { + z := NewListDataset(dtype, data) + c.AddChild(z) + return z +} + type ListDataset NodeDef -func NewListDataset(data string) ListDataset { +func NewListDataset(dtype string, data string) ListDataset { - d := NewNode("dataset", "") + d := NewNode("dataset", dtype) d.SetData(data) return d diff --git a/lovfieldelement.go b/lovfieldelement.go index 863796d..8f33a3a 100644 --- a/lovfieldelement.go +++ b/lovfieldelement.go @@ -2,11 +2,10 @@ package wajaf type LOVFieldElement NodeDef -func NewLOVFieldElement(id string, data string) LOVFieldElement { +func NewLOVFieldElement(id string) LOVFieldElement { e := NewNode("element", "lovfieldElement") e.SetID(id) - e.SetData(data) e.RegisterKnownAttributes([]string{"display", "style", "classname", "left", "width", "right", "top", "height", "bottom", "size", "visible", "info", "disabled", "readonly", "notnull", "helpmode"}) diff --git a/matrixcontainer.go b/matrixcontainer.go index d9b6fd1..34153d4 100644 --- a/matrixcontainer.go +++ b/matrixcontainer.go @@ -1,37 +1,53 @@ package wajaf -type MatrixContainer NodeDef +type MatrixContainer struct { + NodeDef +} -func NewMatrixContainer(id string) MatrixContainer { +func NewMatrixContainer(id string) *MatrixContainer { - c := NewNode("container", "matrixContainer") + c := &MatrixContainer{ + NodeDef: NewNode("container", "matrixContainer"), + } c.SetID(id) c.RegisterKnownAttributes([]string{"display", "style", "classname", "classnamezone", "left", "width", "right", "top", "height", "bottom", "haslistener", "columns", "mode", "classnamezone", "preidbutton", "defaultwidth", "defaultheight"}) - c.RegisterKnownChildren([]string{"zone", "template", "dataset"}) + c.RegisterKnownChildren([]string{"zone", "template", "dataset", "event", "help"}) return c } +func (c *MatrixContainer) NewZone(ztype string, id string) NodeDef { + z := NewMatrixZone(ztype, id) + c.AddChild(z) + return z +} + type MatrixZone NodeDef -func NewMatrixZone(id string) MatrixZone { +func NewMatrixZone(ztype string, id string) MatrixZone { - z := NewNode("zone", "") + z := NewNode("zone", ztype) z.SetID(id) z.RegisterKnownAttributes([]string{"style", "classname", "application", "params"}) - z.RegisterKnownChildren([]string{"container", "element"}) + z.RegisterKnownChildren([]string{"container", "element", "event", "help"}) + + return z +} +func (c *MatrixContainer) NewTemplate(ttype string, name string) NodeDef { + z := NewMatrixTemplate(ttype, name) + c.AddChild(z) return z } type MatrixTemplate NodeDef -func NewMatrixTemplate(name string) MatrixTemplate { +func NewMatrixTemplate(ttype string, name string) MatrixTemplate { - t := NewNode("template", "") + t := NewNode("template", ttype) t.RegisterKnownAttributes([]string{"name"}) t.RegisterKnownChildren([]string{"container", "element"}) @@ -41,11 +57,17 @@ func NewMatrixTemplate(name string) MatrixTemplate { return t } +func (c *MatrixContainer) NewDataset(dtype string, data string) NodeDef { + z := NewMatrixDataset(dtype, data) + c.AddChild(z) + return z +} + type MatrixDataset NodeDef -func NewMatrixDataset(data string) MatrixDataset { +func NewMatrixDataset(dtype string, data string) MatrixDataset { - d := NewNode("dataset", "") + d := NewNode("dataset", dtype) d.SetData(data) return d diff --git a/node.go b/node.go index 84ce8fd..0d82e5f 100644 --- a/node.go +++ b/node.go @@ -136,11 +136,17 @@ func (n *Node) GetAttributes() Attributes { } func (n *Node) AddHelp(tooltip string, title string, description string) { + if tooltip == "" && title == "" && description == "" { + return + } h := NewHelp(tooltip, title, description) n.children = append(n.children, h) } func (n *Node) AddMessage(name string, value string) { + if value == "" { + return + } m := NewMessage(name, value) n.children = append(n.children, m) } @@ -174,6 +180,7 @@ func (n *Node) String() string { for _, val := range n.children { sdata = append(sdata, fmt.Sprintf("%v", val)) } + sdata = append(sdata, n.Data) return "{" + strings.Join(sdata, " ") + "}" } @@ -185,6 +192,7 @@ func (n *Node) GoString() string { for _, val := range n.children { sdata = append(sdata, fmt.Sprintf("%#v", val)) } + sdata = append(sdata, n.Data) return "#{" + strings.Join(sdata, " ") + "}" } @@ -285,6 +293,9 @@ func (n *Node) MarshalJSON() ([]byte, error) { if count > 0 || n.ID != "" || n.Type != "" { buffer.WriteString(",") } + if avalue == "" { + continue + } jsonValue, err := json.Marshal(avalue) if err != nil { return nil, err diff --git a/paginationelement.go b/paginationelement.go index c2b5df3..e47d975 100644 --- a/paginationelement.go +++ b/paginationelement.go @@ -2,11 +2,10 @@ package wajaf type PaginationElement NodeDef -func NewPaginationElement(id string, data string) PaginationElement { +func NewPaginationElement(id string) PaginationElement { e := NewNode("element", "paginationElement") e.SetID(id) - e.SetData(data) e.RegisterKnownAttributes([]string{"display", "style", "classname", "left", "width", "right", "top", "height", "bottom"}) diff --git a/separatorcontainer.go b/separatorcontainer.go index e4db15c..7a73681 100644 --- a/separatorcontainer.go +++ b/separatorcontainer.go @@ -11,32 +11,31 @@ func NewSeparatorContainer(id string) *SeparatorContainer { c := &SeparatorContainer{ NodeDef: NewNode("container", "separatorContainer"), } - // c := NewNode("container", "separatorcontainer") c.SetID(id) c.RegisterKnownAttributes([]string{"display", "style", "classname", "classnamezone", "left", "width", "right", "top", "height", "bottom", "haslistener", "mode", "auto"}) - c.RegisterKnownChildren([]string{"zone"}) + c.RegisterKnownChildren([]string{"zone", "event", "help"}) return c } -func (c *SeparatorContainer) NewZone(id string) NodeDef { - z := NewSeparatorZone(id) +func (c *SeparatorContainer) NewZone(ztype string, id string) NodeDef { + z := NewSeparatorZone(ztype, id) c.AddChild(z) return z } type SeparatorZone NodeDef -func NewSeparatorZone(id string) SeparatorZone { +func NewSeparatorZone(ztype string, id string) SeparatorZone { - z := NewNode("zone", "") + z := NewNode("zone", ztype) z.SetID(id) z.RegisterKnownAttributes([]string{"style", "classname", "application", "params", "size", "classnameseparator", "display"}) - z.RegisterKnownChildren([]string{"container", "element"}) + z.RegisterKnownChildren([]string{"container", "element", "event", "help"}) return z } diff --git a/simplecontainer.go b/simplecontainer.go index ea5ea78..3bac870 100644 --- a/simplecontainer.go +++ b/simplecontainer.go @@ -1,27 +1,37 @@ package wajaf -type SimpleContainer NodeDef +type SimpleContainer struct { + NodeDef +} -func NewSimpleContainer(id string) SimpleContainer { +func NewSimpleContainer(id string) *SimpleContainer { - c := NewNode("container", "simpleContainer") + c := &SimpleContainer{ + NodeDef: NewNode("container", "simpleContainer"), + } c.SetID(id) c.RegisterKnownAttributes([]string{"display", "style", "classname", "classnamezone", "left", "width", "right", "top", "height", "bottom", "haslistener"}) - c.RegisterKnownChildren([]string{"zone"}) + c.RegisterKnownChildren([]string{"zone", "event", "help"}) return c } +func (c *SimpleContainer) NewZone(ztype string, id string) NodeDef { + z := NewSimpleZone(ztype, id) + c.AddChild(z) + return z +} + type SimpleZone NodeDef -func NewSimpleZone(id string) SimpleZone { +func NewSimpleZone(ztype string, id string) SimpleZone { - z := NewNode("zone", "") + z := NewNode("zone", ztype) z.SetID(id) z.RegisterKnownAttributes([]string{"style", "classname", "application", "params"}) - z.RegisterKnownChildren([]string{"container", "element"}) + z.RegisterKnownChildren([]string{"container", "element", "event", "help"}) return z } diff --git a/tabcontainer.go b/tabcontainer.go index 22e980d..054f560 100644 --- a/tabcontainer.go +++ b/tabcontainer.go @@ -1,29 +1,39 @@ package wajaf -type TabContainer NodeDef +type TabContainer struct { + NodeDef +} -func NewTabContainer(id string) TabContainer { +func NewTabContainer(id string) *TabContainer { - c := NewNode("container", "tabContainer") + c := &TabContainer{ + NodeDef: NewNode("container", "tabContainer"), + } c.SetID(id) c.RegisterKnownAttributes([]string{"display", "style", "classname", "classnamezone", "left", "width", "right", "top", "height", "bottom", "haslistener", "mode"}) - c.RegisterKnownChildren([]string{"zone"}) + c.RegisterKnownChildren([]string{"zone", "event", "help"}) return c } +func (c *TabContainer) NewZone(ztype string, id string) NodeDef { + z := NewTabZone(ztype, id) + c.AddChild(z) + return z +} + type TabZone NodeDef -func NewTabZone(id string) TabZone { +func NewTabZone(ztype string, id string) TabZone { - z := NewNode("zone", "") + z := NewNode("zone", ztype) z.SetID(id) z.RegisterKnownAttributes([]string{"style", "classname", "application", "params", "title"}) - z.RegisterKnownChildren([]string{"container", "element"}) + z.RegisterKnownChildren([]string{"container", "element", "event", "help"}) return z } diff --git a/tablecontainer.go b/tablecontainer.go index e4f5f37..1b91e37 100644 --- a/tablecontainer.go +++ b/tablecontainer.go @@ -1,27 +1,37 @@ package wajaf -type TableContainer NodeDef +type TableContainer struct { + NodeDef +} -func NewTableContainer(id string) TableContainer { +func NewTableContainer(id string) *TableContainer { - c := NewNode("container", "tableContainer") + c := &TableContainer{ + NodeDef: NewNode("container", "tableContainer"), + } c.SetID(id) c.RegisterKnownAttributes([]string{"display", "style", "classname", "classnamezone", "left", "width", "right", "top", "height", "bottom", "haslistener"}) - c.RegisterKnownChildren([]string{"zone"}) + c.RegisterKnownChildren([]string{"zone", "event", "help"}) return c } +func (c *TableContainer) NewZone(ztype string, id string) NodeDef { + z := NewTableZone(ztype, id) + c.AddChild(z) + return z +} + type TableZone NodeDef -func NewTableZone(id string) TableZone { +func NewTableZone(ztype string, id string) TableZone { - z := NewNode("zone", "") + z := NewNode("zone", ztype) z.SetID(id) z.RegisterKnownAttributes([]string{"style", "classname", "application", "params"}) - z.RegisterKnownChildren([]string{"container", "element"}) + z.RegisterKnownChildren([]string{"container", "element", "event", "help"}) return z } diff --git a/textareafieldelement.go b/textareafieldelement.go index ef43279..c90e63f 100644 --- a/textareafieldelement.go +++ b/textareafieldelement.go @@ -2,11 +2,10 @@ package wajaf type TextAreaFieldElement NodeDef -func NewTextAreaFieldElement(id string, data string) TextAreaFieldElement { +func NewTextAreaFieldElement(id string) TextAreaFieldElement { e := NewNode("element", "textareafieldElement") e.SetID(id) - e.SetData(data) e.RegisterKnownAttributes([]string{"display", "style", "classname", "left", "width", "right", "top", "height", "bottom", "areawidth", "areaheight", "minlength", "maxlength", "minwords", "maxwords", "format", "visible", "info", "disabled", "readonly", "notnull", "helpmode"}) diff --git a/textfieldelement.go b/textfieldelement.go index add2e7e..233733c 100644 --- a/textfieldelement.go +++ b/textfieldelement.go @@ -2,11 +2,10 @@ package wajaf type TextFieldElement NodeDef -func NewTextFieldElement(id string, data string) TextFieldElement { +func NewTextFieldElement(id string) TextFieldElement { e := NewNode("element", "textfieldElement") e.SetID(id) - e.SetData(data) e.RegisterKnownAttributes([]string{"display", "style", "classname", "left", "width", "right", "top", "height", "bottom", "size", "minlength", "maxlength", "minwords", "maxwords", "format", "visible", "info", "disabled", "readonly", "notnull", "helpmode"}) diff --git a/treecontainer.go b/treecontainer.go index 35dfffa..b183bb8 100644 --- a/treecontainer.go +++ b/treecontainer.go @@ -1,36 +1,52 @@ package wajaf -type TreeContainer NodeDef +type TreeContainer struct { + NodeDef +} -func NewTreeContainer(id string) TreeContainer { +func NewTreeContainer(id string) *TreeContainer { - c := NewNode("container", "treeContainer") + c := &TreeContainer{ + NodeDef: NewNode("container", "treeContainer"), + } c.SetID(id) c.RegisterKnownAttributes([]string{"display", "style", "classname", "classnamezone", "left", "width", "right", "top", "height", "bottom", "haslistener"}) - c.RegisterKnownChildren([]string{"zone", "template", "dataset"}) + c.RegisterKnownChildren([]string{"zone", "template", "dataset", "event", "help"}) return c } +func (c *TreeContainer) NewZone(ztype string, id string) NodeDef { + z := NewTreeZone(ztype, id) + c.AddChild(z) + return z +} + type TreeZone NodeDef -func NewTreeZone(id string) TreeZone { +func NewTreeZone(ztype string, id string) TreeZone { - z := NewNode("zone", "") + z := NewNode("zone", ztype) z.SetID(id) z.RegisterKnownAttributes([]string{"style", "classname", "application", "params"}) - z.RegisterKnownChildren([]string{"container", "element"}) + z.RegisterKnownChildren([]string{"container", "element", "event", "help"}) + + return z +} +func (c *TreeContainer) NewTemplate(ttype string, name string) NodeDef { + z := NewTreeTemplate(ttype, name) + c.AddChild(z) return z } type TreeTemplate NodeDef -func NewTreeTemplate(name string) TreeTemplate { +func NewTreeTemplate(ttype string, name string) TreeTemplate { - t := NewNode("template", "") + t := NewNode("template", ttype) t.RegisterKnownAttributes([]string{"name"}) t.RegisterKnownChildren([]string{"container", "element"}) @@ -40,11 +56,17 @@ func NewTreeTemplate(name string) TreeTemplate { return t } +func (c *TreeContainer) NewDataset(dtype string, data string) NodeDef { + z := NewTreeDataset(dtype, data) + c.AddChild(z) + return z +} + type TreeDataset NodeDef -func NewTreeDataset(data string) TreeDataset { +func NewTreeDataset(dtype string, data string) TreeDataset { - d := NewNode("dataset", "") + d := NewNode("dataset", dtype) d.SetData(data) return d diff --git a/wajaf.go b/wajaf.go index 6f1ecd4..084c906 100644 --- a/wajaf.go +++ b/wajaf.go @@ -7,7 +7,7 @@ package wajaf // VERSION is the used version nombre of the XCore library. -const VERSION = "0.0.10" +const VERSION = "0.0.11" // LOG is the flag to activate logging on the library. // if LOG is set to TRUE, LOG indicates to the XCore libraries to log a trace of functions called, with most important parameters. diff --git a/wajaf_test.go b/wajaf_test.go index 68ca659..c28d561 100644 --- a/wajaf_test.go +++ b/wajaf_test.go @@ -24,19 +24,19 @@ func TestWajaf(t *testing.T) { c1.SetAttributes(Attributes{"width": "max", "height": "max", "mode": "vertical", "auto": "yes"}) app.AddChild(c1) - z0 := c1.NewZone("z0") + z0 := c1.NewZone("", "z0") z0.AddChild(NewHTMLElement("", "HTML

ELEMENT

CONTENT")) - z1 := NewSeparatorZone("z1") + z1 := NewSeparatorZone("", "z1") z1.AddHelp("tooltip on z1", "z1 help", "You can use z1 clicking on it") z1.AddMessage("messageid", "The message is any string with specific tag name") c1.AddChild(z1) - z2 := NewSeparatorZone("z2") + z2 := NewSeparatorZone("", "z2") c1.AddChild(z2) - e1 := NewCodeElement("code1") + e1 := NewCodeElement("code1", "function test() { alert('Wajaf test'); }") app.AddChild(e1) app.AddEvent("start", "function() { alert('Wajaf working'); }") diff --git a/widgetcontainer.go b/widgetcontainer.go index 7c0b409..d3e5117 100644 --- a/widgetcontainer.go +++ b/widgetcontainer.go @@ -1,38 +1,54 @@ package wajaf -type WidgetContainer NodeDef +type WidgetContainer struct { + NodeDef +} -func NewWidgetContainer(id string) WidgetContainer { +func NewWidgetContainer(id string) *WidgetContainer { - c := NewNode("container", "widgetContainer") + c := &WidgetContainer{ + NodeDef: NewNode("container", "widgetContainer"), + } c.SetID(id) c.RegisterKnownAttributes([]string{"id", "type", "id", "display", "style", "classname", "classnamezone", "left", "width", "right", "top", "height", "bottom", "haslistener", "columns", "classnamezone"}) - c.RegisterKnownChildren([]string{"zone", "event", "template", "dataset"}) + c.RegisterKnownChildren([]string{"zone", "event", "template", "dataset", "event", "help"}) return c } +func (c *WidgetContainer) NewZone(ztype string, id string) NodeDef { + z := NewWidgetZone(ztype, id) + c.AddChild(z) + return z +} + type WidgetZone NodeDef -func NewWidgetZone(id string) WidgetZone { +func NewWidgetZone(ztype string, id string) WidgetZone { - z := NewNode("zone", "") + z := NewNode("zone", ztype) z.SetID(id) z.RegisterKnownAttributes([]string{"style", "classname", "application", "params", "title", "size", "column", "closeable", "sizeable", "maskable", "editable", "editor"}) - z.RegisterKnownChildren([]string{"container", "element"}) + z.RegisterKnownChildren([]string{"container", "element", "event", "help"}) + + return z +} +func (c *WidgetContainer) NewTemplate(ttype string, name string) NodeDef { + z := NewWidgetTemplate(ttype, name) + c.AddChild(z) return z } type WidgetTemplate NodeDef -func NewWidgetTemplate(name string) WidgetTemplate { +func NewWidgetTemplate(ttype string, name string) WidgetTemplate { - t := NewNode("template", "") + t := NewNode("template", ttype) t.RegisterKnownAttributes([]string{"name"}) t.RegisterKnownChildren([]string{"container", "element"}) @@ -42,11 +58,17 @@ func NewWidgetTemplate(name string) WidgetTemplate { return t } +func (c *WidgetContainer) NewDataset(dtype string, data string) NodeDef { + z := NewWidgetDataset(dtype, data) + c.AddChild(z) + return z +} + type WidgetDataset NodeDef -func NewWidgetDataset(data string) WidgetDataset { +func NewWidgetDataset(dtype string, data string) WidgetDataset { - d := NewNode("dataset", "") + d := NewNode("dataset", dtype) d.SetData(data) return d diff --git a/windowcontainer.go b/windowcontainer.go index 15e3a68..f242fc4 100644 --- a/windowcontainer.go +++ b/windowcontainer.go @@ -1,27 +1,37 @@ package wajaf -type WindowContainer NodeDef +type WindowContainer struct { + NodeDef +} -func NewWindowContainer(id string) WindowContainer { +func NewWindowContainer(id string) *WindowContainer { - c := NewNode("container", "windowContainer") + c := &WindowContainer{ + NodeDef: NewNode("container", "windowContainer"), + } c.SetID(id) c.RegisterKnownAttributes([]string{"display", "style", "classname", "classnamezone", "left", "width", "right", "top", "height", "bottom", "haslistener"}) - c.RegisterKnownChildren([]string{"zone"}) + c.RegisterKnownChildren([]string{"zone", "event", "help"}) return c } +func (c *WindowContainer) NewZone(ztype string, id string) NodeDef { + z := NewWindowZone(ztype, id) + c.AddChild(z) + return z +} + type WindowZone NodeDef -func NewWindowZone(id string) WindowZone { +func NewWindowZone(ztype string, id string) WindowZone { - z := NewNode("zone", "") + z := NewNode("zone", ztype) z.SetID(id) z.RegisterKnownAttributes([]string{"style", "classname", "application", "params"}) - z.RegisterKnownChildren([]string{"container", "element"}) + z.RegisterKnownChildren([]string{"container", "element", "event", "help"}) return z }