OSDN Git Service

fix paginator
authoryasushiito <yas@pen-chan.jp>
Wed, 3 Sep 2014 05:04:59 +0000 (14:04 +0900)
committeryasushiito <yas@pen-chan.jp>
Wed, 3 Sep 2014 05:04:59 +0000 (14:04 +0900)
app/assets/javascripts/ap.js
app/assets/javascripts/locmare/filer/body/file_body/file_item/edit/account.js.coffee
app/assets/javascripts/locmare/filer/body/file_body/file_item/edit/default.js.coffee
app/assets/javascripts/locmare/filer/body/file_body/file_item/icon/default.js.coffee
app/assets/javascripts/locmare/filer/header.js.coffee
app/assets/javascripts/locmare/filer/pager.js.coffee
app/assets/javascripts/pettanr/tags.js.coffee
app/assets/stylesheets/test.css.scss

index 2ecfbfb..4693988 100644 (file)
 //= require ./i18n/translations
 //= require_directory ./controllers
 //= require_directory ./models
-//= require_directory ./views
 //= require ./pettanr/tags
 //= require ./pettanr/picture
 //= require ./pettanr/pettan_imager
index 4d32e1f..b2eb071 100644 (file)
@@ -7,7 +7,7 @@ class Locmare.FilerModule.BodyModule.FileBodyModule.FileItemModule.EditItemColum
       half: true\r
     })\r
     @edit_btn = new Pettanr.Tag.A({\r
-      href: '/home/configure'\r
+      attr: {href: '/home/configure'}\r
       content: @edit_icon.render().el\r
     })\r
   \r
index 9932daa..391c89f 100644 (file)
@@ -6,16 +6,20 @@ class Locmare.FilerModule.BodyModule.FileBodyModule.FileItemModule.EditItemColum
       attr: {'src': @edit_img_file_name()}, \r
       half: true\r
     })\r
+    url = Pettanr.url(@item.table_name(), 'edit', {id: @item.get('id')})\r
     @edit_btn = new Pettanr.Tag.A({\r
-      href: '/' + Pettanr.url(@item.table_name(), 'edit', {id: @item.get('id')}), \r
+      attr: {href: '/' + url}, \r
+      handler_name: url,\r
       content: @edit_icon.render().el\r
     })\r
     @remove_icon = new Pettanr.Picture.SymbolImg({\r
       attr: {'src': @remove_img_file_name()}, \r
       half: true\r
     })\r
+    url = Pettanr.url(@item.table_name(), 'destroy', {id: @item.get('id')})\r
     @remove_btn = new Pettanr.Tag.A({\r
-      href: '/' + Pettanr.url(@item.table_name(), 'destroy', {id: @item.get('id')}), \r
+      attr: {href: '/' + url}, \r
+      handler_name: url,\r
       content: @remove_icon.render().el\r
     })\r
   \r
index b17f264..4041046 100644 (file)
@@ -4,13 +4,16 @@ class Locmare.FilerModule.BodyModule.FileBodyModule.FileItemModule.IconItemColum
     super(options)\r
   \r
   render: () ->\r
-    i = new Pettanr.Picture.SymbolImg({\r
+    icon = new Pettanr.Picture.SymbolImg({\r
       class_name: 'face', \r
       attr: {\r
         src: @icon_file_name()\r
       }\r
     })\r
-    a = new Pettanr.Tag.A({href: @path_name(), content: i.render().el})\r
+    a = new Pettanr.Tag.A({\r
+      attr: {href: @path_name()}, \r
+      content: icon.render().el\r
+    })\r
     this.$el.html(a.render().el)\r
     this\r
   \r
index 47804b9..2895abe 100644 (file)
@@ -6,13 +6,17 @@ class Locmare.FilerModule.Header extends Backbone.View
   \r
   render: () ->\r
     this.$el.html('')\r
-    icon = new Pettanr.Picture.Icon({item: @model()})\r
+    icon = new Pettanr.Picture.Icon({item: @model(), half: true})\r
     caption = Pettanr.AppHelper.t_m(@model().singular())\r
     url = Pettanr.url(@model().table_name(), 'index', {})\r
-    linked_icon = new Pettanr.Tag.A({href: url, content: icon.render().el})\r
-    linked_caption = new Pettanr.Tag.A({href: url, content: caption})\r
-    this.$el.append(linked_icon)\r
-    this.$el.append(linked_caption)\r
+    linked_icon = new Pettanr.Tag.A({\r
+      attr: {href: url}, handler_name: url, content: icon.render().el\r
+    })\r
+    linked_caption = new Pettanr.Tag.A({\r
+      attr: {href: '/' + url}, handler_name: url, content: caption\r
+    })\r
+    this.$el.append(linked_icon.render().el)\r
+    this.$el.append(linked_caption.render().el)\r
     this\r
   \r
   model: () ->\r
index 9f4dd43..e8222be 100644 (file)
@@ -1,24 +1,4 @@
-class Locmare.FilerModule.Pager extends Backbone.View\r
-  tagName: 'ul'\r
-  className: 'pagination'\r
-  \r
-  initialize: (options) ->\r
-    @filer = options.filer\r
-  \r
-  total_result: () ->\r
-    _this = this\r
-    t = @filer.list_result.total\r
-    t.fetch().done ->\r
-      a = t.count\r
-      _this.render()\r
-  \r
-  list_result: () ->\r
-    @filer.list_result\r
-  \r
-  api_path: () ->\r
-    list_result().path\r
-  \r
-class Locmare.FilerModule.DefaultPager extends Locmare.FilerModule.Pager\r
+class Locmare.FilerModule.DefaultPager extends Backbone.View\r
   tagName: 'ul'\r
   className: 'pagination'\r
   \r
@@ -28,12 +8,14 @@ class Locmare.FilerModule.DefaultPager extends Locmare.FilerModule.Pager
     @current_page = @page_status.current_page\r
     @per_page = @page_status.per_page\r
     @window_size = @page_status.window_size\r
+    @params = @page_status.params\r
     @parts = []\r
     _this = this\r
     @counter.fetch().done ->\r
       _this.total = _this.counter.get('count')\r
       _this.total_page = Math.floor(_this.total / _this.per_page) + 1\r
-      _this.render()\r
+      if _this.total_page > 1\r
+        _this.render()\r
   \r
   render: () ->\r
     @parts = []\r
@@ -47,9 +29,10 @@ class Locmare.FilerModule.DefaultPager extends Locmare.FilerModule.Pager
     this\r
   \r
   build: () ->\r
-    @parts.push(new Locmare.FilerModule.DefaultPager.FirstPage({})) if @hasPreviousPage()\r
-    @parts.push(new Locmare.FilerModule.DefaultPager.PrevPage({})) if @hasPreviousPage()\r
-    @parts.push(new Locmare.FilerModule.DefaultPager.PageGap({})) if @hasPreviousPageGap()\r
+    opt = {pager: this, page_status: @page_status}\r
+    @parts.push(new Locmare.FilerModule.DefaultPager.FirstPage(opt)) if @hasPreviousPage()\r
+    @parts.push(new Locmare.FilerModule.DefaultPager.PrevPage(opt)) if @hasPreviousPage()\r
+    @parts.push(new Locmare.FilerModule.DefaultPager.PageGap(opt)) if @hasPreviousPageGap()\r
     f = if @hasPreviousPageGap()\r
       @current_page - @window_size\r
     else\r
@@ -59,10 +42,10 @@ class Locmare.FilerModule.DefaultPager extends Locmare.FilerModule.Pager
     else\r
       @total_page\r
     for page in [f..t]\r
-      @parts.push(new Locmare.FilerModule.DefaultPager.Page({page: page}))\r
-    @parts.push(new Locmare.FilerModule.DefaultPager.PageGap({})) if @hasNextPageGap()\r
-    @parts.push(new Locmare.FilerModule.DefaultPager.NextPage({})) if @hasNextPage()\r
-    @parts.push(new Locmare.FilerModule.DefaultPager.LastPage({})) if @hasNextPage()\r
+      @parts.push(new Locmare.FilerModule.DefaultPager.Page({pager: this, page: page, page_status: @page_status}))\r
+    @parts.push(new Locmare.FilerModule.DefaultPager.PageGap(opt)) if @hasNextPageGap()\r
+    @parts.push(new Locmare.FilerModule.DefaultPager.NextPage(opt)) if @hasNextPage()\r
+    @parts.push(new Locmare.FilerModule.DefaultPager.LastPage(opt)) if @hasNextPage()\r
   \r
   hasPreviousPage: () ->\r
     @current_page > 1\r
@@ -80,18 +63,46 @@ class Locmare.FilerModule.DefaultPager.FirstPage extends Backbone.View
   tagName: 'li'\r
   className: 'first'\r
   \r
+  initialize: (options) ->\r
+    @page_status = options.page_status\r
+    @params = @page_status.params\r
+  \r
   render: () ->\r
-    this.$el.html('<<')\r
+    my_params = {}\r
+    _.extend(my_params, @params)\r
+    my_params['page'] = 1\r
+    url = Pettanr.url(my_params['controller'], my_params['action'], my_params)\r
+    linked_caption = new Pettanr.Tag.A({\r
+      attr: {href: '/' + url}, \r
+      handler_name: url,\r
+      content: '<<'\r
+    })\r
+    this.$el.html(linked_caption.render().el)\r
     this\r
   \r
 class Locmare.FilerModule.DefaultPager.PrevPage extends Backbone.View\r
   tagName: 'li'\r
   className: 'prev'\r
   \r
+  initialize: (options) ->\r
+    @page_status = options.page_status\r
+    @current_page = @page_status.current_page\r
+    @params = @page_status.params\r
+  \r
   render: () ->\r
-    this.$el.html('<')\r
+    my_params = {}\r
+    _.extend(my_params, @params)\r
+    my_params['page'] = @current_page - 1\r
+    url = Pettanr.url(my_params['controller'], my_params['action'], my_params)\r
+    linked_caption = new Pettanr.Tag.A({\r
+      attr: {href: '/' + url}, \r
+      handler_name: url,\r
+      content: '<'\r
+    })\r
+    this.$el.html(linked_caption.render().el)\r
     this\r
   \r
+  \r
 class Locmare.FilerModule.DefaultPager.PageGap extends Backbone.View\r
   tagName: 'li'\r
   className: 'page-gap'\r
@@ -105,27 +116,66 @@ class Locmare.FilerModule.DefaultPager.Page extends Backbone.View
   className: 'page'\r
   \r
   initialize: (options) ->\r
+    @page_status = options.page_status\r
     @page = options.page\r
+    @params = @page_status.params\r
   \r
   render: () ->\r
-    this.$el.html(@page)\r
+    my_params = {}\r
+    _.extend(my_params, @params)\r
+    my_params['page'] = @page\r
+    url = Pettanr.url(my_params['controller'], my_params['action'], my_params)\r
+    linked_caption = new Pettanr.Tag.A({\r
+      attr: {href: '/' + url}, \r
+      handler_name: url,\r
+      content: @page\r
+    })\r
+    this.$el.html(linked_caption.render().el)\r
     this\r
   \r
 class Locmare.FilerModule.DefaultPager.NextPage extends Backbone.View\r
   tagName: 'li'\r
   className: 'next'\r
   \r
+  initialize: (options) ->\r
+    @page_status = options.page_status\r
+    @current_page = @page_status.current_page\r
+    @params = @page_status.params\r
+  \r
   render: () ->\r
-    this.$el.html('>')\r
+    my_params = {}\r
+    _.extend(my_params, @params)\r
+    my_params['page'] = @current_page + 1\r
+    url = Pettanr.url(my_params['controller'], my_params['action'], my_params)\r
+    linked_caption = new Pettanr.Tag.A({\r
+      attr: {href: '/' + url}, \r
+      handler_name: url,\r
+      content: '>'\r
+    })\r
+    this.$el.html(linked_caption.render().el)\r
     this\r
   \r
 class Locmare.FilerModule.DefaultPager.LastPage extends Backbone.View\r
   tagName: 'li'\r
   className: 'last'\r
   \r
+  initialize: (options) ->\r
+    @page_status = options.page_status\r
+    @pager = options.pager\r
+    @params = @page_status.params\r
+  \r
   render: () ->\r
-    this.$el.html('>>')\r
+    my_params = {}\r
+    _.extend(my_params, @params)\r
+    my_params['page'] = @pager.total_page\r
+    url = Pettanr.url(my_params['controller'], my_params['action'], my_params)\r
+    linked_caption = new Pettanr.Tag.A({\r
+      attr: {href: '/' + url}, \r
+      handler_name: url,\r
+      content: '>>'\r
+    })\r
+    this.$el.html(linked_caption.render().el)\r
     this\r
   \r
-class Locmare.FilerModule.MorePager extends Locmare.FilerModule.Pager\r
+class Locmare.FilerModule.MorePager extends Backbone.View\r
   \r
index ff14503..e7297f8 100644 (file)
@@ -16,18 +16,26 @@ class Pettanr.Tag.Img extends Backbone.View
 \r
 class Pettanr.Tag.A extends Backbone.View\r
   tagName: 'a'\r
+  events: {\r
+    'click': 'click'\r
+  }\r
   \r
   initialize: (options) ->\r
-    @href = options.href\r
+    @attr = options.attr\r
+    @handler_name = options.handler_name\r
     @content = options.content\r
     @class_name = options.class_name\r
   \r
   render: () ->\r
-    this.$el.attr('href', @href)\r
+    this.$el.attr(@attr)\r
     @el.className = @class_name\r
     this.$el.html(@content)\r
     this\r
-    \r
+  \r
+  click: () ->\r
+    window.router.navigate(@handler_name, true) if @handler_name\r
+    return false\r
+  \r
 class Pettanr.Tag.Div extends Backbone.View\r
   tagName: 'div'\r
   \r
index 10c154d..c01c9ef 100644 (file)
@@ -645,5 +645,7 @@ ul.pagination {
 
 ul.pagination li {
   float: left;
+  padding: 3px;
+  font-size: 20px;
 }