OSDN Git Service

fix: view system2
[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     history = @history()\r
37     history.fetch({cache: true}).done =>\r
38       caption = if _.isEmpty(history.models)\r
39         'unpublished'\r
40       else\r
41         head = _.first(history.models)\r
42         Pettanr.to_s(head.get('revision'))\r
43       options.success.call(context, caption)\r
44   \r
45   revision: () ->\r
46     new Pettanr.OriginalPicture.Head({original_picture: this})\r
47   \r
48   history: () ->\r
49     new Pettanr.OriginalPicture.History({original_picture: this})\r
50   \r
51   is_unpublished: () ->\r
52     @get('published_at') == null and @get('stopped_at') == null\r
53   \r
54   is_stopped: () ->\r
55     @get('stopped_at') != null\r
56   \r
57   is_unlicensed: () ->\r
58     dt = @get('published_at') || @get('stopped_at')\r
59     return false if not dt\r
60     @get('uploaded_at') > dt\r
61   \r
62   is_published: () ->\r
63     @get('published_at') != null\r
64   \r
65   state: () ->\r
66     switch true\r
67       when @is_unpublished()\r
68         'unpublished'\r
69       when @is_unlicensed()\r
70         'unlicensed'\r
71       when @is_stopped()\r
72         'stopped'\r
73       when @is_published()\r
74         'published'\r
75   \r
76   initialize: (attr = {}, options = {}) ->\r
77     super(attr, options)\r
78   \r
79 class Pettanr.OriginalPicture.History extends Backbone.Collection\r
80   \r
81   initialize: (options) ->\r
82     @original_picture = options.original_picture\r
83     @model = Pettanr.Picture\r
84     @url = @original_picture.default_url() + '/history'\r
85   \r
86 class Pettanr.OriginalPicture.Head extends Pettanr.View\r
87   tagName: 'span'\r
88   \r
89   initialize: (options) ->\r
90     @original_picture = options.original_picture\r
91     @pictures = new Pettanr.OriginalPicture.History({id: @original_picture.get('id')})\r
92   \r
93   render: () ->\r
94     @pictures.fetch({cache: true}).done =>\r
95       head = @pictures.models[0]\r
96       value = if head\r
97         head.get('revision')\r
98       else\r
99         'unpublished'\r
100       this.$el.html(value)\r
101     this\r
102   \r