OSDN Git Service

fix filer
[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   parse_query_string: (query_string) ->\r
22     params = {}\r
23     if query_string\r
24       ary = _.map decodeURI(query_string).split(/&/g), (el, i) ->\r
25         aux = el.split('=')\r
26         o = {}\r
27         if aux.length >= 1\r
28           val = undefined\r
29           if aux.length == 2\r
30             val = aux[1]\r
31           o[aux[0]] = val\r
32           o\r
33       _.each ary, (o) -> \r
34         _.extend(params, o)\r
35     params\r
36   \r
37   fire: (params) ->\r
38     c = Pettanr[Pettanr.camelize(params['controller']) + 'Controller']\r
39     controller = new c\r
40     controller.params = params\r
41     controller[params['action']]()\r
42   \r
43   initialize: () ->\r
44     this['c_i_a'] = (controller, id, action, query_string) ->\r
45       params = this.parse_query_string(query_string)\r
46       params['controller'] = controller\r
47       params['format'] = 'html'\r
48       t = id.split('.')\r
49       if t.length > 1\r
50         params['format'] = t[1]\r
51         id = t[0]\r
52       t = action.split('.')\r
53       if t.length > 1\r
54         params['format'] = t[1]\r
55         action = t[0]\r
56       if Pettanr.is_number(action)\r
57         params['action'] = id\r
58         params['id'] = action\r
59       else\r
60         params['action'] = action\r
61         params['id'] = id\r
62       this.fire(params)\r
63     this['c_i'] = (controller, id, query_string) ->\r
64       params = this.parse_query_string(query_string)\r
65       params['controller'] = controller\r
66       params['format'] = 'html'\r
67       t = id.split('.')\r
68       if t.length > 1\r
69         params['format'] = t[1]\r
70         id = t[0]\r
71       if Pettanr.is_number(id)\r
72         params['action'] = 'show'\r
73         params['id'] = id\r
74       else\r
75         params['action'] = 'index'\r
76       this.fire(params)\r
77     this.route('', 'home')\r
78     this.route(':controller/:id/:action?*query_string', 'c_i_a')\r
79     this.route(':controller/:id/:action', 'c_i_a')\r
80     this.route(':controller/:id?*query_string', 'c_i')\r
81     this.route(':controller/:id', 'c_i')\r
82   \r
83   home: () ->\r
84     params = {}\r
85     params['controller'] = 'folders'\r
86     params['action'] = 'root'\r
87     @fire(params)\r
88   \r
89   hoge: () ->\r
90     names = _.map Manifest.manifest().controllers, (controller_manifest, controller_name) ->\r
91       c = Pettanr[Pettanr.camelize(controller_name) + 'Controller']\r
92       controller = new c\r
93       _.map controller_manifest.actions, (action_manifest, action_name) ->\r
94         {\r
95           event_name: controller_name + '_' + action_name, \r
96           controller: controller,\r
97           controller_name: controller_name,\r
98           action_manifest: action_manifest,\r
99           action_name: action_name\r
100         }\r
101     _this = this\r
102     _.each _.flatten(names), (status) ->\r
103       _status = status\r
104       switch status.action_manifest.type\r
105         when 'list'\r
106           e = status.event_name\r
107           e_f = e + '_format'\r
108           _this[e] = (queryString) ->\r
109             params = _this.parse_query_string(query_string)\r
110             console.log(params)\r
111             _status.controller[_status.action_name](params)\r
112           c = _status.controller_name\r
113           a = _status.action_name\r
114           c_a_url = c + '/' + a\r
115           _this.route(c_a_url, e)\r
116           r = r + '?*queryString'\r
117           _this.route(r, _status.event_name)\r
118           if _status.action_name == 'index'\r
119             r = _status.controller_name + '/'\r
120             _this.route(r, _status.event_name)\r
121         when 'show'\r
122           e = status.event_name\r
123           e_f = e + '_format'\r
124           _this[e] = (id, query_string) ->\r
125             params = _this.parse_query_string(query_string)\r
126             t = id.split('.')\r
127             if t.length > 1\r
128               params['format'] = t[1]\r
129               id = t[0]\r
130             console.log(id)\r
131             console.log(params)\r
132             _status.controller[_status.action_name](id, params)\r
133           _this[e_f] = (id, format, query_string) ->\r
134             params = _this.parse_query_string(query_string)\r
135             params['format'] = format\r
136             console.log(id)\r
137             console.log(params)\r
138             _status.controller[_status.action_name](id, params)\r
139           c = _status.controller_name\r
140           a = _status.action_name\r
141           q = '?*query_string'\r
142           i = '\/([0-9]+)'\r
143           c_id_a_url = c + '/:id/' + a\r
144           c_id_a_f_url = c + '/:id/' + a + '.:format'\r
145           c_id_a_q_url = c_id_a_url + q\r
146           c_id_a_q_url = c_id_a_url + '.:format' + q\r
147           _this.route(c_id_a_q_url, e_f)\r
148           _this.route(c_id_a_q_url, e)\r
149           _this.route(c_id_a_f_url, e_f)\r
150           _this.route(c_id_a_url, e)\r
151           if a == 'show'\r
152             c_id_url = c + '/:id'\r
153             c_id_q_url = c_id_url + q\r
154             _this.route(c_id_q_url, e)\r
155             _this.route(c_id_url, e)\r
156 \r