From 928399eceec50e3d37ea08669a12789a9410a9d2 Mon Sep 17 00:00:00 2001
From: 沙世明 <shashiming@prec-tech.com>
Date: 星期二, 22 十一月 2022 16:51:16 +0800
Subject: [PATCH] 111

---
 force-app/main/default/pages/NewAndEditReport.page |   88 +++++++++++++++++++++++++++++++++----------
 1 files changed, 67 insertions(+), 21 deletions(-)

diff --git a/force-app/main/default/pages/NewAndEditReport.page b/force-app/main/default/pages/NewAndEditReport.page
index e6f18fa..f21bad0 100644
--- a/force-app/main/default/pages/NewAndEditReport.page
+++ b/force-app/main/default/pages/NewAndEditReport.page
@@ -3,7 +3,7 @@
     <apex:includeScript value="{! URLFOR($Resource.AWSService, 'AWSService.js') }" />
     <apex:includeScript value="{!URLFOR($Resource.jquery183minjs)}"/>
     <apex:includeScript value="{!URLFOR($Resource.PleaseWaitDialog)}"/>
-    <script src="../../soap/ajax/53.0/connection.js" type="text/javascript"></script>
+    <apex:includeScript value="{!URLFOR($Resource.connection20)}"/>
 
     <style>
         .disabledbutton {
@@ -13,16 +13,18 @@
     </style>
 
     <script>
+        sforce.connection.sessionId = '{!GETSESSIONID()}';
         AWSService.sfSessionId = '{!GETSESSIONID()}';
         var staticResources = JSON.parse('{!staticResource}');
         var staticResourcesContact = JSON.parse('{!staticResourceContact}');
         var redirectMode = 'Save';//1. Save 2. SaveAndNew
         var requiredFieldAPIList = JSON.parse('{!requiredFieldAPIListStr}');
         var fieldAPIToLabelMap = JSON.parse('{!fieldAPIToLabelMapStr}');
-        var VLookUpFields = new Set(['Hospital_Reference__c', 'Department_Class_Ref__c', 'Daily_Report__c', 'OwnerId','Hospital_Department__c',
-        'Competition_Company_Name__c','Report_OPDPlan__c','Loaner_request_no1__c','Practitioner1__c','Practitioner2__c','Practitioner3__c','Practitioner4__c',
-        'Practitioner5__c','Opportunity1__c',
-        'Opportunity2__c','Product01__c','Product1__c','Product2__c','Product3__c','Product4__c','Product5__c','Order_No__c','Person_In_Charge__c']);
+        // var VLookUpFields = new Set(['Hospital_Reference__c','Consum_Apply__c','Department_Class_Ref__c', 'Daily_Report__c', 'OwnerId','Hospital_Department__c',
+        // 'Competition_Company_Name__c','Report_OPDPlan__c','Loaner_request_no1__c','Practitioner1__c','Practitioner2__c','Practitioner3__c','Practitioner4__c',
+        // 'Practitioner5__c','Opportunity1__c','Responsible_Person__c',
+        // 'Opportunity2__c','Product01__c','Product1__c','Product2__c','Product3__c','Product4__c','Product5__c','Order_No__c','Person_In_Charge__c','CIC_Number__c']);
+        var VLookUpFields = {! VLookUpFieldsJson};
         var closeField = '';
         // var myCkeditor = null;
         // try {
@@ -31,17 +33,30 @@
         //     console.log('娌℃湁CKEDITOR')
         // }
 
+        function EditButton(isDisabled){
+            var topele = document.getElementById('topButtonRow');
+            var bottomele = document.getElementById('bottomButtonRow');
+
+            if (isDisabled) {
+                topele.classList.add("disabledbutton");
+                bottomele.classList.add("disabledbutton");
+            }else {
+                topele.classList.remove("disabledbutton");
+                bottomele.classList.remove("disabledbutton");
+            }
+        }
 
         //閿欒鎻愮ず
         function alertErrorMessage(errorMsg) {
-            let errorMsgNode = document.getElementById("page:form:j_id5:msgContent");
+            let errorMsgNode = document.getElementById("page:form:pageBlock:msgContent");
             errorMsg = '閿欒锛氭棤鏁堟暟鎹��'+'\n' + errorMsg;
             errorMsgNode.innerText = errorMsg;
             errorMsgNode.className = 'pbError';
             unblockUI();
+            EditButton(false);
         }
         function hiddenErrorMsgNode() {
-            let errorMsgNode = document.getElementById("page:form:j_id5:msgContent");
+            let errorMsgNode = document.getElementById("page:form:pageBlock:msgContent");
             errorMsgNode.innerText = '';
             errorMsgNode.className = '';
         }
@@ -61,12 +76,25 @@
             let result = {}
             result.RecordTypeId = '{!rtTypeId}';
             for (let index = 0; index < nodelist.length; index++) {
-                if (VLookUpFields.has(nodelist[index].getAttribute("data-id"))) {
+                let tag_name = nodelist[index].tagName.toLowerCase();
+                if(tag_name == 'div'){
+                    console.log(nodelist[index])
+                }
+                if (VLookUpFields.indexOf(nodelist[index].getAttribute("data-id")) >= 0) {
                     console.log(nodelist[index].id.indexOf('lkwgt'));
                     if (nodelist[index].id.indexOf('lkwgt') == -1) {
                         let vlookUpNodeId = nodelist[index].id + '_lkid';
-                        let vlookUpNodeValue = document.getElementById(vlookUpNodeId).value;
-                        result[nodelist[index].getAttribute("data-id")] = vlookUpNodeValue;
+                        if (tag_name == 'div') {
+                            vlookUpNodeId = nodelist[index].id.substring(0,nodelist[index].id.length-4) + '_lkid';
+                        }
+                        let vlookUpNodeValue = document.getElementById(vlookUpNodeId);
+                        let v = '';
+                        if(vlookUpNodeValue){
+                            v = vlookUpNodeValue.value;
+                        }else{
+                            v = nodelist[index].value;
+                        }
+                        result[nodelist[index].getAttribute("data-id")] = v;
                     }
                 } else if (nodelist[index].type == 'checkbox') {
                     result[nodelist[index].getAttribute("data-id")] = nodelist[index].checked;
@@ -166,7 +194,7 @@
             // if(document.querySelector("[aria-describedby = 'cke_38']")){
             //     result.VOC_follow_up_result__c = document.querySelector("[aria-describedby = 'cke_38']").contentWindow.document.getElementsByTagName('body')[0].innerHTML
             // }
-            // //瀵瑰簲缁撴灉绗竴娆� 	VOC_follow_up_result1__c cke_71
+            // //瀵瑰簲缁撴灉绗竴娆�    VOC_follow_up_result1__c cke_71
             // if(document.querySelector("[aria-describedby = 'cke_71']")){
             //     result.VOC_follow_up_result1__c = document.querySelector("[aria-describedby = 'cke_71']").contentWindow.document.getElementsByTagName('body')[0].innerHTML
             // }
@@ -183,7 +211,7 @@
         function validateFieldValueFormate() {
             //VOC_Informer_Contact__c,Caller_phone_c__c
             let error_msg = '';
-            // let textEmail = "[data-id='	Follow_staff_email__c']";
+            // let textEmail = "[data-id='  Follow_staff_email__c']";
             // let textPhone1 = "[data-id='VOC_Informer_Contact__c']";
             // let textPhone2 = "[data-id='Caller_phone_c__c']";
             // //Email
@@ -221,7 +249,9 @@
         function checkRequiredFieldMsg(formData) {
             let blankRequiredFields = '';
             for(i = 0;i<requiredFieldAPIList.length;i++){
-                if(formData[requiredFieldAPIList[i]]){
+                if (formData[requiredFieldAPIList[i]] && (VLookUpFields.indexOf(requiredFieldAPIList[i]) == -1)) {
+                    continue;
+                }else if((VLookUpFields.indexOf(requiredFieldAPIList[i]) != -1) && formData[requiredFieldAPIList[i]] != '000000000000000'){
                     continue;
                 }else{
                     if(blankRequiredFields == ''){
@@ -255,10 +285,10 @@
             if (!tag_name) {
                 return false;
             }
-            return ['input','select','textarea'].indexOf(tag_name.toLowerCase())>-1;
+            return ['input','select','textarea','div'].indexOf(tag_name.toLowerCase())>-1;
         }
-    	
-    	function IsFormElement(e){
+        
+        function IsFormElement(e){
             return IsFormTag(e.tagName);
         }
 
@@ -300,7 +330,7 @@
         //鏂板缓
         function NewPIToAWS(reportJson, payloadForNewPI) {
             let controllerSaveMethod = '{!$RemoteAction.NewAndEditReportController.saveReport}';
-            AWSService.insert(staticResources.newUrl, reportJson, payloadForNewPI, controllerSaveMethod, staticResources.token, staticResources.transactionUrl, true, insertOrUpdateBack, redirectCallBack);
+            AWSService.insert(staticResources.newUrl, reportJson, payloadForNewPI, controllerSaveMethod, staticResources.token, staticResources.transactionUrl, {!isNewMode}, insertOrUpdateBack, redirectCallBack);
         }
 
         //缂栬緫
@@ -533,6 +563,19 @@
             } else {
                 payloadJson.AWS_Data_Id__c = '{!AWSDataId}';
             }
+            if('{!sfRecordIdForEdit}'){
+                payloadJson.Id = '{!sfRecordIdForEdit}';
+            }
+            if('{!rtTypeId}'){
+                payloadJson.RecordTypeId = '{!rtTypeId}';//Add by Li Jun for Record Type Issue 20220421
+            }
+            if('{!isCloneMode}' == 'true'){
+                var reportId = '{!sfRecordIdForEdit}';
+                var r = sforce.connection.query("select Practitioner4__c,Practitioner5__c from Report__c where id='"+reportId+"'")
+                payloadJson.Practitioner4__c = r.getArray("records")[0].Practitioner4__c
+                payloadJson.Practitioner5__c = r.getArray("records")[0].Practitioner5__c
+                payloadJson.Id = null
+            }
             return payloadJson;
         }
 
@@ -551,6 +594,8 @@
 
         //鐐瑰嚮淇濆瓨鎸夐挳
         function saveReportProcess(saveMode) {
+            EditButton(true);
+
             redirectMode = saveMode;
             console.log('redirectMode' + redirectMode);
             hiddenErrorMsgNode();
@@ -604,7 +649,7 @@
         <!-- <apex:outputPanel id="errorMsg">
             <apex:pageMessages id="msgContent" escape="false" />
         </apex:outputPanel> -->
-        <apex:pageblock >
+        <apex:pageblock id="pageBlock">
             <div class="pbHeader">
                 <table cellspacing="0" cellpadding="0" border="0">
                     <tbody>
@@ -695,7 +740,8 @@
                     //Replace Vlookup Field
                     replaceSearchContactLookup();
                     //3. Set Readonly Attribute
-                    document.querySelector("[data-id='OwnerId']").classList.add("disabledbutton");
+                    if(document.querySelector("[data-id='OwnerId']"))
+                        document.querySelector("[data-id='OwnerId']").classList.add("disabledbutton");
 
                     //濡傛灉鏄疧PD璁″垝杩囨潵鐨�
                     if('{!no1Name}' != '' && '{!no1Id}' != ''){
@@ -707,8 +753,8 @@
                         }
                     }
                     
-					document.getElementById('topButtonRow').style = '';
-聽 聽 聽 聽 聽 聽 聽document.getElementById('bottomButtonRow').style = '';
+                    document.getElementById('topButtonRow').style = '';
+                    document.getElementById('bottomButtonRow').style = '';
                     
                     let previous_value = {};
                     jQuery(".lookupInput input").each(function(i,e){

--
Gitblit v1.9.1