OSDN Git Service

fix summary
[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: () ->\r
53     @tmb_opt_img_tag()\r
54   \r
55   is_enable: () ->\r
56     if @head().resource_picture()\r
57       true\r
58     else\r
59       false\r
60   \r
61   @head: (opid) ->\r
62     #Picture.find( conditions => ['original_picture_id = ?', opid], :order => 'pictures.revision desc')\r
63   \r
64   head: () ->\r
65     Picture.head(@get('original_picture_id'))\r
66   \r
67   is_head: () ->\r
68     #this == @head()\r
69   \r
70   subdirs: () ->\r
71     if @license_extend().reverse < 0\r
72       ['']\r
73     else\r
74       ['', 'v', 'h', 'vh']\r
75   \r
76   is_showable: (operators = null) ->\r
77     return false if not @original_picture()\r
78     return true if @is_own(operators)\r
79     #@is_enable() and @is_head()\r
80   \r
81   credit_icon_view: () ->\r
82     new Pettanr.Views.Picture.CreditIcon({item: this})\r
83   \r
84   credit_view: (with_icon = true) ->\r
85     new Pettanr.Views.Picture.Credit({item: this, with_icon: with_icon})\r
86   \r
87   fetch: (options) ->\r
88     if @id\r
89       @credit_icon = @credit_icon_view()\r
90       @credit = null\r
91       f = (data, status) =>\r
92         @credit = data\r
93         @trigger('ready')\r
94       $.get(@url + '/credit', null, f, 'html')\r
95     super(options)\r
96   \r
97   initialize: () ->\r
98     if @id\r
99       @url = @url + @id\r
100   \r