load( local!isNew:if(rule!APN_isEmpty(ri!pl_REGION),true(),false()), local!EID:rule!pl_getSequence().EID, local!region:rule!pl_getCountriesByIsRegion(IS_COUNTRY:"N"), local!countries:rule!pl_getCountriesByIsRegion(IS_COUNTRY:"Y"), local!unassignedCountries:rule!pl_getRegionByParentEREF("99.PU"), local!memberCountries:rule!pl_getRegionByParentEREF(ri!pl_REGION.REGION_EID), local!thisRegion:rule!pl_q_getRegionByEID(ri!REGION_EID), local!regionLabel:"Test", local!itemsToken, local!region_EID:"99.PULSE", local!regions:rule!pl_getCountriesByIsRegion(IS_REGION:"Y"), local!items: if( local!isNew, { 'type!{http://pu-dev.nu.intra/suite/types/}pl_REGION'( REGION_EID:local!EID, IS_CLUSTER:"Y" ) }, local!thisRegion ), local!associatedItemCount:count({local!memberCountries}), local!initialItemCount:if(local!isNew,0,count({local!items})), a!formLayout( label:if(local!isNew, "Create New DRA Business ", "Modify DRA Business "), firstColumnContents:{ a!textField( label: "Name", value: local!region.NAME, required: true, saveInto: { local!region.NAME, }, validations: { if(fn!lenb(local!region.NAME)>256, "Maximum length is 255 characters", "" ), if(rule!APN_isBlank(local!region.NAME), "", if(not(rule!pl_isDuplicateRegionField("NAME",local!region.NAME,local!region,local!region.REGION_EID)), "", "DRA Business " & lower(local!regionLabel) & " name already exists" ) ) } ), if( local!isNew, a!sectionLayout( label: local!regionLabel & " Membership", firstColumnContents: { a!gridLayout( label:"Countries", headerCells: { a!gridLayoutHeaderCell(label: "Countries"), a!gridLayoutHeaderCell(label: ""), }, columnConfigs: { a!gridLayoutColumnConfig(width: "DISTRIBUTE", align: "RIGHT"), a!gridLayoutColumnConfig(width: "NARROW"), }, rows: a!applyComponents( function: rule!Sprint7_RegionEdit_ItemRowEach ( items: local!membercountries, initialItemCount:local!initialItemCount, index: _, itemsToken: local!itemsToken, /*regions: if(ri!isCluster,local!membercountries,local!unallocatedCountriesAndClusters),*/ PARENT_EREF:ri!REGION_EID, associatedCountries:true(), readOnly:false() ), array: if(or(isnull(local!membercountries), count(local!membercountries)<1), {}, 1+enumerate(count(local!membercountries)) ), arrayVariable: local!itemsToken ) ), a!linkField( label: "Add Link", labelPosition: "COLLAPSED", links: a!dynamicLink( label: "+Add new", value: 'type!{http://pu.nv.intra/suite/types/}pl_REGION'( REGION_EID:rule!pl_getSequence().EID, IS_CLUSTER: "Y"), saveInto: { a!save(local!items, append(local!items, save!value)), a!save(local!itemsToken, append(local!itemsToken, save!value)) } ) ) } ), {} /* a!sectionLayout( label:local!regionLabel & " Membership", firstColumnContents: { a!gridLayout( label:"Countries", headerCells: { a!gridLayoutHeaderCell(label: "Countries"), a!gridLayoutHeaderCell(label: ""), }, columnConfigs: { a!gridLayoutColumnConfig(width: "DISTRIBUTE", align: "RIGHT"), a!gridLayoutColumnConfig(width: "NARROW"), }, rows: a!applyComponents( function: rule!Sprint7_RegionEdit_ItemRowEach ( items: local!membercountries, initialItemCount:local!initialItemCount, index: _, itemsToken: local!itemsToken, PARENT_EREF:ri!REGION_EID, associatedCountries:true(), readOnly:false() ), array: if(or(isnull(local!membercountries), count(local!membercountries)<1), {}, 1+enumerate(count(local!membercountries)) ), arrayVariable: local!itemsToken ) ) } )*/ ), buttons: a!buttonLayout( primaryButtons: { if( not(local!isNew), rule!pl_b_delete(ri!action, "Are you sure you want to delete this Region? This cannot be undone."), {} ), a!buttonWidgetSubmit( label:"Submit", style: "PRIMARY", value:local!items, saveInto: a!save(ri!pl_REGION,save!value), confirmMessage: null ) }, secondaryButtons: { rule!pl_b_cancel(ri!action) } ) } ) )