From 08a21f49f2eaf9cfc19ceb67b196cc36ba689305 Mon Sep 17 00:00:00 2001
From: buli <137736985@qq.com>
Date: 星期五, 13 五月 2022 20:52:25 +0800
Subject: [PATCH] FIxSWOPageIssue

---
 force-app/main/default/pages/SWOPage.page |  267 ++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 254 insertions(+), 13 deletions(-)

diff --git a/force-app/main/default/pages/SWOPage.page b/force-app/main/default/pages/SWOPage.page
index b9d64c1..ec2d8f2 100644
--- a/force-app/main/default/pages/SWOPage.page
+++ b/force-app/main/default/pages/SWOPage.page
@@ -5,8 +5,100 @@
 	<apex:includeScript value="{!URLFOR($Resource.PleaseWaitDialog)}"/>
 	<apex:includeScript value="{!URLFOR($Resource.connection20)}"/>
 	<apex:includeScript value="{!URLFOR($Resource.apex20)}"/>
+	<!-- 20220313 PI鏀归�� by Chen Yanan -->
+	<apex:includeScript value="{! URLFOR($Resource.AWSService, 'AWSService.js') }" />	
 
 	<script>
+		// 20220313 PI鏀归�� by Chen Yanan start
+		AWSService.sfSessionId = '{!GETSESSIONID()}';
+		var staticResources = JSON.parse('{!staticResource}');
+		var contactstaticResource = JSON.parse('{!contactstaticResource}');
+		var aws_data = {};
+		console.log('AWS' + '{!contactAWSDataId}');
+		var isNew = {!isNew};
+		console.log('isNew: ' + isNew);
+
+		function Decrypt(r,dataIds,callback){
+			if (!(dataIds && dataIds.length)) {
+				if(callback)callback();
+				return;
+			}
+
+			let Foo = function(){
+				for (const id of dataIds) {
+					if (aws_data.hasOwnProperty(id)) {
+						let d = aws_data[id];
+						let $e =j$("[aws-id='"+d.dataId+ "']");
+						$e.each((i,e)=>{
+							//j$(e).html(d[j$(e).attr("aws-api")]);
+							j$(e).attr('value',d[j$(e).attr("aws-api")])
+						})
+						
+					}
+				}
+				if(callback)callback();
+			}
+			let ids = [];
+			for (const id of dataIds) {
+				if (!aws_data.hasOwnProperty(id)) {
+					ids.push(id);
+				}
+			}
+			if (ids.length > 0) {
+				
+				// AWSService.search(r.searchUrl,JSON.stringify({
+				// 	"dataIds":ids
+				// }),function(data){
+				AWSService.query(r.queryUrl,ids[0],function(data){	
+					console.log('data: ' + JSON.stringify(data));
+					// if(data.object && data.object.length > 0){
+					if(data.object){
+						
+						// for(let d of data.object){
+						// 	if(d.dataId){
+						// 		aws_data[d.dataId] = d;
+						// 	}
+						// }
+						aws_data[data.object.dataId] = data.object;
+						Foo();
+					}else{
+						if(callback)callback();
+					}
+				},r.token);
+			}else{
+				Foo();
+			}
+		}
+
+		function DecryptAll(callback){
+			let dataIds1 = [];
+			j$('[aws-id][aws-obj="Contact"]').each((i,e)=>{
+				let v = j$(e).attr('aws-id');
+				if (v) {
+					dataIds1.push(v);
+				}
+			});
+			Decrypt(contactstaticResource,dataIds1,callback);
+
+			
+		}
+
+		function DecryptSWOAll(callback) {
+			let dataIds2 = [];
+			j$('[aws-id][aws-obj="SWO__c"]').each((i,e)=>{
+				let v = j$(e).attr('aws-id');
+				if (v) {
+					dataIds2.push(v);
+				}
+			});
+			Decrypt(staticResources,dataIds2,callback);
+		}
+
+		j$(function(){
+			DecryptSWOAll();
+			DecryptAll();
+		})
+		// 20220313 PI鏀归�� by Chen Yanan end
 		var IS_OPEN = true;
 
 		j$(document).ready(function() {
@@ -159,6 +251,114 @@
     			IS_OPEN = false;
     		}
     	}
+		//Add By Li JUn for PIPL 20220414 Start
+		var aws_result = {};
+
+		function saveSWOToAWS(){
+            // document.getElementById("errorMsg").innerHTML = '';
+            // if(!document.getElementById("Page:mainForm:idSearchVisitor:updateContactLastName").value){
+            //     document.getElementById("errorMsg").innerHTML = '<strong>閿欒:</strong> 蹇呴』濉啓銆�';
+            //     return;
+            // }
+            blockme();
+            let es = document.getElementsByTagName('select')
+            for(let ei in es){
+                let e = es[ei];
+                for(let opi in e.options){
+                    let op = e.options[opi];
+                    if(!op)continue;
+                    if(op.value == "*****" && op.selected){
+                        unblockUI();
+                        alert('涓嬫媺妗嗕笉鑳戒富鍔ㄩ�夋嫨瀵嗘枃閫夐」')
+                        return;
+                    }
+                }
+            }
+            ProcessPIForAWS({},GetEditObj());
+        }
+
+		function ProcessPIForAWS(sobjJson, payloadForNewPI) {
+            let url = staticResources.newUrl
+            let moduleName = AWSService.insertModule;
+            if (!isNew) {
+				console.log('Update');
+                moduleName = AWSService.updateModule;
+            	url = staticResources.updateUrl
+            }
+            console.log('Payload for AWS:'+payloadForNewPI + ' Module Name:'+moduleName);
+            // AWSService.postAWS(url,moduleName, payloadForNewPI, function(result){
+            AWSService.post(url, payloadForNewPI, function(result){
+                aws_result = result;
+                SetEditObj();
+                saveNew();
+            }, staticResources.token);
+        }
+
+        function GetEditObj(){
+    		var swoId = j$(escapeVfId("swoid")).value();
+			console.log('swoId: ' + swoId);
+            return JSON.stringify([{
+                // lastName : document.getElementById("Page:mainForm:idSearchVisitor:updateContactLastName").value,
+                // phone : document.getElementById("Page:mainForm:idSearchVisitor:updateContactPhone").value,
+                // type : document.getElementById("Page:mainForm:idSearchVisitor:updateContactType").value,
+                // doctorDivision1 : document.getElementById("Page:mainForm:idSearchVisitor:updateContactDoctorDivision").value,
+                // dataId:selectedAwsDataId
+				contactNameHidden: document.getElementById("Page:mainForm:CONTACT_NAME_HIDDEN__c").value,
+                dataId:'{!swoawsDataId}'
+            }]);
+        }
+
+		function SetEditObj(){
+            let obj = GetAWSResultObj();
+            if(obj){
+                console.log('Result from AWS:'+JSON.stringify(obj));
+                document.getElementById('Page:mainForm:AWS_Data_Id__c').value = obj.dataId;
+                document.getElementById("Page:mainForm:CONTACT_NAME_HIDDEN__c").value = obj.contactNameHidden;
+                
+                // document.getElementById("Page:mainForm:idSearchVisitor:updateContactLastName").value = obj.lastName;
+                // document.getElementById("Page:mainForm:LastName_Encrypted__c").value = obj.lastNameEncrypt;
+
+                // document.getElementById("Page:mainForm:idSearchVisitor:updateContactPhone").value = obj.phone;
+                // document.getElementById("Page:mainForm:Phone_Encrypted__c").value = obj.phoneEncrypt;
+
+                // document.getElementById("Page:mainForm:idSearchVisitor:updateContactType").value = obj.type;
+                // document.getElementById("Page:mainForm:Type_Encrypted__c").value = obj.typeEncrypt;
+
+                // document.getElementById("Page:mainForm:idSearchVisitor:updateContactDoctorDivision").value = obj.doctorDivision1;
+                // document.getElementById("Page:mainForm:Doctor_Division1_Encrypted__c").value = obj.doctorDivision1Encrypt;
+            }
+            
+        }
+
+		function GetAWSResultObj(){
+            if(aws_result && aws_result.object && aws_result.object.length > 0){
+                return aws_result.object[0];
+            }
+            return null;
+        }
+
+		function Trans(){
+			console.log('SWO ID : ' + document.getElementById('swoid').value);
+    		var swoId = j$(escapeVfId("swoid")).value();
+            console.log('SFRcordId:'+swoId);
+            // AWSService.postAWS(staticResources.transactionUrl,AWSService.confirmTrans, JSON.stringify({
+            //         "txId":aws_result.txId,
+            //         "sfRecordId":swoId,
+            //         "isSuccess":1
+            // }), function(result){
+			AWSService.post(staticResources.transactionUrl, JSON.stringify({
+                    "txId":aws_result.txId,
+                    "sfRecordId":swoId,
+                    "isSuccess":1
+            }), function(result){
+				//let id  = document.getElementById('Page:mainForm:frontSwoId').value
+				let id = j$(escapeVfId("swoid")).value();
+				window.location.href = '/apex/SWOPageRead?id=' + id +'&type='+'{!type}';
+                //window.location.reload();
+            }, staticResources.token);
+        }
+
+		//Add By Li JUn for PIPL 20220414 End
 	</script>
 
 	<style type="text/css"> 
@@ -219,6 +419,7 @@
 	</style>
 
 	<apex:form id="mainForm" style="width: 95%; margin-left: 30px;">
+
 		<apex:actionFunction name="mustData" action="{!mustData}" reRender="messageInfo" oncomplete="clickColorChange('Repair')"></apex:actionFunction>
 		<apex:actionFunction name="repairReturn" action="{!init}" reRender="mainForm" >
 			<apex:param name="swoid" assignTo="{!swoid}" value="" /><!-- mailRepair mainForm-->
@@ -226,6 +427,12 @@
 		<apex:actionFunction name="openPageSave" action="{!openPageSave}" reRender="">
 		</apex:actionFunction>
 		<apex:actionFunction name="uploadFile" action="{!uploadFile}"></apex:actionFunction>
+		<!-- Add save method for PIPL 20220414 by Li Jun Start -->
+		<apex:inputHidden id="frontSwoId" value="{!frontSwoId}" />
+		<apex:actionFunction name="saveNew" action="{!save}" reRender="swoid,frontSwoId" onComplete="Trans()">
+			<apex:param name="frontCaseId" assignto="{!caseId}" value="{!caseId}"/>
+        </apex:actionFunction>
+		<!-- Add save method for PIPL 20220414 by Li Jun End -->
 		<input type="hidden" id="baseUrl" value="{!baseUrl}"/>
 		<input type="hidden" id="swoid" value="{!swoid}"/>
 		<input type="hidden" id="type" value="{!type}"/>
@@ -242,7 +449,12 @@
 		<apex:outputPanel id="messageInfo">
 			<apex:pagemessages />
         </apex:outputPanel>
-		<apex:commandButton onclick="blockme();" value="Save" action="{!save}" style="width: 5%;"/>
+		<!-- Before PIPL Update 20220414 By Chen Yanan Start -->
+		<!-- <apex:commandButton onclick="blockme();" value="Save" action="{!save}" style="width: 5%;"/> -->
+		<!-- Before PIPL Update 20220414 By Chen Yanan end -->
+		<!-- After PIPL Update 20220414 By Chen Yanan Start -->
+		<apex:commandButton id="saveSWO" value="Save" style="width: 5%;" onclick="saveSWOToAWS();"  rerender="dummy" />
+		<!-- After PIPL Update 20220414 By Chen Yanan end -->
 		<table style="width: 100%;">
 			<colgroup>
 	            <col width="16%"/>
@@ -299,12 +511,19 @@
 	        	<td colspan="2">{!$ObjectType.SWO__c.fields.OFFICE__c.label}<span class="textRed">*</span></td>
 	        	<td><apex:inputField value="{!swo.TYPE__c}"/></td>
 	        	<td colspan="2">{!$ObjectType.SWO__c.fields.CONTACT_NAME_HIDDEN__c.label}</td>
+				
 	        </tr>
 
 	         <tr>
 	        	<td colspan="2"><apex:inputField value="{!swo.OFFICE__c}"/></td>
 	        	<td></td>
-	        	<td colspan="2"><apex:inputField value="{!swo.CONTACT_NAME_HIDDEN__c}"/></td>
+				<!-- Update By Yanan -->
+	        	<!-- <td colspan="2"><apex:inputField value="{!swo.CONTACT_NAME_HIDDEN__c}"/></td>				 -->
+				<td colspan="2" >
+					<apex:inputHidden id="AWS_Data_Id__c" value="{!swo.AWS_Data_Id__c}"/>
+					<apex:inputField html-aws-obj="SWO__c" html-aws-api="contactNameHidden" html-aws-id="{!swo.AWS_Data_Id__c}" id="CONTACT_NAME_HIDDEN__c" value="{!swo.CONTACT_NAME_HIDDEN__c }" />
+				</td>
+				<!-- Update By Yanan -->
 	        </tr>
 
 	        <tr>
@@ -456,8 +675,12 @@
 	    <table style="width: 100%;border-collapse: collapse;">
 	    	<tr class="title">
 	    		<td id="titleProduct" class="title1"><apex:commandLink oncomplete="clickColorChange('Product')" action="{!setProduct}" reRender="table" value="Product Info" /></td>
-	    		<td id="titleCase" class="title1"><apex:commandLink oncomplete="clickColorChange('Case')" action="{!setCase}" reRender="table" value="Case Info" /></td>
-	    		<td id="titlemail" class="title1"><apex:commandLink oncomplete="clickColorChange('mail')" action="{!setMail}" reRender="table" value="Mail Merge" /></td>
+	    		<!-- PIPL Update 20220414 By Chen Yanan Start -->
+				<!-- <td id="titleCase" class="title1"><apex:commandLink oncomplete="clickColorChange('Case')" action="{!setCase}" reRender="table" value="Case Info" /></td> -->
+	    		<!-- After -->
+				<td id="titleCase" class="title1"><apex:commandLink oncomplete="clickColorChange('Case');DecryptAll();" action="{!setCase}" reRender="table" value="Case Info" /></td>
+	    		<!-- PIPL Update 20220414 By Chen Yanan End -->
+				<td id="titlemail" class="title1"><apex:commandLink oncomplete="clickColorChange('mail')" action="{!setMail}" reRender="table" value="Mail Merge" /></td>
 	    		<td id="titleTracking" class="title1"><apex:commandLink oncomplete="clickColorChange('Tracking')" action="{!setTracking}" reRender="table" value="Tracking" /></td>
 	    		<td id="titleTechnical" class="title1"><apex:commandLink oncomplete="clickColorChange('Technical')" action="{!setTechnical}" reRender="table" value="Technical Info" /></td>
 	    		<td id="titleEstimation" class="title1"><apex:commandLink oncomplete="clickColorChange('Estimation')" action="{!setEstimation}" reRender="table" value="Estimation" /></td>
@@ -701,7 +924,13 @@
 			        </tr>
 			        <tr>
 			        	<td><apex:outputField value="{!swo.CASE_NUMBER__c}" ></apex:outputField></td>
-	        			<td><apex:inputField value="{!swo.EMAIL__c}"/></td>
+						<!-- PIPL Update 20220414 By Chen Yanan Start -->
+	        			<!-- <td><apex:inputField value="{!swo.EMAIL__c}"/></td> -->
+						<td colspan="2" align="left" >
+							<apex:inputField html-aws-obj="Contact" html-aws-api="email" html-aws-id="{!contactAWSDataId}" value="{!swo.EMAIL__c}" />
+						</td>
+
+						<!-- PIPL Update 20220414 By Chen Yanan End -->
 			        </tr>
 			        <tr>
 			        	<td>{!$ObjectType.SWO__c.fields.COMPANY__c.label}</td>
@@ -716,7 +945,13 @@
 			        	<td>{!$ObjectType.SWO__c.fields.TRAN__c.label}</td>
 			        </tr>
 			        <tr>
-			        	<td><apex:outputField value="{!swo.CONTACT__c}" ></apex:outputField></td>
+						<!-- 20220313 PI鏀归�� by Chen Yanan -->
+			        	<!-- <td><apex:outputField value="{!swo.CONTACT__c}" ></apex:outputField></td> -->
+						<td colspan="2" align="left" >
+							<!-- <a href="/{!swo.CONTACT__c}" aws-obj="Contact" aws-api="lastName" aws-id="{!contactAWSDataId}">{!swo.CONTACT__r.Name}</a> -->
+							<a href="/{!swo.CONTACT__c}" aws-obj="Contact" aws-api="lastName" aws-id="{!contactAWSDataId}">{!contactName}</a>
+						</td>
+						<!-- 20220313 PI鏀归�� by Chen Yanan -->
 	        			<td><apex:inputField value="{!swo.TRAN__c}"/></td>
 			        </tr>
 	    		</table>
@@ -1381,9 +1616,12 @@
 	    	</apex:outputPanel>
 
 	    	<apex:outputPanel rendered="{!IF(type = 'General' || type = 'All',true,false)}">
-	    		<apex:commandButton value="Attach" onclick="uploadFileJS();return false;"></apex:commandButton>
-					
-			   
+				<!-- Before PIPL Update by Li Jun 20220414 Start -->
+	    		<apex:commandButton value="Attach" action="{!uploadFile}"></apex:commandButton>
+				<!-- Before PIPL Update by Li Jun 20220414 End -->
+				<!-- After PIPL Update by Li Jun 20220414 Start -->
+			    <input class="btn" type="Button" value="PIPL Attach" onclick="window.open('/apex/SWOFileUploadPage')" />
+				<!-- After PIPL Update by Li Jun 20220414 End -->
 		    	<table class="tableCss" style="border:1px solid #000000;width: 80%">	
 		    		<tr style="text-align:center;">
 		    			<th style="text-align:center;width: 33%;">File Name</th>
@@ -1393,9 +1631,9 @@
 		    		<apex:repeat id="attachmentList" value="{!attachmentList}" var="attachment">
 		    			<tr style="text-align:center; vertical-align: middle;">
 		    				<!-- <td><input value="{!attachment.Name}" readonly="readonly" style="border:none;"/></td> -->
-		    				<td><apex:outputLink value="/{!attachment.Id}">{!attachment.Name}</apex:outputLink></td>
+		    				<td><apex:outputLink value="/{!attachment.Id}">{!attachment.FileName__c}</apex:outputLink></td>
 		    				<td><apex:inputField value="{!attachment.CreatedDate}"/></td>
-		    				<td><apex:inputField value="{!attachment.BodyLength}"/></td>
+		    				<!-- <td><apex:inputField value="{!attachment.BodyLength}"/></td>-->
 		    			</tr>
 		    		</apex:repeat>
 		    	</table>
@@ -1775,8 +2013,11 @@
 		<br/>
 		<br/>
 		<!-- <apex:commandButton action="{!save}" onclick="blockme();" value="Save" oncomplete="isOk();unblockUI();" reRender="Page,mainForm" style="width: 5%;"/> -->
-		<apex:commandButton onclick="blockme();" value="Save" action="{!save}" style="width: 5%;"/>
-
+		<!-- PIPL Update 20220414 By Chen Yanan -->
+		<!-- <apex:commandButton onclick="blockme();" value="Save" action="{!save}" style="width: 5%;"/> -->
+		<apex:commandButton id="saveSWOs" value="Save" style="width: 5%;" onclick="saveSWOToAWS();" rerender="dummy" />
+		<!-- PIPL Update 20220414 By Chen Yanan -->
+		
 	</apex:form>
 	
 	<br/>

--
Gitblit v1.9.1