1 class Pettanr.View.Layout
\r
2 class Pettanr.View.Layout.Base extends Pettanr.View
\r
4 class Pettanr.View.Layout.Sns extends Pettanr.View.Layout.Base
\r
5 className: 'layout-sns'
\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
20 this.$el.append(@header.render().el)
\r
21 this.$el.append(@history.render().el)
\r
23 this.$el.append(@body.render().el)
\r
24 this.$el.append(@footer.render().el)
\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
36 reset_operators: () ->
\r
37 Pettanr.cache.operators.init({
\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
52 test_ok: (user, response) ->
\r
55 test_ng: (response) ->
\r
57 # @head_http_get('users/guest')
\r
58 @body_http_get('user_sessions/new')
\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
67 @init_operators(user)
\r
68 @head_http_get('users/account')
\r
74 #@head_http_get('user_sessions/end')
\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
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
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
100 body_http_get: (url, form) ->
\r
101 @getter_proxy().http_get(url, form)
\r
103 body_get: (params, form) ->
\r
104 @getter_proxy().get(params, form)
\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
111 body_done: (params) ->
\r
112 url = Pettanr.params_to_url(params)
\r
113 @global_router.navigate(url, {trigger: false})
\r
115 push_history: (params, str = null) ->
\r
116 @history.push(params, str)
\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
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
134 body_http_post: (url, form) ->
\r
135 @poster_proxy().http_post(url, form)
\r
137 body_post: (params, form) ->
\r
138 @poster_proxy().post(params, form)
\r
140 body_success: (url) ->
\r
143 body_fail: (url) ->
\r
146 body_redirect: (url) ->
\r
147 @global_router.navigate(url)
\r
148 @getter_proxy().http_get(url)
\r
150 body_deny: (params, form, safe_url) ->
\r
151 @getter_proxy().http_get(safe_url, params, form)
\r
153 body_lock: (params, form) ->
\r
154 @gate.lock(params, form)
\r
156 body_unlock: (params, form) ->
\r
159 cancel: (params, form) ->
\r
161 class Pettanr.View.Layout.Blog extends Pettanr.View.Layout.Base
\r
162 className: 'layout-blog'
\r
166 @router.navigate('users/sign_in')
\r
167 @header.navigate('users/guest')
\r
168 @body.navigate('top/demo')
\r
170 sign_in_fail: (user, response) ->
\r
171 view = new Pettanr.Views.UserSeeeion.New({})
\r
173 @body.navigate('top/demo')
\r
175 header_class: () ->
\r
176 Pettanr.Views.Layout.Blog.Header
\r
179 Pettanr.Views.Layout.Blog.Body
\r
181 footer_class: () ->
\r
182 Pettanr.Views.Layout.Blog.Footer
\r