OSDN Git Service

fix:element remove func failed
[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     @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
20   \r
21   render: () ->\r
22     this.$el.html('')\r
23     this.$el.append(@header.render().el)\r
24     this.$el.append(@history.render().el)\r
25     @append_rb()\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
30       autoOpen: false,\r
31       resizable: false,\r
32       width: 500, \r
33       height: 600,\r
34       modal: true,\r
35       buttons: {\r
36         close: () ->\r
37           $(@).dialog('close')\r
38       }\r
39     })\r
40     this\r
41   \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
46       user: user, \r
47       author: author, \r
48       artist: artist\r
49     })\r
50   \r
51   reset_operators: () ->\r
52     Pettanr.cache.operators.init({\r
53       user: null, \r
54       author: null, \r
55       artist: null\r
56     })\r
57   \r
58   start: () ->\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
66   \r
67   test_ok: (user, response) ->\r
68     @history.enable()\r
69   \r
70   test_ng: (response) ->\r
71     @history.disable()\r
72     # @head_http_get('users/guest')\r
73     @body_http_get('user_sessions/new')\r
74   \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
80   \r
81   sign_in: (user) ->\r
82     @init_operators(user)\r
83     @head_http_get('users/account')\r
84     @history.enable()\r
85   \r
86   sign_out: () ->\r
87     @reset_operators()\r
88     @header.remove()\r
89     #@head_http_get('user_sessions/end')\r
90     @history.disable()\r
91     window.location='/'\r
92   \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
97   \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
102   \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
114     proxy\r
115   \r
116   body_http_get: (url, form) ->\r
117     @getter_proxy().http_get(url, form)\r
118   \r
119   body_get: (params, form) ->\r
120     @getter_proxy().get(params, form)\r
121   \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
126   \r
127   body_fail: (response, options) ->\r
128     @error_dialog.start(response, options)\r
129   \r
130   body_done: (params) ->\r
131     url = Pettanr.params_to_url(params)\r
132     @global_router.navigate(url, {trigger: false})\r
133   \r
134   push_history: (params, str = null) ->\r
135     @history.push(params, str)\r
136   \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
141   \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
151     proxy\r
152   \r
153   body_http_post: (url, form) ->\r
154     @poster_proxy().http_post(url, form)\r
155   \r
156   body_post: (params, form) ->\r
157     @poster_proxy().post(params, form)\r
158   \r
159   body_success: (url) ->\r
160     \r
161   \r
162   body_redirect: (url) ->\r
163     @global_router.navigate(url)\r
164     @getter_proxy().http_get(url)\r
165   \r
166   body_deny: (params, form, safe_url) ->\r
167     @getter_proxy().http_get(safe_url, params, form)\r
168   \r
169   body_lock: (params, form) ->\r
170     @gate.lock(params, form)\r
171   \r
172   body_unlock: (params, form) ->\r
173     @gate.unlock()\r
174   \r
175   cancel: (params, form) ->\r
176   \r
177   open_dialog: () ->\r
178     @trigger('dialog:open', dialog)\r
179   \r
180   close_dialog: () ->\r
181     @trigger('dialog:close', @dialog)\r
182     if @dialog.is_catch()\r
183       # stored panel back to player\r
184       @back()\r
185   \r
186 class Pettanr.View.Layout.Blog extends Pettanr.View.Layout.Base\r
187   className: 'layout-blog'\r
188   \r
189   start: () ->\r
190     # initial page\r
191     @router.navigate('users/sign_in')\r
192     @header.navigate('users/guest')\r
193     @body.navigate('top/demo')\r
194   \r
195   sign_in_fail: (user, response) ->\r
196     view = new Pettanr.Views.UserSeeeion.New({})\r
197     view.render()\r
198     @body.navigate('top/demo')\r
199   \r
200   header_class: () ->\r
201     Pettanr.Views.Layout.Blog.Header\r
202   \r
203   body_class: () ->\r
204     Pettanr.Views.Layout.Blog.Body\r
205   \r
206   footer_class: () ->\r
207     Pettanr.Views.Layout.Blog.Footer\r
208   \r