Example #1
0
func (this *TopicController) EditTopicShow() {
	tid := this.Input().Get("tid")
	this.Data["Username"] = this.GetSession("username")
	this.Data["toplicList"] = true
	if tid == "" {
		this.Layout = "admin/layout.html"
		this.TplNames = "admin/Tpl/T.error.tpl"
	} else {
		this.Layout = "admin/layout.html"
		this.TplNames = "admin/Tpl/T.editTopic.tpl"
		topic, err := models.GetTopic(tid)
		if err != nil {
			beego.Error(err)
			this.Redirect("/admin/home", 302)
			return
		}
		this.Data["Topic"] = topic
		Categories, err := models.GetAllCategories()
		if err != nil {
			beego.Error(err)
		}
		for _, v := range Categories {
			cate, _ := strconv.Atoi(topic.Category)
			if v.Id == int64(cate) {
				v.IsSelected = true
			} else {
				v.IsSelected = false
			}
		}
		this.Data["Categories"] = Categories
		AllLabels, err := models.GetAllLabels()
		Lables := strings.Split(topic.Lables, " ")
		if len(Lables) > 0 {
			for _, v := range AllLabels {
				v.IsSelected = false
				for _, s := range Lables {
					lab, _ := strconv.Atoi(s)
					if v.Id == int64(lab) {
						v.IsSelected = true
						break
					}
				}
			}
		}
		this.Data["Labels"] = AllLabels
		if err != nil {
			beego.Error(err)
		}
	}
}
Example #2
0
func (this *TopicController) Get() {
	topicId := this.Input().Get("topicId")
	if topicId == "" {
		this.TplNames = "error.html"
	} else {
		topic, err := models.GetTopic(topicId)
		if err != nil {
			beego.Error(err)
			this.Redirect("/", 302)
			return
		}
		this.Data["Topic"] = topic
		this.Data["Category"] = models.GetCategory(topic.Category)
		//AllLabels := make([]string, 10)
		Lables := strings.Split(topic.Lables, " ")
		var MyLables []MyLabel

		if len(Lables) > 0 {
			for i, n := 0, len(Lables); i < n; i++ {
				//AllLabels[i] = models.GetLabel(Lables[i])
				LabelOne := MyLabel{
					Name: models.GetLabel(Lables[i]),
					Id:   Lables[i],
				}
				MyLables = append(MyLables, LabelOne)
			}
			//this.Data["LablesId"] = Lables[0:len(Lables)]
		}
		this.Data["Label"] = MyLables
		if err != nil {
			beego.Error(err)
		}
		this.Data["Categories"], _ = models.GetAllCategories()
		this.Data["Labels"], err = models.GetAllLabels()
		this.Data["NewTopics"], err = models.GetAllNewTopics()
		this.Data["VIewsTopics"], err = models.GetAllViewsTopics()
		this.TplNames = "topicView.html"
	}
}