Exemplo n.º 1
0
// view for update object
func (this *PageAdminRouter) Update() {
	form := page.PageAdminForm{}
	if this.ValidFormSets(&form) == false {
		return
	}

	// get changed field names
	changes := utils.FormChanges(&this.object, &form)

	url := fmt.Sprintf("/admin/page/%d", this.object.Id)

	// update changed fields only
	if len(changes) > 0 {
		form.SetToPage(&this.object)
		if err := this.object.Update(changes...); err == nil {
			this.FlashRedirect(url, 302, "UpdateSuccess")
			return
		} else {
			beego.Error(err)
			this.Data["Error"] = err
		}
	} else {
		this.Redirect(url, 302)
	}
}
Exemplo n.º 2
0
// view for new object save
func (this *PageAdminRouter) Save() {
	form := page.PageAdminForm{Create: true}
	if !this.ValidFormSets(&form) {
		return
	}

	var a models.Page
	form.SetToPage(&a)
	if err := a.Insert(); err == nil {
		this.FlashRedirect(fmt.Sprintf("/admin/page/%d", a.Id), 302, "CreateSuccess")
		return
	} else {
		beego.Error(err)
		this.Data["Error"] = err
	}
}
Exemplo n.º 3
0
// view for edit object
func (this *PageAdminRouter) Edit() {
	form := page.PageAdminForm{}
	form.SetFromPage(&this.object)
	this.SetFormSets(&form)
}