Example #1
0
//新增图片
func (this *Image) Create() {

	//Get方法
	if this.methodGet {
		id, err := this.getParamsInt64(":id")
		if err != nil {
			this.errorHandle(utils.JsonMessage(false, "invalidRequestParams", this.lang("invalidRequestParams")))
			return
		}
		this.Data["articleid"] = id
		this.Data["token"] = this.token()
		this.TplNames = this.getTplFileName("create")
		this.Render()
		return
	}
	//Post方法
	//签名错误,返回重复提交错误
	if this.invalidToken() {
		this.renderLoseToken()
		return
	}
	//数据模型
	m := new(models.Images)

	models.Extend(m, this.xm)

	m.Articleid, _ = this.GetInt("articleid")
	m.Title = this.GetString("title")
	m.Url = this.GetString("url")

	if this.GetString("status") == "on" {
		m.Status = 1
	} else {
		m.Status = 0
	}

	files, err := this.upload("file")
	if err == nil {
		m.Path = files[0].Path
		m.Ext = files[0].Ext
		m.Srcfilename = files[0].Name
		m.Size = files[0].Size
	}

	//数据合法性检验
	if data, inv := this.invalidModel(m); inv {
		this.renderJson(data)
		return
	}
	//提交DDL
	var data interface{}
	_, err = images.Add(m)

	if err != nil {
		data = utils.JsonMessage(false, "", err.Error())
	} else {
		data = utils.JsonResult(true, "", files)
	}
	this.renderJson(data)
}
Example #2
0
//频道列表
func (this *Article) GetAll() {
	var data interface{}
	//
	page := new(models.Pagination)
	if v, err := this.GetInt("index"); err == nil {
		page.Index = int(v)
	}
	if v, err := this.GetInt("size"); err == nil {
		page.Size = int(v)
	}

	//参数错误
	if page.Index <= 0 {
		page.Index = 1
	}
	if page.Size <= 0 {
		//data = utils.JsonMessage(false, "invalidRequestParams", this.lang("invalidRequestParams"))
		page.Size = 15
	}
	channelid, _ := this.GetInt("channelid")

	//
	us, err := articles.GetAll(channelid, page)
	if err == nil {
		data = utils.JsonResult(true, fmt.Sprintf("%d", page.Count), us)
	} else {
		data = utils.JsonMessage(false, "", "")
	}

	this.renderJson(data)
}
Example #3
0
//图片列表
func (this *Image) GetAll() {
	us, err := images.GetAll()

	var data interface{}
	if err == nil {
		data = utils.JsonResult(true, "", us)
	} else {
		data = utils.JsonMessage(false, "", "")
	}

	this.renderJson(data)
}
Example #4
0
//频道列表
func (this *Channel) GetAll() {
	t, err := this.GetInt("type")
	if err != nil {
		t = -1
	}
	us, err := channels.GetAll(int(t))

	var data interface{}
	if err == nil {
		data = utils.JsonResult(true, "", us)
	} else {
		data = utils.JsonMessage(false, "", err.Error())
	}

	this.renderJson(data)
}
Example #5
0
//修改账户信息
func (this *Image) Edit() {

	//Get方法
	if this.methodGet {

		id, err := this.getParamsInt64(":id")
		if err != nil {
			this.errorHandle(utils.JsonMessage(false, "invalidRequestParams", this.lang("invalidRequestParams")))
			return
		}

		c, err := images.Get(id)

		if err != nil {
			this.errorHandle(utils.JsonMessage(false, "", err.Error()))
			return
		}
		this.Data["image"] = c

		this.Data["token"] = this.token()
		this.TplNames = this.getTplFileName("edit")
		this.Render()
		return
	}
	//Post方法
	//签名错误,返回重复提交错误
	if this.invalidToken() {
		this.renderLoseToken()
		return
	}
	//提交DDL
	var data interface{}

	id, err := this.GetInt("id")
	if err != nil || id == 0 {
		this.errorHandle(utils.JsonMessage(false, "invalidRequestParams", this.lang("invalidRequestParams")))
		return
	}

	//获取原始数据模型
	m, err := images.Get(id)
	if err != nil {
		this.errorHandle(utils.JsonMessage(false, "", err.Error()))
		return
	}
	//赋值
	m.Id = id
	m.Articleid, _ = this.GetInt("articleid")
	m.Title = this.GetString("title")
	m.Url = this.GetString("url")
	m.Updated = this.xm.Updated
	m.Updator = this.xm.Updator
	m.Ip = this.xm.Ip
	//
	if this.GetString("status") == "on" {
		m.Status = 1
	} else {
		m.Status = 0
	}

	files, err := this.upload("file")
	if err == nil && len(files) > 0 {
		m.Path = files[0].Path
		m.Ext = files[0].Ext
		m.Srcfilename = files[0].Name
		m.Size = files[0].Size
	}

	//数据合法性检验
	if data, inv := this.invalidModel(m); inv {
		this.renderJson(data)
		return
	}
	//提交
	_, err = images.Update(m)

	if err != nil {
		data = utils.JsonMessage(false, "", err.Error())
	} else {
		data = utils.JsonResult(true, "", files)
	}

	this.renderJson(data)
}