OSDN Git Service

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