OSDN Git Service

fix: any
[pettanr/pettanr.git] / app / assets / javascripts / views / scrolls / play.js.coffee
index 5dfdd63..87dde98 100644 (file)
@@ -16,7 +16,7 @@ class Pettanr.Views.Scroll.PlayModule.FooterSwitch extends Pettanr.View
   render: () ->\r
     this.$el.html('')\r
     attr = {\r
-      style: Pettanr.to_style({height: Pettanr.to_s(@panel.get('height')) + 'px'})\r
+      style: Pettanr.to_style({height: Pettanr.to_s(@height()) + 'px'})\r
     }\r
     this.$el.attr(attr)\r
     face =  if @visible\r
@@ -28,6 +28,12 @@ class Pettanr.Views.Scroll.PlayModule.FooterSwitch extends Pettanr.View
     this.$el.append(caption.render().el) if @enabled\r
     this\r
   \r
+  height: () ->\r
+    if @panel\r
+      @panel.get('height')\r
+    else\r
+      20\r
+  \r
   click: () ->\r
     return false if !@enabled\r
     @visible = !@visible\r
@@ -48,6 +54,7 @@ class Pettanr.Views.Scroll.PlayModule.Footer extends Pettanr.View
   className: 'player-item-footer'\r
   \r
   initialize: (options) ->\r
+    @parent = options.parent\r
     @scroll = options.scroll\r
     @scroll_panel = options.scroll_panel\r
     @panel = options.panel\r
@@ -55,56 +62,63 @@ class Pettanr.Views.Scroll.PlayModule.Footer extends Pettanr.View
   render: () ->\r
     this.$el.html('')\r
     @hide()\r
-    @panel.get_parent('author', this, {\r
-      success: (@author) =>\r
-        @panel_face_button = @panel.mini_face_button({\r
-          context: this,\r
-          click: () ->\r
-            @trigger('click:panel')\r
-        })\r
-        @author_face_button = @author.mini_face_button({\r
-          context: this,\r
-          click: () ->\r
-            @trigger('click:author', @author)\r
-        })\r
-        l1 = new Tag.H3({\r
-          content: Pettanr.AppHelper.t_m('Panel')\r
-        })\r
-        l2 = new Tag.H3({\r
-          content: Pettanr.AppHelper.t_m('ScrollPanel')\r
-        })\r
-        this.$el.append(l1.render().el)\r
-        this.$el.append(@panel_face_button.render().el)\r
-        this.$el.append(@author_face_button.render().el)\r
-        this.$el.append(\r
-          Pettanr.AppHelper.distance_of_time_in_words_to_now(@panel.get('updated_at'))\r
-        )\r
-        this.$el.append(l2.render().el)\r
-        if @scroll.is_own()\r
-          @new_scroll_panel = new Pettanr.ScrollPanel()\r
-          @insert_button = new Pettanr.View.Button.ItemAction(@new_scroll_panel, 'new', 'scroll_panels.player.before_insert', {\r
+    if @panel\r
+      @panel.get_parent('author', this, {\r
+        success: (@author) =>\r
+          @panel_face_button = @panel.mini_face_button({\r
             context: this,\r
             click: () ->\r
-              @trigger('click:insert')\r
+              @trigger('click:panel')\r
           })\r
-          @move_button = new Pettanr.View.Button.ItemAction(@scroll_panel, 'edit', 'scroll_panels.player.move', {\r
+          @author_face_button = @author.mini_face_button({\r
             context: this,\r
             click: () ->\r
-              @trigger('click:move')\r
+              @trigger('click:author', @author)\r
           })\r
-          @destroy_button = new Pettanr.View.Button.ItemAction(@scroll_panel, 'destroy', 'scroll_panels.player.destroy', {\r
-            context: this,\r
-            click: () ->\r
-              @trigger('click:destroy')\r
+          l1 = new Tag.H3({\r
+            content: Pettanr.AppHelper.t_m('Panel')\r
           })\r
-          this.$el.append(@insert_button.render().el)\r
-          @append_rb()\r
-          this.$el.append(@move_button.render().el)\r
-          @append_rb()\r
-          this.$el.append(@destroy_button.render().el)\r
-    })\r
+          this.$el.append(l1.render().el)\r
+          this.$el.append(@panel_face_button.render().el)\r
+          this.$el.append(@author_face_button.render().el)\r
+          this.$el.append(\r
+            Pettanr.AppHelper.distance_of_time_in_words_to_now(@panel.get('updated_at'))\r
+          )\r
+          @append_scroll_panel()\r
+      })\r
+    else\r
+      @append_scroll_panel()\r
     this\r
   \r
+  append_scroll_panel: () ->\r
+    l2 = new Tag.H3({\r
+      content: Pettanr.AppHelper.t_m('ScrollPanel')\r
+    })\r
+    this.$el.append(l2.render().el)\r
+    if @scroll.is_own()\r
+      @new_scroll_panel = new Pettanr.ScrollPanel()\r
+      @insert_button = new Pettanr.View.Button.ItemAction(@new_scroll_panel, 'new', 'scroll_panels.player.before_insert', {\r
+        context: this,\r
+        click: () ->\r
+          @trigger('click:insert')\r
+      })\r
+      @move_button = new Pettanr.View.Button.ItemAction(@scroll_panel, 'edit', 'scroll_panels.player.move', {\r
+        context: this,\r
+        click: () ->\r
+          @trigger('click:move')\r
+      })\r
+      @destroy_button = new Pettanr.View.Button.ItemAction(@scroll_panel, 'destroy', 'scroll_panels.player.destroy', {\r
+        context: this,\r
+        click: () ->\r
+          @trigger('click:destroy')\r
+      })\r
+      this.$el.append(@insert_button.render().el)\r
+      @append_rb()\r
+      if @is_movable()\r
+        this.$el.append(@move_button.render().el)\r
+        @append_rb()\r
+      this.$el.append(@destroy_button.render().el)\r
+  \r
   hide: () ->\r
     attr = {\r
       style: Pettanr.to_style({display: 'none'})\r
@@ -117,6 +131,9 @@ class Pettanr.Views.Scroll.PlayModule.Footer extends Pettanr.View
     }\r
     this.$el.attr(attr)\r
   \r
+  is_movable: () ->\r
+    @parent.parent.views.length > 1\r
+  \r
 class Pettanr.Views.Scroll.PlayModule.PanelBody extends Pettanr.View\r
   tagName: 'div'\r
   className: 'player-item-panel'\r
@@ -130,22 +147,36 @@ class Pettanr.Views.Scroll.PlayModule.PanelBody extends Pettanr.View
       panel: @panel,\r
       spot: null\r
     })\r
+    @listenTo(body, 'http_get', @http_get)\r
     this.$el.append(body.render().el)\r
     this\r
   \r
+  http_get: (url) ->\r
+    @trigger('http_get', url)\r
+  \r
 class Pettanr.Views.Scroll.PlayModule.Panel extends Pettanr.View\r
   tagName: 'li'\r
   className: 'player-item'\r
   \r
   initialize: (options) ->\r
+    @parent = options.parent\r
     @scroll = options.scroll\r
     @scroll_panel = options.scroll_panel\r
+    @panel = options.panel\r
   \r
   clear: () ->\r
     this.$el.html('')\r
     @scroll_panel.get_parent('panel', this, {\r
       success: (@panel) =>\r
+        @trigger('exist', this)\r
         @render()\r
+      fail: (response, opt) =>\r
+        @panel = null\r
+        @append_insert_point()\r
+        this.$el.append('Not found')\r
+        @append_footer_switch()\r
+        @append_footer()\r
+        @trigger('lost', response, opt)\r
     })\r
     this\r
   \r
@@ -155,44 +186,56 @@ class Pettanr.Views.Scroll.PlayModule.Panel extends Pettanr.View
     @panel.fetch({\r
       success: (model, response, opt) => \r
         @panel.attributes = @panel.decoded_attributes()\r
+        @append_insert_point()\r
         body = new Pettanr.Views.Scroll.PlayModule.PanelBody({\r
           panel: @panel\r
         })\r
-        @footer_switch = new Pettanr.Views.Scroll.PlayModule.FooterSwitch({\r
-          scroll_panel: @scroll_panel,\r
-          panel: @panel\r
-        })\r
-        @listenTo(@footer_switch, 'click', @click_footer_switch)\r
-        move_to = new Tag.A({\r
-          attr: {href: '/' + @scroll_panel.edit_url()},\r
-          content: I18n.t('scroll_panels.player.move_to')\r
-        })\r
-        @insert_point = new Pettanr.Views.Scroll.PlayModule.InsertPoint({\r
-          class_name: 'insert-point', content: move_to.render().el\r
-        })\r
-        @footer = new Pettanr.Views.Scroll.PlayModule.Footer({\r
-          scroll: @scroll,\r
-          scroll_panel: @scroll_panel,\r
-          panel: @panel,\r
-        })\r
-        @listenTo(move_to, 'click', @click_move_to)\r
-        @listenTo(@footer, 'click:panel', @click_show)\r
-        @listenTo(@footer, 'click:author', @click_author)\r
-        @listenTo(@footer, 'click:insert', @click_insert)\r
-        @listenTo(@footer, 'click:move', @click_move)\r
-        @listenTo(@footer, 'click:edit', @click_edit)\r
-        @listenTo(@footer, 'click:destroy', @click_destroy)\r
-        this.$el.append(@insert_point.clear().el)\r
-        @append_rb()\r
+        @listenTo(body, 'http_get', @http_get)\r
         this.$el.append(body.render().el)\r
-        this.$el.append(@footer_switch.render().el)\r
-        this.$el.append(@footer.render().el)\r
+        @append_footer_switch()\r
+        @append_footer()\r
         @trigger('ready', @panel)\r
       error: (item, response, opt) =>\r
         @open_error_dialog(response, opt)\r
     })\r
     this\r
   \r
+  append_insert_point: () ->\r
+    move_to = new Tag.A({\r
+      attr: {href: '/' + @scroll_panel.edit_url()},\r
+      content: I18n.t('scroll_panels.player.move_to')\r
+    })\r
+    @insert_point = new Pettanr.Views.Scroll.PlayModule.InsertPoint({\r
+      class_name: 'insert-point', content: move_to.render().el\r
+    })\r
+    @listenTo(move_to, 'click', @click_move_to)\r
+    this.$el.append(@insert_point.clear().el)\r
+    @append_rb()\r
+  \r
+  append_footer_switch: () ->\r
+    @footer_switch = new Pettanr.Views.Scroll.PlayModule.FooterSwitch({\r
+      parent: this,\r
+      scroll_panel: @scroll_panel,\r
+      panel: @panel\r
+    })\r
+    @listenTo(@footer_switch, 'click', @click_footer_switch)\r
+    this.$el.append(@footer_switch.render().el)\r
+  \r
+  append_footer: () ->\r
+    @footer = new Pettanr.Views.Scroll.PlayModule.Footer({\r
+      parent: this,\r
+      scroll: @scroll,\r
+      scroll_panel: @scroll_panel,\r
+      panel: @panel,\r
+    })\r
+    @listenTo(@footer, 'click:panel', @click_show)\r
+    @listenTo(@footer, 'click:author', @click_author)\r
+    @listenTo(@footer, 'click:insert', @click_insert)\r
+    @listenTo(@footer, 'click:move', @click_move)\r
+    @listenTo(@footer, 'click:edit', @click_edit)\r
+    @listenTo(@footer, 'click:destroy', @click_destroy)\r
+    this.$el.append(@footer.render().el)\r
+  \r
   hide: () ->\r
     @set_style({display: 'none'})\r
   \r
@@ -240,6 +283,9 @@ class Pettanr.Views.Scroll.PlayModule.Panel extends Pettanr.View
   click_move_to: () ->\r
     @trigger('click:move_to', this)\r
   \r
+  http_get: (url) ->\r
+    @trigger('http_get', url)\r
+  \r
 class Pettanr.Views.Scroll.PlayModule.InsertPoint extends Tag.Div\r
   \r
   clear: () ->\r
@@ -306,22 +352,28 @@ class Pettanr.Views.Scroll.PlayModule.Panels extends Pettanr.View
   append_scroll_panel: (scroll_panel) ->\r
     return if not scroll_panel.has_panel()\r
     panel_view = @create_panel_view(scroll_panel)\r
+    @views.push(panel_view)\r
     this.$el.append(panel_view.clear().el)\r
     @refresh_empty_notice()\r
   \r
   create_panel_view: (scroll_panel) ->\r
     panel_view = new Pettanr.Views.Scroll.PlayModule.Panel({\r
-      scroll: @binder, scroll_panel: scroll_panel,\r
+      parent: this, scroll: @binder, scroll_panel: scroll_panel,\r
     })\r
+    @listenTo(panel_view, 'exist', @exist)\r
+    @listenTo(panel_view, 'lost', @lost)\r
     @listenTo(panel_view, 'ready', @ready)\r
     @listenTo(panel_view, 'http_get', @http_get)\r
     @listenTo(panel_view, 'click:insert', @click_insert)\r
     @listenTo(panel_view, 'click:move', @click_move)\r
     @listenTo(panel_view, 'click:destroy', @click_destroy)\r
     @listenTo(panel_view, 'click:move_to', @click_move_to)\r
-    @views.push(panel_view)\r
     panel_view\r
   \r
+  exist: (panel_view) ->\r
+  \r
+  lost: (response, opt) ->\r
+  \r
   ready: (panel) ->\r
     this.credits.push(panel.licensed_pictures())\r
   \r
@@ -545,8 +597,6 @@ class Pettanr.Views.Scroll.PlayModule.Body extends Pettanr.View
       if !@pager.hasNextPage()\r
         @appender.enable()\r
       this.$el.append(@pager.render().el)\r
-      this.$el.append(credits.render().el)\r
-      @append_rb()\r
       true\r
   \r
   click_credit_icon: (item) ->\r