OSDN Git Service

fix: fetch fail
[pettanr/pettanr.git] / app / assets / javascripts / views / history.js.coffee
1 class Pettanr.Views.History extends Pettanr.View\r
2   tagName: 'div'\r
3   className: 'history'\r
4   \r
5   initialize: (options) ->\r
6     @power = true\r
7     @root = new Pettanr.Views.History.Root({})\r
8     @list = new Pettanr.Views.History.List({})\r
9     @listenTo(@root, 'click', @click_root)\r
10     @listenTo(@list, 'click:log', @click_log)\r
11   \r
12   render: () ->\r
13     this.$el.html('')\r
14     return if !@power\r
15     this.$el.append(@root.render().el)\r
16     this.$el.append(@list.render().el)\r
17     this\r
18   \r
19   enable: () ->\r
20     @power = true\r
21     @render()\r
22   \r
23   disable: () ->\r
24     @power = false\r
25     @render()\r
26   \r
27   # push history\r
28   # options: str:page title\r
29   push: (params, options) ->\r
30     return if !@power\r
31     @list.push(params, options)\r
32   \r
33   click_root: () ->\r
34     @trigger('http_get', 'folders/root')\r
35   \r
36   click_log: (log) ->\r
37     @trigger('get', log.params, null)\r
38   \r
39 class Pettanr.Views.History.List extends Pettanr.View\r
40   tagName: 'div'\r
41   className: 'history-list'\r
42   \r
43   initialize: (options) ->\r
44     @max_logs = options.max_logs || 10\r
45     @buttons = []\r
46   \r
47   render: () ->\r
48     this.$el.html('')\r
49     _.each @buttons, (button) =>\r
50       this.$el.append(button.render().el)\r
51     this\r
52   \r
53   # options: str:page title\r
54   push: (params, options) ->\r
55     _.last(@buttons).release() if !_.isEmpty(@buttons)\r
56     if @buttons.length > @max_logs\r
57       b = @buttons.shift()\r
58       b.remove()\r
59     button = new Pettanr.Views.History.List.Log({\r
60       params: params, \r
61       selected: true,\r
62       options: options\r
63     })\r
64     @listenTo(button, 'click', @click_log)\r
65     @buttons.push(button)\r
66     this.$el.append(button.render().el)\r
67   \r
68   click_log: (log) ->\r
69     @trigger('click:log', log)\r
70   \r
71 class Pettanr.Views.History.List.Log extends Pettanr.View\r
72   tagName: 'div'\r
73   className: 'history-list-log'\r
74   \r
75   initialize: (options) ->\r
76     @params = options.params\r
77     @selected = options.selected\r
78     @options = options.options\r
79     # get caption and icon\r
80     @item_name = Manifest.manifest().singularize(@params['controller'])\r
81     @controller = Manifest.manifest().controllers[@params['controller']]\r
82     @action = @controller.actions[@params['action']]\r
83     @model = Manifest.manifest().models[@action.item_name].classify()\r
84     icon = new Pettanr.Image.Icon({item: @model, title: @options, half: true})\r
85     @button = new Tag.A({\r
86       attr: {href: '/' + @action.url(@params)}, \r
87       content: icon.render().el\r
88     })\r
89     @listenTo(@button, 'click', @click)\r
90   \r
91   render: () ->\r
92     this.$el.html('')\r
93     this.$el.append(@button.render().el)\r
94     @refresh()\r
95     this\r
96   \r
97   refresh: () ->\r
98     border = if @selected\r
99       '3px'\r
100     else\r
101       '0px'\r
102     this.$el.css('border-width', border)\r
103   \r
104   catch: () ->\r
105     @selected = true\r
106     @refresh()\r
107   \r
108   release: () ->\r
109     @selected = false\r
110     @refresh()\r
111   \r
112   click: () ->\r
113     @trigger('click', this)\r
114   \r
115 class Pettanr.Views.History.Root extends Pettanr.View\r
116   tagName: 'div'\r
117   \r
118   initialize: (options) ->\r
119     icon = new Pettanr.View.Minicon(Pettanr.View.Image.icon_root_file())\r
120     @button = new Pettanr.View.Button('/', icon.render().el, {\r
121       context: this,\r
122       click: () =>\r
123         @trigger('click')\r
124     })\r
125   \r
126   render: () ->\r
127     this.$el.html('')\r
128     this.$el.append(@button.render().el)\r
129     this\r
130   \r