OSDN Git Service

fix: finder
[pettanr/pettanr.git] / app / assets / javascripts / models / original_picture.js.coffee
1 class Pettanr.OriginalPicture extends Peta.Content\r
2   \r
3   @singular: () ->\r
4     'OriginalPicture'\r
5   \r
6   @plural: () ->\r
7     'OriginalPictures'\r
8   \r
9   defaults: {\r
10     id: null,\r
11     artist_id: null\r
12   } \r
13   \r
14   is_visible: (operators = Pettanr.cache.operators) ->\r
15     @is_own(operators)\r
16   \r
17   filename: () ->\r
18     @get('id') + '.' + @get('ext')\r
19   \r
20   mime_type: () ->\r
21     'image/' + @get('ext')\r
22   \r
23   r_url: () ->\r
24     '/original_pictures/' + @filename()\r
25   \r
26   license_url: () ->\r
27     '/original_picture_license_groups/new/' + @get('id')\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   symbol_option: (context, options) ->\r
41     @retrieve(this, {\r
42       success: (symbol_item) => \r
43         options.success.call(context, symbol_item.to_symbol())\r
44     })\r
45   \r
46   filer_caption: (context, options) ->\r
47     history = @history()\r
48     history.fetch({cache: true}).done =>\r
49       caption = if _.isEmpty(history.models)\r
50         'unpublished'\r
51       else\r
52         head = _.first(history.models)\r
53         Pettanr.to_s(head.get('revision'))\r
54       options.success.call(context, caption)\r
55   \r
56   revision: () ->\r
57     new Pettanr.OriginalPicture.Head({original_picture: this})\r
58   \r
59   history: () ->\r
60     new Pettanr.OriginalPicture.History({original_picture: this})\r
61   \r
62   is_unpublished: () ->\r
63     @get('published_at') == null and @get('stopped_at') == null\r
64   \r
65   is_stopped: () ->\r
66     @get('stopped_at') != null\r
67   \r
68   is_unlicensed: () ->\r
69     dt = @get('published_at') || @get('stopped_at')\r
70     return false if not dt\r
71     @get('uploaded_at') > dt\r
72   \r
73   is_published: () ->\r
74     @get('published_at') != null\r
75   \r
76   state: () ->\r
77     switch true\r
78       when @is_unpublished()\r
79         'unpublished'\r
80       when @is_unlicensed()\r
81         'unlicensed'\r
82       when @is_stopped()\r
83         'stopped'\r
84       when @is_published()\r
85         'published'\r
86   \r
87   initialize: (attr = {}, options = {}) ->\r
88     super(attr, options)\r
89   \r
90 class Pettanr.OriginalPicture.History extends Backbone.Collection\r
91   \r
92   initialize: (options) ->\r
93     @original_picture = options.original_picture\r
94     @model = Pettanr.Picture\r
95     @url = @original_picture.default_url() + '/history'\r
96   \r
97 class Pettanr.OriginalPicture.Head extends Pettanr.View\r
98   tagName: 'span'\r
99   \r
100   initialize: (options) ->\r
101     @original_picture = options.original_picture\r
102     @pictures = new Pettanr.OriginalPicture.History({id: @original_picture.get('id')})\r
103   \r
104   render: () ->\r
105     @pictures.fetch({cache: true}).done =>\r
106       head = @pictures.models[0]\r
107       value = if head\r
108         head.get('revision')\r
109       else\r
110         'unpublished'\r
111       this.$el.html(value)\r
112     this\r
113   \r