github.com/kotovmak/go-admin@v1.1.1/template/components/treeview.go (about)

     1  package components
     2  
     3  import (
     4  	"encoding/json"
     5  	"html/template"
     6  
     7  	"github.com/kotovmak/go-admin/modules/utils"
     8  	"github.com/kotovmak/go-admin/template/types"
     9  )
    10  
    11  type TreeViewAttribute struct {
    12  	Name      string
    13  	ID        string
    14  	Tree      types.TreeViewData
    15  	TreeJSON  template.JS
    16  	UrlPrefix string
    17  	types.Attribute
    18  }
    19  
    20  func (compo *TreeViewAttribute) SetID(id string) types.TreeViewAttribute {
    21  	compo.ID = id
    22  	return compo
    23  }
    24  
    25  func (compo *TreeViewAttribute) SetTree(value types.TreeViewData) types.TreeViewAttribute {
    26  	compo.Tree = value
    27  	return compo
    28  }
    29  
    30  func (compo *TreeViewAttribute) SetUrlPrefix(value string) types.TreeViewAttribute {
    31  	compo.UrlPrefix = value
    32  	return compo
    33  }
    34  
    35  func (compo *TreeViewAttribute) GetContent() template.HTML {
    36  	if compo.ID == "" {
    37  		compo.ID = utils.Uuid(10)
    38  	}
    39  	b, _ := json.Marshal(compo.Tree)
    40  	compo.TreeJSON = template.JS(b)
    41  	return ComposeHtml(compo.TemplateList, compo.Separation, *compo, "treeview")
    42  }