Exemplo n.º 1
0
// 一个发起Post请求的按钮
// url: 将把url转化为表单并使用Post方法提交
// title: 按钮上面的字
// 在当前页面打开连接
//不支持一个 key 里塞多个 value 的 url
func NewPostButton(urlStr string, title string) kmgView.HtmlRenderer {
	formAction, err := url.Parse(urlStr)
	kmgErr.PanicIfError(err)
	query, err := url.ParseQuery(formAction.RawQuery)
	kmgErr.PanicIfError(err)
	formAction.RawQuery = ""
	id := kmgRand.MustCryptoRandToReadableAlphaNum(10)
	form := Form{
		Id:        id,
		NoSubmit:  true,
		Url:       formAction.String(),
		InputList: []kmgView.HtmlRenderer{},
		IsHidden:  true,
	}
	for k, v := range query {
		form.InputList = append(form.InputList, InputHidden{
			Name:  k,
			Value: v[0],
		})
	}
	button := Button{
		FormId:  id,
		Type:    ButtonTypeButton,
		Content: kmgView.String(title),
		Size:    ButtonSizeExtraSmall,
		Color:   ButtonColorInfo,
	}
	return kmgView.Html(form.HtmlRender() + button.HtmlRender())
}
Exemplo n.º 2
0
// 一个发起Get请求的按钮
// url: 点击后的跳转链接
// title: 按钮上面的字
// 在当前页面打开连接
func NewGetButton(url string, title string) Button {
	return Button{
		Type:    ButtonTypeA,
		Url:     url,
		Content: kmgView.String(title),
		Size:    ButtonSizeExtraSmall,
		Color:   ButtonColorInfo,
	}
}
Exemplo n.º 3
0
func (p *Table) SetDataListString(DataList [][]string) {
	for _, row := range DataList {
		renderRow := []kmgView.HtmlRenderer{}
		for _, value := range row {
			renderRow = append(renderRow, kmgView.String(value))
		}
		p.DataList = append(p.DataList, renderRow)
	}
}
Exemplo n.º 4
0
func H(index int, content kmgView.HtmlRenderer) kmgView.HtmlRenderer {
	if content == nil {
		return kmgView.String("")
	}
	if index == 0 {
		index = 1
	}
	iStr := strconv.Itoa(index)
	return kmgView.Html(`<h` + iStr + `>` + content.HtmlRender() + `</h` + iStr + `>`)
}
Exemplo n.º 5
0
// 1.这个函数顺序会变,基本不靠谱.
// 2.直接从数据库取的数据,字段信息没有翻译.
func NewTableFromMapList(m []map[string]string) Table {
	t := Table{}
	if len(m) == 0 {
		return t
	}
	i := 0
	for k := range m[0] {
		// TODO 排序
		t.TitleList = append(t.TitleList, kmgView.String(k))
		i++
	}
	for _, row := range m {
		viewRow := []kmgView.HtmlRenderer{}
		for _, k := range t.TitleList {
			viewRow = append(viewRow, kmgView.String(row[string(k.(kmgView.String))]))
		}
		t.DataList = append(t.DataList, viewRow)
	}
	return t
}
Exemplo n.º 6
0
func (e Example) Demo1(ctx *kmgHttp.Context) {
	ctx.WriteString(kmgBootstrap.NewWrap("kmg bootstrap demo",
		kmgBootstrap.NavBar{
			Title: kmgView.String("kmgBootstrap DEMO"),
			OptionList: []kmgBootstrap.NavBarNode{
				{Name: "主页", Url: "/"},
				{
					Name: "测试菜单1",
					Url:  "/?menu=1",
					ChildList: []kmgBootstrap.NavBarNode{
						{
							Name: "测试菜单-子菜单1-1",
							Url:  "/?menu=1-1",
							ChildList: []kmgBootstrap.NavBarNode{
								{
									Name: "测试菜单-子菜单1-1-1",
									Url:  "/?menu=1-1-1",
									ChildList: []kmgBootstrap.NavBarNode{
										{Name: "测试菜单-子菜单1-1-1-1", Url: "/?menu=1-1-1-1"},
									},
								},
								{Name: "测试菜单-子菜单1-1-2", Url: "/?menu=1-1-2"},
							},
						},
						{Name: "测试菜单-子菜单1-2", Url: "/?menu=1-2"},
					},
				},
			},
			RightOptionList: []kmgBootstrap.NavBarNode{
				{
					Name: "测试菜单1右",
					Url:  "/",
					ChildList: []kmgBootstrap.NavBarNode{
						{Name: "测试菜单-子菜单1-1右边", Url: "/"},
					},
				},
			},
		},
		kmgBootstrap.Panel{
			Title: "Panel",
			Body: kmgBootstrap.Panel{
				Title: "Panel",
				Body:  kmgView.String("Body"),
			},
		},
		kmgBootstrap.Panel{
			Title: "Table",
			Body: kmgBootstrap.Table{
				Caption: kmgView.String("Caption"),
				TitleList: []kmgView.HtmlRenderer{
					kmgView.String("title1"),
					kmgView.String("title2"),
				},
				DataList: [][]kmgView.HtmlRenderer{
					{
						kmgView.String("r1c1"),
						kmgView.String("r1c2"),
					},
					{
						kmgView.String("r2c1"),
						kmgView.String("r2c2"),
					},
				},
			},
		},
		kmgBootstrap.Panel{
			Title: "DropDown",
			Body: kmgView.HtmlRendererList{
				kmgView.String("使用 DropDown"),
				kmgBootstrap.DropDown{
					Title: kmgBootstrap.Button{
						Size:  kmgBootstrap.ButtonSizeSmall,
						Color: kmgBootstrap.ButtonColorSuccess,
						Content: kmgView.HtmlRendererList{
							kmgView.String("更多"),
							kmgBootstrap.Blank(1),
							kmgBootstrap.NewCaret(),
						},
					},
					OptionList: []kmgBootstrap.NavBarNode{
						{
							Name: "Say",
							Url:  "/",
							ChildList: []kmgBootstrap.NavBarNode{
								{
									Name: "你好",
								},
								{
									Name: "Hello",
								},
								{
									Name: "もしもし",
								},
								{
									Name: "Ciao",
								},
							},
						},
						{
							Name: "Do",
							ChildList: []kmgBootstrap.NavBarNode{
								{
									Name: "Walk",
								},
								{
									Name: "Sleep",
								},
							},
						},
					},
				},
				kmgView.String("将操作集中起来,节省空间"),
				kmgBootstrap.Br(1),
				kmgView.String("还可以使用快捷方法 kmgBootstrap.NewMoreButton,获得默认样式"),
				kmgBootstrap.NewMoreButton([]kmgBootstrap.NavBarNode{
					{
						Name: "新增",
					},
					{
						Name: "删除",
					},
					{
						Name: "编辑",
					},
				}),
			},
		},
		kmgBootstrap.Panel{
			Title: "Icon",
			Body: kmgBootstrap.Icon{
				IconName:      "exchange",
				IconColor:     kmgBootstrap.TextDanger,
				AttributeNode: kmgBootstrap.Popover{Title: "这里应该有一个图标"},
			},
		},
		kmgBootstrap.Panel{
			Title: "NavTabList",
			Body: kmgView.HtmlRendererList{
				kmgBootstrap.NavTabList{
					ActiveName: "状态1",
					OptionList: []kmgBootstrap.NavTabOption{
						{Name: "状态1", Url: "/#1"},
						{Name: "状态2", Url: "/#2"},
					},
				},
				kmgBootstrap.Br(1),
				kmgBootstrap.NavTabList{
					ActiveName:  "状态3",
					CustomClass: "nav-tabs",
					OptionList: []kmgBootstrap.NavTabOption{
						{Name: "状态3", Url: "/#3"},
						{Name: "状态4", Url: "/#4"},
					},
				},
			},
		},
		kmgBootstrap.Panel{
			Title: "Form",
			Body: kmgView.HtmlRendererList{
				kmgBootstrap.Form{
					Url: "/",
					InputList: []kmgView.HtmlRenderer{
						kmgBootstrap.InputVerticalString{
							Name:     "UserName",
							ShowName: "用户名",
							Value:    "enter your username here",
							Comment:  "必填",
							Need:     true,
						},
						kmgBootstrap.TextAreaVerticalString{
							ShowName: "服务条款",
							Value:    "服务条款",
							ReadOnly: true,
						},
						kmgBootstrap.SelectVerticalString{
							ShowName: "性别",
							Value:    "girl",
							Name:     "Gender",
							OptionList: []kmgBootstrap.SelectOption{
								{ShowName: "男", Value: "boy"},
								{ShowName: "女", Value: "girl"},
							},
						},
					},
				},
				kmgBootstrap.Br(2),
				kmgBootstrap.Pre(`从 URL 直接发送 POST 的链接`),
				kmgBootstrap.NewPostButton("/?n=main.Example.DemoPostAction&Name=kmg&Age=12", "POST 请求"),
				kmgBootstrap.Blank(2),
				kmgBootstrap.NewGetButton("/?n=main.Example.DemoPostAction&Name=kmg&Age=12", "非 POST 请求"),
			},
		},
	).HtmlRender())
}
Exemplo n.º 7
0
func (p *Table) SetTitleListString(TitleList []string) {
	p.TitleList = make([]kmgView.HtmlRenderer, len(TitleList))
	for i, title := range TitleList {
		p.TitleList[i] = kmgView.String(title)
	}
}