OSDN Git Service

57ecedcf9ef6903e1bb8062167a9e49c11e3727e
[pettanr/pettanr.git] / app / assets / javascripts / models / panel_picture.js.coffee
1 class Pettanr.PanelPicture extends Peta.Element\r
2   url: '/panel_pictures/'\r
3   \r
4   @singular: () ->\r
5     'PanelPicture'\r
6   \r
7   @plural: () ->\r
8     'PanelPictures'\r
9   \r
10   defaults: {\r
11     id: null\r
12   } \r
13   \r
14   picture: () ->\r
15     new Pettanr.Picture({id: @get('picture_id')})\r
16   \r
17   panel: (options = {}) ->\r
18     new Pettanr.Panel({id: @get('panel_id')}, options)\r
19   \r
20   @has_picture: () ->\r
21     true\r
22   \r
23   flip: () ->\r
24     v = if @get('height') > 0\r
25       ''\r
26     else\r
27       'v'\r
28     h = if @get('width') > 0\r
29       ''\r
30     else\r
31       'h'\r
32     res = v + h\r
33     res = res # format of /1.png?subdir=v\r
34     # res += '/' unless res.empty? # format of /v/1.png\r
35     res\r
36   \r
37   filename: (picture) ->\r
38     picture.filename() + '?subdir=' + @flip()\r
39   \r
40   r_url: (picture) ->\r
41     '/pictures/' + @filename(picture)\r
42   \r
43   tmb_opt_img_tag: (picture) ->\r
44     new Pettanr.Image.SymbolPicture({\r
45       attr: {\r
46         src: picture.r_url(), \r
47         alt: @escape('caption')\r
48       },\r
49       picture: picture\r
50     })\r
51   \r
52   symbol_option: () ->\r
53     i = @picture()\r
54     i.fetch({cache: true}).done =>\r
55       @symbol_picture = i.tmb_opt_img_tag()\r
56       @trigger('ready:symbol')\r
57   \r
58   element_face: () ->\r
59     new Pettanr.Views.PanelPicture.ElementFace({element: this})\r
60   \r
61   initialize: () ->\r
62     if @id\r
63       @url = @url + @id\r
64   \r