OSDN Git Service

40e91e60101de53ac9486943eca2c483efd47c8d
[pettanr/pettanr.git] / app / assets / javascripts / routes.js.coffee
1 class Pettanr.Router extends Backbone.Router\r
2   \r
3   _index: () ->\r
4     list_result = new Pettanr.Scroll.Collection({})\r
5     new Pettanr.FilerRender('scroll', list_result, 'default', window.operators)\r
6   \r
7   show_html_format: (format) -> \r
8   \r
9   folders_show: (id) ->\r
10     console.log(controller_name)\r
11   \r
12   count: () ->\r
13   \r
14   new: () ->\r
15   \r
16   edit: () ->\r
17   \r
18   create: () ->\r
19   \r
20   update: () ->\r
21   \r
22   destroy: () ->\r
23     \r
24   \r
25   initialize: () ->\r
26     names = _.map Manifest.manifest().controllers, (controller_manifest, controller_name) ->\r
27       c = Pettanr[Pettanr.camelize(controller_name) + 'Controller']\r
28       controller = new c\r
29       _.map controller_manifest.actions, (action_manifest, action_name) ->\r
30         {\r
31           event_name: controller_name + '_' + action_name, \r
32           controller: controller,\r
33           controller_name: controller_name,\r
34           action_manifest: action_manifest,\r
35           action_name: action_name\r
36         }\r
37     _this = this\r
38     _.each _.flatten(names), (status) ->\r
39       _status = status\r
40       f = switch status.action_manifest.type\r
41         when 'list'\r
42           _this[status.event_name] = () ->\r
43             _status.controller[_status.action_name]()\r
44           r = _status.controller_name + '/' + _status.action_name\r
45           _this.route(r, _status.event_name)\r
46           if _status.action_name == 'index'\r
47             r = _status.controller_name + '/'\r
48             _this.route(r, _status.event_name)\r
49         when 'show'\r
50           _this[status.event_name] = (id) ->\r
51             _status.controller[_status.action_name](id)\r
52           r = _status.controller_name + '/:id/' + _status.action_name\r
53           _this.route(r, _status.event_name)\r
54           if _status.action_name == 'show'\r
55             r = _status.controller_name + '/:id'\r
56             _this.route(r, _status.event_name)\r
57 \r