summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorPeter Kozak <spag@golwen.net>2013-06-11 11:20:08 +0200
committerPeter Kozak <spag@golwen.net>2013-06-11 11:20:08 +0200
commit6ec40d4f0b99801354a342644e788ce13fcc204b (patch)
tree3378799f1794fe5e03932084c8a32920d837ddff /app
parent0d795581c63dcbeccb5a10e1e4c2f5bacfe4723c (diff)
pagination added
Diffstat (limited to 'app')
-rw-r--r--app/controllers/phones_controller.rb14
-rw-r--r--app/views/phones/_index_core.html.haml11
2 files changed, 21 insertions, 4 deletions
diff --git a/app/controllers/phones_controller.rb b/app/controllers/phones_controller.rb
index 3672390..cfa6d7b 100644
--- a/app/controllers/phones_controller.rb
+++ b/app/controllers/phones_controller.rb
@@ -6,7 +6,13 @@ class PhonesController < ApplicationController
before_filter :set_and_authorize_parent
before_filter :spread_breadcrumbs
+ helper_method :sort_column, :sort_descending
+
def index
+ @phones = @parent.phones.order(sort_column + ' ' + (sort_descending ? 'DESC' : 'ASC')).paginate(
+ :page => params[:page],
+ :per_page => GsParameter.get('DEFAULT_PAGINATION_ENTRIES_PER_PAGE')
+ )
end
def show
@@ -85,5 +91,13 @@ class PhonesController < ApplicationController
end
@fallback_sip_accounts = SipAccount.where(:sip_accountable_type => 'Tenant') - SipAccount.where(:id => used_sip_account_ids)
end
+
+ def sort_descending
+ params[:desc].to_s == 'true'
+ end
+
+ def sort_column
+ Phone.column_names.include?(params[:sort]) ? params[:sort] : 'id'
+ end
end
diff --git a/app/views/phones/_index_core.html.haml b/app/views/phones/_index_core.html.haml
index 9a865f0..a77395c 100644
--- a/app/views/phones/_index_core.html.haml
+++ b/app/views/phones/_index_core.html.haml
@@ -1,18 +1,21 @@
+- if defined?(phones.total_pages)
+ = will_paginate phones, :renderer => BootstrapPagination::Rails, :previous_label => raw('<i class = "icon-chevron-left"></i>'), :next_label => raw('<i class = "icon-chevron-right"></i>')
+
%table.table.table-striped
%thead
%tr
- %th= t('phones.index.mac_address')
+ %th= sortable :mac_address, t('phones.index.mac_address')
%th
%span.hidden-phone
- = t('phones.index.phone_model_id')
+ = sortable :phone_model_id, t('phones.index.phone_model_id')
%span.visible-phone
= truncate(t('phones.index.phone_model_id'), :length => 9)
%th
%span.hidden-phone
- = t('phones.index.hot_deskable')
+ = sortable :hot_deskable, t('phones.index.hot_deskable')
%th
%span.hidden-phone
- = t('phones.index.ip_address')
+ = sortable :ip_address, t('phones.index.ip_address')
%tbody
- for phone in phones