OSDN Git Service

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