OSDN Git Service

93ee926efcf7fc5b4e060999c598471209cdffc7
[pettanr/pettanr.git] / app / assets / javascripts / models / ground_color.js.coffee
1 class Pettanr.GroundColor extends Peta.Element\r
2   url: '/ground_colors/'\r
3   \r
4   @singular: () ->\r
5     'GroundColor'\r
6   \r
7   @plural: () ->\r
8     'GroundColors'\r
9   \r
10   defaults: {\r
11     id: null,\r
12     code: 0,\r
13   } \r
14   \r
15   @has_picture: () ->\r
16     false\r
17   \r
18   div_offset: () ->\r
19     if @get('xy')\r
20       @get('xy')\r
21     else\r
22       0\r
23   \r
24   div_size: () ->\r
25     if @get('wh')\r
26       @get('wh')\r
27     else\r
28       100 - @div_offset()\r
29   \r
30   div_x: () ->\r
31     if @get('orientation') == 0\r
32       0\r
33     else\r
34       @div_offset()\r
35   \r
36   div_y: () ->\r
37     if @get('orientation') == 0\r
38       @div_offset()\r
39     else\r
40       0\r
41   \r
42   div_width: () ->\r
43     if @get('orientation') == 0\r
44       100\r
45     else\r
46       @div_size()\r
47   \r
48   div_height: () ->\r
49     if @get('orientation') == 0\r
50       @div_size()\r
51     else\r
52       100\r
53   \r
54   style: (spot = null, opacity = 20) ->\r
55     r = {\r
56       position: 'absolute', \r
57       'z-index': @get('z'), \r
58       top: Pettanr.to_s(@div_y()) + '%', \r
59       left: Pettanr.to_s(@div_x()) + '%', \r
60       width: Pettanr.to_s(@div_width()) + '%', \r
61       height: Pettanr.to_s(@div_height()) + '%', \r
62       'background-color': '#' + ('000000' + Pettanr.to_s(@get('code'))).slice(-6)\r
63     }\r
64     @merge_opacity(r, opacity) if spot and spot != this\r
65     r\r
66   \r
67   initialize: () ->\r
68     if @id\r
69       @url = @url + @id\r
70   \r
71 class Pettanr.GroundColor.Collection extends Backbone.Collection\r
72   model: Pettanr.GroundColor\r
73   url: '/ground_colors'\r