From 3d0b0437a9909484d13928d3ffae0dd332c630d7 Mon Sep 17 00:00:00 2001 From: yasushiito Date: Tue, 2 Sep 2014 11:43:44 +0900 Subject: [PATCH] fix paginator --- .../filer/symbol/default/link/action.js.coffee | 7 ----- app/assets/javascripts/locmare/filer.js.coffee | 2 +- .../caption/default/link/action.js.coffee | 10 ++++++- .../file_item/symbol/default/link/action.js.coffee | 10 ++++++- .../javascripts/locmare/filer/pager.js.coffee | 35 ++++++++++++---------- app/assets/javascripts/models/picture.js.coffee | 8 +++-- .../javascripts/models/resource_picture.js.coffee | 2 +- app/assets/javascripts/pettanr.js.coffee | 21 +++++++------ app/assets/stylesheets/test.css.scss | 9 ++++++ app/controllers/application_controller.rb | 2 +- app/views/panels/show.html.erb | 2 +- app/views/top/ap.html.erb | 11 ------- app/views/top/index.html.erb | 3 -- 13 files changed, 68 insertions(+), 54 deletions(-) diff --git a/app/assets/javascripts/local_manifest/filer/symbol/default/link/action.js.coffee b/app/assets/javascripts/local_manifest/filer/symbol/default/link/action.js.coffee index ed0f3185..fdc3fa38 100644 --- a/app/assets/javascripts/local_manifest/filer/symbol/default/link/action.js.coffee +++ b/app/assets/javascripts/local_manifest/filer/symbol/default/link/action.js.coffee @@ -15,10 +15,3 @@ class LocalManifest.FilerModule.SymbolModule.DefaultModule.LinkModule.ActionLink @action_name + '/' '/' + this.filer().item_class.path_name() + '/' + a - js_action_path: () -> - a = if @action_name == 'show' - '' - else - @action_name + '/' - this.filer().item_class.path_name() + '/' + a - diff --git a/app/assets/javascripts/locmare/filer.js.coffee b/app/assets/javascripts/locmare/filer.js.coffee index 6d3d2782..e566b434 100644 --- a/app/assets/javascripts/locmare/filer.js.coffee +++ b/app/assets/javascripts/locmare/filer.js.coffee @@ -15,7 +15,7 @@ class Locmare.Filer extends Backbone.View this.$el.html('') this.$el.append(@header.render().el) this.$el.append(@body.render().el) - this.$el.append(@pager.render().el) if @pager + this.$el.append(@pager.el) if @pager this model: () -> diff --git a/app/assets/javascripts/locmare/filer/body/file_body/file_item/caption/default/link/action.js.coffee b/app/assets/javascripts/locmare/filer/body/file_body/file_item/caption/default/link/action.js.coffee index ca1eaec1..f7ed6a63 100644 --- a/app/assets/javascripts/locmare/filer/body/file_body/file_item/caption/default/link/action.js.coffee +++ b/app/assets/javascripts/locmare/filer/body/file_body/file_item/caption/default/link/action.js.coffee @@ -13,5 +13,13 @@ class Locmare.FilerModule.BodyModule.FileBodyModule.FileItemModule.CaptionItemCo "javascript:void(0)" url: () -> - @my_manifest.js_action_path() + @item.get('id').toString() + controller = Manifest.manifest().controllers[@item.table_name()] + action = controller.actions[@my_manifest.action_name] + params = { + controller: controller, + action: action, + id: @item.get('id'), + format: 'html' + } + '/' + action.url(params) diff --git a/app/assets/javascripts/locmare/filer/body/file_body/file_item/symbol/default/link/action.js.coffee b/app/assets/javascripts/locmare/filer/body/file_body/file_item/symbol/default/link/action.js.coffee index 13f84c31..e3c8c52c 100644 --- a/app/assets/javascripts/locmare/filer/body/file_body/file_item/symbol/default/link/action.js.coffee +++ b/app/assets/javascripts/locmare/filer/body/file_body/file_item/symbol/default/link/action.js.coffee @@ -13,5 +13,13 @@ class Locmare.FilerModule.BodyModule.FileBodyModule.FileItemModule.SymbolItemCol "javascript:void(0)" url: () -> - @my_manifest.js_action_path() + @item.get('id').toString() + controller = Manifest.manifest().controllers[@item.table_name()] + action = controller.actions[@my_manifest.action_name] + params = { + controller: controller, + action: action, + id: @item.get('id'), + format: 'html' + } + '/' + action.url(params) diff --git a/app/assets/javascripts/locmare/filer/pager.js.coffee b/app/assets/javascripts/locmare/filer/pager.js.coffee index 9a142403..52a3e600 100644 --- a/app/assets/javascripts/locmare/filer/pager.js.coffee +++ b/app/assets/javascripts/locmare/filer/pager.js.coffee @@ -23,30 +23,32 @@ class Locmare.FilerModule.DefaultPager extends Locmare.FilerModule.Pager className: 'pagination' initialize: (options) -> - @filer = options.filer - @counter = @list_result.counter - @current_page = @list_result.page - @per_page = @list_result.page_size - @total_page = (@total / @per_page) + 1 - @window_size = 3 + @page_status = options.page_status + @counter = @page_status.counter + @current_page = @page_status.current_page + @per_page = @page_status.per_page + @window_size = @page_status.window_size @parts = [] _this = this @counter.fetch().done -> - _this.total = @counter.count - _this.build() + _this.total = _this.counter.get('count') + _this.total_page = Math.floor(_this.total / _this.per_page) + 1 _this.render() render: () -> + @parts = [] + @build() _this = this this.$el.html('') _.each @parts, (part) -> _this.$el.append(part.render().el) + this.$el.append(div('row_break').render().el) this build: () -> - @parts.push(new Locmare.FilerModule.DefaultPager.FirstPage({})) if hasPreviousPage() - @parts.push(new Locmare.FilerModule.DefaultPager.PrevPage({})) if hasPreviousPage() - @parts.push(new Locmare.FilerModule.DefaultPager.PageGap({})) if hasPreviousPageGap() + @parts.push(new Locmare.FilerModule.DefaultPager.FirstPage({})) if @hasPreviousPage() + @parts.push(new Locmare.FilerModule.DefaultPager.PrevPage({})) if @hasPreviousPage() + @parts.push(new Locmare.FilerModule.DefaultPager.PageGap({})) if @hasPreviousPageGap() f = if @hasPreviousPageGap() @current_page - @window_size else @@ -57,9 +59,9 @@ class Locmare.FilerModule.DefaultPager extends Locmare.FilerModule.Pager @total_page for page in [f..t] @parts.push(new Locmare.FilerModule.DefaultPager.Page({page: page})) - @parts.push(new Locmare.FilerModule.DefaultPager.NextPageGap({})) if hasNextPageGap() - @parts.push(new Locmare.FilerModule.DefaultPager.NextPage({})) if hasNextPage() - @parts.push(new Locmare.FilerModule.DefaultPager.LastPage({})) if hasNextPage() + @parts.push(new Locmare.FilerModule.DefaultPager.PageGap({})) if @hasNextPageGap() + @parts.push(new Locmare.FilerModule.DefaultPager.NextPage({})) if @hasNextPage() + @parts.push(new Locmare.FilerModule.DefaultPager.LastPage({})) if @hasNextPage() hasPreviousPage: () -> @current_page > 1 @@ -101,8 +103,11 @@ class Locmare.FilerModule.DefaultPager.Page extends Backbone.View tagName: 'li' className: 'page' + initialize: (options) -> + @page = options.page + render: () -> - this.$el.html() + this.$el.html(@page) this class Locmare.FilerModule.DefaultPager.NextPage extends Backbone.View diff --git a/app/assets/javascripts/models/picture.js.coffee b/app/assets/javascripts/models/picture.js.coffee index 2af7542c..a0f42e47 100644 --- a/app/assets/javascripts/models/picture.js.coffee +++ b/app/assets/javascripts/models/picture.js.coffee @@ -31,7 +31,7 @@ class Pettanr.Picture extends Peta.Content tmb_opt_img_tag: () -> wh = Pettanr.Imager.thumbnail_size(@get('width'), @get('height')) - {src: @r_url(), width: wh[0], height: wh[1]} + new Pettanr.AppHelperImg({src: @r_url(), size: wh[0]}) tail_opt_img_tag: (img) -> {src: img, width: @get('width'), height: @get('height')} @@ -45,8 +45,10 @@ class Pettanr.Picture extends Peta.Content ln = Pettanr.to_s(@license().get('caption')) lgn + '[' + ln + ']' - symbol_option: () -> - this + symbol_option: (cb) -> + _this = this + this.fetch().done -> + cb(_this.tmb_opt_img_tag()) is_enable: () -> if @head().resource_picture() diff --git a/app/assets/javascripts/models/resource_picture.js.coffee b/app/assets/javascripts/models/resource_picture.js.coffee index fb2cb026..9f4bc4b1 100644 --- a/app/assets/javascripts/models/resource_picture.js.coffee +++ b/app/assets/javascripts/models/resource_picture.js.coffee @@ -32,7 +32,7 @@ class Pettanr.ResourcePicture extends Peta.Content tmb_opt_img_tag: () -> wh = Pettanr.Imager.thumbnail_size(@get('width'), @get('height')) - {src: @r_url(), width: wh[0], height: wh[1]} + new Pettanr.AppHelperImg({src: @r_url(), size: wh[0], alt: @get('caption')}) opt_img_tag: () -> {src: @url('full'), width: @get('width'), height: @get('height')} diff --git a/app/assets/javascripts/pettanr.js.coffee b/app/assets/javascripts/pettanr.js.coffee index 034f26c3..b9d5e98f 100644 --- a/app/assets/javascripts/pettanr.js.coffee +++ b/app/assets/javascripts/pettanr.js.coffee @@ -134,18 +134,15 @@ class Pettanr count: () -> @get('count') - class Pettanr.Pager extends Backbone.View + class Pettanr.PageStatus - initialize: (options) -> + constructor: (options) -> @action = options['action'] @params = options['params'] - @current_page = @params['page'] - @per_page = @params['page_size'] + @current_page = @params['page'] || 1 + @per_page = @params['page_size'] || 25 @window_size = 3 @counter = new Pettanr.CounterModel({}, {url: '/' + @action.counter_url(@params)}) - _this = this - @counter.fetch().done -> - _this.total_page = (@total / _this.per_page) + 1 class Pettanr.FilerCollection extends Backbone.Collection @@ -171,8 +168,13 @@ class Pettanr @set_model() @my_list_model = Manifest.manifest().models[@my_action.item_name] @my_list_model_class = @my_list_model.classify() - @pager = new Pettanr.Pager({action: @my_action, params: @params}) - @list = new Pettanr.FilerCollection({}, {model: @my_list_model_class, action: @my_action, params: @params}) + @list_options = { + model: @my_list_model_class, + action: @my_action, + params: @params + } + @page_status = new Pettanr.PageStatus(@list_options) + @list = new Pettanr.FilerCollection({}, @list_options) set_show: () -> @set_model() @@ -180,6 +182,7 @@ class Pettanr filer_list: () -> @set_list() + @pager = new Locmare.FilerModule.DefaultPager({page_status: @page_status}) f = new Locmare.Filer({ el: "#pettanr", item_name: @my_list_model_class.item_name(), diff --git a/app/assets/stylesheets/test.css.scss b/app/assets/stylesheets/test.css.scss index 87f1dae6..10c154de 100644 --- a/app/assets/stylesheets/test.css.scss +++ b/app/assets/stylesheets/test.css.scss @@ -638,3 +638,12 @@ font-family : monospace; } .filer-item-speech_balloon_template .filer-item-caption { } + +ul.pagination { + list-style-type: none; +} + +ul.pagination li { + float: left; +} + diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 42e87806..0c38d665 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -165,7 +165,7 @@ class ApplicationController < ActionController::Base def show_prof_format format format.prof { self.formats = [:html] - @profiler = Locmare::Profiler.new @my_model.item_name, @item, @operators + @profiler = Locmare::Profiler.new @my_model_class.item_name, @item, @operators render @profiler.template_name, :locals => { :profiler => @profiler } diff --git a/app/views/panels/show.html.erb b/app/views/panels/show.html.erb index 29f04964..dfb2e7f8 100644 --- a/app/views/panels/show.html.erb +++ b/app/views/panels/show.html.erb @@ -11,7 +11,7 @@

<%= t_m 'Panel.publish' -%>: - <%= t_selected_item('panel_visible_items', @item.publish) %> + <%= t_selected_item('panel_publish_items', @item.publish) %>

<%= link_to t('link.edit'), edit_panel_path(@item) %> diff --git a/app/views/top/ap.html.erb b/app/views/top/ap.html.erb index 46215094..1d21d4be 100644 --- a/app/views/top/ap.html.erb +++ b/app/views/top/ap.html.erb @@ -1,16 +1,5 @@

-
- filer -
- - -