@@ -16,14 +16,14 @@ def index
1616 def new
1717 @plan = Plan . new
1818 authorize @plan
19-
19+
2020 # Get all of the available funders and non-funder orgs
2121 @funders = Org . funders . joins ( :templates ) . where ( templates : { published : true } ) . uniq . sort { |x , y | x . name <=> y . name }
2222 @orgs = ( Org . institutions + Org . managing_orgs ) . flatten . uniq . sort { |x , y | x . name <=> y . name }
23-
23+
2424 # Get the current user's org
2525 @default_org = current_user . org if @orgs . include? ( current_user . org )
26-
26+
2727 respond_to :html
2828 end
2929
@@ -32,48 +32,48 @@ def new
3232 def create
3333 @plan = Plan . new
3434 authorize @plan
35-
35+
3636 @plan . principal_investigator = current_user . surname . blank? ? nil : "#{ current_user . firstname } #{ current_user . surname } "
3737 @plan . data_contact = current_user . email
3838 @plan . funder_name = plan_params [ :funder_name ]
39-
39+
4040 # If a template hasn't been identified look for the available templates
4141 if plan_params [ :template_id ] . blank?
4242 template_options ( plan_params [ :org_id ] , plan_params [ :funder_id ] )
4343
4444 # Return the 'Select a template' section
4545 respond_to do |format |
46- format . js { }
46+ format . js { }
4747 end
48-
48+
4949 # Otherwise create the plan
5050 else
5151 @plan . template = Template . find ( plan_params [ :template_id ] )
52-
52+
5353 if plan_params [ :title ] . blank?
54- @plan . title = current_user . firstname . blank? ? _ ( 'My Plan' ) + '(' + @plan . template . title + ')' :
54+ @plan . title = current_user . firstname . blank? ? _ ( 'My Plan' ) + '(' + @plan . template . title + ')' :
5555 current_user . firstname + "'s" + _ ( " Plan" )
5656 else
5757 @plan . title = plan_params [ :title ]
5858 end
59-
59+
6060 if @plan . save
6161 @plan . assign_creator ( current_user )
62-
62+
6363 # pre-select org's guidance
64- ggs = GuidanceGroup . where ( org_id : plan_params [ :org_id ] ,
65- optional_subset : false ,
64+ ggs = GuidanceGroup . where ( org_id : plan_params [ :org_id ] ,
65+ optional_subset : false ,
6666 published : true )
67- if !ggs . blank? then @plan . guidance_groups << ggs end
68-
67+ if !ggs . blank? then @plan . guidance_groups << ggs end
68+
6969 default = Template . find_by ( is_default : true )
70-
70+
7171 msg = "#{ _ ( 'Plan was successfully created.' ) } "
72-
72+
7373 if !default . nil? && default == @plan . template
7474 # We used the generic/default template
7575 msg += _ ( 'This plan is based on the default template.' )
76-
76+
7777 elsif !@plan . template . customization_of . nil?
7878 # We used a customized version of the the funder template
7979 msg += "#{ _ ( 'This plan is based on the' ) } #{ plan_params [ :funder_name ] } #{ _ ( 'template with customisations by the' ) } #{ plan_params [ :org_name ] } "
@@ -82,9 +82,9 @@ def create
8282 # We used the specified org's or funder's template
8383 msg += "#{ _ ( 'This plan is based on the' ) } #{ @plan . template . org . name } template."
8484 end
85-
85+
8686 flash [ :notice ] = msg
87-
87+
8888 respond_to do |format |
8989 format . js { render js : "window.location='#{ plan_url ( @plan ) } ?editing=true'" }
9090 end
@@ -93,7 +93,7 @@ def create
9393 # Something went wrong so report the issue to the user
9494 flash [ :notice ] = failed_create_error ( @plan , 'Plan' )
9595 respond_to do |format |
96- format . js { }
96+ format . js { }
9797 end
9898 end
9999 end
@@ -115,8 +115,8 @@ def show
115115 @important_ggs = [ ]
116116 @important_ggs << [ current_user . org , @all_ggs_grouped_by_org . delete ( current_user . org ) ]
117117 @all_ggs_grouped_by_org . each do |org , ggs |
118- if org . organisation?
119- @important_ggs << [ org , ggs ]
118+ if org . organisation?
119+ @important_ggs << [ org , ggs ]
120120 @all_ggs_grouped_by_org . delete ( org )
121121 end
122122 end
@@ -226,96 +226,6 @@ def status
226226 end
227227 end
228228
229-
230- # TODO: Remove these endpoints now that we're no longer using them
231- =begin
232- def section_answers
233- @plan = Plan.find(params[:id])
234- authorize @plan
235- respond_to do |format|
236- format.json { render json: @plan.section_answers(params[:section_id]) }
237- end
238- end
239-
240- def locked
241- @plan = Plan.find(params[:id])
242- authorize @plan
243- if [email protected] ? && user_signed_in? && @plan.readable_by(current_user.id) then 244- respond_to do |format|
245- format.json { render json: @plan.locked(params[:section_id],current_user.id) }
246- end
247- else
248- render(:file => File.join(Rails.root, 'public/403.html'), :status => 403, :layout => false)
249- end
250- end
251-
252- def delete_recent_locks
253- @plan = Plan.find(params[:id])
254- authorize @plan
255- if user_signed_in? && @plan.editable_by(current_user.id) then
256- respond_to do |format|
257- if @plan.delete_recent_locks(current_user.id)
258- format.html { render action: "edit" }
259- else
260- format.html { render action: "edit" }
261- end
262- end
263- else
264- render(:file => File.join(Rails.root, 'public/403.html'), :status => 403, :layout => false)
265- end
266- end
267-
268- def unlock_all_sections
269- @plan = Plan.find(params[:id])
270- authorize @plan
271- if user_signed_in? && @plan.editable_by(current_user.id) then
272- respond_to do |format|
273- if @plan.unlock_all_sections(current_user.id)
274- format.html { render action: "edit" }
275- else
276- format.html { render action: "edit" }
277- end
278- end
279- else
280- render(:file => File.join(Rails.root, 'public/403.html'), :status => 403, :layout => false)
281- end
282- end
283-
284- def lock_section
285- @plan = Plan.find(params[:id])
286- authorize @plan
287- if user_signed_in? && @plan.editable_by(current_user.id) then
288- respond_to do |format|
289- if @plan.lock_section(params[:section_id], current_user.id)
290- format.html { render action: "edit" }
291- else
292- format.html { render action: "edit" }
293- format.json { render json: @plan.errors, status: :unprocessable_entity }
294- end
295- end
296- else
297- render(:file => File.join(Rails.root, 'public/403.html'), :status => 403, :layout => false)
298- end
299- end
300-
301- def unlock_section
302- @plan = Plan.find(params[:id])
303- authorize @plan
304- if user_signed_in? && @plan.editable_by(current_user.id) then
305- respond_to do |format|
306- if @plan.unlock_section(params[:section_id], current_user.id)
307- format.html { render action: "edit" }
308-
309- else
310- format.html { render action: "edit" }
311- end
312- end
313- else
314- render(:file => File.join(Rails.root, 'public/403.html'), :status => 403, :layout => false)
315- end
316- end
317- =end
318-
319229 def answer
320230 @plan = Plan . find ( params [ :id ] )
321231 authorize @plan
@@ -388,7 +298,7 @@ def export
388298
389299 private
390300
391- def plan_params
301+ def plan_params
392302 params . require ( :plan ) . permit ( :org_id , :org_name , :funder_id , :funder_name , :template_id , :title )
393303 end
394304
@@ -459,7 +369,7 @@ def rollup(plan, src_plan_key, super_id, obj_plan_key)
459369 # --------------------------------------------------------------------------
460370 def template_options ( org_id , funder_id )
461371 @templates = [ ]
462-
372+
463373 if !org_id . blank? || !funder_id . blank?
464374 if funder_id . blank?
465375 # Load the org's template(s)
@@ -468,15 +378,15 @@ def template_options(org_id, funder_id)
468378 @templates = Template . valid . where ( published : true , org : org , customization_of : nil ) . to_a
469379 @msg = _ ( "We found multiple DMP templates corresponding to the research organisation." ) if @templates . count > 1
470380 end
471-
381+
472382 else
473383 funder = Org . find ( funder_id )
474384 # Load the funder's template(s)
475385 @templates = Template . valid . where ( published : true , org : funder ) . to_a
476-
386+
477387 unless org_id . blank?
478388 org = Org . find ( org_id )
479-
389+
480390 # Swap out any organisational cusotmizations of a funder template
481391 @templates . each do |tmplt |
482392 customization = Template . valid . find_by ( published : true , org : org , customization_of : tmplt . dmptemplate_id )
@@ -486,17 +396,17 @@ def template_options(org_id, funder_id)
486396 end
487397 end
488398 end
489-
399+
490400 msg = _ ( "We found multiple DMP templates corresponding to the funder." ) if @templates . count > 1
491401 end
492402 end
493-
403+
494404 # If no templates were available use the generic templates
495405 if @templates . empty?
496406 @msg = _ ( "Using the generic Data Management Plan" )
497407 @templates << Template . find_by ( is_default : true )
498408 end
499-
409+
500410 @templates = @templates . sort { |x , y | x . title <=> y . title } if @templates . count > 1
501411 end
502412
0 commit comments