Ejemplo n.º 1
0
func EditPlant(ren render.Render, db *sql.DB, params martini.Params, t *template.TemplateData) {
	var plant_id string = params["id"]

	if plant_id != "new" {
		plant, err := repository.GetPlant(db, plant_id)

		if err != nil || plant == nil {
			t.SessionMessage.AddDanger("Failed to load plant.")

			ren.Redirect("/plant")

			return
		}

		id, _ := strconv.ParseInt(params["id"], 10, 64)

		plant.PopularNames.Names, err = repository.GetPopularNames(db, id, PLANT)

		t.Data = plant

		t.MediaList = getMediaList(db, PLANT, id)

		ren.HTML(200, "blah/plant/edit", t)
	} else {
		ren.HTML(200, "blah/plant/edit", nil)
	}
}
Ejemplo n.º 2
0
func EditCoral(ren render.Render, db *sql.DB, params martini.Params, t *template.TemplateData) {
	var coral_id string = params["id"]

	if coral_id != "new" {
		coral, err := repository.GetCoral(db, coral_id)

		if err != nil || coral == nil {
			t.SessionMessage.AddDanger("Failed to load coral.")

			ren.Redirect("/coral")

			return
		}

		id, _ := strconv.ParseInt(params["id"], 10, 64)

		coral.PopularNames.Names, err = repository.GetPopularNames(db, id, CORAL)

		t.Data = coral

		t.MediaList = getMediaList(db, CORAL, id)

		ren.HTML(200, "blah/coral/edit", t)
	} else {
		ren.HTML(200, "blah/coral/edit", nil)
	}
}
Ejemplo n.º 3
0
func EditInvertebrate(ren render.Render, db *sql.DB, params martini.Params, t *template.TemplateData) {
	var invertebrate_id string = params["id"]

	if invertebrate_id != "new" {
		invertebrate, err := repository.GetInvertebrate(db, invertebrate_id)

		if err != nil || invertebrate == nil {
			t.SessionMessage.AddDanger("Failed to load invertebrate.")

			ren.Redirect("/invertebrate")

			return
		}

		id, _ := strconv.ParseInt(params["id"], 10, 64)

		invertebrate.PopularNames.Names, err = repository.GetPopularNames(db, id, INVERTEBRATE)

		t.Data = invertebrate

		t.MediaList = getMediaList(db, INVERTEBRATE, id)

		ren.HTML(200, "blah/invertebrate/edit", t)
	} else {
		ren.HTML(200, "blah/invertebrate/edit", nil)
	}
}
Ejemplo n.º 4
0
func updatePopularNames(db *sql.DB, fk int64, table_name string, names []string) {
	posted_names := getNamesMap(names)

	current_names_slices, err := repository.GetPopularNames(db, fk, table_name)
	current_names := getNamesMap(current_names_slices)
	if err != nil {
		return
	}

	new_names := getNewNames(current_names, posted_names)
	for _, new_name := range new_names {
		repository.InsertPopularName(db, fk, table_name, new_name)
	}

	deleted_names := getDeletedNames(current_names, posted_names)
	for _, deleted_name := range deleted_names {
		repository.DeletePopularName(db, deleted_name)
	}
}