OSDN Git Service

Merge branch 'v06' of git.sourceforge.jp:/gitroot/pettanr/pettanr into v06
[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   picture: () ->\r
15     new Pettanr.Cache.Retriever(Pettanr.Picture, @get('picture_id'))\r
16   \r
17   artist: () ->\r
18     new Pettanr.Cache.Retriever(Pettanr.Artist, @get('artist_id'))\r
19   \r
20   is_visible: (operators = Pettanr.cache.operators) ->\r
21     @is_own(operators)\r
22   \r
23   filename: () ->\r
24     @get('id') + '.' + @get('ext')\r
25   \r
26   mime_type: () ->\r
27     'image/' + @get('ext')\r
28   \r
29   r_url: () ->\r
30     '/original_pictures/' + @filename()\r
31   \r
32   license_url: () ->\r
33     '/original_picture_license_groups/new/' + @get('id')\r
34   \r
35   opt_img_tag: () ->\r
36     {src: @r_url(), width: @get('width'), height: @get('height')}\r
37   \r
38   tmb_opt_img_tag: () ->\r
39     new Pettanr.Image.SymbolPicture({\r
40       attr: {\r
41         src: @r_url()\r
42       },\r
43       picture: this\r
44     })\r
45   \r
46   symbol_option: () ->\r
47     retriever = @retriever()\r
48     @listenTo(retriever, 'retrieve', @retrieve_symbol)\r
49     retriever.retrieve()\r
50   \r
51   retrieve_symbol: (item) -> \r
52     @trigger('ready:symbol', item.tmb_opt_img_tag())\r
53   \r
54   filer_caption: () ->\r
55     history = @history()\r
56     history.fetch({cache: true}).done =>\r
57       caption = if _.isEmpty(history.models)\r
58         'unpublished'\r
59       else\r
60         head = _.first(history.models)\r
61         Pettanr.to_s(head.get('revision'))\r
62       @trigger('ready:caption', caption)\r
63   \r
64   revision: () ->\r
65     new Pettanr.OriginalPicture.Head({original_picture: this})\r
66   \r
67   history: () ->\r
68     new Pettanr.OriginalPicture.History({original_picture: this})\r
69   \r
70   is_unpublished: () ->\r
71     @get('published_at') == null and @get('stopped_at') == null\r
72   \r
73   is_stopped: () ->\r
74     @get('stopped_at') != null\r
75   \r
76   is_unlicensed: () ->\r
77     dt = @get('published_at') || @get('stopped_at')\r
78     return false if not dt\r
79     @get('uploaded_at') > dt\r
80   \r
81   is_published: () ->\r
82     @get('published_at') != null\r
83   \r
84   state: () ->\r
85     switch true\r
86       when @is_unpublished()\r
87         'unpublished'\r
88       when @is_unlicensed()\r
89         'unlicensed'\r
90       when @is_stopped()\r
91         'stopped'\r
92       when @is_published()\r
93         'published'\r
94   \r
95   initialize: (attr = {}, options = {}) ->\r
96     super(attr, options)\r
97   \r
98 class Pettanr.OriginalPicture.History extends Backbone.Collection\r
99   \r
100   initialize: (options) ->\r
101     @original_picture = options.original_picture\r
102     @model = Pettanr.Picture\r
103     @url = @original_picture.default_url() + '/history'\r
104   \r
105 class Pettanr.OriginalPicture.Head extends Backbone.View\r
106   tagName: 'span'\r
107   \r
108   initialize: (options) ->\r
109     @original_picture = options.original_picture\r
110     @pictures = new Pettanr.OriginalPicture.History({id: @original_picture.get('id')})\r
111   \r
112   render: () ->\r
113     @pictures.fetch({cache: true}).done =>\r
114       head = @pictures.models[0]\r
115       value = if head\r
116         head.get('revision')\r
117       else\r
118         'unpublished'\r
119       this.$el.html(value)\r
120     this\r
121   \r