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
17 @error_dialog = new Editor.Error.Dialog({parent: this})
\r
18 @listenTo(@error_dialog, 'open', @open_dialog)
\r
19 @listenTo(@error_dialog, 'close', @close_dialog)
\r
23 this.$el.append(@header.render().el)
\r
24 this.$el.append(@history.render().el)
\r
26 this.$el.append(@body.render().el)
\r
27 this.$el.append(@footer.render().el)
\r
28 this.$el.append(@error_dialog.render().el)
\r
29 @error_dialog.$el.dialog({
\r
37 $(@).dialog('close')
\r
42 init_operators: (user) ->
\r
43 author = new Pettanr.Author(user.get('author')) if user.get('author')
\r
44 artist = new Pettanr.Artist(user.get('artist')) if user.get('artist')
\r
45 Pettanr.cache.operators.init({
\r
51 reset_operators: () ->
\r
52 Pettanr.cache.operators.init({
\r
59 # check current user signed in?
\r
60 proxy = new Pettanr.Proxy({})
\r
61 @listenTo(proxy, 'redirect', @test_redirect)
\r
62 # @listenTo(proxy, 'success', @test_ok)
\r
63 @listenTo(proxy, 'fail', @test_ng)
\r
64 @listenTo(proxy, 'sign_in', @sign_in)
\r
65 proxy.http_post('users/test')
\r
67 test_ok: (user, response) ->
\r
70 test_ng: (response) ->
\r
72 # @head_http_get('users/guest')
\r
73 @body_http_get('user_sessions/new')
\r
75 test_redirect: (url) ->
\r
76 proxy = @getter_proxy()
\r
77 @stopListening(proxy, 'done') # ignore global routing
\r
78 @stopListening(proxy, 'title', @push_history) # ignore push_history
\r
79 proxy.http_get(url, null)
\r
82 @init_operators(user)
\r
83 @head_http_get('users/account')
\r
89 #@head_http_get('user_sessions/end')
\r
93 head_http_get: (url) ->
\r
94 proxy = new Pettanr.Proxy({})
\r
95 @listenTo(proxy, 'ready', @head_ready)
\r
96 proxy.http_get(url, null)
\r
98 head_ready: (view) ->
\r
99 @listenTo(view, 'http_get', @body_http_get)
\r
100 @listenTo(view, 'http_post', @body_http_post)
\r
101 @header.refresh(view)
\r
103 getter_proxy: () ->
\r
104 proxy = new Pettanr.Proxy({gate: @gate})
\r
105 @listenTo(proxy, 'ready', @body_ready)
\r
106 @listenTo(proxy, 'fail', @body_fail)
\r
107 @listenTo(proxy, 'title', @body_title)
\r
108 @listenTo(proxy, 'title', @push_history)
\r
109 @listenTo(proxy, 'done', @body_done)
\r
110 @listenTo(proxy, 'deny', @body_deny)
\r
111 @listenTo(proxy, 'lock', @body_lock)
\r
112 @listenTo(proxy, 'unlock', @body_unlock)
\r
113 @listenTo(proxy, 'cancel', @cancel)
\r
116 body_http_get: (url, form) ->
\r
117 @getter_proxy().http_get(url, form)
\r
119 body_get: (params, form) ->
\r
120 @getter_proxy().get(params, form)
\r
122 body_ready: (view) ->
\r
123 @listenTo(view, 'http_get', @body_http_get)
\r
124 @listenTo(view, 'http_post', @body_http_post)
\r
125 @body.refresh(view)
\r
127 body_fail: (response, options) ->
\r
128 @error_dialog.start(response, options)
\r
130 body_done: (params) ->
\r
131 url = Pettanr.params_to_url(params)
\r
132 @global_router.navigate(url, {trigger: false})
\r
134 push_history: (params, str = null) ->
\r
135 @history.push(params, str)
\r
137 body_title: (params, str = null) ->
\r
138 t = str || I18n.t(params['controller'] + '.' + params['action'] + '.title')
\r
139 site_caption = _.escape(Manifest.manifest().magic_numbers.profile.users.caption)
\r
140 $(document).attr('title', t + ' - ' + site_caption)
\r
142 poster_proxy: () ->
\r
143 proxy = new Pettanr.Proxy({})
\r
144 @listenTo(proxy, 'success', @body_success)
\r
145 @listenTo(proxy, 'fail', @body_fail)
\r
146 @listenTo(proxy, 'redirect', @body_redirect)
\r
147 @listenTo(proxy, 'sign_in', @sign_in)
\r
148 @listenTo(proxy, 'sign_out', @sign_out)
\r
149 @listenTo(proxy, 'deny', @body_deny)
\r
150 @listenTo(proxy, 'unlock', @body_unlock)
\r
153 body_http_post: (url, form) ->
\r
154 @poster_proxy().http_post(url, form)
\r
156 body_post: (params, form) ->
\r
157 @poster_proxy().post(params, form)
\r
159 body_success: (url) ->
\r
162 body_redirect: (url) ->
\r
163 @global_router.navigate(url)
\r
164 @getter_proxy().http_get(url)
\r
166 body_deny: (params, form, safe_url) ->
\r
167 @getter_proxy().http_get(safe_url, params, form)
\r
169 body_lock: (params, form) ->
\r
170 @gate.lock(params, form)
\r
172 body_unlock: (params, form) ->
\r
175 cancel: (params, form) ->
\r
178 @trigger('dialog:open', dialog)
\r
180 close_dialog: () ->
\r
181 @trigger('dialog:close', @dialog)
\r
182 if @dialog.is_catch()
\r
183 # stored panel back to player
\r
186 class Pettanr.View.Layout.Blog extends Pettanr.View.Layout.Base
\r
187 className: 'layout-blog'
\r
191 @router.navigate('users/sign_in')
\r
192 @header.navigate('users/guest')
\r
193 @body.navigate('top/demo')
\r
195 sign_in_fail: (user, response) ->
\r
196 view = new Pettanr.Views.UserSeeeion.New({})
\r
198 @body.navigate('top/demo')
\r
200 header_class: () ->
\r
201 Pettanr.Views.Layout.Blog.Header
\r
204 Pettanr.Views.Layout.Blog.Body
\r
206 footer_class: () ->
\r
207 Pettanr.Views.Layout.Blog.Footer
\r