Created
March 31, 2017 09:03
-
-
Save Sunil02kumar/7fa6b00960e005c560c2a24a7352ace0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<aura:component controller="SkRecordTypeSelectionController"> | |
<aura:attribute name="objType" type="String" required="true" default="Opportunity"/> | |
<aura:attribute name="selectedRecordType" type="String"/> | |
<aura:attribute name="recordTypeList" type="Object[]"/> | |
<aura:handler name="init" action="{!c.doInit}" value="{!this}" /> | |
<div role="dialog" tabindex="-1" class="slds-modal slds-fade-in-open"> | |
<div class="slds-modal__container"> | |
<div class="slds-modal__header"> | |
<lightning:buttonIcon class="slds-modal__close" iconName="utility:close" size="large" | |
variant="bare-inverse" alternativeText="Close" onclick="{!c.defaultCloseAction}" /> | |
<h2 id="header43" class="slds-text-heading--medium">Please select record Type</h2> | |
</div> | |
<div class="slds-modal__content slds-p-around--medium"> | |
<div class="slds-align--absolute-center"> | |
<div class="slds-p-top--small slds-p-bottom--small" > | |
<fieldset class="slds-form-element"> | |
<div class="slds-form-element__control"> | |
<aura:iteration items="{!v.recordTypeList}" var="item"> | |
<label class="slds-radio slds-p-top--small"> | |
<tr> | |
<td> | |
<ui:inputRadio name="benefits" change="{!c.onChange}" text="{!item.recordTypeId}" value="true"/> | |
<span class="slds-radio--faux"></span> | |
</td> | |
<td> | |
<span class="slds-form-element__label">{!item.recordTypeLabel}</span> | |
</td> | |
</tr> | |
</label> | |
</aura:iteration> | |
</div> | |
</fieldset> | |
</div> | |
</div> | |
</div> | |
<div class="slds-modal__footer"> | |
<lightning:button label="Cancel" variant="neutral" onclick="{!c.defaultCloseAction}"/> | |
<lightning:button label="Continue" variant="brand" onclick="{!c.onconfirm}"/> | |
</div> | |
</div> | |
</div> | |
<div class="slds-backdrop slds-backdrop--open"></div> | |
</aura:component> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
({ | |
doInit : function(component,event,helper){ | |
// alert('do init get called'); | |
helper.callToServer( | |
component, | |
"c.findRecordTypes", | |
function(response) { | |
//alert(JSON.parse(response)); | |
var jsonObject=JSON.parse(response); | |
component.set('v.recordTypeList',jsonObject); | |
component.set('v.selectedRecordType',jsonObject[0].recordTypeId); | |
}, | |
{objName: component.get('v.objType')} | |
); | |
}, | |
onChange : function(component, event, helper) { | |
var value = event.getSource().get("v.text"); | |
component.set('v.selectedRecordType', value); | |
}, | |
defaultCloseAction : function(component, event, helper) { | |
//$A.util.addClass(component, "hideModal"); | |
$A.util.addClass(component, "slds-hide"); | |
}, | |
onconfirm : function(component, event, helper){ | |
//alert('confirm get called'); | |
var selectedRecType=component.get('v.selectedRecordType'); | |
alert('selected recordtype:'+selectedRecType); | |
} | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
({ | |
callToServer : function(component, method, callback, params) { | |
//alert('Calling helper callToServer function'); | |
var action = component.get(method); | |
if(params){ | |
action.setParams(params); | |
} | |
//alert(JSON.stringify(params)); | |
action.setCallback(this, function(response) { | |
var state = response.getState(); | |
if (state === "SUCCESS") { | |
//alert('Processed successfully at server'); | |
callback.call(this,response.getReturnValue()); | |
}else if(state === "ERROR"){ | |
alert('Problem with connection. Please try again.'); | |
} | |
}); | |
$A.enqueueAction(action); | |
} | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public with sharing class SkRecordTypeSelectionController { | |
@AuraEnabled | |
public static string findRecordTypes(string objName){ | |
string returnString=''; | |
string queryString='Select id, name from RecordType where sobjectType =: objName and IsActive=true'; | |
List<sobject> recordList= Database.query(queryString); | |
List<RecordTypeWrapper> wrapperList=new List<RecordTypeWrapper>(); | |
for(sobject sb : recordList) { | |
RecordTypeWrapper rw=new RecordTypeWrapper(); | |
rw.recordTypeLabel=string.valueof(sb.get('name')); | |
rw.recordTypeId=string.valueof(sb.get('id')); | |
wrapperList.add(rw); | |
} | |
returnString= JSON.serialize(wrapperList); | |
system.debug('*****'+returnString); | |
return returnString; | |
} | |
public class RecordTypeWrapper{ | |
public string recordTypeLabel{get;set;} | |
public string recordTypeId{get;set;} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<aura:application extends="force:slds"> | |
<c:SkDemoRecordtTypeSelector objType="Opportunity"/> | |
</aura:application> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment