OSDN Git Service

fix: views
[pettanr/pettanr.git] / app / assets / javascripts / views / original_pictures / show.js.coffee
1 class Pettanr.Views.OriginalPicture.Show extends Pettanr.View.Show\r
2   \r
3   initialize: (options) ->\r
4     @header = new Pettanr.View.Show.Header(@item, this, @default_header_options())\r
5     @authored_by = @item.authored_by()\r
6     @listenTo(@header, 'click:pick', @click_pick)\r
7     @listenTo(@authored_by, 'click', @click_authored_by)\r
8     @body = new Pettanr.Views.OriginalPicture.Show.Body(@item, {})\r
9     @history = new Pettanr.Views.OriginalPicture.Show.History(@item, {})\r
10     @listenTo(@history, 'http_get', @http_get)\r
11   \r
12   render: () ->\r
13     this.$el.html('')\r
14     this.$el.append(@header.render().el)\r
15     this.$el.append(@authored_by.render().el)\r
16     this.$el.append(@body.render().el)\r
17     this.$el.append(@history.render().el)\r
18     this\r
19   \r
20   http_get: (url) ->\r
21     @trigger('http_get', url)\r
22   \r
23   is_pickable: () ->\r
24     false\r
25   \r
26 class Pettanr.Views.OriginalPicture.Show.Body extends Pettanr.View\r
27   className: 'op-body'\r
28   \r
29   constructor: (@item, options) ->\r
30     super(options)\r
31   \r
32   initialize: (options) ->\r
33     @img = @item.real_picture()\r
34     @owner = new Pettanr.View.Show.Footer(@item, this, {\r
35       actions: {\r
36         select: {\r
37           url: @item.license_url(),\r
38           dic_name: 'original_pictures.show.select', \r
39           click: () =>\r
40             @create_dialog()\r
41             @trigger('click:license', @dialog)\r
42         }, \r
43         replace: {\r
44           url: @item.edit_url(),\r
45           dic_name: 'original_pictures.show.replace', \r
46           click: () =>\r
47             @trigger('http_get', @item.edit_url())\r
48         }, \r
49         destroy: {\r
50           url: @item.destroy_url(),\r
51           click: () =>\r
52             redirect = (url) =>\r
53               @trigger('http_get', url)\r
54             Pettanr.Proxy.destroy(@item, {redirect: redirect})\r
55         }, \r
56       }, \r
57     })\r
58     @summary = @item.summary(this, {})\r
59     @listenTo(@summary, 'http_get', @http_get)\r
60   \r
61   render: () ->\r
62     this.$el.html('')\r
63     this.$el.append(@img.render().el)\r
64     this.$el.append(@summary.render().el)\r
65     @append_rb()\r
66     this.$el.append(@owner.render().el)\r
67     this\r
68   \r
69   create_dialog: () ->\r
70     @dialog = new Editor.PicturePublisher.Dialog({\r
71       parent: this\r
72     })\r
73     this.$el.append(@dialog.render().el)\r
74     _this = this\r
75     @dialog.$el.dialog({\r
76       autoOpen: false,\r
77       width: 500, \r
78       height: 500,\r
79       close: (ui, event) ->\r
80         _this.close_dialog()\r
81     })\r
82     params = {\r
83       controller: 'original_picture_license_groups', action: 'new', id: @item.get('id'), \r
84     }\r
85     @listenTo(@dialog, 'success', @success)\r
86     @dialog.start(params, null)\r
87     @dialog\r
88   \r
89   success: (resource_picture) ->\r
90     #Pettanr.cache.fix(@item)\r
91     @trigger('success', @params, @dialog)\r
92     @trigger('http_get', resource_picture.show_url())\r
93     Pettanr.cache.refresh(@item)\r
94   \r
95   close_dialog: () ->\r
96     #Pettanr.cache.release(@item)\r
97     @trigger('click:close', @dialog)\r
98   \r
99 class Pettanr.Views.OriginalPicture.Show.History extends Pettanr.View\r
100   className: 'op-history'\r
101   \r
102   constructor: (@item, options) ->\r
103     super(options)\r
104   \r
105   initialize: (options) ->\r
106     super(options)\r
107     controller = Manifest.manifest().controllers['original_pictures']\r
108     action = controller.actions['history']\r
109     @list = action.find(id: @item.get('id'))\r
110   \r
111   render: () ->\r
112     this.$el.html('')\r
113     h = new Tag.H2({\r
114       content: I18n.t('original_pictures.show.history')\r
115     })\r
116     this.$el.append(h.render().el)\r
117     @list.open(this, {\r
118       success: (pictures) => \r
119         _.each pictures, (picture) =>\r
120           history = new Pettanr.Views.Picture.History(picture)\r
121           @listenTo(history, 'http_get', @http_get)\r
122           this.$el.append(history.render().el)\r
123     })\r
124     this\r
125   \r
126   http_get: (url) ->\r
127     @trigger('http_get', url)\r
128   \r