package front

import (
	. "../util"
	qu "qfw/util"
	"time"
)

func (f *Front) LogicManager() {
	defer qu.Catch()
	f.Render("com/logic_list.html")
}

func (f *Front) LogicPre() {
	defer qu.Catch()
	if f.Method() == "POST" {
		data, _ := Mgo.Find("logic", nil, nil, nil, false, -1, -1)
		f.ServeJson(map[string]interface{}{
			"data": data,
		})
	} else {
		f.Render("com/logic_pre.html")
	}
}

func (f *Front) LogicMatch() {
	defer qu.Catch()
	if f.Method() == "POST" {
		data, _ := Mgo.Find("logic", nil, nil, nil, false, -1, -1)
		f.ServeJson(map[string]interface{}{
			"data": data,
		})
	} else {
		f.Render("com/logic_match.html")
	}
}

func (f *Front) LogicClean() {
	defer qu.Catch()
	if f.Method() == "POST" {
		data, _ := Mgo.Find("logic", nil, nil, nil, false, -1, -1)
		f.ServeJson(map[string]interface{}{
			"data": data,
		})
	} else {
		f.Render("com/logic_clean.html")
	}
}

func (f *Front) LogicPreSav() {
	defer qu.Catch()
	_id := f.GetString("_id")
	data := GetPostForm(f.Request)
	b := false
	if _id == "" {
		data["delete"] = false
		data["l_comeintime"] = time.Now().Unix()
		data["i_type"] = 0
		//session := f.GetSession("user").(map[string]interface{})
		//data["s_username"] = session["name"].(string)
		//data["s_userid"] = session["id"].(string)
		//data["i_runstate"] = 0
		b = Mgo.Save("logic", data) != ""
	} else {
		data["l_lasttime"] = time.Now().Unix()
		b = Mgo.Update("logic", `{"_id":"`+_id+`"}`, map[string]interface{}{
			"$set": data,
		}, false, false)
	}
	f.ServeJson(map[string]interface{}{
		"rep": b,
	})
}

