OSDN Git Service

fix: js models
[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   count: () ->\r
10   \r
11   new: () ->\r
12   \r
13   edit: () ->\r
14   \r
15   create: () ->\r
16   \r
17   update: () ->\r
18   \r
19   destroy: () ->\r
20     \r
21   \r
22   initialize: () ->\r
23     names = _.map Manifest.manifest().controllers, (controller_manifest, controller_name) ->\r
24       c = Pettanr[Pettanr.camelize(controller_name) + 'Controller']\r
25       controller = new c\r
26       _.map controller_manifest.actions, (action_manifest, action_name) ->\r
27         {\r
28           event_name: controller_name + '_' + action_name, \r
29           controller: controller,\r
30           controller_name: controller_name,\r
31           action_manifest: action_manifest,\r
32           action_name: action_name\r
33         }\r
34     _this = this\r
35     _.each _.flatten(names), (status) ->\r
36       _status = status\r
37       switch status.action_manifest.type\r
38         when 'list'\r
39           _this[status.event_name] = () ->\r
40             _status.controller[_status.action_name]()\r
41           r = _status.controller_name + '/' + _status.action_name\r
42           _this.route(r, _status.event_name)\r
43           if _status.action_name == 'index'\r
44             r = _status.controller_name + '/'\r
45             _this.route(r, _status.event_name)\r
46         when 'show'\r
47           _this[status.event_name] = (id) ->\r
48             _status.controller[_status.action_name](id)\r
49           r = '^' + _status.controller_name + '\/([0-9]+)\/' + _status.action_name + '$'\r
50           _this.route(r, _status.event_name)\r
51           if _status.action_name == 'show'\r
52             r = '^' + _status.controller_name + '\/([0-9]+)$'\r
53             _this.route(///#{r}///, _status.event_name)\r
54 \r