OSDN Git Service

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