OSDN Git Service

fix: finder
[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   @trace_routes: () ->\r
14     {\r
15       resource_picture: ['resource_picture_picture', 'resource_picture']\r
16     }\r
17   \r
18   is_visible: (operators = Pettanr.cache.operators) ->\r
19     return true\r
20   \r
21   filename: () ->\r
22     @get('id') + '.' + @get('ext')\r
23   \r
24   gifname: () ->\r
25     @get('id') + '.gif'\r
26   \r
27   mime_type: () ->\r
28     'image/' + @get('ext')\r
29   \r
30   r_url: () ->\r
31     '/pictures/' + @filename()\r
32   \r
33   opt_img_tag: () ->\r
34     {src: @r_url(), width: @get('width'), height: @get('height')}\r
35   \r
36   tmb_opt_img_tag: () ->\r
37     new Pettanr.Image.SymbolPicture({\r
38       attr: {\r
39         src: @r_url()\r
40       },\r
41       picture: this\r
42     })\r
43   \r
44   tail_opt_img_tag: (img) ->\r
45     {src: img, width: @get('width'), height: @get('height')}\r
46   \r
47   tail_tmb_opt_img_tag: (img) ->\r
48     wh = Pettanr.Imager.thumbnail_size(@get('width'), @get('height'))\r
49     {src: img, width: wh[0], height: wh[1]}\r
50   \r
51   alt_name: () ->\r
52     lgn = Pettanr.to_s(@license().license_group().get('caption'))\r
53     ln = Pettanr.to_s(@license().get('caption'))\r
54     lgn + '[' + ln + ']'\r
55   \r
56   symbol_option: (context, options) ->\r
57     @retrieve(this, {\r
58       success: (symbol_item) => \r
59         options.success.call(context, symbol_item.to_symbol())\r
60     })\r
61   \r
62   is_enable: () ->\r
63     if @head().resource_picture()\r
64       true\r
65     else\r
66       false\r
67   \r
68   @head: (opid) ->\r
69     #Picture.find( conditions => ['original_picture_id = ?', opid], :order => 'pictures.revision desc')\r
70   \r
71   head: () ->\r
72     Picture.head(@get('original_picture_id'))\r
73   \r
74   is_head: () ->\r
75     #this == @head()\r
76   \r
77   subdirs: () ->\r
78     if @license_extend().reverse < 0\r
79       ['']\r
80     else\r
81       ['', 'v', 'h', 'vh']\r
82   \r
83   is_showable: (operators = Pettanr.cache.operators) ->\r
84     return false if not @original_picture()\r
85     return true if @is_own(operators)\r
86     #@is_enable() and @is_head()\r
87   \r
88   history_view: () ->\r
89     new Pettanr.Views.Picture.History({item: this})\r
90   \r
91   credit_icon_view: () ->\r
92     new Pettanr.Views.Picture.CreditIcon({item: this})\r
93   \r
94   credit_view: (with_icon = true) ->\r
95     new Pettanr.Views.Picture.Credit({item: this, with_icon: with_icon})\r
96   \r
97   fetch: (options) ->\r
98     if @id\r
99       @credit_icon = @credit_icon_view()\r
100       @credit = null\r
101       f = (data, status) =>\r
102         @credit = data\r
103         @trigger('ready')\r
104       $.get(@url + '/credit', null, f, 'html')\r
105     super(options)\r
106   \r
107   initialize: (attr = {}, options = {}) ->\r
108     super(attr, options)\r
109   \r