示例#1
0
func AddHandler(w http.ResponseWriter, r *http.Request, params router.Params) *protocol.DropsResponse {
	data := params.ByName("data").(map[string]interface{})
	modelname := data["model"].(string)

	fmt.Printf("%# v", pretty.Formatter(data))

	store.AddModel(modelname, data)
	sessionId := session.GetSessionId(r, params.ByName("session").(string))

	message.NewMessage(sessionId, modelname+" saved")

	dom := session.GetSessionActiveDOM(sessionId)
	message.ProcessMessages(sessionId, dom)

	response := &protocol.DropsResponse{}
	response.Dom = dom
	response.Route = "/" + strings.ToLower(modelname) + "/"
	return response
}
示例#2
0
func SaveHandler(w http.ResponseWriter, r *http.Request, params router.Params) *protocol.DropsResponse {
	data := params.ByName("data").(map[string]interface{})
	modelname := data["model"].(string)
	id, err := strconv.ParseInt(data["id"].(string), 0, 64)
	if err != nil {
		log.Printf("Error parsing id %v", err)
	}
	data["id"] = id
	fmt.Printf("%# v", pretty.Formatter(data))

	store.SaveModel(modelname, data)

	sessionId := session.GetSessionId(r, params.ByName("session").(string))
	message.NewMessage(sessionId, modelname+" saved")

	dom := session.GetSessionActiveDOM(sessionId)
	message.ProcessMessages(sessionId, dom)

	response := &protocol.DropsResponse{}
	response.Dom = dom
	return response
}