issue.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. // Copyright 2014 The Gogs Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package auth
  5. import (
  6. "net/http"
  7. "reflect"
  8. "github.com/go-martini/martini"
  9. "github.com/gogits/gogs/modules/base"
  10. "github.com/gogits/gogs/modules/log"
  11. )
  12. type CreateIssueForm struct {
  13. IssueName string `form:"title" binding:"Required;MaxSize(50)"`
  14. MilestoneId int64 `form:"milestoneid"`
  15. AssigneeId int64 `form:"assigneeid"`
  16. Labels string `form:"labels"`
  17. Content string `form:"content"`
  18. }
  19. func (f *CreateIssueForm) Name(field string) string {
  20. names := map[string]string{
  21. "IssueName": "Issue name",
  22. }
  23. return names[field]
  24. }
  25. func (f *CreateIssueForm) Validate(errors *base.BindingErrors, req *http.Request, context martini.Context) {
  26. if req.Method == "GET" || errors.Count() == 0 {
  27. return
  28. }
  29. data := context.Get(reflect.TypeOf(base.TmplData{})).Interface().(base.TmplData)
  30. data["HasError"] = true
  31. AssignForm(f, data)
  32. if len(errors.Overall) > 0 {
  33. for _, err := range errors.Overall {
  34. log.Error("CreateIssueForm.Validate: %v", err)
  35. }
  36. return
  37. }
  38. validate(errors, data, f)
  39. }