OSDN Git Service

fix gate
[pettanr/pettanr.git] / app / assets / javascripts / views / layout.js.coffee
index 8de257c..aff7337 100644 (file)
@@ -8,13 +8,20 @@ class Pettanr.Views.Layout.Sns extends Pettanr.Views.Layout.Base
     @operators = new Pettanr.Operator({})\r
     @global_router = new Pettanr.GlobalRouter({operators: @operators})\r
     @listenTo(@global_router, 'go', @body_get)\r
+    @gate = new Pettanr.BeforeUnload()\r
     @header = new Pettanr.Views.Layout.Sns.Header({parent: this})\r
+    @history = new Pettanr.Views.History({parent: this})\r
+    @listenTo(@history, 'http_get', @body_http_get)\r
+    @listenTo(@history, 'get', @body_get)\r
     @body = new Pettanr.Views.Layout.Sns.Body({parent: this})\r
     @footer = new Pettanr.Views.Layout.Sns.Footer({parent: this})\r
   \r
   render: () ->\r
     this.$el.html('')\r
     this.$el.append(@header.render().el)\r
+    this.$el.append(@history.render().el)\r
+    rb = new Tag.RowBreak()\r
+    this.$el.append(rb.render().el)\r
     this.$el.append(@body.render().el)\r
     this.$el.append(@footer.render().el)\r
     this\r
@@ -47,24 +54,28 @@ class Pettanr.Views.Layout.Sns extends Pettanr.Views.Layout.Base
     proxy.http_post('users/test')\r
   \r
   test_ok: (user, response) ->\r
-    \r
+    @history.enable()\r
   \r
   test_ng: (response) ->\r
+    @history.disable()\r
     @head_http_get('users/guest')\r
     @body_http_get('user_sessions/new')\r
   \r
   test_redirect: (url) ->\r
     proxy = @getter_proxy()\r
     @stopListening(proxy, 'done')  # ignore global routing\r
+    @stopListening(proxy, 'title', @push_history)  # ignore push_history\r
     proxy.http_get(url, null)\r
   \r
   sign_in: (user) ->\r
     @init_operators(user)\r
     @head_http_get('users/account')\r
+    @history.enable()\r
   \r
   sign_out: () ->\r
     @reset_operators()\r
     @head_http_get('users/guest')\r
+    @history.disable()\r
   \r
   head_http_get: (url) ->\r
     proxy = new Pettanr.Proxy({operators: @operators})\r
@@ -77,10 +88,13 @@ class Pettanr.Views.Layout.Sns extends Pettanr.Views.Layout.Base
     @header.refresh(view)\r
   \r
   getter_proxy: () ->\r
-    proxy = new Pettanr.Proxy({operators: @operators})\r
+    proxy = new Pettanr.Proxy({operators: @operators, gate: @gate})\r
     @listenTo(proxy, 'ready', @body_ready)\r
     @listenTo(proxy, 'title', @body_title)\r
+    @listenTo(proxy, 'title', @push_history)\r
     @listenTo(proxy, 'done', @body_done)\r
+    @listenTo(proxy, 'lock', @body_lock)\r
+    @listenTo(proxy, 'unlock', @body_unlock)\r
     proxy\r
   \r
   body_http_get: (url, form) ->\r
@@ -98,6 +112,9 @@ class Pettanr.Views.Layout.Sns extends Pettanr.Views.Layout.Base
     url = Pettanr.params_to_url(params)\r
     @global_router.navigate(url, {trigger: false})\r
   \r
+  push_history: (params, str = null) ->\r
+    @history.push(params, str)\r
+  \r
   body_title: (params, str = null) ->\r
     t = str || I18n.t(params['controller'] + '.' + params['action'] + '.title')\r
     site_caption = _.escape(Manifest.manifest().magic_numbers.profile.users.caption)\r
@@ -110,6 +127,7 @@ class Pettanr.Views.Layout.Sns extends Pettanr.Views.Layout.Base
     @listenTo(proxy, 'redirect', @body_redirect)\r
     @listenTo(proxy, 'sign_in', @sign_in)\r
     @listenTo(proxy, 'sign_out', @sign_out)\r
+    @listenTo(proxy, 'unlock', @body_unlock)\r
     proxy\r
   \r
   body_http_post: (url, form) ->\r
@@ -128,6 +146,12 @@ class Pettanr.Views.Layout.Sns extends Pettanr.Views.Layout.Base
     @global_router.navigate(url)\r
     @getter_proxy().http_get(url)\r
   \r
+  body_lock: (params, form) ->\r
+    @gate.lock(params, form)\r
+  \r
+  body_unlock: (params, form) ->\r
+    @gate.unlock()\r
+  \r
 class Pettanr.Views.Layout.Blog extends Pettanr.Views.Layout.Base\r
   className: 'layout-blog'\r
   \r