Ejemplo n.º 1
0
func AdminDriverDocumentGetAll(w http.ResponseWriter, r *http.Request, c *web.Context) {
	if !c.CheckAuth(w, r, "/login", "admin", "employee", "developer") {
		return
	}
	msgK, msgV := c.GetFlash()
	ts.Render(w, "admin-driver-document.tmpl", tmpl.Model{
		msgK:        msgV,
		"driver":    service.FindOneDriver(c.GetPathVar("driverId")),
		"documents": service.FindAllDocumentByDriver(c.GetPathVar("driverId")),
		"dqfs":      service.DQFS,
	})
	return
}
Ejemplo n.º 2
0
func AdminDriverDocumentGetOne(w http.ResponseWriter, r *http.Request, c *web.Context) {
	if !c.CheckAuth(w, r, "/login", "admin", "employee", "developer") {
		return
	}
	driver := service.FindOneDriver(c.GetPathVar("driverId"))
	document := service.FindOneDocument(c.GetPathVar("documentId"))
	ts.Render(w, document.Name+".tmpl", tmpl.Model{
		"driver":   driver,
		"company":  service.FindOneCompany(driver.CompanyId),
		"document": document,
		"admin":    true,
	})
}
Ejemplo n.º 3
0
// GET admin get driver
func AdminDriverGetOne(w http.ResponseWriter, r *http.Request, c *web.Context) {
	if !c.CheckAuth(w, r, "/login", "admin", "employee", "developer") {
		return
	}
	msgK, msgV := c.GetFlash()
	driver := service.FindOneDriver(c.GetPathVar("id"))
	ts.Render(w, "admin-driver-form.tmpl", tmpl.Model{
		msgK:        msgV,
		"driver":    driver,
		"drivers":   service.FindAllDriver(),
		"companies": service.CompanyNames(),
		"user":      service.FindOneUser(driver.UserId),
	})
	return
}
Ejemplo n.º 4
0
func getDriverHome(w http.ResponseWriter, r *http.Request, c *web.Context) {
	if !c.CheckAuth(w, r, "/"+c.GetPathVar("slug"), "driver") {
		return
	}
	if c.GetFromSession("slug") != c.GetPathVar("slug") {
		http.Redirect(w, r, "/"+c.GetFromSession("slug").(string)+"/driver", 303)
	}
	msgK, msgV := c.GetFlash()
	ts.Render(w, "driver-home.tmpl", tmpl.Model{
		msgK:        msgV,
		"driver":    service.FindOneDriver(c.GetFromSession("id").(string)),
		"slug":      c.GetPathVar("slug"),
		"documents": service.FindAllIncompleteDocumentByDriver(c.GetFromSession("id").(string)),
	})
	return
}
Ejemplo n.º 5
0
// GET driver get document
func getDocument(w http.ResponseWriter, r *http.Request, c *web.Context) {
	if !c.CheckAuth(w, r, "/"+c.GetPathVar("slug"), "driver") {
		return
	}
	if c.GetFromSession("slug") != c.GetPathVar("slug") {
		http.Redirect(w, r, "/"+c.GetFromSession("slug").(string)+"/document/"+c.GetPathVar("id"), 303)
	}
	document := service.FindOneDocument(c.GetPathVar("id"))
	driver := service.FindOneDriver(c.GetFromSession("id").(string))
	if document.DriverId != driver.Id {
		http.Redirect(w, r, "/"+c.GetFromSession("slug").(string)+"/driver/", 303)
		return
	}
	ts.Render(w, document.Name+".tmpl", tmpl.Model{
		"driver":   driver,
		"company":  service.FindOneCompany(c.GetFromSession("companyId").(string)),
		"document": document,
	})

}
Ejemplo n.º 6
0
func AdminDriverDocumentAdd(w http.ResponseWriter, r *http.Request, c *web.Context) {
	if !c.CheckAuth(w, r, "/login", "admin", "employee", "developer") {
		return
	}
	driver := service.FindOneDriver(c.GetPathVar("driverId"))
	docIds := util.SliceString(r.FormValue("docIds"), ',')
	for _, id := range docIds {
		document := service.Document{
			Id:         util.UUID4(),
			Name:       "dqf-" + id,
			DocumentId: id,
			Complete:   false,
			CompanyId:  driver.CompanyId,
			DriverId:   driver.Id,
		}
		service.SaveDocument(document)
	}
	c.SetFlash("alertSuccess", "Successfully added documents")
	http.Redirect(w, r, "/admin/driver/"+c.GetPathVar("driverId")+"/document", 303)

}
Ejemplo n.º 7
0
// POST admin save driver
func AdminDriverSave(w http.ResponseWriter, r *http.Request, c *web.Context) {
	if !c.CheckAuth(w, r, "/login", "admin", "employee", "developer") {
		return
	}
	if !service.CanUpdateUser(r.FormValue("userId"), r.FormValue("email")) {
		c.SetFlash("alertError", "Email already registered")
		http.Redirect(w, r, "/admin/driver/"+c.GetPathVar("id"), 303)
		return
	}
	r.ParseForm()
	driver := service.FindOneDriver(r.FormValue("id"))
	util.FormToStruct(&driver, r.Form, "")
	user := service.FindOneUser(driver.UserId)
	util.FormToStruct(&user, r.Form, "")
	user.Id = driver.UserId
	service.SaveDriver(driver)
	service.SaveUser(user)
	c.SetFlash("alertSuccess", "Successfully saved driver")
	http.Redirect(w, r, "/admin/driver", 303)
	return
}