"github.com/YouthBuild-USA/godata/templates"
	"github.com/YouthBuild-USA/godata/web"
	"github.com/coopernurse/gorp"
	"github.com/gorilla/context"
	"net/http"
)

var dbMap *gorp.DbMap

func Initialize(db *gorp.DbMap) {
	dbMap = db
	dbMap.AddTableWithName(SubjectType{}, "subject_type").SetKeys(true, "Id")
}

var (
	subjecTypeIndexTemplate = templates.OneColumn().Add("subjects/typeList")
)

func AddRoutes(handleAdder web.HandlerAdder) error {
	handleAdder("/admin/subject-types", subjectTypeIndex).Methods("GET")
	return nil
}

func subjectTypeIndex(w http.ResponseWriter, r *http.Request) error {

	types, err := LoadSubjectTypes()
	if err != nil {
		return err
	}

	subjecTypeIndexTemplate.Render(w, r, "Subject Types", types)
Exemple #2
0
	"net/http"
	"strconv"
)

func AddRoutes(adder web.HandlerAdder) {
	types.AddRoutes(adder)
	adder("/admin/questions", questionList).Methods("GET")
	adder("/admin/questions/add/{questionType}", addQuestionForm).Methods("GET")
	adder("/admin/questions/add/{questionType}", addQuestion).Methods("POST")
	adder("/admin/questions/{id:[0-9]+}", showQuestion).Methods("GET")
	adder("/admin/questions/{id:[0-9]+}/edit", editQuestionForm).Methods("GET")
	adder("/admin/questions/{id:[0-9]+}/edit", editQuestion).Methods("POST")
}

var (
	questionListTemplate = templates.OneColumn().Add("questions/list")
	addQuestionTemplate  = templates.OneColumn().Add("questions/add", "forms/horizontal")
	viewQuestionTemplate = templates.OneColumn().Add("questions/view")
)

func showQuestion(w http.ResponseWriter, r *http.Request) error {
	vars := mux.Vars(r)
	questionId, _ := strconv.ParseInt(vars["id"], 10, 64)
	question, err := LoadQuestion(int(questionId))
	if err != nil {
		return err
	}
	return viewQuestionTemplate.Render(w, r, question.Name, question)
}

func questionList(w http.ResponseWriter, r *http.Request) error {
package types

import (
	"github.com/YouthBuild-USA/godata/templates"
	"github.com/YouthBuild-USA/godata/web"
	"net/http"
	"net/url"
	"reflect"
)

var (
	typeListTemplate = templates.OneColumn().Add("questions/types/list")
)

type QuestionType interface {
	Name() string
	Label() string
	Description() string
	Template() string
	FieldType() FieldType
	Parse(form url.Values) (reflect.Value, error)
}

var QuestionTypes = make(map[string]QuestionType)

func Register(questionType QuestionType) {
	if _, ok := QuestionTypes[questionType.Name()]; !ok {
		QuestionTypes[questionType.Name()] = questionType
	}
}
Exemple #4
0
package users

import (
	"fmt"
	"github.com/YouthBuild-USA/godata/log"
	"github.com/YouthBuild-USA/godata/templates"
	"github.com/YouthBuild-USA/godata/web"
	"net/http"
)

var userLog = log.New("User")

var (
	loginFormTemplate = templates.OneColumn().Add("users/loginForm")
	userTemplate      = templates.OneColumn().Add("users/user")
)

func init() {
}

func (module userModule) AddRoutes(handleAdder web.HandlerAdder) error {

	handleAdder("/login", loginForm).Methods("GET")
	handleAdder("/login", login).Methods("POST")
	handleAdder("/user", userPage).Methods("GET")
	handleAdder("/logout", logout).Methods("GET")
	return nil
}

func loginForm(w http.ResponseWriter, r *http.Request) error {
	user, _ := CurrentUser(r)