2014-06-28 23:07:34 +08:00
|
|
|
package controllers
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/revel/revel"
|
2015-10-10 17:23:27 +08:00
|
|
|
// "encoding/json"
|
2014-06-28 23:07:34 +08:00
|
|
|
"github.com/leanote/leanote/app/info"
|
2014-09-02 15:45:44 +08:00
|
|
|
"gopkg.in/mgo.v2/bson"
|
2015-10-10 17:23:27 +08:00
|
|
|
// . "github.com/leanote/leanote/app/lea"
|
|
|
|
// "io/ioutil"
|
2014-06-28 23:07:34 +08:00
|
|
|
)
|
|
|
|
|
2014-09-09 19:34:59 +08:00
|
|
|
// Album controller
|
2014-06-28 23:07:34 +08:00
|
|
|
type Album struct {
|
|
|
|
BaseController
|
|
|
|
}
|
|
|
|
|
2015-10-14 18:47:01 +08:00
|
|
|
// 图片管理, iframe
|
|
|
|
func (c Album) Index() revel.Result {
|
2015-11-13 17:58:41 +08:00
|
|
|
c.SetLocale()
|
2015-10-14 18:47:01 +08:00
|
|
|
return c.RenderTemplate("album/index.html")
|
|
|
|
}
|
|
|
|
|
2014-06-28 23:07:34 +08:00
|
|
|
// all albums by userId
|
|
|
|
func (c Album) GetAlbums() revel.Result {
|
|
|
|
re := albumService.GetAlbums(c.GetUserId())
|
2017-04-08 18:55:42 +08:00
|
|
|
return c.RenderJSON(re)
|
2014-06-28 23:07:34 +08:00
|
|
|
}
|
|
|
|
func (c Album) DeleteAlbum(albumId string) revel.Result {
|
|
|
|
re, msg := albumService.DeleteAlbum(c.GetUserId(), albumId)
|
2017-04-08 18:55:42 +08:00
|
|
|
return c.RenderJSON(info.Re{Ok: re, Msg: msg})
|
2014-06-28 23:07:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// add album
|
|
|
|
func (c Album) AddAlbum(name string) revel.Result {
|
|
|
|
album := info.Album{
|
|
|
|
AlbumId: bson.NewObjectId(),
|
2015-10-10 17:23:27 +08:00
|
|
|
Name: name,
|
|
|
|
Seq: -1,
|
|
|
|
UserId: c.GetObjectUserId()}
|
2014-06-28 23:07:34 +08:00
|
|
|
re := albumService.AddAlbum(album)
|
|
|
|
|
2015-10-10 17:23:27 +08:00
|
|
|
if re {
|
2017-04-08 18:55:42 +08:00
|
|
|
return c.RenderJSON(album)
|
2014-06-28 23:07:34 +08:00
|
|
|
} else {
|
2017-04-08 18:55:42 +08:00
|
|
|
return c.RenderJSON(false)
|
2014-06-28 23:07:34 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// update alnum name
|
|
|
|
func (c Album) UpdateAlbum(albumId, name string) revel.Result {
|
2017-04-08 18:55:42 +08:00
|
|
|
return c.RenderJSON(albumService.UpdateAlbum(albumId, c.GetUserId(), name))
|
2015-10-10 17:23:27 +08:00
|
|
|
}
|