OSDN Git Service

Merge branch 'v06' of git.sourceforge.jp:/gitroot/pettanr/pettanr into v06
[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     wh = Pettanr.Imager.thumbnail_size(@get('width'), @get('height'))\r
34     new Pettanr.AppHelperImg({src: @r_url(), size: wh[0]})\r
35   \r
36   tail_opt_img_tag: (img) ->\r
37     {src: img, width: @get('width'), height: @get('height')}\r
38   \r
39   tail_tmb_opt_img_tag: (img) ->\r
40     wh = Pettanr.Imager.thumbnail_size(@get('width'), @get('height'))\r
41     {src: img, width: wh[0], height: wh[1]}\r
42   \r
43   alt_name: () ->\r
44     lgn = Pettanr.to_s(@license().license_group().get('caption'))\r
45     ln = Pettanr.to_s(@license().get('caption'))\r
46     lgn + '[' + ln + ']'\r
47   \r
48   symbol_option: (cb) ->\r
49     _this = this\r
50     this.fetch().done ->\r
51       cb(_this.tmb_opt_img_tag())\r
52   \r
53   is_enable: () ->\r
54     if @head().resource_picture()\r
55       true\r
56     else\r
57       false\r
58   \r
59   @head: (opid) ->\r
60     #Picture.find( conditions => ['original_picture_id = ?', opid], :order => 'pictures.revision desc')\r
61   \r
62   head: () ->\r
63     Picture.head(@get('original_picture_id'))\r
64   \r
65   is_head: () ->\r
66     #this == @head()\r
67   \r
68   subdirs: () ->\r
69     if @license_extend().reverse < 0\r
70       ['']\r
71     else\r
72       ['', 'v', 'h', 'vh']\r
73   \r
74   is_showable: (operators = null) ->\r
75     return false if not @original_picture()\r
76     return true if @is_own(operators)\r
77     #@is_enable() and @is_head()\r
78   \r
79   initialize: () ->\r
80     if @id\r
81       @url = @url + @id\r
82   \r
83 class Pettanr.Picture.Collection extends Backbone.Collection\r
84   model: Pettanr.Picture\r
85   url: '/pictures'\r