OSDN Git Service

fix: suport yasapp oauth
[pettanr/pettanr.git] / app / assets / javascripts / view / layout.js.coffee
1 class Pettanr.View.Layout\r
2 class Pettanr.View.Layout.Base extends Pettanr.View\r
3   \r
4 class Pettanr.View.Layout.Sns extends Pettanr.View.Layout.Base\r
5   className: 'layout-sns'\r
6   \r
7   initialize: (options) ->\r
8     @global_router = new Pettanr.GlobalRouter({})\r
9     @listenTo(@global_router, 'go', @body_get)\r
10     @gate = new Pettanr.BeforeUnload()\r
11     @header = new Pettanr.View.Layout.Sns.Header({parent: this})\r
12     @history = new Pettanr.Views.History({parent: this})\r
13     @listenTo(@history, 'http_get', @body_http_get)\r
14     @listenTo(@history, 'get', @body_get)\r
15     @body = new Pettanr.View.Layout.Sns.Body({parent: this})\r
16     @footer = new Pettanr.View.Layout.Sns.Footer({parent: this})\r
17   \r
18   render: () ->\r
19     this.$el.html('')\r
20     this.$el.append(@header.render().el)\r
21     this.$el.append(@history.render().el)\r
22     @append_rb()\r
23     this.$el.append(@body.render().el)\r
24     this.$el.append(@footer.render().el)\r
25     this\r
26   \r
27   init_operators: (user) ->\r
28     author = new Pettanr.Author(user.get('author')) if user.get('author')\r
29     artist = new Pettanr.Artist(user.get('artist')) if user.get('artist')\r
30     Pettanr.cache.operators.init({\r
31       user: user, \r
32       author: author, \r
33       artist: artist\r
34     })\r
35   \r
36   reset_operators: () ->\r
37     Pettanr.cache.operators.init({\r
38       user: null, \r
39       author: null, \r
40       artist: null\r
41     })\r
42   \r
43   start: () ->\r
44     # check current user signed in?\r
45     proxy = new Pettanr.Proxy({})\r
46     @listenTo(proxy, 'redirect', @test_redirect)\r
47     # @listenTo(proxy, 'success', @test_ok)\r
48     @listenTo(proxy, 'fail', @test_ng)\r
49     @listenTo(proxy, 'sign_in', @sign_in)\r
50     proxy.http_post('users/test')\r
51   \r
52   test_ok: (user, response) ->\r
53     @history.enable()\r
54   \r
55   test_ng: (response) ->\r
56     @history.disable()\r
57     # @head_http_get('users/guest')\r
58     @body_http_get('user_sessions/new')\r
59   \r
60   test_redirect: (url) ->\r
61     proxy = @getter_proxy()\r
62     @stopListening(proxy, 'done')  # ignore global routing\r
63     @stopListening(proxy, 'title', @push_history)  # ignore push_history\r
64     proxy.http_get(url, null)\r
65   \r
66   sign_in: (user) ->\r
67     @init_operators(user)\r
68     @head_http_get('users/account')\r
69     @history.enable()\r
70   \r
71   sign_out: () ->\r
72     @reset_operators()\r
73     @header.remove()\r
74     #@head_http_get('user_sessions/end')\r
75     @history.disable()\r
76     window.location='/'\r
77   \r
78   head_http_get: (url) ->\r
79     proxy = new Pettanr.Proxy({})\r
80     @listenTo(proxy, 'ready', @head_ready)\r
81     proxy.http_get(url, null)\r
82   \r
83   head_ready: (view) ->\r
84     @listenTo(view, 'http_get', @body_http_get)\r
85     @listenTo(view, 'http_post', @body_http_post)\r
86     @header.refresh(view)\r
87   \r
88   getter_proxy: () ->\r
89     proxy = new Pettanr.Proxy({gate: @gate})\r
90     @listenTo(proxy, 'ready', @body_ready)\r
91     @listenTo(proxy, 'title', @body_title)\r
92     @listenTo(proxy, 'title', @push_history)\r
93     @listenTo(proxy, 'done', @body_done)\r
94     @listenTo(proxy, 'deny', @body_deny)\r
95     @listenTo(proxy, 'lock', @body_lock)\r
96     @listenTo(proxy, 'unlock', @body_unlock)\r
97     @listenTo(proxy, 'cancel', @cancel)\r
98     proxy\r
99   \r
100   body_http_get: (url, form) ->\r
101     @getter_proxy().http_get(url, form)\r
102   \r
103   body_get: (params, form) ->\r
104     @getter_proxy().get(params, form)\r
105   \r
106   body_ready: (view) ->\r
107     @listenTo(view, 'http_get', @body_http_get)\r
108     @listenTo(view, 'http_post', @body_http_post)\r
109     @body.refresh(view)\r
110   \r
111   body_done: (params) ->\r
112     url = Pettanr.params_to_url(params)\r
113     @global_router.navigate(url, {trigger: false})\r
114   \r
115   push_history: (params, str = null) ->\r
116     @history.push(params, str)\r
117   \r
118   body_title: (params, str = null) ->\r
119     t = str || I18n.t(params['controller'] + '.' + params['action'] + '.title')\r
120     site_caption = _.escape(Manifest.manifest().magic_numbers.profile.users.caption)\r
121     $(document).attr('title', t + ' - ' + site_caption)\r
122   \r
123   poster_proxy: () ->\r
124     proxy = new Pettanr.Proxy({})\r
125     @listenTo(proxy, 'success', @body_success)\r
126     @listenTo(proxy, 'fail', @body_fail)\r
127     @listenTo(proxy, 'redirect', @body_redirect)\r
128     @listenTo(proxy, 'sign_in', @sign_in)\r
129     @listenTo(proxy, 'sign_out', @sign_out)\r
130     @listenTo(proxy, 'deny', @body_deny)\r
131     @listenTo(proxy, 'unlock', @body_unlock)\r
132     proxy\r
133   \r
134   body_http_post: (url, form) ->\r
135     @poster_proxy().http_post(url, form)\r
136   \r
137   body_post: (params, form) ->\r
138     @poster_proxy().post(params, form)\r
139   \r
140   body_success: (url) ->\r
141     \r
142   \r
143   body_fail: (url) ->\r
144     \r
145   \r
146   body_redirect: (url) ->\r
147     @global_router.navigate(url)\r
148     @getter_proxy().http_get(url)\r
149   \r
150   body_deny: (params, form, safe_url) ->\r
151     @getter_proxy().http_get(safe_url, params, form)\r
152   \r
153   body_lock: (params, form) ->\r
154     @gate.lock(params, form)\r
155   \r
156   body_unlock: (params, form) ->\r
157     @gate.unlock()\r
158   \r
159   cancel: (params, form) ->\r
160   \r
161 class Pettanr.View.Layout.Blog extends Pettanr.View.Layout.Base\r
162   className: 'layout-blog'\r
163   \r
164   start: () ->\r
165     # initial page\r
166     @router.navigate('users/sign_in')\r
167     @header.navigate('users/guest')\r
168     @body.navigate('top/demo')\r
169   \r
170   sign_in_fail: (user, response) ->\r
171     view = new Pettanr.Views.UserSeeeion.New({})\r
172     view.render()\r
173     @body.navigate('top/demo')\r
174   \r
175   header_class: () ->\r
176     Pettanr.Views.Layout.Blog.Header\r
177   \r
178   body_class: () ->\r
179     Pettanr.Views.Layout.Blog.Body\r
180   \r
181   footer_class: () ->\r
182     Pettanr.Views.Layout.Blog.Footer\r
183   \r