OSDN Git Service

27471271e132099274b7f74393e9b9237790c0db
[pettanr/pettanr.git] / app / assets / javascripts / models / picture.js.coffee
1 class Pettanr.Picture extends Peta.Content\r
2   url: '/pictures/'\r
3   \r
4   @singular: () ->\r
5     'Picture'\r
6   \r
7   @plural: () ->\r
8     'Pictures'\r
9   \r
10   defaults: {\r
11     id: null\r
12   } \r
13   \r
14   is_visible: (operators) ->\r
15     return true\r
16   \r
17   filename: () ->\r
18     @get('id') + '.' + @get('ext')\r
19   \r
20   gifname: () ->\r
21     @get('id') + '.gif'\r
22   \r
23   mime_type: () ->\r
24     'image/' + @get('ext')\r
25   \r
26   r_url: () ->\r
27     '/pictures/' + @filename()\r
28   \r
29   opt_img_tag: () ->\r
30     {src: @r_url(), width: @get('width'), height: @get('height')}\r
31   \r
32   tmb_opt_img_tag: () ->\r
33     new Pettanr.Image.SymbolPicture({\r
34       attr: {\r
35         src: @r_url()\r
36       },\r
37       picture: this\r
38     })\r
39   \r
40   tail_opt_img_tag: (img) ->\r
41     {src: img, width: @get('width'), height: @get('height')}\r
42   \r
43   tail_tmb_opt_img_tag: (img) ->\r
44     wh = Pettanr.Imager.thumbnail_size(@get('width'), @get('height'))\r
45     {src: img, width: wh[0], height: wh[1]}\r
46   \r
47   alt_name: () ->\r
48     lgn = Pettanr.to_s(@license().license_group().get('caption'))\r
49     ln = Pettanr.to_s(@license().get('caption'))\r
50     lgn + '[' + ln + ']'\r
51   \r
52   symbol_option: (cb) ->\r
53     @fetch({cache: true}).done =>\r
54       cb(@tmb_opt_img_tag())\r
55   \r
56   is_enable: () ->\r
57     if @head().resource_picture()\r
58       true\r
59     else\r
60       false\r
61   \r
62   @head: (opid) ->\r
63     #Picture.find( conditions => ['original_picture_id = ?', opid], :order => 'pictures.revision desc')\r
64   \r
65   head: () ->\r
66     Picture.head(@get('original_picture_id'))\r
67   \r
68   is_head: () ->\r
69     #this == @head()\r
70   \r
71   subdirs: () ->\r
72     if @license_extend().reverse < 0\r
73       ['']\r
74     else\r
75       ['', 'v', 'h', 'vh']\r
76   \r
77   is_showable: (operators = null) ->\r
78     return false if not @original_picture()\r
79     return true if @is_own(operators)\r
80     #@is_enable() and @is_head()\r
81   \r
82   credit_icon_view: () ->\r
83     new Pettanr.Views.Picture.CreditIcon({item: this})\r
84   \r
85   credit_view: (with_icon = true) ->\r
86     new Pettanr.Views.Picture.Credit({item: this, with_icon: with_icon})\r
87   \r
88   initialize: () ->\r
89     if @id\r
90       @url = @url + @id\r
91   \r