1 class Pettanr.Views.Layout
\r
2 class Pettanr.Views.Layout.Base extends Backbone.View
\r
4 class Pettanr.Views.Layout.Sns extends Pettanr.Views.Layout.Base
\r
5 className: 'layout-sns'
\r
7 initialize: (options) ->
\r
8 @operators = new Pettanr.Operator({})
\r
9 @global_router = new Pettanr.GlobalRouter({operators: @operators})
\r
10 @listenTo(@global_router, 'go', @body_get)
\r
11 @gate = new Pettanr.BeforeUnload()
\r
12 @header = new Pettanr.Views.Layout.Sns.Header({parent: this})
\r
13 @history = new Pettanr.Views.History({parent: this})
\r
14 @listenTo(@history, 'http_get', @body_http_get)
\r
15 @listenTo(@history, 'get', @body_get)
\r
16 @body = new Pettanr.Views.Layout.Sns.Body({parent: this})
\r
17 @footer = new Pettanr.Views.Layout.Sns.Footer({parent: this})
\r
21 this.$el.append(@header.render().el)
\r
22 this.$el.append(@history.render().el)
\r
23 rb = new Tag.RowBreak()
\r
24 this.$el.append(rb.render().el)
\r
25 this.$el.append(@body.render().el)
\r
26 this.$el.append(@footer.render().el)
\r
29 init_operators: (user) ->
\r
30 author = new Pettanr.Author(user.get('author')) if user.get('author')
\r
31 artist = new Pettanr.Artist(user.get('artist')) if user.get('artist')
\r
37 @global_router.operators = @operators
\r
39 reset_operators: () ->
\r
45 @global_router.operators = @operators
\r
48 # check current user signed in?
\r
49 proxy = new Pettanr.Proxy({operators: @operators})
\r
50 @listenTo(proxy, 'redirect', @test_redirect)
\r
51 # @listenTo(proxy, 'success', @test_ok)
\r
52 @listenTo(proxy, 'fail', @test_ng)
\r
53 @listenTo(proxy, 'sign_in', @sign_in)
\r
54 proxy.http_post('users/test')
\r
56 test_ok: (user, response) ->
\r
59 test_ng: (response) ->
\r
61 @head_http_get('users/guest')
\r
62 @body_http_get('user_sessions/new')
\r
64 test_redirect: (url) ->
\r
65 proxy = @getter_proxy()
\r
66 @stopListening(proxy, 'done') # ignore global routing
\r
67 @stopListening(proxy, 'title', @push_history) # ignore push_history
\r
68 proxy.http_get(url, null)
\r
71 @init_operators(user)
\r
72 @head_http_get('users/account')
\r
77 @head_http_get('users/guest')
\r
80 head_http_get: (url) ->
\r
81 proxy = new Pettanr.Proxy({operators: @operators})
\r
82 @listenTo(proxy, 'ready', @head_ready)
\r
83 proxy.http_get(url, null)
\r
85 head_ready: (view) ->
\r
86 @listenTo(view, 'http_get', @body_http_get)
\r
87 @listenTo(view, 'http_post', @body_http_post)
\r
88 @header.refresh(view)
\r
91 proxy = new Pettanr.Proxy({operators: @operators, gate: @gate})
\r
92 @listenTo(proxy, 'ready', @body_ready)
\r
93 @listenTo(proxy, 'title', @body_title)
\r
94 @listenTo(proxy, 'title', @push_history)
\r
95 @listenTo(proxy, 'done', @body_done)
\r
96 @listenTo(proxy, 'lock', @body_lock)
\r
97 @listenTo(proxy, 'unlock', @body_unlock)
\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({operators: @operators})
\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, 'unlock', @body_unlock)
\r
133 body_http_post: (url, form) ->
\r
134 @poster_proxy().http_post(url, form)
\r
136 body_post: (params, form) ->
\r
137 @poster_proxy().post(params, form)
\r
139 body_success: (url) ->
\r
142 body_fail: (url) ->
\r
145 body_redirect: (url) ->
\r
146 @global_router.navigate(url)
\r
147 @getter_proxy().http_get(url)
\r
149 body_lock: (params, form) ->
\r
150 @gate.lock(params, form)
\r
152 body_unlock: (params, form) ->
\r
155 class Pettanr.Views.Layout.Blog extends Pettanr.Views.Layout.Base
\r
156 className: 'layout-blog'
\r
160 @router.navigate('users/sign_in')
\r
161 @header.navigate('users/guest')
\r
162 @body.navigate('top/demo')
\r
164 sign_in_fail: (user, response) ->
\r
165 view = new Pettanr.Views.UserSeeeion.New({
\r
166 operators: @operators
\r
169 @body.navigate('top/demo')
\r
171 header_class: () ->
\r
172 Pettanr.Views.Layout.Blog.Header
\r
175 Pettanr.Views.Layout.Blog.Body
\r
177 footer_class: () ->
\r
178 Pettanr.Views.Layout.Blog.Footer
\r