load( local!regProjectCountries:rule!pl_getVRegulatoryProjectByRegulatoryProjectEID(ri!REGULATORY_PROJECT_EID), local!staticRegProjectCountries:rule!pl_getVRegulatoryProjectByRegulatoryProjectEID(ri!REGULATORY_PROJECT_EID), local!globalActionCountries:rule!pl_q_getGlobalActionCountryByGlobalActionEREF(ri!GLOBAL_ACTION_EID), local!noAvailableCountries:rule!APN_isEmpty(local!regProjectCountries), local!noSelections:rule!APN_isEmpty(local!globalActionCountries), local!availableCountryEREFs:if(local!noSelections,local!regProjectCountries.REGION_EREF,difference(local!regProjectCountries.REGION_EREF,local!globalActionCountries.REGION_EREF)), local!availableCountries:index(local!regProjectCountries,wherecontains(local!availableCountryEREFs,local!regProjectCountries.REGION_EREF),local!regProjectCountries), local!availableCountriesToken, local!selectedCountryIndexes, local!selectedCountryEIDs, local!disableRegionRemovalForEREFs:rule!pl_returnRegionErefsWithDependencies(ri!GLOBAL_ACTION_EID), local!selectedCountryNames, local!removeSelectedIndexes, local!showTestData: false(), local!showReadOnly:true(), local!refCountries: rule!pl_getRefAllActiveCountries(), local!addedCountries, local!removedCountries, with( local!disableIndexes:wherecontains(local!disableRegionRemovalForEREFs,local!selectedCountryEIDs), local!nullSelections:rule!APN_isEmpty(local!selectedCountryEIDs), {/*group sections*/ if(local!showReadOnly, a!sectionLayout( label: "Global Action Countries "&rule!pl_displayCount(local!globalActionCountries), isCollapsible: true(), firstColumnContents: { a!buttonLayout( secondaryButtons: { a!buttonWidget( label: "Update Global Action Countries", disabled: rule!APN_isEmpty(local!regProjectCountries), saveInto: {a!save(local!showReadOnly,false())} ) } ), a!pickerFieldCustom( readOnly:true(), selectedLabels: if(rule!APN_isEmpty(local!globalActionCountries.REGION_EREF),null, rule!ucArrayPickerGetLabelForIdentifier( identifier: local!globalActionCountries.REGION_EREF, labels: local!refCountries.NAME, identifiers: local!refCountries.REGION_EID) ), value: local!globalActionCountries.REGION_EREF, saveInto: {local!globalActionCountries} ) } ), a!sectionLayout( label: "Global Action Countries", isCollapsible: true(), firstColumnContents: { a!multipleDropdownFieldByIndex( label: "Available Countries "&rule!pl_displayCount(local!availableCountries), instructions: if(local!showTestData, local!selectedCountryIndexes, ""), choiceLabels: index(local!availableCountries, "REGION_NAME", {}), choiceValues: index(local!availableCountries, "REGION_EREF", {}), disabled:rule!APN_isEmpty(local!availableCountries), value:local!selectedCountryIndexes, saveInto: { local!selectedCountryIndexes, a!save( local!selectedCountryEIDs, append( local!selectedCountryEIDs, index(local!availableCountries.REGION_EREF,local!selectedCountryIndexes,{}) ) ), a!save( local!selectedCountryNames, append( local!selectedCountryNames, index(local!availableCountries.REGION_NAME,local!selectedCountryIndexes,{}) ) ), a!save(local!availableCountries,remove(local!availableCountries,local!selectedCountryIndexes)), a!save(local!availableCountriesToken,remove(local!availableCountriesToken,local!selectedCountryIndexes)), a!save(local!addedCountries, rule!pl_buildMultipleGlobalActionCountryCDTs( REGION_EREFS:local!selectedCountryEIDs, GLOBAL_ACTION_EREF:ri!GLOBAL_ACTION_EID, X_CREATE_PERSON:loggedInUser())), a!save(ri!addedCountries, local!addedCountries), a!save(local!selectedCountryIndexes,null) } ), a!buttonLayout( primaryButtons: { a!buttonWidget( label: ">> Add All ", disabled: rule!APN_isEmpty(local!availableCountries), value: "Add all available", saveInto: { a!save( local!selectedCountryEIDs, append(local!selectedCountryEIDs,local!availableCountries.REGION_EREF) ), a!save( local!selectedCountryNames, append(local!selectedCountryNames,local!availableCountries.REGION_NAME) ), a!save(local!availableCountries,{}), a!save(local!availableCountriesToken,{}), a!save(local!addedCountries, rule!pl_buildMultipleGlobalActionCountryCDTs( REGION_EREFS:local!selectedCountryEIDs, GLOBAL_ACTION_EREF:ri!GLOBAL_ACTION_EID, X_CREATE_PERSON:loggedInUser())), a!save(ri!addedCountries, local!addedCountries), } ) } ) }, secondColumnContents: { a!multipleDropdownFieldByIndex( label: "Global Action Countries "&rule!pl_displayCount(local!selectedCountryNames), choiceLabels: local!selectedCountryNames, choiceValues: local!selectedCountryEIDs, /* choiceLabels: index(local!regProjectCountries, "REGION_NAME", {}), choiceValues: index(local!regProjectCountries, "REGION_EREF", {}),*/ value:local!removeSelectedIndexes, saveInto: { a!save( local!removeSelectedIndexes, if( rule!APN_isEmpty(local!disableIndexes), save!value, difference(save!value,local!disableIndexes) ) ), a!save( local!availableCountries, append( local!availableCountries, index(local!staticRegProjectCountries,wherecontains(local!selectedCountryEIDs,local!staticRegProjectCountries.REGION_EREF),{}) ) ), a!save(local!selectedCountryNames,remove(local!selectedCountryNames,local!removeSelectedIndexes)), a!save(local!selectedCountryEIDs,remove(local!selectedCountryEIDs,local!removeSelectedIndexes)), a!save(local!addedCountries, rule!pl_buildMultipleGlobalActionCountryCDTs( REGION_EREFS:local!selectedCountryEIDs, GLOBAL_ACTION_EREF:ri!GLOBAL_ACTION_EID, X_CREATE_PERSON:loggedInUser())), a!save(ri!addedCountries, local!addedCountries), a!save(local!removedCountries, if(rule!APN_isEmpty(local!selectedCountryEIDs), local!globalActionCountries.REGION_EREF, difference(local!globalActionCountries.REGION_EREF,local!selectedCountryEIDs))), a!save(ri!deleteGlobalActionCountryEIDs,index(local!removedCountries,"GLOBAL_ACTION_COUNTRY_EID",{})), a!save(local!removeSelectedIndexes,null) } ), a!buttonLayout( secondaryButtons: { a!buttonWidget( label: "<< Remove All", saveInto: { a!save( local!availableCountries, append( local!availableCountries, index(local!staticRegProjectCountries, wherecontains(local!selectedCountryEIDs,local!staticRegProjectCountries.REGION_EREF),{}) ) ), a!save(local!selectedCountryNames,{}), a!save(local!selectedCountryEIDs,null), a!save(local!addedCountries, rule!pl_buildMultipleGlobalActionCountryCDTs( REGION_EREFS:local!selectedCountryEIDs, GLOBAL_ACTION_EREF:ri!GLOBAL_ACTION_EID, X_CREATE_PERSON:loggedInUser())), a!save(ri!addedCountries, local!addedCountries), a!save(local!removedCountries, if(rule!APN_isEmpty(local!selectedCountryEIDs), local!globalActionCountries.REGION_EREF, difference(local!globalActionCountries.REGION_EREF,local!selectedCountryEIDs))), a!save(ri!deleteGlobalActionCountryEIDs,index(local!removedCountries,"GLOBAL_ACTION_COUNTRY_EID",{})) } ) } ) } ) ), if(local!showTestData, a!sectionLayout( label:"test data", isCollapsible:true(), firstColumnContents:{ a!textField( readOnly:true(), value:"ri!GLOBAL_ACTION_EID"&ri!GLOBAL_ACTION_EID, label:local!regProjectCountries[1], instructions:"local!globalActionCountries-"&local!globalActionCountries.GLOBAL_ACTION_EREF ), a!textField( readOnly:true(), label:"local!selectedCountryIndexes "&local!selectedCountryIndexes, value:"local!selectedCountryEIDs"&local!selectedCountryEIDs, instructions:"local!selectedCountryNames-"&local!selectedCountryNames ), a!textField( readOnly:true(), label:"local!removedCountries-"&local!removedCountries, instructions:"local!addedCountries-"&local!addedCountries ), a!textField( readOnly:true(), label:"ri!addedCountries-"&ri!addedCountries ) } ), {} ) }/*group sections*/ ) )