3232 AppManagerException ,
3333 FormNotFoundException ,
3434)
35- from corehq .apps .app_manager .models import ModuleNotFoundException
35+ from corehq .apps .app_manager .helpers .validators import load_case_reserved_words
36+ from corehq .apps .app_manager .models import ModuleNotFoundException , AdvancedForm
3637from corehq .apps .app_manager .templatetags .xforms_extras import translate
3738from corehq .apps .app_manager .util import (
3839 app_callout_templates ,
4950 set_lang_cookie ,
5051)
5152from corehq .apps .cloudcare .utils import should_show_preview_app
53+ from corehq .apps .data_dictionary .util import get_case_properties
5254from corehq .apps .domain .decorators import track_domain_request
5355from corehq .apps .fixtures .fixturegenerators import item_lists_by_domain
5456from corehq .apps .users .permissions import SUBMISSION_HISTORY_PERMISSION , has_permission_to_view_report
@@ -147,7 +149,7 @@ def _get_form_designer_view(request, domain, app, module, form):
147149
148150 vellum_options = _get_base_vellum_options (request , domain , form , context ['lang' ])
149151 vellum_options ['core' ] = _get_vellum_core_context (request , domain , app , module , form , context ['lang' ])
150- vellum_options ['plugins' ] = _get_vellum_plugins (domain , form , module )
152+ vellum_options ['plugins' ] = _get_vellum_plugins (domain , form , module , vellum_options )
151153 vellum_options ['features' ] = _get_vellum_features (request , domain , app )
152154 context ['vellum_options' ] = vellum_options
153155
@@ -228,7 +230,7 @@ def _get_base_vellum_options(request, domain, form, displayLang):
228230 :param displayLang: --> derived from the base context
229231 """
230232 app = form .get_app ()
231- return {
233+ options = {
232234 'intents' : {
233235 'templates' : next (app_callout_templates ),
234236 },
@@ -248,6 +250,19 @@ def _get_base_vellum_options(request, domain, form, displayLang):
248250 },
249251 }
250252
253+ has_vellum_case_mapping = toggles .FORMBUILDER_SAVE_TO_CASE .enabled_for_request (request )
254+ is_advanced_form = isinstance (form , AdvancedForm )
255+ case_type = form .get_module ().case_type
256+ if case_type and has_vellum_case_mapping and not is_advanced_form :
257+ options ['caseManagement' ] = {
258+ 'mappings' : form .actions .get_mappings (),
259+ 'properties' : sorted (get_case_properties (domain , case_type ).values_list ('name' , flat = True )),
260+ 'view_form_url' : reverse ('view_form' , args = [domain , app .id , form .unique_id ]),
261+ 'reserved_words' : load_case_reserved_words (),
262+ }
263+
264+ return options
265+
251266
252267def _get_vellum_core_context (request , domain , app , module , form , lang ):
253268 """
@@ -291,7 +306,7 @@ def _get_vellum_core_context(request, domain, app, module, form, lang):
291306 return core
292307
293308
294- def _get_vellum_plugins (domain , form , module ):
309+ def _get_vellum_plugins (domain , form , module , options ):
295310 """
296311 Returns a list of enabled vellum plugins based on the domain's
297312 privileges.
@@ -300,6 +315,8 @@ def _get_vellum_plugins(domain, form, module):
300315 if (toggles .COMMTRACK .enabled (domain )
301316 or toggles .NON_COMMTRACK_LEDGERS .enabled (domain )):
302317 vellum_plugins .append ("commtrack" )
318+ if "caseManagement" in options :
319+ vellum_plugins .append ("caseManagement" )
303320 if toggles .VELLUM_SAVE_TO_CASE .enabled (domain ):
304321 vellum_plugins .append ("saveToCase" )
305322 if toggles .COMMCARE_CONNECT .enabled (domain ):
0 commit comments