OSDN Git Service

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