OSDN Git Service

add: short cut
[pettanr/pettanr.git] / app / assets / javascripts / views / layout.js.coffee
index 77710fe..0d984b7 100644 (file)
@@ -5,12 +5,13 @@ class Pettanr.Views.Layout.Sns extends Pettanr.Views.Layout.Base
   className: 'layout-sns'\r
   \r
   initialize: (options) ->\r
-    @operators = new Pettanr.Operator({})\r
-    @global_router = new Pettanr.GlobalRouter({operators: @operators})\r
+    @global_router = new Pettanr.GlobalRouter({})\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
@@ -27,24 +28,22 @@ class Pettanr.Views.Layout.Sns extends Pettanr.Views.Layout.Base
   init_operators: (user) ->\r
     author = new Pettanr.Author(user.get('author')) if user.get('author')\r
     artist = new Pettanr.Artist(user.get('artist')) if user.get('artist')\r
-    @operators.init({\r
+    Pettanr.cache.operators.init({\r
       user: user, \r
       author: author, \r
       artist: artist\r
     })\r
-    @global_router.operators = @operators\r
   \r
   reset_operators: () ->\r
-    @operators.init({\r
+    Pettanr.cache.operators.init({\r
       user: null, \r
       author: null, \r
       artist: null\r
     })\r
-    @global_router.operators = @operators\r
   \r
   start: () ->\r
     # check current user signed in?\r
-    proxy = new Pettanr.Proxy({operators: @operators})\r
+    proxy = new Pettanr.Proxy({})\r
     @listenTo(proxy, 'redirect', @test_redirect)\r
     # @listenTo(proxy, 'success', @test_ok)\r
     @listenTo(proxy, 'fail', @test_ng)\r
@@ -52,9 +51,10 @@ 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
@@ -75,7 +75,7 @@ class Pettanr.Views.Layout.Sns extends Pettanr.Views.Layout.Base
     @history.disable()\r
   \r
   head_http_get: (url) ->\r
-    proxy = new Pettanr.Proxy({operators: @operators})\r
+    proxy = new Pettanr.Proxy({})\r
     @listenTo(proxy, 'ready', @head_ready)\r
     proxy.http_get(url, null)\r
   \r
@@ -85,11 +85,15 @@ 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({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, 'deny', @body_deny)\r
+    @listenTo(proxy, 'lock', @body_lock)\r
+    @listenTo(proxy, 'unlock', @body_unlock)\r
+    @listenTo(proxy, 'cancel', @cancel)\r
     proxy\r
   \r
   body_http_get: (url, form) ->\r
@@ -116,12 +120,14 @@ class Pettanr.Views.Layout.Sns extends Pettanr.Views.Layout.Base
     $(document).attr('title', t + ' - ' + site_caption)\r
   \r
   poster_proxy: () ->\r
-    proxy = new Pettanr.Proxy({operators: @operators})\r
+    proxy = new Pettanr.Proxy({})\r
     @listenTo(proxy, 'success', @body_success)\r
     @listenTo(proxy, 'fail', @body_fail)\r
     @listenTo(proxy, 'redirect', @body_redirect)\r
     @listenTo(proxy, 'sign_in', @sign_in)\r
     @listenTo(proxy, 'sign_out', @sign_out)\r
+    @listenTo(proxy, 'deny', @body_deny)\r
+    @listenTo(proxy, 'unlock', @body_unlock)\r
     proxy\r
   \r
   body_http_post: (url, form) ->\r
@@ -140,6 +146,17 @@ class Pettanr.Views.Layout.Sns extends Pettanr.Views.Layout.Base
     @global_router.navigate(url)\r
     @getter_proxy().http_get(url)\r
   \r
+  body_deny: (params, form, safe_url) ->\r
+    @getter_proxy().http_get(safe_url, params, form)\r
+  \r
+  body_lock: (params, form) ->\r
+    @gate.lock(params, form)\r
+  \r
+  body_unlock: (params, form) ->\r
+    @gate.unlock()\r
+  \r
+  cancel: (params, form) ->\r
+  \r
 class Pettanr.Views.Layout.Blog extends Pettanr.Views.Layout.Base\r
   className: 'layout-blog'\r
   \r
@@ -150,9 +167,7 @@ class Pettanr.Views.Layout.Blog extends Pettanr.Views.Layout.Base
     @body.navigate('top/demo')\r
   \r
   sign_in_fail: (user, response) ->\r
-    view = new Pettanr.Views.UserSeeeion.New({\r
-      operators: @operators\r
-    })\r
+    view = new Pettanr.Views.UserSeeeion.New({})\r
     view.render()\r
     @body.navigate('top/demo')\r
   \r