示例#1
0
func (self *TextField) Render(context *Context, writer *utils.XMLWriter) (err error) {
	writer.OpenTag("input").Attrib("id", self.id).AttribIfNotDefault("class", self.Class)

	writer.Attrib("name", self.Name)
	writer.AttribIfNotDefault("tabindex", self.TabIndex)
	if self.Readonly {
		writer.Attrib("readonly", "readonly")
	}
	if self.Disabled {
		writer.Attrib("disabled", "disabled")
	}

	switch self.Type {
	case PasswordTextField:
		writer.Attrib("type", "password")
	case EmailTextField:
		writer.Attrib("type", "email")
	default:
		writer.Attrib("type", "text")
	}

	writer.AttribIfNotDefault("size", self.Size)
	writer.AttribIfNotDefault("maxlength", self.MaxLength)
	writer.Attrib("value", self.Text)

	writer.CloseTag()
	return nil
}
示例#2
0
func (self *DummyImage) Render(context *Context, writer *utils.XMLWriter) (err error) {
	src := fmt.Sprintf("http://dummyimage.com/%dx%d", self.Width, self.Height)

	if self.BackgroundColor != "" || self.ForegroundColor != "" {
		if self.BackgroundColor != "" {
			src += "/" + self.BackgroundColor
		} else {
			src += "/ccc"
		}

		if self.ForegroundColor != "" {
			src += "/" + self.ForegroundColor
		}
	}

	src += ".png"

	if self.Text != "" {
		src += "&text=" + url.QueryEscape(self.Text)
	}

	writer.OpenTag("img").Attrib("id", self.id).AttribIfNotDefault("class", self.Class)
	writer.Attrib("src", src)
	writer.AttribIfNotDefault("width", self.Width)
	writer.AttribIfNotDefault("height", self.Height)
	writer.AttribIfNotDefault("alt", self.Text)
	writer.CloseTag()
	return nil
}
示例#3
0
func (self *TextArea) Render(context *Context, writer *utils.XMLWriter) (err error) {
	writer.OpenTag("textarea").Attrib("id", self.id).AttribIfNotDefault("class", self.Class)

	cols := self.Cols
	if cols == 0 {
		cols = TextAreaDefaultCols
	}
	rows := self.Rows
	if rows == 0 {
		rows = TextAreaDefaultRows
	}

	writer.Attrib("name", self.Name)
	writer.Attrib("rows", rows)
	writer.Attrib("cols", cols)
	writer.AttribIfNotDefault("tabindex", self.TabIndex)
	if self.Readonly {
		writer.Attrib("readonly", "readonly")
	}
	if self.Disabled {
		writer.Attrib("disabled", "disabled")
	}

	writer.EscapeContent(self.Text)
	writer.CloseTag()
	return nil
}
示例#4
0
func (self *Video) Render(context *Context, writer *utils.XMLWriter) (err error) {
	youtubeId := ""

	switch {
	case strings.HasPrefix(self.URL, "http://youtu.be/"):
		i := len("http://youtu.be/")
		youtubeId = self.URL[i : i+11]

	case strings.HasPrefix(self.URL, "http://www.youtube.com/watch?v="):
		i := len("http://www.youtube.com/watch?v=")
		youtubeId = self.URL[i : i+11]
	}

	if youtubeId != "" {
		writer.OpenTag("iframe").Attrib("id", self.id).AttribIfNotDefault("class", self.Class)
		width := self.Width
		if width == 0 {
			width = 640
		}
		height := self.Height
		if height == 0 {
			height = 390
		}
		writer.Attrib("src", "http://www.youtube.com/embed/", youtubeId)
		writer.Attrib("width", width)
		writer.Attrib("height", height)
		writer.Attrib("frameborder", "0")
		writer.Attrib("allowfullscreen", "allowfullscreen")
		writer.CloseTag()
		return nil
	}

	return errs.Format("Unsupported video URL: %s", self.URL)
}
示例#5
0
func (self *HiddenInput) Render(context *Context, writer *utils.XMLWriter) (err error) {
	writer.OpenTag("input").Attrib("id", self.id)
	writer.Attrib("type", "hidden")
	writer.Attrib("name", self.Name)
	writer.Attrib("value", self.Value)
	writer.CloseTag()
	return nil
}
示例#6
0
func (self *FileInput) Render(context *Context, writer *utils.XMLWriter) (err error) {
	writer.OpenTag("input").Attrib("id", self.id).AttribIfNotDefault("class", self.Class)
	writer.Attrib("type", "file").Attrib("name", self.Name)
	if self.Disabled {
		writer.Attrib("disabled", "disabled")
	}
	writer.CloseTag()
	return err
}
示例#7
0
func (self *Image) Render(context *Context, writer *utils.XMLWriter) (err error) {
	writer.OpenTag("img").Attrib("id", self.id).AttribIfNotDefault("class", self.Class)
	writer.Attrib("src", self.URL)
	writer.AttribIfNotDefault("width", self.Width)
	writer.AttribIfNotDefault("height", self.Height)
	writer.AttribIfNotDefault("alt", self.Description)
	writer.CloseTag()
	return nil
}
示例#8
0
func (self *Label) Render(context *Context, writer *utils.XMLWriter) (err error) {
	var forID string
	if self.For != nil {
		forID = self.For.ID()
	}
	writer.OpenTag("label").Attrib("id", self.id).AttribIfNotDefault("class", self.Class)
	writer.AttribIfNotDefault("for", forID)
	if self.Content != nil {
		err = self.Content.Render(context, writer)
	}
	writer.CloseTag()
	return err
}
示例#9
0
func (self *Tag) Render(context *Context, writer *utils.XMLWriter) (err error) {
	writer.OpenTag(self.Tag).Attrib("id", self.id).AttribIfNotDefault("class", self.Class)
	for key, value := range self.Attribs {
		writer.Attrib(key, value)
	}
	if self.Content != nil {
		err = self.Content.Render(context, writer)
	}
	if self.ExtraClose {
		writer.ForceCloseTag()
	} else {
		writer.CloseTag()
	}
	return err
}
示例#10
0
func (self *Checkbox) Render(context *Context, writer *utils.XMLWriter) (err error) {
	writer.OpenTag("input").Attrib("id", self.id).AttribIfNotDefault("class", self.Class)
	writer.Attrib("type", "checkbox")
	writer.Attrib("name", self.Name)
	writer.Attrib("value", "true")
	if self.Disabled {
		writer.Attrib("disabled", "disabled")
	}
	if self.Checked {
		writer.Attrib("checked", "checked")
	}
	writer.CloseTag()

	if self.Label != "" {
		writer.OpenTag("label").Attrib("for", self.id).Content(self.Label).CloseTag()
	}
	return nil
}
示例#11
0
func (self *Select) Render(context *Context, writer *utils.XMLWriter) (err error) {
	writer.OpenTag("select").Attrib("id", self.id).AttribIfNotDefault("class", self.Class)
	writer.Attrib("name", self.Name)
	if self.Disabled {
		writer.Attrib("disabled", "disabled")
	}

	size := self.Size

	if self.Model != nil {
		numOptions := self.Model.NumOptions()
		if size == 0 {
			size = numOptions
		}
		writer.Attrib("size", size)

		for i := 0; i < numOptions; i++ {
			writer.OpenTag("option")
			writer.AttribIfNotDefault("value", self.Model.Value(i))
			if self.Model.Selected(i) {
				writer.Attrib("selected", "selected")
			}
			if self.Model.Disabled(i) {
				writer.Attrib("disabled", "disabled")
			}
			err = self.Model.RenderItem(i, context, writer)
			if err != nil {
				return err
			}
			writer.CloseTag() // option
		}
	} else {
		writer.Attrib("size", size)
	}

	writer.CloseTag() // select
	return nil
}
示例#12
0
func (self *Button) Render(context *Context, writer *utils.XMLWriter) (err error) {
	if self.Submit {
		writer.OpenTag("input").Attrib("id", self.id).AttribIfNotDefault("class", self.Class)
		writer.Attrib("type", "submit")
		writer.AttribIfNotDefault("name", self.Name)
		writer.AttribIfNotDefault("value", self.Value)
		if self.Disabled {
			writer.Attrib("disabled", "disabled")
		}
		writer.AttribIfNotDefault("tabindex", self.TabIndex)
		if self.OnClickConfirm != "" {
			writer.Attrib("onclick", "return confirm('", self.OnClickConfirm, "');")
		} else {
			writer.AttribIfNotDefault("onclick", self.OnClick)
		}
		writer.CloseTag()
	} else {
		writer.OpenTag("button").Attrib("id", self.id).AttribIfNotDefault("class", self.Class)
		writer.Attrib("type", "button")
		writer.AttribIfNotDefault("name", self.Name)
		writer.AttribIfNotDefault("value", self.Value)
		if self.Disabled {
			writer.Attrib("disabled", "disabled")
		}
		writer.AttribIfNotDefault("tabindex", self.TabIndex)
		if self.OnClickConfirm != "" {
			writer.Attrib("onclick", "return confirm('", self.OnClickConfirm, "');")
		} else {
			writer.AttribIfNotDefault("onclick", self.OnClick)
		}
		if self.Content != nil {
			err = self.Content.Render(context, writer)
		}
		writer.ForceCloseTag()
	}
	return nil
}