OSDN Git Service

add history buttons
[pettanr/pettanr.git] / app / assets / javascripts / views / layout.js.coffee
index 8de257c..77710fe 100644 (file)
@@ -9,12 +9,17 @@ class Pettanr.Views.Layout.Sns extends Pettanr.Views.Layout.Base
     @global_router = new Pettanr.GlobalRouter({operators: @operators})\r
     @listenTo(@global_router, 'go', @body_get)\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
     @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
@@ -56,15 +61,18 @@ class Pettanr.Views.Layout.Sns extends Pettanr.Views.Layout.Base
   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
@@ -80,6 +88,7 @@ class Pettanr.Views.Layout.Sns extends Pettanr.Views.Layout.Base
     proxy = new Pettanr.Proxy({operators: @operators})\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
     proxy\r
   \r
@@ -98,6 +107,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