OSDN Git Service

fix: suport yasapp oauth
[pettanr/pettanr.git] / app / assets / javascripts / view / credit.js.coffee
1 class Pettanr.View.Credit extends Pettanr.View\r
2   tagName: 'div'\r
3   className: 'credit'\r
4   \r
5   constructor: (@item, options) ->\r
6     super(options)\r
7   \r
8   initialize: (options = {icon: true}) ->\r
9     @icon_options = options.icon\r
10     @data_options = options.data\r
11   \r
12   render: () ->\r
13     this.$el.html('')\r
14     if @icon_options\r
15       icon = new Pettanr.View.Credit.Icon(@item)\r
16       @listenTo(icon, 'click', @click_icon)\r
17       this.$el.append(icon.render().el)\r
18     data = new Pettanr.View.Credit.Data(@item, @data_options)\r
19     this.$el.append(data.render().el)\r
20     this\r
21   \r
22   click_icon: () ->\r
23     @trigger('click:icon', @item)\r
24   \r
25 class Pettanr.View.Credit.Data extends Pettanr.View\r
26   tagName: 'div'\r
27   className: 'credit-data'\r
28   \r
29   constructor: (@item, options) ->\r
30     super(options)\r
31   \r
32   initialize: (options) ->\r
33     @credit_api_url = @item.url + '/credit'\r
34   \r
35   render: () ->\r
36     super()\r
37     if @item.credit_data\r
38       @append_credit_data()\r
39     else\r
40       f = (data, status) =>\r
41         @item.credit_data = data\r
42         @append_credit_data()\r
43       $.get(@credit_api_url, null, f, 'html')\r
44     this\r
45   \r
46   append_credit_data: () ->\r
47     this.$el.html('')\r
48     this.$el.append(@item.credit_data)\r
49     this.$el.map ->\r
50       $(@).click ->\r
51         confirm('leave?')\r
52     @append_rb()\r
53   \r
54 class Pettanr.View.Credit.Icon extends Pettanr.View\r
55   tagName: 'div'\r
56   className: 'credit-icon'\r
57   \r
58   constructor: (@item, options) ->\r
59     super(options)\r
60   \r
61   render: () ->\r
62     this.$el.html('')\r
63     symbol_button = @item.symbol_button({\r
64       context: this,\r
65       click: () =>\r
66         @trigger('click')\r
67     })\r
68     this.$el.append(symbol_button.render().el)\r
69     this\r
70   \r