OSDN Git Service

fix filer
[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   @has_picture: () ->\r
18     true\r
19   \r
20   flip: () ->\r
21     v = if @get('height') > 0\r
22       ''\r
23     else\r
24       'v'\r
25     h = if @get('width') > 0\r
26       ''\r
27     else\r
28       'h'\r
29     res = v + h\r
30     res = res # format of /1.png?subdir=v\r
31     # res += '/' unless res.empty? # format of /v/1.png\r
32     res\r
33   \r
34   filename: () ->\r
35     @picture().filename() + '?subdir=' + @flip()\r
36   \r
37   r_url: () ->\r
38     '/pictures/' + @filename()\r
39   \r
40   opt_div_style: () ->\r
41     "top:#{@get('y')}px; left:#{@get('x')}px; z-index:#{@get('z')}; position: absolute;"\r
42   \r
43   opt_img_tag: (spot = null, opacity = 20) ->\r
44     o = if spot and spot != this\r
45       "opacity: #{opacity.to_f/100}; filter:alpha(opacity=#{opacity});"\r
46     else\r
47       ''\r
48     @tag_attributes('img', {\r
49       class: "panel-picture", \r
50       vPicture: @get('id'), \r
51       src: @r_url(), \r
52       width: Math.abs(@get('width')), \r
53       height: Math.abs(@get('height')), \r
54       picture_id: @get('picture_id'), \r
55       ext: @picture.ext, \r
56       alt: @get('caption'), \r
57       style: "#{o}"\r
58     })\r
59   \r
60   tmb_opt_img_tag: (picture) ->\r
61     wh = Pettanr.Imager.thumbnail_size(@get('width'), @get('height'))\r
62     new Pettanr.AppHelperImg({src: picture.r_url(), size: Math.abs(wh[0]), alt: @get('caption')})\r
63   \r
64   symbol_option: (cb) ->\r
65     i = @picture()\r
66     _this = this\r
67     i.fetch().done ->\r
68       cb(_this.tmb_opt_img_tag(i))\r
69   \r
70   initialize: () ->\r
71     if @id\r
72       @url = @url + @id\r
73   \r
74 class Pettanr.PanelPicture.Collection extends Backbone.Collection\r
75   model: Pettanr.PanelPicture\r
76   url: '/panel_pictures'\r