OSDN Git Service

fix: view system2
[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   img_option: () ->\r
34     title = if @['get']  # is instance?\r
35       @model_name() + ' ID:' + Pettanr.to_s(@get('id'))\r
36     else\r
37       @model_name()\r
38     {\r
39       title: title\r
40       alt: @model_name()\r
41     }\r
42   \r
43   opt_img_tag: () ->\r
44     @picture_file()\r
45   \r
46   tmb_opt_img_tag: () ->\r
47     @symbol_file()\r
48   \r
49   tail_opt_img_tag: (img) ->\r
50     {src: img, width: @get('width'), height: @get('height')}\r
51   \r
52   tail_tmb_opt_img_tag: (img) ->\r
53     wh = Pettanr.Imager.thumbnail_size(@get('width'), @get('height'))\r
54     {src: img, width: wh[0], height: wh[1]}\r
55   \r
56   alt_name: () ->\r
57     lgn = Pettanr.to_s(@license().license_group().get('caption'))\r
58     ln = Pettanr.to_s(@license().get('caption'))\r
59     lgn + '[' + ln + ']'\r
60   \r
61   symbol_option: (context, options) ->\r
62     @retrieve(this, {\r
63       success: (symbol_item) => \r
64         options.success.call(context, symbol_item.to_symbol())\r
65     })\r
66   \r
67   is_enable: () ->\r
68     if @head().resource_picture()\r
69       true\r
70     else\r
71       false\r
72   \r
73   @head: (opid) ->\r
74     #Picture.find( conditions => ['original_picture_id = ?', opid], :order => 'pictures.revision desc')\r
75   \r
76   head: () ->\r
77     Picture.head(@get('original_picture_id'))\r
78   \r
79   is_head: () ->\r
80     #this == @head()\r
81   \r
82   subdirs: () ->\r
83     if @license_extend().reverse < 0\r
84       ['']\r
85     else\r
86       ['', 'v', 'h', 'vh']\r
87   \r
88   is_showable: (operators = Pettanr.cache.operators) ->\r
89     return false if not @original_picture()\r
90     return true if @is_own(operators)\r
91     #@is_enable() and @is_head()\r
92   \r
93   history_view: () ->\r
94     new Pettanr.Views.Picture.History({item: this})\r
95   \r
96   initialize: (attr = {}, options = {}) ->\r
97     super(attr, options)\r
98   \r