OSDN Git Service

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