OSDN Git Service

fix:
[pettanr/pettanr.git] / app / assets / javascripts / views / original_pictures / publish.js.coffee
1 class Pettanr.Views.OriginalPicture.Publish extends Backbone.View\r
2   \r
3   initialize: (options) ->\r
4     super(options)\r
5     @file_item = options.file_item\r
6     @my_manifest = options.my_manifest\r
7     @item = options.item\r
8   \r
9   render: () ->\r
10     this.$el.html('')\r
11     if @is_own()\r
12       resource_picture_list = @item.has_one('resource_picture')\r
13       resource_picture_list.open(() =>\r
14         @resource_picture = resource_picture_list.items()[0]\r
15         if @resource_picture\r
16           @stop_btn = new Tag.A({\r
17             attr: {href: '/' + @resource_picture.destroy_url()}, \r
18             content: I18n.t('original_pictures.index.stop')\r
19           })\r
20           @listenTo(@stop_btn, 'click', @click_stop)\r
21           this.$el.append(@stop_btn.render().el)\r
22         @edit_icon = new Pettanr.Image.SymbolImg({\r
23           attr: {'src': @edit_img_file_name()}, \r
24           half: true\r
25         })\r
26         @edit_btn = new Tag.A({\r
27           attr: {href: '/' + @item.edit_url()}, \r
28           content: @edit_icon.render().el\r
29         })\r
30         @remove_icon = new Pettanr.Image.SymbolImg({\r
31           attr: {'src': @remove_img_file_name()}, \r
32           half: true\r
33         })\r
34         @remove_btn = new Tag.A({\r
35           attr: {href: '/' + @item.destroy_url()}, \r
36           content: @remove_icon.render().el\r
37         })\r
38         @listenTo(@edit_btn, 'click', @click_edit)\r
39         @listenTo(@remove_btn, 'click', @click_remove)\r
40         this.$el.append(@edit_btn.render().el)\r
41         this.$el.append(@remove_btn.render().el)\r
42       )\r
43     this\r
44   \r
45   is_own: () ->\r
46     if @item.is_own()\r
47       true\r
48     else\r
49       false\r
50    \r
51   filer: () ->\r
52     @file_item.filer()\r
53   \r
54   manifest: () ->\r
55     @filer().manifest\r
56   \r
57   item_name: () ->\r
58     @filer().item_name\r
59   \r
60   image_dir: () ->\r
61     @filer().image_dir()\r
62   \r
63   edit_img_file_name: () ->\r
64     @image_dir() + 'edit.png'\r
65   \r
66   remove_img_file_name: () ->\r
67     @image_dir() + 'remove.png'\r
68   \r
69   click_stop: () ->\r
70     return if !confirm('remove?')\r
71     proxy = new Pettanr.Proxy({})\r
72     @listenTo(proxy, 'success', @remove_success)\r
73     @listenTo(proxy, 'fail', @remove_fail)\r
74     @listenTo(proxy, 'deny', @remove_deny)\r
75     proxy.http_post(@resource_picture.destroy_url())\r
76   \r
77   remove_success: () ->\r
78     @trigger('update')\r
79   \r
80   remove_fail: () ->\r
81     # no update\r
82   \r
83   remove_deny: () ->\r
84   \r
85   click_edit: () ->\r
86     @trigger('http_get', @item.edit_url())\r
87   \r
88   click_remove: () ->\r
89     @trigger('remove')\r
90   \r