summaryrefslogtreecommitdiff
path: root/app/controllers/voicemail_messages_controller.rb
diff options
context:
space:
mode:
authorPeter Kozak <spag@golwen.net>2013-04-30 10:13:09 +0200
committerPeter Kozak <spag@golwen.net>2013-04-30 10:13:09 +0200
commit7f50ae3e137a2c14754f79e31e8034c4e2a40cf4 (patch)
treebbc2b87fa72c14459055ad8ffe0a2ae13452bfcb /app/controllers/voicemail_messages_controller.rb
parent0a560d242aa093856a3e16dac986c37471fcce84 (diff)
sorting
Diffstat (limited to 'app/controllers/voicemail_messages_controller.rb')
-rw-r--r--app/controllers/voicemail_messages_controller.rb20
1 files changed, 17 insertions, 3 deletions
diff --git a/app/controllers/voicemail_messages_controller.rb b/app/controllers/voicemail_messages_controller.rb
index 239fed4..3c75a64 100644
--- a/app/controllers/voicemail_messages_controller.rb
+++ b/app/controllers/voicemail_messages_controller.rb
@@ -5,6 +5,8 @@ class VoicemailMessagesController < ApplicationController
before_filter :set_and_authorize_parent
before_filter :spread_breadcrumbs
+
+ helper_method :sort_column, :sort_descending
before_filter { |controller|
if ! params[:type].blank? then
@@ -22,17 +24,17 @@ class VoicemailMessagesController < ApplicationController
@messages_read_count = @messages_count - @messages_unread_count
if @type == 'read'
- @voicemail_messages = @voicemail_account.voicemail_messages.where('read_epoch > 0').order('created_epoch DESC').paginate(
+ @voicemail_messages = @voicemail_account.voicemail_messages.where('read_epoch > 0').order(sort_column + ' ' + (sort_descending ? 'DESC' : 'ASC')).paginate(
:page => @pagination_page_number,
:per_page => GsParameter.get('DEFAULT_PAGINATION_ENTRIES_PER_PAGE')
)
elsif @type == 'unread'
- @voicemail_messages = @voicemail_account.voicemail_messages.where(:read_epoch => 0).order('created_epoch DESC').paginate(
+ @voicemail_messages = @voicemail_account.voicemail_messages.where(:read_epoch => 0).order(sort_column + ' ' + (sort_descending ? 'DESC' : 'ASC')).paginate(
:page => @pagination_page_number,
:per_page => GsParameter.get('DEFAULT_PAGINATION_ENTRIES_PER_PAGE')
)
else
- @voicemail_messages = @voicemail_account.voicemail_messages.order('created_epoch DESC').paginate(
+ @voicemail_messages = @voicemail_account.voicemail_messages.order(sort_column + ' ' + (sort_descending ? 'DESC' : 'ASC')).paginate(
:page => @pagination_page_number,
:per_page => GsParameter.get('DEFAULT_PAGINATION_ENTRIES_PER_PAGE')
)
@@ -137,4 +139,16 @@ class VoicemailMessagesController < ApplicationController
end
end
+ def sort_descending
+ if sort_column == 'created_epoch' && params[:desc].to_s.blank?
+ return true
+ end
+
+ params[:desc].to_s == 'true'
+ end
+
+ def sort_column
+ VoicemailMessage.column_names.include?(params[:sort]) ? params[:sort] : 'created_epoch'
+ end
+
end