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   url: '/original_pictures/'\r
3   \r
4   @singular: () ->\r
5     'OriginalPicture'\r
6   \r
7   @plural: () ->\r
8     'OriginalPictures'\r
9   \r
10   defaults: {\r
11     id: null,\r
12     artist_id: null\r
13   } \r
14   \r
15   picture: () ->\r
16     new Pettanr.Picture({id: @get('picture_id')})\r
17   \r
18   is_visible: (operators) ->\r
19     @is_own(operators)\r
20   \r
21   filename: () ->\r
22     @get('id') + '.' + @get('ext')\r
23   \r
24   mime_type: () ->\r
25     'image/' + @get('ext')\r
26   \r
27   r_url: () ->\r
28     '/original_pictures/' + @filename()\r
29   \r
30   opt_img_tag: () ->\r
31     {src: @r_url(), width: @get('width'), height: @get('height')}\r
32   \r
33   tmb_opt_img_tag: () ->\r
34     new Pettanr.Image.SymbolPicture({\r
35       attr: {\r
36         src: @r_url()\r
37       },\r
38       picture: this\r
39     })\r
40   \r
41   symbol_option: () ->\r
42     @fetch({cache: true}).done =>\r
43       @trigger('ready:symbol', @tmb_opt_img_tag())\r
44   \r
45   filer_caption: () ->\r
46     history = @history()\r
47     history.fetch({cache: true}).done =>\r
48       caption = if _.isEmpty(history.models)\r
49         'unpublished'\r
50       else\r
51         head = _.first(history.models)\r
52         Pettanr.to_s(head.get('revision'))\r
53       @trigger('ready:caption', caption)\r
54   \r
55   revision: () ->\r
56     new Pettanr.OriginalPicture.Head({original_picture: this})\r
57   \r
58   history: () ->\r
59     new Pettanr.OriginalPicture.History({original_picture: this})\r
60   \r
61   is_unpublished: () ->\r
62     @get('published_at') == null and @get('stopped_at') == null\r
63   \r
64   is_stopped: () ->\r
65     @get('stopped_at') != null\r
66   \r
67   is_unlicensed: () ->\r
68     dt = @get('published_at') || @get('stopped_at')\r
69     return false if not dt\r
70     @get('uploaded_at') > dt\r
71   \r
72   is_published: () ->\r
73     @get('published_at') != null\r
74   \r
75   state: () ->\r
76     switch true\r
77       when @is_unpublished()\r
78         'unpublished'\r
79       when @is_unlicensed()\r
80         'unlicensed'\r
81       when @is_stopped()\r
82         'stopped'\r
83       when @is_published()\r
84         'published'\r
85   \r
86   initialize: () ->\r
87     if @id\r
88       @url = @url + @id\r
89   \r
90 class Pettanr.OriginalPicture.History extends Backbone.Collection\r
91   url: '/original_pictures/'\r
92   \r
93   initialize: (options) ->\r
94     @original_picture = options.original_picture\r
95     @model = Pettanr.Picture\r
96     @url = @url + @original_picture.get('id') + '/history'\r
97   \r
98 class Pettanr.OriginalPicture.Head extends Backbone.View\r
99   tagName: 'span'\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