OSDN Git Service

fix filer
[pettanr/pettanr.git] / app / assets / javascripts / models / ground_picture.js.coffee
1 class Pettanr.GroundPicture extends Peta.Element\r
2   url: '/ground_pictures/'\r
3   \r
4   @singular: () ->\r
5     'GroundPicture'\r
6   \r
7   @plural: () ->\r
8     'GroundPictures'\r
9   \r
10   defaults: {\r
11     id: null,\r
12     x: 0,\r
13     y: 0,\r
14     repeat: 0\r
15   } \r
16   \r
17   @repeat_texts: () -> \r
18     ['repeat', 'repeat-x', 'repeat-y', 'no-repeat']\r
19   \r
20   picture: () ->\r
21     new Pettanr.Picture({id: @get('picture_id')})\r
22   \r
23   has_picture: () ->\r
24     true\r
25   \r
26   style: (spot = null, opacity = 20) ->\r
27     r = {\r
28       position: 'absolute', \r
29       top: '0px', \r
30       left: '0px',\r
31       'z-index': @get('z'), \r
32       'background-image': 'url(' + @picture().r_url() + ')', \r
33       'background-repeat': @repeat_text(), \r
34       'background-position': Pettanr.to_s(@get('x')) + 'px ' + Pettanr.to_s(@get('y')) + 'px'\r
35     }\r
36     @merge_opacity(r, opacity) if spot and spot != this\r
37     r\r
38   \r
39   tmb_opt_img_tag: (picture) ->\r
40     wh = Pettanr.Imager.thumbnail_size(picture().get('width'), picture().get('height'))\r
41     new Pettanr.AppHelperImg({src: picture.r_url(), size: Math.abs(wh[0]), alt: @get('caption')})\r
42   \r
43   symbol_option: (cb) ->\r
44     i = @picture()\r
45     _this = this\r
46     i.fetch().done ->\r
47       cb(_this.tmb_opt_img_tag(i))\r
48   \r
49   repeat_text: () ->\r
50     Pettanr.GroundPicture.repeat_texts()[@get('repeat')]\r
51   \r
52   initialize: () ->\r
53     if @id\r
54       @url = @url + @id\r
55   \r
56 class Pettanr.GroundPicture.Collection extends Backbone.Collection\r
57   model: Pettanr.GroundPicture\r
58   url: '/ground_pictures'\r