aboutsummaryrefslogtreecommitdiffstats
path: root/app/controllers
diff options
context:
space:
mode:
authorLuc Donnet2018-02-01 14:04:54 +0100
committerGitHub2018-02-01 14:04:54 +0100
commitb3d46e56c65b9dcfee9c8a81fd567cba956c63fc (patch)
tree04c6447a57ac81cfaa7ba098d7efcecd056c7109 /app/controllers
parent972e988e0f52a6ee69bf97c112be28e6f852be00 (diff)
parent9caa25a7c2267f715822178b84ea15376f079a29 (diff)
downloadchouette-core-b3d46e56c65b9dcfee9c8a81fd567cba956c63fc.tar.bz2
Merge pull request #255 from af83/5682-add-days-to-calendars
Add application days to calendars
Diffstat (limited to 'app/controllers')
-rw-r--r--app/controllers/calendars_controller.rb29
1 files changed, 29 insertions, 0 deletions
diff --git a/app/controllers/calendars_controller.rb b/app/controllers/calendars_controller.rb
index de8f9d10c..43ed0cfd9 100644
--- a/app/controllers/calendars_controller.rb
+++ b/app/controllers/calendars_controller.rb
@@ -1,8 +1,11 @@
class CalendarsController < ChouetteController
include PolicyChecker
+ include TimeTablesHelper
+
defaults resource_class: Calendar
before_action :ransack_contains_date, only: [:index]
respond_to :html
+ respond_to :json, only: :show
respond_to :js, only: :index
def index
@@ -14,6 +17,32 @@ class CalendarsController < ChouetteController
def show
end
+ def month
+ @date = params['date'] ? Date.parse(params['date']) : Date.today
+ @calendar = resource
+ end
+
+ def create
+ create! do
+ if @calendar.valid? && has_feature?('application_days_on_calendars')
+ redirect_to([:edit, @calendar])
+ return
+ end
+ end
+ end
+
+ def update
+ if params[:calendar]
+ super
+ else
+ state = JSON.parse request.raw_post
+ resource.state_update state
+ respond_to do |format|
+ format.json { render json: state, status: state['errors'] ? :unprocessable_entity : :ok }
+ end
+ end
+ end
+
private
def calendar_params
permitted_params = [:id, :name, :short_name, :shared, periods_attributes: [:id, :begin, :end, :_destroy], date_values_attributes: [:id, :value, :_destroy]]