diff options
Diffstat (limited to 'app/controllers')
-rw-r--r-- | app/controllers/cdrs_controller.rb | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/app/controllers/cdrs_controller.rb b/app/controllers/cdrs_controller.rb new file mode 100644 index 0000000..3815f52 --- /dev/null +++ b/app/controllers/cdrs_controller.rb @@ -0,0 +1,43 @@ +class CdrsController < ApplicationController + load_and_authorize_resource :tenant + + before_filter :set_and_authorize_parent + before_filter :spread_breadcrumbs + + helper_method :sort_column, :sort_descending + + def index + @cdrs = Cdr.order(sort_column + ' ' + (sort_descending ? 'DESC' : 'ASC')).paginate( + :page => params[:page], + :per_page => GsParameter.get('DEFAULT_PAGINATION_ENTRIES_PER_PAGE') + ) + end + + def show + end + + def destroy + @cdr.destroy + m = method( :"#{@parent.class.name.underscore}_cdrs_url" ) + redirect_to m.(@parent), :notice => t('cdrs.controller.successfuly_destroyed') + end + + private + def set_and_authorize_parent + @parent = @user || @tenant + authorize! :read, @parent + end + + def spread_breadcrumbs + add_breadcrumb t("cdrs.index.page_title"), tenant_cdrs_path(@tenant) + end + + def sort_descending + params[:desc].to_s == 'true' + end + + def sort_column + Cdr.column_names.include?(params[:sort]) ? params[:sort] : 'start_stamp' + end + +end |