OSDN Git Service

fix: fetch fail
[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   symbol_option: (context, options) ->\r
30     @retrieve(this, {\r
31       success: (symbol_item) => \r
32         options.success.call(context, symbol_item.symbol_file())\r
33       fail: (response, opt) =>\r
34         options.fail.call(context, response, opt)\r
35     })\r
36   \r
37   filer_caption: (context, options) ->\r
38     controller = Manifest.manifest().controllers['original_pictures']\r
39     action = controller.actions['history']\r
40     list = action.find(id: @get('id'))\r
41     list.open(this, {\r
42       success: (pictures) => \r
43         caption = if _.isEmpty(pictures)\r
44           'unpublished'\r
45         else\r
46           head = _.first(pictures)\r
47           Pettanr.to_s(head.get('revision'))\r
48         options.success.call(context, caption)\r
49       fail: (response, opt) =>\r
50         options.fail.call(context, response, opt)\r
51     })\r
52   \r
53   is_unpublished: () ->\r
54     @get('published_at') == null and @get('stopped_at') == null\r
55   \r
56   is_stopped: () ->\r
57     @get('stopped_at') != null\r
58   \r
59   is_unlicensed: () ->\r
60     dt = @get('published_at') || @get('stopped_at')\r
61     return false if not dt\r
62     @get('uploaded_at') > dt\r
63   \r
64   is_published: () ->\r
65     @get('published_at') != null\r
66   \r
67   state: () ->\r
68     switch true\r
69       when @is_unpublished()\r
70         'unpublished'\r
71       when @is_unlicensed()\r
72         'unlicensed'\r
73       when @is_stopped()\r
74         'stopped'\r
75       when @is_published()\r
76         'published'\r
77   \r
78   initialize: (attr = {}, options = {}) ->\r
79     super(attr, options)\r
80   \r