Beispiel #1
0
func (p *OrderPrint) Setup() *exit.Exit {
	order, err := orderservice.GetOrderByTrackingNumber(p.TrackNumber)
	if err != nil {
		panic(err.Error())
	}

	p.Order = order
	if p.Customer, err = service.Person.GetPersonById(p.Order.CustomerId); err != nil {
		panic(err)
	} else if p.Customer == nil {
		panic("Customer does not exist!")
	}

	if p.First == false {
		needprice := person_need_price(p.Customer.Id)
		if needprice {
			// Redirect to print no pirce page.
			return exit.Redirect(fmt.Sprintf("/order/printnoprice/%d", p.TrackNumber))
		}
	}

	p.ShowPicture = showPicture()

	p.Sumprice = p.sumprice()
	return nil
}
Beispiel #2
0
func (p *ProductSalesChart) OnCombineNode(combine_day int) *exit.Exit {
	url := services.Link.GeneratePageUrlWithContextAndQueryParameters("product/detail",
		map[string]interface{}{
			"period":     p.Period,
			"combineday": combine_day,
		}, p.ProductId,
	)
	return exit.Redirect(url)
}
Beispiel #3
0
// 忽略 CombineNode 合并节点参数!
func (p *ProductSalesChart) OnPeriod(days int) *exit.Exit {
	url := services.Link.GeneratePageUrlWithContextAndQueryParameters("product/detail",
		map[string]interface{}{
			"period":     days,
			"combineday": 0, // 目的是点击period时间间隔的时候清除合并点策略
		}, p.ProductId,
	)
	return exit.Redirect(url)
}
Beispiel #4
0
func (p *TrendStat) OnCombineNode(combine_day int) *exit.Exit {
	url := services.Link.GeneratePageUrlWithContextAndQueryParameters("stat/trend",
		map[string]interface{}{
			"period":     p.Period,
			"combineday": combine_day,
		}, 0,
	)
	return exit.Redirect(url)
}
Beispiel #5
0
// 忽略 CombineNode 合并节点参数!
func (p *TrendStat) OnPeriod(days int) *exit.Exit {
	url := services.Link.GeneratePageUrlWithContextAndQueryParameters("stat/trend",
		map[string]interface{}{
			"period":     days,
			"combineday": 0, // 0的目的是点击period时间间隔的时候清除合并点。
		}, 0,
	)
	return exit.Redirect(url)
}
Beispiel #6
0
// 模式切换
func (p *ProductList) OnChangeMode() *exit.Exit {
	url := services.Link.GeneratePageUrlWithContextAndQueryParameters("product/list",
		map[string]interface{}{
			"showall":    p.ShowAll,
			"detailmode": !p.DetailMode, // 目的是点击period时间间隔的时候清除合并点策略
		}, p.Capital,
	)
	return exit.Redirect(url)
}
Beispiel #7
0
func (p *AccountLogin) OnSuccessFromLoginForm() *exit.Exit {
	// fmt.Printf("-------------- login form success -----------------\n")
	// fmt.Println("Username ", p.LoginUser)

	_, err := service.User.Login(p.LoginUser.Username, p.LoginUser.Password, p.W, p.R)
	if err != nil {
		// error can't login, How to redirect to the current page and show errors.
		p.FormError = "Error: Login failed!"

		// TODO: immulate flash message. automatically return empty page with parameter.
		url := services.Link.GeneratePageUrlWithContextAndQueryParameters("account/login",
			map[string]interface{}{"errmsg": "Login failed! " + err.Error()},
		)
		return exit.Redirect(url) // return nil // <-- should return nil
	} else {
		// service already set userToken to session and cookie. redirect if needed.

		p.FormMessage = "Login Success!" // nouse! No one can see this.
		return exit.Redirect("/")        // Return to homepage; TODO: return to where I comes from!
	}
}
Beispiel #8
0
func (p *ProductEdit) OnSuccessFromProductForm() *exit.Exit {
	// clear values
	p.Product.ClearValues()

	// transfer stocks value to product.Stocks
	if p.Stocks != nil {

		// p.Product.Stocks = make([]*model.ProductStockItem, len(p.Product.Colors)*len(p.Product.Sizes))
		p.Product.Stocks = model.NewStocks()
		i := 0
		for _, color := range p.Product.Colors {
			for _, size := range p.Product.Sizes {
				p.Product.Stocks.Set(color, size, p.Stocks[i])
				i = i + 1
			}
		}
	}

	// transfer pictures value to pictures.
	if p.Pictures != nil {
		p.Product.Pictures = strings.Join(p.Pictures, ";")
	}

	// write to db
	if p.Id != nil {
		service.Product.UpdateProduct(p.Product)
	} else {
		service.Product.CreateProduct(p.Product)
	}

	if p.Referer == "view" {
		return exit.Redirect(fmt.Sprintf("/product/detail/%v", p.Product.Id))
	}
	// TODO: return to original page.
	return exit.Redirect("/product/list")
}
Beispiel #9
0
func (p *AccountRegister) OnSuccessFromRegisterForm() *exit.Exit {
	fmt.Printf("-------------- register form success -----------------\n")
	fmt.Println("Username ", p.User)

	// TODO: validate user.

	if user, err := userdao.CreateUser(p.User); err != nil {
		panic(err)
	} else {
		p.User = user
	}

	// TODO: log create action.

	return exit.Redirect("/")
}
func (p *AccountChangePassword) OnSuccessFromChangePasswordForm() *exit.Exit {
	fmt.Printf("-------------- login form success -----------------\n")
	fmt.Println("Username ", p.User)

	// verify login
	userToken := service.User.RequireLogin(p.W, p.R)

	// verify login old password
	user, err := userdao.GetUserWithCredential(userToken.Username, p.User.Password) // p.User.Password is old password;
	if err != nil {
		//		panic(err)
		p.FormError = "Error: Login failed!" + err.Error()
		return nil
	} else if user == nil {
		p.FormError = "Error: Login failed!"
		return nil
	}

	// update new password
	user.Password = p.NewPassword // set new password
	if _, err := service.User.UpdateUser(user); err != nil {
		p.FormError = "Error: Login failed!" + err.Error()
		return nil
		// panic(err)
	}
	return exit.Redirect("/")

	// _, err := service.User.Login(p.User.Username, p.User.Password, p.W, p.R)
	// if err != nil {
	// 	// error can't login, How to redirect to the current page and show errors.
	// 	p.FormError = "Error: Login failed!"

	// 	// TODO return to this
	// 	return nil

	// } else {

	// 	// service already set userToken to session and cookie. redirect if needed.

	// 	// TODO:  why this not works.
	// 	p.FormMessage = "Login Success!"

	// 	return exit.Redirect("/")
	// }
}
Beispiel #11
0
func (p *InventoryList) OnSuccessFromStoreSelectorForm() *exit.Exit {
	var stores bytes.Buffer
	if nil != p.FilterStores {
		for idx, v := range p.FilterStores {
			if idx > 0 {
				stores.WriteRune(',')
			}
			stores.WriteString(v)
		}
	}
	params := map[string]interface{}{
		"stores": stores.String(),
	}
	url := services.Link.GeneratePageUrlWithContextAndQueryParameters("inventory",
		params, p.Tab, p.Current, p.PageItems)
	fmt.Println("redirect to : ", url)
	return exit.Redirect(url)
}
Beispiel #12
0
func (p *AccountLogin) OnSuccessFromLoginForm() *exit.Exit {
	fmt.Printf("-------------- login form success -----------------\n")
	fmt.Println("Username ", p.User)

	_, err := service.User.Login(p.User.Username, p.User.Password, p.W, p.R)
	if err != nil {
		// error can't login, How to redirect to the current page and show errors.
		p.FormError = "Error: Login failed!"

		// TODO return to this
		return nil

	} else {

		// service already set userToken to session and cookie. redirect if needed.

		// TODO:  why this not works.
		p.FormMessage = "Login Success!"

		return exit.Redirect("/")
	}
}
func (p *FactorySettleAccount) OnSuccessFromSearchForm() *exit.Exit {
	// time is injected and then return linkpage.
	return exit.Redirect(p.ThisPageLink())
}
Beispiel #14
0
func (p *InventoryIndex) OnClearForm() *exit.Exit {
	p.TimeFrom = time.Date(0, 0, 0, 0, 0, 0, 0, time.Local)
	p.TimeTo = p.TimeFrom
	return exit.Redirect(p.ThisPageLink())
}
Beispiel #15
0
func (p *AccountLogout) Setup() *exit.Exit {
	service.User.Logout(p.W, p.R) // TODO Need check permission to logout?
	return exit.Redirect("/")
}
Beispiel #16
0
func (p *InventoryIndex) OnSuccessFromSearchForm() *exit.Exit {
	// time is injected and then return linkpage.
	return exit.Redirect(p.ThisPageLink())
}
func (p *FactorySettleAccount) OnClearForm() *exit.Exit {
	p.TimeFrom = time.Date(0, 0, 0, 0, 0, 0, 0, time.Local)
	p.TimeTo = p.TimeFrom
	return exit.Redirect(p.ThisPageLink())
}
Beispiel #18
0
func (p *OrderQuery) OnTab(tab string) *exit.Exit {
	// fmt.Println("============================= p.Tab/tab is ,", p.Tab, "/", tab)
	p.Tab = tab
	return exit.Redirect(p.ThisPageLink())
}
Beispiel #19
0
func (p *OrderQuery) OnClearForm() *exit.Exit {
	p.TimeFrom = time.Date(0, 0, 0, 0, 0, 0, 0, time.Local)
	p.TimeTo = time.Now() //  p.TimeFrom
	return exit.Redirect(p.ThisPageLink())
}
Beispiel #20
0
func (p *OrderQuery) OnSuccessFromSearchForm() *exit.Exit {
	// time is injected and then return linkpage.
	return exit.Redirect(p.ThisPageLink())
}