Created
September 18, 2017 23:21
-
-
Save pchittum/ef484fc705a301c23f914d0bf24d5693 to your computer and use it in GitHub Desktop.
PropertyDialog Stuff
This file contains 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="PicklistController"> | |
<aura:attribute name="sObjectName" type="String" /> | |
<aura:attribute name="fieldName" type="String" /> | |
<aura:attribute name="picklistValues" type="Object" /> | |
<aura:handler name="init" value="{!this}" action="{!c.doInit}" /> | |
</aura:component> |
This file contains 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) { | |
var action = component.get("c.getPickListValuesIntoList"); | |
action.setParams({ | |
objectType: component.get("v.sObjectName"), | |
selectedField: component.get("v.fieldName") | |
}); | |
action.setCallback(this, function(response) { | |
var list = response.getReturnValue(); | |
component.set("v.picklistValues", list); | |
}) | |
$A.enqueueAction(action); | |
} | |
}) |
This file contains 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 implements="lightning:actionOverride,flexipage:availableForRecordHome,force:hasRecordId"> | |
<aura:attribute name="picklistValues" type="Object" /> | |
<aura:attribute name="propertyRecord" type="Property__c" /> | |
<aura:attribute name="modalContext" type="String" default="New" /> | |
<force:recordData aura:id="forceRecord" | |
recordId="{!v.recordId}" | |
targetFields="{!v.propertyRecord}" | |
fields="Id,Name,Beds__c,Baths__c,Price__c,Status__c" | |
mode="EDIT" /> | |
<aura:handler name="init" value="{!this}" action="{!c.doInit}" /> | |
<c:PickListValues sObjectName="Property__c" fieldName="Status__c" picklistValues="{!v.picklistValues}" /> | |
<div aura:id="editDialog" role="dialog" tabindex="-1" aria-labelledby="header43" class="slds-modal slds-fade-in-open"> | |
<div class="slds-modal__container"> | |
<div class="slds-modal__header"> | |
<h2 class="slds-text-heading--medium">{!v.modalContext} Record</h2> | |
</div> | |
<div class="slds-modal__content slds-p-around--medium slds-grid slds-wrap "> | |
<lightning:input aura:id="propName" name="propName" label="Property Name" value="{!v.propertyRecord.Name}" required="true" class="slds-size--1-of-1 slds-p-horizontal_x-small" /> | |
<lightning:input aura:id="propBeds" name="propBeds" label="Beds" value="{!v.propertyRecord.Beds__c}" class="slds-size--1-of-2 slds-p-horizontal_x-small" /> | |
<lightning:input aura:id="propBaths" name="propBaths" label="Baths" value="{!v.propertyRecord.Baths__c}" class="slds-size--1-of-2 slds-p-horizontal_x-small" /> | |
<lightning:input aura:id="propPrice" name="propPrice" label="Price" value="{!v.propertyRecord.Price__c}" class="slds-size--1-of-2 slds-p-horizontal_x-small" /> | |
<lightning:select aura:id="propStatus" name="propStatus" label="Status" value="{!v.propertyRecord.Status__c}" class="slds-size--1-of-2 slds-p-horizontal_x-small"> | |
<aura:iteration items="{!v.picklistValues}" var="item"> | |
<option value="{!item}">{!item}</option> | |
</aura:iteration> | |
</lightning:select> | |
</div> | |
<div class="slds-modal__footer"> | |
<lightning:button variant="neutral" label="Cancel" onclick="{!c.cancelDialog}"/> | |
<lightning:button variant="brand" label="Submit" onclick="{!c.saveRecord}" /> | |
</div> | |
</div> | |
</div> | |
<div aura:id="overlay" class="slds-backdrop slds-backdrop--open"></div> | |
</aura:component> |
This file contains 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) { | |
var recId = component.get("v.recordId"); | |
if (recId) { | |
component.set("v.modalContext", "Edit"); | |
} | |
if (recId) { | |
component.find("forceRecord").getNewRecord( | |
"Property__c", | |
null, | |
false, | |
$A.getCallback(function() { | |
var rec = component.get("v.propertyRecord"); | |
var error = component.get("v.recordError"); | |
if (error || (rec === null)) { | |
console.log("Error initializing record template: " + error); | |
return; | |
} | |
}) | |
); | |
} | |
}, | |
saveRecord : function(component, event, helper) { | |
var propBeds = parseInt(component.find('propBeds').get("v.value"), 10); | |
var propBaths = parseInt(component.find('propBaths').get("v.value"), 10); | |
var propPrice = parseInt(component.find('propPrice').get("v.value"), 10); | |
component.set("v.propertyRecord.Name", component.find('propName').get("v.value")); | |
component.set("v.propertyRecord.Beds__c", propBeds); | |
component.set("v.propertyRecord.Baths__c", propBaths); | |
component.set("v.propertyRecord.Price__c", propPrice); | |
component.set("v.propertyRecord.Status__c", component.find('propStatus').get("v.value")); | |
var tempRec = component.find("forceRecord"); | |
tempRec.saveRecord($A.getCallback(function(result) { | |
console.log(result.state); | |
var resultsToast = $A.get("e.force:showToast"); | |
if (result.state === "SUCCESS") { | |
resultsToast.setParams({ | |
"title": "Saved", | |
"message": "The record was saved." | |
}); | |
resultsToast.fire(); | |
} else if (result.state === "ERROR") { | |
console.log('Error: ' + JSON.stringify(result.error)); | |
resultsToast.setParams({ | |
"title": "Error", | |
"message": "There was an error saving the record: " + JSON.stringify(result.error) | |
}); | |
resultsToast.fire(); | |
var recId = result.recordId; | |
helper.navigateTo(component, recId); | |
} else { | |
console.log('Unknown problem, state: ' + result.state + ', error: ' + JSON.stringify(result.error)); | |
} | |
})); | |
}, | |
cancelDialog: function(component, event, helper) { | |
var recId = component.get("v.recordId"); | |
if (!recId) { | |
var homeEvt = $A.get("e.force:navigateToObjectHome"); | |
homeEvt.setParams({ | |
"scope": "Property__c" | |
}); | |
homeEvt.fire(); | |
} else { | |
helper.navigateTo(component, recId); | |
} | |
} | |
}) |
This file contains 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
({ | |
navigateTo: function(component, recId) { | |
var navEvt = $A.get("e.force:navigateToSObject"); | |
navEvt.setParams({ | |
"recordId": recId | |
}); | |
navEvt.fire(); | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment