github.com/keysonZZZ/kmg@v0.0.0-20151121023212-05317bfd7d39/kmgView/kmgBootstrap/form.go (about) 1 package kmgBootstrap 2 3 import ( 4 "github.com/bronze1man/kmg/kmgStrconv" 5 "github.com/bronze1man/kmg/kmgView" 6 ) 7 8 // 自带一个提交按钮的From表单. 9 // TODO 允许调用者配置,去掉自带的按钮. 10 type Form struct { 11 Id string 12 Url string 13 IsGet bool // 默认是POST 14 InputList []kmgView.HtmlRenderer 15 NoSubmit bool // 默认有一个提交按钮. 16 IsHidden bool 17 } 18 19 func (f Form) HtmlRender() string { 20 return tplForm(f) 21 } 22 23 // 纵向输入框外壳 24 type InputWrapVertical struct { 25 ShowName string 26 Comment string 27 Body kmgView.HtmlRenderer 28 AppendTpl kmgView.HtmlRenderer 29 Need bool 30 } 31 32 func (f InputWrapVertical) HtmlRender() string { 33 return tplInputWrapVertical(f) 34 } 35 36 // html的输入框 37 type Input struct { 38 Type string 39 Name string 40 Value string 41 ReadOnly bool 42 } 43 44 func (f Input) HtmlRender() string { 45 return tplInput(f) 46 } 47 48 type Select struct { 49 Name string 50 Value string 51 ReadOnly bool 52 OptionList []SelectOption 53 } 54 55 type SelectOption struct { 56 Value string 57 ShowName string 58 Disable bool 59 } 60 61 func (s Select) HtmlRender() string { 62 return tplSelect(s) 63 } 64 65 type SelectVerticalString struct { 66 Name string 67 Value string 68 ReadOnly bool 69 OptionList []SelectOption 70 ShowName string 71 Comment string 72 Need bool 73 } 74 75 func (s SelectVerticalString) HtmlRender() string { 76 if s.ShowName == "" { 77 s.ShowName = s.Name 78 } 79 return InputWrapVertical{ 80 ShowName: s.ShowName, 81 Comment: s.Comment, 82 Need: s.Need, 83 Body: Select{ 84 Name: s.Name, 85 Value: s.Value, 86 ReadOnly: s.ReadOnly, 87 OptionList: s.OptionList, 88 }, 89 }.HtmlRender() 90 } 91 92 type TextArea struct { 93 Name string 94 Value string 95 ReadOnly bool 96 } 97 98 func (f TextArea) HtmlRender() string { 99 return tplTextArea(f) 100 } 101 102 // 纵向输入框 (横向占满) 103 type InputVerticalString struct { 104 Name string 105 Value string 106 ShowName string 107 Comment string 108 Need bool 109 ReadOnly bool 110 AppendTpl kmgView.HtmlRenderer 111 } 112 113 func (f InputVerticalString) HtmlRender() string { 114 if f.ShowName == "" { 115 f.ShowName = f.Name 116 } 117 return InputWrapVertical{ 118 ShowName: f.ShowName, 119 Comment: f.Comment, 120 Need: f.Need, 121 Body: Input{ 122 Type: "text", 123 Name: f.Name, 124 Value: f.Value, 125 ReadOnly: f.ReadOnly, 126 }, 127 AppendTpl: f.AppendTpl, 128 }.HtmlRender() 129 } 130 131 type InputVerticalInt struct { 132 Name string 133 Value int 134 ShowName string 135 Comment string 136 Need bool 137 ReadOnly bool 138 } 139 140 func (f InputVerticalInt) HtmlRender() string { 141 if f.ShowName == "" { 142 f.ShowName = f.Name 143 } 144 return InputWrapVertical{ 145 ShowName: f.ShowName, 146 Comment: f.Comment, 147 Need: f.Need, 148 Body: Input{ 149 Type: "number", 150 Name: f.Name, 151 Value: kmgStrconv.FormatInt(f.Value), 152 ReadOnly: f.ReadOnly, 153 }, 154 }.HtmlRender() 155 } 156 157 type TextAreaVerticalString struct { 158 Name string 159 Value string 160 ShowName string 161 Comment string 162 Need bool 163 ReadOnly bool 164 } 165 166 func (f TextAreaVerticalString) HtmlRender() string { 167 if f.ShowName == "" { 168 f.ShowName = f.Name 169 } 170 return InputWrapVertical{ 171 ShowName: f.ShowName, 172 Comment: f.Comment, 173 Need: f.Need, 174 Body: TextArea{ 175 Name: f.Name, 176 Value: f.Value, 177 ReadOnly: f.ReadOnly, 178 }, 179 }.HtmlRender() 180 } 181 182 type InputHidden struct { 183 Name string 184 Value string 185 } 186 187 func (f InputHidden) HtmlRender() string { 188 return Input{ 189 Type: "hidden", 190 Name: f.Name, 191 Value: f.Value, 192 }.HtmlRender() 193 }