OSDN Git Service

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