OSDN Git Service

add history buttons
[pettanr/pettanr.git] / app / assets / javascripts / views / history.js.coffee
1 class Pettanr.Views.History extends Backbone.View\r
2   tagName: 'div'\r
3   className: 'history'\r
4   \r
5   initialize: (options) ->\r
6     @power = true\r
7     @back = new Pettanr.Views.History.Back({})\r
8     @forward = new Pettanr.Views.History.Forward({})\r
9     @list = new Pettanr.Views.History.List({})\r
10     @root = new Pettanr.Views.History.Root({})\r
11     @listenTo(@back, 'click', @click_back)\r
12     @listenTo(@forward, 'click', @click_forward)\r
13     @listenTo(@list, 'http_get', @http_get)\r
14     @listenTo(@root, 'click', @click_root)\r
15   \r
16   render: () ->\r
17     this.$el.html('')\r
18     return if !@power\r
19     this.$el.append(@back.render().el)\r
20     this.$el.append(@forward.render().el)\r
21     this.$el.append(@list.render().el)\r
22     this.$el.append(@root.render().el)\r
23     this\r
24   \r
25   enable: () ->\r
26     @power = true\r
27     @render()\r
28   \r
29   disable: () ->\r
30     @power = false\r
31     @render()\r
32   \r
33   # push history\r
34   push: (params, options) ->\r
35     if @power\r
36       @list.push(params, options)\r
37   \r
38   click_back: () ->\r
39     @list.back()\r
40   \r
41   click_forward: () ->\r
42     @list.forward()\r
43   \r
44   click_root: () ->\r
45     @trigger('http_get', 'folders/root')\r
46   \r
47   http_get: (url) ->\r
48     @trigger('http_get', url)\r
49   \r
50 class Pettanr.Views.History.Back extends Backbone.View\r
51   tagName: 'div'\r
52   \r
53   initialize: (options) ->\r
54     icon = new Pettanr.Views.Common.BackIcon()\r
55     @button = new Tag.A({\r
56       attr: {href: '#'}, \r
57       content: icon.render().el\r
58     })\r
59     @listenTo(@button, 'click', @click)\r
60   \r
61   render: () ->\r
62     this.$el.html('')\r
63     this.$el.append(@button.render().el)\r
64     this\r
65   \r
66   click: () ->\r
67     @trigger('click')\r
68   \r
69 class Pettanr.Views.History.Forward extends Backbone.View\r
70   tagName: 'div'\r
71   \r
72   initialize: (options) ->\r
73   \r
74   render: () ->\r
75     this.$el.html('')\r
76     icon = new Pettanr.Views.Common.ForwardIcon()\r
77     @button = new Tag.A({\r
78       attr: {href: '#'}, \r
79       content: icon.render().el\r
80     })\r
81     @listenTo(@button, 'click', @click)\r
82     this.$el.append(@button.render().el)\r
83     this\r
84   \r
85   click: () ->\r
86     @trigger('click')\r
87   \r
88 class Pettanr.Views.History.List extends Backbone.View\r
89   tagName: 'div'\r
90   className: 'history-list'\r
91   \r
92   initialize: (options) ->\r
93     @buttons = []\r
94     @cursor = null\r
95   \r
96   render: () ->\r
97     this.$el.html('')\r
98     _.each @buttons, (button) =>\r
99       this.$el.append(button.render().el)\r
100     this\r
101   \r
102   push: (params, options) ->\r
103     @buttons.push(\r
104       new Pettanr.Views.History.List.Log({params: params, options: options})\r
105     )\r
106     @cursor = @buttons.length - 1\r
107     @render()\r
108   \r
109   back: () ->\r
110     return if !cursor\r
111     return if @cursor <= 0\r
112     @buttons[@cursor].release()\r
113     @cursor--\r
114     @buttons[@cursor].catch()\r
115     @trigger('http_get', 'folders/root')\r
116   \r
117   forward: () ->\r
118     return if !@cursor\r
119     return if @cursor >= @buttons.length - 1 - 1\r
120     @buttons[@cursor].release()\r
121     @cursor++\r
122     @buttons[@cursor].catch()\r
123   \r
124 class Pettanr.Views.History.List.Log extends Backbone.View\r
125   tagName: 'div'\r
126   className: 'history-list-log'\r
127   \r
128   initialize: (options) ->\r
129     @params = options.params\r
130     @options = options.options\r
131     # get caption and icon\r
132     @item_name = Manifest.manifest().singularize(@params['controller'])\r
133     @model = Manifest.item_name_to_model(@item_name)\r
134   \r
135   render: () ->\r
136     this.$el.html('')\r
137     icon = new Pettanr.Image.Icon({item: @model, title: @options, half: true})\r
138     @button = new Tag.A({\r
139       attr: {href: '#'}, \r
140       content: icon.render().el\r
141     })\r
142     @listenTo(@button, 'click', @click)\r
143     this.$el.append(@button.render().el)\r
144     this\r
145   \r
146   catch: () ->\r
147     this.$el.css('border-width', '3px')\r
148   \r
149   release: () ->\r
150     this.$el.css('border-width', '0px')\r
151   \r
152   click: () ->\r
153     @trigger('click')\r
154   \r
155 class Pettanr.Views.History.Root extends Backbone.View\r
156   tagName: 'div'\r
157   \r
158   initialize: (options) ->\r
159     icon = new Pettanr.Views.Common.RootIcon()\r
160     @button = new Tag.A({\r
161       attr: {href: '#'}, \r
162       content: icon.render().el\r
163     })\r
164     @listenTo(@button, 'click', @click)\r
165   \r
166   render: () ->\r
167     this.$el.html('')\r
168     this.$el.append(@button.render().el)\r
169     this\r
170   \r
171   click: () ->\r
172     @trigger('click')\r
173   \r