@@ -70,6 +70,29 @@ def form_action
7070 end
7171 end
7272
73+ def form_options
74+ {
75+ scope : :meeting ,
76+ model : @meeting ,
77+ method : form_method ,
78+ data : {
79+ turbo : true ,
80+ controller : [
81+ "show-when-value-selected" ,
82+ "show-when-checked" ,
83+ @meeting . is_a? ( RecurringMeeting ) ? "recurring-meetings--form" : nil ,
84+ "meetings--form" ,
85+ use_refresh_on_form_changes? ? "refresh-on-form-changes" : nil
86+ ] . compact . join ( " " ) ,
87+ "recurring-meetings--form-persisted-value" : @meeting . persisted? ,
88+ "refresh-on-form-changes-target" : "form" ,
89+ "refresh-on-form-changes-turbo-stream-url-value" : fetch_templates_url
90+ } ,
91+ html : { id : "meeting-form" } ,
92+ url : { controller : form_controller , action : form_action , project_id : @project }
93+ }
94+ end
95+
7396 def creating_onetime_meeting?
7497 return false unless EnterpriseToken . allows_to? ( :meeting_templates )
7598
@@ -80,10 +103,56 @@ def no_preselection?
80103 !@copy_from
81104 end
82105
106+ def show_template_selector?
107+ return false unless creating_onetime_meeting? && no_preselection?
108+
109+ if @project . nil?
110+ # Global context - show if user can see any templates
111+ globally_visible_templates . any?
112+ else
113+ # Project context - only show if the project actually has templates
114+ available_templates . any?
115+ end
116+ end
117+
118+ def template_selector_disabled?
119+ effective_project . nil? || available_templates . empty?
120+ end
121+
122+ def template_selector_placeholder
123+ if effective_project . nil?
124+ I18n . t ( :placeholder_meeting_template_select_project_first )
125+ elsif available_templates . empty?
126+ I18n . t ( :placeholder_meeting_template_no_templates_for_project )
127+ end
128+ end
129+
130+ def use_refresh_on_form_changes?
131+ creating_onetime_meeting? && no_preselection? && @project . nil?
132+ end
133+
134+ def fetch_templates_url
135+ if @project
136+ fetch_templates_project_meetings_path ( @project )
137+ else
138+ fetch_templates_meetings_path
139+ end
140+ end
141+
83142 def available_templates
84- return [ ] unless @project
143+ @available_templates ||= if effective_project
144+ Meeting . templates_visible_in_project ( effective_project )
145+ else
146+ Meeting . templates_visible_globally
147+ end
148+ end
149+
150+ def globally_visible_templates
151+ @globally_visible_templates ||= Meeting . templates_visible_globally
152+ end
85153
86- @available_templates ||= Meeting . templates_visible_in_project ( @project )
154+ def effective_project
155+ @project || @meeting . project
87156 end
88157 end
89158end
0 commit comments