// POST /releases/changelog/{id}
func ChangelogReleases(w http.ResponseWriter, r *http.Request) {
	vars := mux.Vars(r)
	id, _ := strconv.ParseInt(vars["id"], 10, 64)
	release := models.FindRelease(id)
	file := models.FindFile(release.FileId)
	url := fmt.Sprintf("/changelog/%s.txt", file.Incremental)
	http.Redirect(w, r, url, http.StatusFound)
}
// POST /releases/edit/:id
func EditReleases(w http.ResponseWriter, r *http.Request) {
	vars := mux.Vars(r)
	id, _ := strconv.ParseInt(vars["id"], 10, 64)
	release := models.FindRelease(id)
	data := map[string]interface{}{
		"release":  release,
		"files":    models.FilesIndex(),
		"title":    "Edit Release",
		"endpoint": "/admin/releases/update",
	}
	R.HTML(w, http.StatusOK, "releases_form", data)
}
// POST /releases/delete
func DeleteReleases(w http.ResponseWriter, r *http.Request) {
	r.ParseForm()
	id, _ := strconv.ParseInt(r.FormValue("Id"), 10, 64)
	release := models.FindRelease(id)
	file := models.FindFile(release.FileId)

	// Delete from DB
	models.DeleteRelease(release)
	models.UnpublishFile(file)
	go models.RefreshBuilds()

	http.Redirect(w, r, "/admin/releases", http.StatusFound)
}
// POST /releases/update
func UpdateReleases(w http.ResponseWriter, r *http.Request) {
	r.ParseForm()

	// Parse form and append to struct
	id, _ := strconv.ParseInt(r.FormValue("Id"), 10, 64)
	fileId, _ := strconv.ParseInt(r.FormValue("FileId"), 10, 64)
	release := models.FindRelease(id)
	file := models.FindFile(fileId)
	release.FileId = file.Id
	release.FileName = file.Name
	release.Channel = r.FormValue("Channel")
	release.Changelog = r.FormValue("Changelog")

	// Append to db
	models.UpdateRelease(release)

	// Redirect
	http.Redirect(w, r, "/admin/releases", http.StatusFound)
}