aboutsummaryrefslogtreecommitdiffstats
path: root/app/controllers/calendars_controller.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/controllers/calendars_controller.rb')
-rw-r--r--app/controllers/calendars_controller.rb64
1 files changed, 19 insertions, 45 deletions
diff --git a/app/controllers/calendars_controller.rb b/app/controllers/calendars_controller.rb
index 84b432bf3..563c126e4 100644
--- a/app/controllers/calendars_controller.rb
+++ b/app/controllers/calendars_controller.rb
@@ -2,42 +2,13 @@ class CalendarsController < BreadcrumbController
defaults resource_class: Calendar
before_action :check_policy, only: [:edit, :update, :destroy]
- def new
- new! do
- @calendar.date_ranges = []
- @calendar.dates = []
- end
- end
-
- def create
- @calendar = current_organisation.calendars.build(calendar_params)
-
- if @calendar.valid?
- respond_with @calendar
- else
- render action: 'new'
- end
- end
-
- def update
- update! do |success, failure|
- success.html { redirect_to calendar_path(@calendar) }
- end
- end
-
- def destroy
- destroy! do |success, failure|
- success.html { redirect_to calendars_path }
- end
- end
-
private
def calendar_params
params.require(:calendar).permit(:id, :name, :short_name, :shared, ranges_attributes: [:id, :begin, :end, :_destroy], dates: [])
end
def sort_column
- current_organisation.calendars.column_names.include?(params[:sort]) ? params[:sort] : 'short_name'
+ Calendar.column_names.include?(params[:sort]) ? params[:sort] : 'short_name'
end
def sort_direction
@@ -45,24 +16,27 @@ class CalendarsController < BreadcrumbController
end
protected
- def collection
- # if params[:q]
- # if params[:q][:shared_eq]
- # if params[:q][:shared_eq] == 'all'
- # params[:q].delete(:shared_eq)
- # else
- # params[:q][:shared_eq] = params[:q][:shared_eq] == 'true'
- # end
- # end
- # end
+ def resource
+ @calendar = current_organisation.calendars.find_by_id(params[:id])
+ end
- @q = current_organisation.calendars.search(params[:q])
+ def build_resource
+ super.tap do |calendar|
+ calendar.organisation = current_organisation
+ end
+ end
- if sort_column && sort_direction
- @calendars ||= @q.result(distinct: true).order(sort_column + ' ' + sort_direction).paginate(page: params[:page])
- else
- @calendars ||= @q.result(distinct: true).paginate(page: params[:page])
+ def collection
+ return @calendars if @calendars
+ if params[:q]
+ params[:q].delete(:shared_eq) if params[:q][:shared_eq] == ''
+ params[:q].delete(:short_name_cont) if params[:q][:short_name_cont] == ''
end
+
+ @q = current_organisation.calendars.search(params[:q])
+ calendars = @q.result(distinct: true)
+ calendars = calendars.order(sort_column + ' ' + sort_direction) if sort_column && sort_direction
+ @calendars = calendars.paginate(page: params[:page])
end
def check_policy