Lighting componentワークブック(s1コンタクトリストコンポーネント)

26
Lightning Component ハハハハハ S1 ハハハハハハハハハハハハハハハハハハハ ハハハハハハハハハハハハ ハハハハハ

Transcript of Lighting componentワークブック(s1コンタクトリストコンポーネント)

Page 1: Lighting componentワークブック(s1コンタクトリストコンポーネント)

Lightning Component ハンズオンS1アプリ用コンタクトリストコンポーネント

株式会社セールスフォース・ドットコム

Page 2: Lighting componentワークブック(s1コンタクトリストコンポーネント)

S1用コンタクトリストコンポーネント

コンタクトリスト表示コンタクト新規画面

コンタクト編集画面

Page 3: Lighting componentワークブック(s1コンタクトリストコンポーネント)

S1用コンタクトリストコンポーネント

コンタクト詳細画面

関連ケースリスト表示

Page 4: Lighting componentワークブック(s1コンタクトリストコンポーネント)

ContactController Apex作成

1

3

2

次ページのソースコードをコピー &ペーストして下さい

Page 5: Lighting componentワークブック(s1コンタクトリストコンポーネント)

ソース

public with sharing class ContactController {@AuraEnabled public static List<Contact> getContacts() { List<Contact> contacts = [SELECT Id, Name, MailingStreet, Phone, Email, Level__c FROM Contact];

//Add isAccessible() check return contacts; } @AuraEnabled // Retrieve all primary contacts public static List<Contact> getPrimary() { List<Contact> primaryContacts = [SELECT Id, Name, MailingStreet, Phone, Email, Level__c FROM Contact WHERE Level__c = 'Primary'];

//Add isAccessible() check return primaryContacts; }}

Page 6: Lighting componentワークブック(s1コンタクトリストコンポーネント)

1

3

2

4

次ページのソースコードをコピー &ペーストして下さい

contactList Lightningコンポーネント作成

Page 7: Lighting componentワークブック(s1コンタクトリストコンポーネント)

ソース<aura:component> <aura:attribute name="contact" type="Contact"/> <!-- If you’re using a namespace, use {!v.contact.myNamespace__Level__c} instead --> <div class="{!v.contact.Level__c == 'Primary' ? 'row primary' : 'row '}" >

<!-- Display a contact name and navigate to record when the name is clicked --> <div class="col-sm-4"> <ui:outputText value="{!v.contact.Name}" click="{!c.gotoRecord}"/> </div> <div class="col-sm-4"> <ui:outputEmail value="{!v.contact.Email}"/> <ui:outputPhone value="{!v.contact.Phone}"/>

<!-- Display the edit record page when the icon is clicked --> <div onclick="{!c.editRecord}"> <img src="/img/icon/custom51_100/pencil16.png" alt="Edit Contact" title="Edit Contact" /> </div> </div> <div class="col-sm-4"> <ui:outputTextArea aura:id="address" value="{!v.contact.MailingStreet}" click="{!c.navigate}"/> </div>

<!-- Navigate to the related list when the button is clicked --> <ui:button label="View Cases" press="{!c.relatedList}"/> </div></aura:component>

Page 8: Lighting componentワークブック(s1コンタクトリストコンポーネント)

contactList CSS 作成

1

2

次ページのソースコードをコピー &ペーストして下さい

3

Page 9: Lighting componentワークブック(s1コンタクトリストコンポーネント)

ソース

.THIS.primary{ background: #4ECDC4 !important;}

.THIS .uiOutputText { width: 25%; float: left; font-weight: bold;}

.THIS .uiOutputPhone { color: #2574A9;}

.THIS .uiOutputTextArea { float:clear;}

.THIS .uiOutputEmail { float: right;}

.THIS .uiButton { margin-top: 20px !important;}

Page 10: Lighting componentワークブック(s1コンタクトリストコンポーネント)

contacts Lightningコンポーネント作成

1

2

Page 11: Lighting componentワークブック(s1コンタクトリストコンポーネント)

contacts Lightningコンポーネント作成

次ページのソースコードをコピー &ペーストして下さい

1

2

Page 12: Lighting componentワークブック(s1コンタクトリストコンポーネント)

ソース

<aura:component controller="ContactController" implements="force:appHostable"> <!-- Handle component initialization in a client-side controller --> <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>

<!-- Handle loading events by displaying a spinner --> <aura:handler event="aura:waiting" action="{!c.showSpinner}"/> <aura:handler event="aura:doneWaiting" action="{!c.hideSpinner}"/>

<!-- Dynamically load the list of contacts --> <aura:attribute name="contacts" type="Contact[]"/>

<!-- Create a drop-down list with two options --> <ui:inputSelect aura:id="selection" change="{!c.select}"> <ui:inputSelectOption text="All Contacts" label="All Contacts"/> <ui:inputSelectOption text="All Primary" label="All Primary"/> </ui:inputSelect> <div class="icons"> <img src="/img/icon/custom51_100/chalkboard16.png" alt="Create New" title="Create New" onclick="{!c.createRecord}"/> </div> <div><center><ui:spinner aura:id="spinner"/></center></div> <!-- Iterate over the list of contacts and display them --> <aura:iteration var="contact" items="{!v.contacts}"> <!-- If you’re using a namespace, replace with myNamespace:contactList --> <c:contactList contact="{!contact}"/> </aura:iteration></aura:component>

Page 13: Lighting componentワークブック(s1コンタクトリストコンポーネント)

13

2

次ページのソースコードをコピー &ペーストして下さい

contacts コントローラー作成

Page 14: Lighting componentワークブック(s1コンタクトリストコンポーネント)

ソース

({ doInit : function(component, event, helper) { // Retrieve contacts during component initialization helper.getContacts(component); },

showSpinner : function (component, event, helper) { var spinner = component.find('spinner'); var evt = spinner.get("e.toggle"); evt.setParams({ isVisible : true }); evt.fire(); }, hideSpinner : function (component, event, helper) { var spinner = component.find('spinner'); var evt = spinner.get("e.toggle"); evt.setParams({ isVisible : false }); evt.fire(); },//Delimiter for future code})

Page 15: Lighting componentワークブック(s1コンタクトリストコンポーネント)

contacts ヘルパー作成

1

2

3

次ページのソースコードをコピー &ペーストして下さい

Page 16: Lighting componentワークブック(s1コンタクトリストコンポーネント)

ソース ({ getContacts : function(cmp) { // Load all contact data var action = cmp.get("c.getContacts"); var self = this; action.setCallback(this, function(response) { var state = response.getState(); if (cmp.isValid() && state === "SUCCESS") { cmp.set("v.contacts", response.getReturnValue()); }

// Display toast message to indicate load status var toastEvent = $A.get("e.force:showToast"); if (state === 'SUCCESS'){ toastEvent.setParams({ "title": "Success!", "message": " Your contacts have been loaded successfully." }); } else { toastEvent.setParams({ "title": "Error!", "message": " Something has gone wrong." }); } toastEvent.fire(); }); $A.enqueueAction(action); }})

Page 17: Lighting componentワークブック(s1コンタクトリストコンポーネント)

contacts CSS作成

3

次ページのソースコードをコピー &ペーストして下さい

2

Page 18: Lighting componentワークブック(s1コンタクトリストコンポーネント)

ソース

.THIS.row { background: #fff; max-width:90%; border-bottom: 2px solid #f0f1f2; padding: 10px; margin-left: 2%; margin-bottom: 10px; min-height: 70px; border-radius: 4px;}

.THIS.uiInputSelect { width: 80%; padding-left: 10px; min-height: 28px; margin-bottom: 20px; margin-left: 20px; margin-top: 40px;}

.THIS img { float: right; padding-right:5%; padding-top: 20px;}

.THIS.icons { height:60px;}

Page 19: Lighting componentワークブック(s1コンタクトリストコンポーネント)

Salesforce1への統合

1

3

2

4

Page 20: Lighting componentワークブック(s1コンタクトリストコンポーネント)

タブの追加

1 2

Page 21: Lighting componentワークブック(s1コンタクトリストコンポーネント)

画面確認

1

2

Page 22: Lighting componentワークブック(s1コンタクトリストコンポーネント)

1

イベントの追加

3

2

4

次ページのソースコードをコピー &ペーストして下さい

5

Page 23: Lighting componentワークブック(s1コンタクトリストコンポーネント)

ソース({ gotoRecord : function(component, event, helper) { // Fire the event to navigate to the contact record var sObjectEvent = $A.get("e.force:navigateToSObject"); sObjectEvent.setParams({ "recordId": component.get("v.contact.Id"), "slideDevName": 'related' }) sObjectEvent.fire(); }, editRecord : function(component, event, helper) { // Fire the event to navigate to the edit contact page var editRecordEvent = $A.get("e.force:editRecord"); editRecordEvent.setParams({ "recordId": component.get("v.contact.Id") }); editRecordEvent.fire(); }, navigate : function(component, event, helper) { // Navigate to an external URL var address = component.find("address").get("v.value"); var urlEvent = $A.get("e.force:navigateToURL"); urlEvent.setParams({ "url": 'https://www.google.com/maps/place/' + address }); urlEvent.fire(); },

relatedList : function (component, event, helper) { // Navigate to the related cases var relatedListEvent = $A.get("e.force:navigateToRelatedList"); relatedListEvent.setParams({ "relatedListId": "Cases", "parentRecordId": component.get("v.contact.Id") }); relatedListEvent.fire(); }})

Page 24: Lighting componentワークブック(s1コンタクトリストコンポーネント)

イベントの追加

1

3

2

次ページのソースコードをコピー &ペーストして下さい

4

Page 25: Lighting componentワークブック(s1コンタクトリストコンポーネント)

ソースcreateRecord : function (component, event, helper) { // Open the create record page var createRecordEvent = $A.get("e.force:createRecord"); createRecordEvent.setParams({ "entityApiName": "Contact" }); createRecordEvent.fire();},

select : function(component, event, helper){ // Get the selected value of the ui:inputSelect component var selectCmp = component.find("selection"); var selectVal = selectCmp.get("v.value"); // Display all primary contacts or all contacts if (selectVal==="All Primary"){ var action = component.get("c.getPrimary"); action.setCallback(this, function(response){ var state = response.getState(); if (component.isValid() && state === "SUCCESS") { component.set("v.contacts", response.getReturnValue()); } }); $A.enqueueAction(action); } else { // Return all contacts helper.getContacts(component); }}

Page 26: Lighting componentワークブック(s1コンタクトリストコンポーネント)

END