예제 #1
0
func editSchedule(w http.ResponseWriter, r *http.Request) {
	id, err := strconv.Atoi(r.URL.Query().Get(":scheduleId"))
	if err != nil {
		log.Println(err)
	}

	schedule, err := models.GetScheduleById(int32(id))

	err = templates["editSchedule"].Execute(w, schedule)

	if err != nil {
		log.Panicln(err)
	}
	return
}
예제 #2
0
func updateSchedule(w http.ResponseWriter, r *http.Request) {
	id, err := strconv.Atoi(r.URL.Query().Get(":scheduleId"))
	if err != nil {
		log.Println(err)
	}

	schedule, err := models.GetScheduleById(int32(id))

	err = schedule.SetInterval(
		r.PostFormValue("interval[multiplicator]"),
		r.PostFormValue("interval[denominator]"))

	if err != nil {
		log.Println(err)
		return
	}

	err = schedule.SetLength(
		r.PostFormValue("length[multiplicator]"),
		r.PostFormValue("length[denominator]"))

	if err != nil {
		log.Println(err)
		return
	}

	err = schedule.SetStart(r.PostFormValue("date"))
	if err != nil {
		log.Println(err)
	}

	schedule.SetActive(r.PostFormValue("status"))

	db.Orm().Update(schedule)

	valve, err := schedule.Valve()
	if err != nil {
		http.Redirect(w, r, "/", 302)
		return
	}

	http.Redirect(w, r, "/valves/"+strconv.Itoa(int(valve.Id)), 302)
	return
}