沙世明
2023-03-09 99b667bdfd8d4fd4d56c2952510169d7f7be794c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
({
    //use this method to keep the “alert” functionality
    showToast : function(message, type) {
        console.log(type);
        if(type === undefined || type === ""){
            type = "info";
        }
        var toastEvent = $A.get("e.force:showToast");
        toastEvent.setParams({
            "title": "",
            "type": type,
                "duration": 10000,
            "message": message
        });
        toastEvent.fire();
    },
    
    //use this method to load user info in order to replace the global variable $User
    loadUserInfo : function(component,callback){
        //Call Your Apex Controller Method.
        var action = component.get("c.getUserInfo");
        
        action.setCallback(this, function(response) {
            var state = response.getState();
            if (state === "SUCCESS") {
                console.log("User info is loaded successfully.");
                component.set("v.User",response.getReturnValue());
                callback();
            } else {
                //Do Something
            }
        });
        
        $A.enqueueAction(action);
    },
    
    //use this method to load profile info in order to replace the global variable $Profile
    loadProfileInfo : function(component, callback){
        //Call Your Apex Controller Method.
        var action = component.get("c.getProfileInfo");
        
        action.setCallback(this, function(response) {
            var state = response.getState();
            if (state === "SUCCESS") {
                console.log("Profile is loaded successfully.");
                component.set("v.Profile",response.getReturnValue());
                callback();
            } else {
                //Do Something
            }
        });
        
        $A.enqueueAction(action);
    },
    
    //use this method to load site info in order to replace the global variable $Site
    loadSiteInfo : function(component,callback){
        //Call Your Apex Controller Method.
        var action = component.get("c.getSiteInfo");
        
        action.setCallback(this, function(response) {
            var state = response.getState();
            if (state === "SUCCESS") {
                console.log("Site is loaded successfully.");
                component.set("v.Site",response.getReturnValue());
                callback();
            } else {
                //Do Something
            }
        });
        
        $A.enqueueAction(action);
    },
    
    //use this method to execute a query
    executeQuery : function(component, event, helper, query) {
        
        
        var action = component.get("c.executeQuery");
        action.setParams({
            "theQuery": query
        });
        
        action.setCallback(this, function(response) {
            
            var state = response.getState();
            
            if(state == "SUCCESS" && component.isValid()){
                var queryResult = response.getReturnValue();
                component.set("v.queryResult", queryResult);
                var appEvent = $A.get("e.c:LCC_QueryApplicationEvent");
                appEvent.fire();
            }
            else{
                console.error("fail:" + response.getError()[0].message); 
                var toastEvent = $A.get("e.force:showToast");
            toastEvent.setParams({
                "title": "Error",
                        "duration": 10000,
                        "type": "error",
                "message": "Something went wrong in your org: " + response.getError()[0].message
            });
            toastEvent.fire();
                $A.get("e.force:closeQuickAction").fire();
            }
        });
        $A.enqueueAction(action);
    },
 
    // For loading additional objects not supported by <force:recordData>
    loadAdditionalObject: function(component, event) {
        var action = component.get("c.loadObjectInfoById");
        action.setParams({
            "recordId": component.get("v.recordId")
        });
 
        action.setCallback(this, function(response) {
            var state = response.getState();
 
            if(state == "SUCCESS" && component.isValid()){
                component.set("v.sObjectInfo", response.getReturnValue());
            } else {
                console.error("Error loading object: " + response.getError()[0].message);
                var toastEvent = $A.get("e.force:showToast");
                toastEvent.setParams({
                    "title": "Error",
                    "duration": 10000,
                    "type": "error",
                    "message": "Something went wrong: " + response.getError()[0].message
                });
                toastEvent.fire();
                $A.get("e.force:closeQuickAction").fire();
            }
        });
        $A.enqueueAction(action);
    },
 
    // for Display Model,set the "isOpen" attribute to "true"
    openModel: function(component, event, helper,text) {
        component.set("v.promptText", text);
        component.set("v.isOpen", true);
        
    },
    
    // for Display Model,set the "isOpenAlert" attribute to "true"
    openModelAlert: function(component, event, helper,text) {
        component.set("v.alertText", text);
        component.set("v.isOpenAlert", true);
        
    },
 
    // for display alerts inside lightning modal popup
    showTextAlert: function(component, text) {
        component.set("v.alertText", text);
        component.set("v.showAlert", true);
    },
    
    //for navigate to another url
    gotoURL : function (component, urlToNavigate) {
        var urlEvent = $A.get("e.force:navigateToURL");
        urlEvent.setParams({"url": urlToNavigate});
        urlEvent.fire();
    },
    
    idTruncate : function (str) {
        if (str != null && str.length > 15) {
            return str.substring(0, 15);
        } else {
            return str;
        }
    },
    
    cloneli : function (oldOppId, newOppId, component){
        //Call Your Apex Controller Method.
        var action = component.get("c.cloneOpportunityLineItems");
    
        action.setParams({
            "oldOppId": oldOppId,
            "newOppId": newOppId
        });
        
        action.setCallback(this, function(response) {
            var state = response.getState();
            if (state === "SUCCESS") {
                console.log("LI cloned successfully.");
                
            } else {
                //Do Something
            }
        });
        
        $A.enqueueAction(action);
    }
 
})