Add a new line following the last <aura:attribute>
on line 4 and paste:
<aura:attribute name="property" type="Property__c" />
<aura:attribute name="remoteRecordId" type="Id" />
<aura:attribute name="showDialog" type="String" default="false" />
Make another new line below the <aura:handler>
tag (currently line 8, if your line numbers match) and add:
<force:recordPreview aura:id="propertyService"
recordId="{!v.recordId}"
targetRecord="{!v.property}"
recordUpdated="{!c.doSearch}"
layoutType="FULL" />
Paste the following into the helper:
({
getProps : function(component) {
var recId = component.get("v.recordId");
var compValue = component.get("v.searchCriteria");
var action = component.get("c.getSimilarProperties");
action.setParams({
recordId: recId,
searchCriteria: compValue
});
action.setCallback(this, function(response){
var res = response.getReturnValue();
component.set("v.similarProperties", res);
});
$A.enqueueAction(action);
}
})
Replace the contents with:
({
doInit : function(component, event, helper) {
helper.getProps(component);
},
doSearch : function (component, event, helper) {
helper.getProps(component);
}
})
Replace the contents of the SimilarProperty.cmp file with:
<aura:component implements="force:hasRecordId" access="global">
<aura:attribute name="propertyId" type="Id" />
<aura:attribute name="selectedProperty" type="Property__c" />
<aura:attribute name="showDialog" type="String" />
<aura:attribute name="remoteRecordId" type="Id" />
<force:recordPreview aura:id="propertyRecord"
recordId="{!v.propertyId}"
targetRecord="{!v.selectedProperty}"
layoutType="FULL" />
<div class="slds-media">
<div class="slds-media__figure">
<img src="{!v.selectedProperty.Thumbnail__c}" class="slds-avatar--large slds-avatar--circle" alt="{!v.selectedProperty.Title_c}" />
</div>
<div class="slds-media__body">
<div class="slds-grid">
<a data-record="{!v.selectedProperty.Id}" onclick="{!c.navToRecord}">
<h3 class="slds-text-heading--small slds-m-bottom--xx-small">{!v.selectedProperty.Name}</h3>
</a>
<lightning:buttonIcon iconName="utility:edit" class="slds-col--bump-left" variant="bare" alternativeText="Edit Record" onclick="{!c.editMini}" value="{!v.selectedProperty.Id}" />
</div>
<div class="slds-m-top--small">
<ul class="slds-grid slds-wrap">
<li class="slds-list__item slds-size--1-of-2"><span class="slds-text-color--weak slds-m-right--small">Beds:</span> {!v.selectedProperty.Beds__c}</li>
<li class="slds-list__item slds-size--1-of-2"><span class="slds-text-color--weak slds-m-right--small">Baths:</span> {!v.selectedProperty.Baths__c}</li>
<li class="slds-list__item slds-size--1-of-2"><span class="slds-text-color--weak slds-m-right--small">Price:</span> {!v.selectedProperty.Price__c}</li>
<li class="slds-list__item slds-size--1-of-2"><span class="slds-text-color--weak slds-m-right--small">Status:</span> {!v.selectedProperty.Status__c}</li>
</ul>
</div>
</div>
</div>
</aura:component>
Replace the contents with:
({
editMini : function(component, event, helper) {
var recId = component.get("v.propertyId");
component.set("v.remoteRecordId", recId);
component.set("v.showDialog", "true");
},
navToRecord : function (component, event, helper) {
var selectedItem = event.currentTarget;
var recId = selectedItem.dataset.record;
var navEvt = $A.get("e.force:navigateToSObject");
navEvt.setParams({
"recordId": recId
});
navEvt.fire();
}
})
Replace the contents of <li class="slds-list__item">
with:
<c:SimilarProperty propertyId="{!item.Id}" selectedProperty="{!item}" remoteRecordId="{!v.remoteRecordId}" showDialog="{!v.showDialog}" />
Replace the contents of the file with:
<aura:component >
<aura:attribute name="showDialog" type="String" default="false" />
<aura:attribute name="remoteRecordId" type="Id" />
<aura:attribute name="selectedProperty" type="Property__c" />
<aura:handler name="change" value="{!v.showDialog}" action="{!c.toggleDialog}" />
<aura:handler name="change" value="{!v.remoteRecordId}" action="{!c.getRecord}" />
<force:recordPreview aura:id="editRecord"
targetRecord="{!v.selectedProperty}"
fields="Id,Name,Beds__c,Baths__c,Price__c,Status__c"
mode="EDIT" />
<div aura:id="editDialog" role="dialog" tabindex="-1" aria-labelledby="header43" class="slds-modal">
<div class="slds-modal__container">
<div class="slds-modal__header">
<button class="slds-button slds-modal__close " title="Close" onclick="{!c.toggleDialog}">
<lightning:icon iconName="utility:close" variant="bare" ></lightning:icon>
<span class="slds-assistive-text">Close</span>
</button>
<h2 id="header43" class="slds-text-heading--medium">Edit Record</h2>
</div>
<div class="slds-modal__content slds-p-around--medium slds-grid slds-wrap slds-grid--align-spread">
<lightning:input aura:id="propName" name="propName" label="Property Name" required="true" value="{!v.selectedProperty.Name}" class="slds-size--1-of-1 slds-p-horizontal--x-small" />
<lightning:input aura:id="propBeds" name="propBeds" label="Beds" value="{!v.selectedProperty.Beds__c}" class="slds-size--1-of-2 slds-p-horizontal--x-small" />
<lightning:input aura:id="propBaths" name="propBaths" label="Baths" value="{!v.selectedProperty.Baths__c}" class="slds-size--1-of-2 slds-p-horizontal--x-small" />
<lightning:input aura:id="propPrice" name="propPrice" label="Price" value="{!v.selectedProperty.Price__c}" class="slds-size--1-of-2 slds-p-horizontal--x-small" />
<lightning:input aura:id="propStatus" name="propStatus" label="Status" value="{!v.selectedProperty.Status__c}" class="slds-size--1-of-2 slds-p-horizontal--x-small" />
</div>
<div class="slds-modal__footer">
<button class="slds-button slds-button--neutral" onclick="{!c.toggleDialog}">Cancel</button>
<button class="slds-button slds-button--brand" onclick="{!c.saveRecord}">Save</button>
</div>
</div>
</div>
<div aura:id="overlay" class="slds-backdrop"></div>
</aura:component>
Replace the contents with the following:
({
getRecord : function(component) {
var tempRec = component.find("editRecord");
tempRec.set("v.recordId", component.get("v.remoteRecordId"));
tempRec.reloadRecord();
},
toggleDialog : function(component, event, helper) {
helper.showHideModal(component);
},
saveRecord : function(component,event,helper) {
var tempRec = component.find("editRecord");
tempRec.saveRecord($A.getCallback(function(result){
console.log(result.state);
var event = $A.get("e.c:recordUpdated");
event.fire();
}));
helper.showHideModal(component);
}
})
Replace the contents with:
({
showHideModal : function(component) {
var modal = component.find("editDialog");
$A.util.toggleClass(modal, 'slds-fade-in-open');
var overlay = component.find("overlay");
$A.util.toggleClass(overlay, 'slds-backdrop--open');
component.set("v.showDialog", "false");
}
})
Replace the line <aura:handler event="force:refreshView" action="{!c.doInit}" />
with the following:
<aura:handler event="c:recordUpdated" action="{!c.doSearch}"/>
Add a new line just before the closing </lightning:card>
(probably line 25) and paste the following:
<c:SimilarPropertyEdit showDialog="{!v.showDialog}" remoteRecordId="{!v.remoteRecordId}" />
Not working as expected? The final implementation of the components for this exercise are available here:
SimilarPropertyEdit Component
SimilarPropertyEdit.cmp, SimilarPropertyEditController.js, SimilarPropertyEditHelper.js
SimilarProperty Component
SimilarProperty.cmp, SimilarPropertyController.js
SimilarProperties Component
SimilarProperties.cmp, SimilarPropertiesController.js, SimilarPropertiesHelper.js
Feel free to check it out or cut and paste it in your own component.