|  |  | 
 |  |  | <apex:page standardController="Case" extensions="NewAndEditCaseController" id="page"> | 
 |  |  | <apex:page standardController="Case" extensions="NewAndEditCaseController" id="page" lightningStylesheets="true"> | 
 |  |  |     <apex:includeScript value="{! URLFOR($Resource.AWSService, 'AWSService.js') }" /> | 
 |  |  |     <apex:includeScript value="{!URLFOR($Resource.jquery183minjs)}"/> | 
 |  |  |     <apex:includeScript value="{!URLFOR($Resource.PleaseWaitDialog)}"/> | 
 |  |  |     <apex:stylesheet value="{!URLFOR($Resource.blockUIcss)}"/> | 
 |  |  |     <script src="../../soap/ajax/53.0/connection.js" type="text/javascript"></script> | 
 |  |  |     <apex:includeScript value="{!URLFOR($Resource.connection20)}"/> | 
 |  |  |     <style> | 
 |  |  |         .disabledbutton { | 
 |  |  |             pointer-events: none; | 
 |  |  | 
 |  |  |     <script> | 
 |  |  |         AWSService.sfSessionId = '{!GETSESSIONID()}'; | 
 |  |  |         var staticResources = JSON.parse('{!staticResource}'); | 
 |  |  |         //zhj MEBG新方案改造 2022-11-29 start | 
 |  |  |         var staticResourcesV2 = JSON.parse('{!staticResourceV2}'); | 
 |  |  |         //zhj MEBG新方案改造 2022-11-29 end | 
 |  |  |         var staticResourcesContact = JSON.parse('{!staticResourceContact}'); | 
 |  |  |         var requiredFieldAPIList = JSON.parse('{!requiredFieldAPIListStr}'); | 
 |  |  |         var fieldAPIToLabelMap = JSON.parse('{!fieldAPIToLabelMapStr}'); | 
 |  |  | 
 |  |  |         var requiredAPIToChangedLabelMap = new Map(); | 
 |  |  |         requiredAPIToChangedLabelMap.set('LastName', '{!PIPL_Name_Label}'); | 
 |  |  |         console.log('{!contactsInfo}'); | 
 |  |  |         var VLookUpFields = new Set(['Account__c', 'ContactId', 'Asset__c', 'prod__c', 'Competitor_info__c', 'AccountId', 'Field1_staff__c']); | 
 |  |  |         //var VLookUpFields = new Set(['Account__c', 'ContactId', 'Asset__c', 'prod__c', 'Competitor_info__c', 'AccountId', 'Field1_staff__c','OwnerId']); | 
 |  |  |         var VLookUpFields = {! VLookUpFieldsJson}; | 
 |  |  |         //判断insert or update | 
 |  |  |         function ProcessPI(caseJson, payloadForNewPI) { | 
 |  |  |             blockme(); | 
 |  |  |             if ({!isNewMode}) { | 
 |  |  |             if ({!isNewMode} || {!isCloneMode}||!'{!AWSDataId}') {//Add by Li Jun, if the awsdataid is blank. go to insert process | 
 |  |  |                 NewPIToAWS(caseJson, payloadForNewPI) | 
 |  |  |             }else { | 
 |  |  |                 UpdatePIToAWS(caseJson, payloadForNewPI) | 
 |  |  |             } | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         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 enableButton(obj){ | 
 |  |  |             obj.classList.remove("btnDisabled"); | 
 |  |  | 
 |  |  |                 for (let idx = 0; idx < describedbyAll.length; idx++) { | 
 |  |  |                     let describedby = describedbyAll[idx]; | 
 |  |  |                     if (describedby.title.indexOf('Text_attachement__c') > 0){ | 
 |  |  |                        result.Text_attachement__c = describedby.contentWindow.document.getElementsByTagName('body')[0].innerHTML; | 
 |  |  |                         result.Text_attachement__c = describedby.contentWindow.document.getElementsByTagName('body')[0].innerHTML; | 
 |  |  |                         if (result.Text_attachement__c == '<br>') { | 
 |  |  |                             result.Text_attachement__c = ''; | 
 |  |  |                         } | 
 |  |  | 
 |  |  |                 } | 
 |  |  |             }  | 
 |  |  |             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; | 
 |  |  | 
 |  |  |                     index++; | 
 |  |  |                 } | 
 |  |  |             } | 
 |  |  |             //针对id的手动添加 | 
 |  |  |             if (document.getElementById("page:form:block:j_id31:0:j_id32:j_id33:1:j_id34_lkid") && (!result.hasOwnProperty("Field1_staff__c") || !result["Field1_staff__c"])){ | 
 |  |  |                 if(document.getElementById("page:form:block:j_id31:0:j_id32:j_id33:1:j_id34_lkid").value != '000000000000000'){ | 
 |  |  |                    result["Field1_staff__c"] = document.getElementById("page:form:block:j_id31:0:j_id32:j_id33:1:j_id34_lkid").value; | 
 |  |  |                 } | 
 |  |  |             } | 
 |  |  |              | 
 |  |  |             return result; | 
 |  |  |         } | 
 |  |  | 
 |  |  |         //需要解密字段 | 
 |  |  |         var queryBack = function queryBack(data) { | 
 |  |  |             console.log('data = ' + data); | 
 |  |  |             document.querySelector("[data-id='cic_telephone__c']").value = data.object.cicTelephone; | 
 |  |  |             document.querySelector("[data-id='CASE_CUSTOMER__c']").value = data.object.caseCustomer; | 
 |  |  |             document.querySelector("[data-id='Customer_manual__c']").value = data.object.customerManual; | 
 |  |  |             if (document.querySelector("[data-id='cic_telephone__c']")) { | 
 |  |  |                 document.querySelector("[data-id='cic_telephone__c']").value = data.object.cicTelephone; | 
 |  |  |             } | 
 |  |  |             if (document.querySelector("[data-id='CASE_CUSTOMER__c']")) { | 
 |  |  |                 document.querySelector("[data-id='CASE_CUSTOMER__c']").value = data.object.caseCustomer; | 
 |  |  |             } | 
 |  |  |             if (document.querySelector("[data-id='Customer_manual__c']")) { | 
 |  |  |                 document.querySelector("[data-id='Customer_manual__c']").value = data.object.customerManual; | 
 |  |  |             } | 
 |  |  |         }; | 
 |  |  |  | 
 |  |  |         var insertOrUpdateBack = function insertOrUpdateBack(payloadJson, result, isNewMode) { | 
 |  |  | 
 |  |  |             payloadJson.cic_telephone__c = r.object[0].cicTelephone; | 
 |  |  |             payloadJson.CASE_CUSTOMER__c = r.object[0].caseCustomer; | 
 |  |  |             payloadJson.Customer_manual__c = r.object[0].customerManual; | 
 |  |  |             payloadJson.cic_telephone_Encrypted__c = r.object[0].cicTelephoneEncrypt; | 
 |  |  |             payloadJson.CASE_CUSTOMER_Encrypted__c = r.object[0].caseCustomerEncrypt; | 
 |  |  |             payloadJson.Customer_manual_Encrypted__c = r.object[0].customerManualEncrypt; | 
 |  |  |             //zhj MEBG新方案改造 2022-11-29 start | 
 |  |  |             // payloadJson.cic_telephone_Encrypted__c = r.object[0].cicTelephoneEncrypt; | 
 |  |  |             // payloadJson.CASE_CUSTOMER_Encrypted__c = r.object[0].caseCustomerEncrypt; | 
 |  |  |             // payloadJson.Customer_manual_Encrypted__c = r.object[0].customerManualEncrypt; | 
 |  |  |             //zhj MEBG新方案改造 2022-11-29 end | 
 |  |  |             //payloadJson.AWS_Data_Id__c = r.object[0].dataId; | 
 |  |  |             payloadJson.AWS_Data_Id__c = '{!AWSDataId}'; | 
 |  |  |             if (isNewMode) { | 
 |  |  |             if (isNewMode || {!isCloneMode} || !'{!AWSDataId}') { | 
 |  |  |                 payloadJson.AWS_Data_Id__c = r.object[0].dataId; | 
 |  |  |             } else { | 
 |  |  |                 payloadJson.AWS_Data_Id__c = '{!AWSDataId}'; | 
 |  |  |             } | 
 |  |  |             if('{!sfRecordIdForEdit}'){ | 
 |  |  |                 payloadJson.Id = '{!sfRecordIdForEdit}'; | 
 |  |  |             } | 
 |  |  |             if('{!rtTypeId}'){ | 
 |  |  |                 payloadJson.RecordTypeId = '{!rtTypeId}';//Add by zhj for Record Type Issue 20220421 | 
 |  |  |             } | 
 |  |  |             return payloadJson; | 
 |  |  |         } | 
 |  |  | 
 |  |  |             let obj = JSON.parse(payloadForNewPI); | 
 |  |  |             obj[0].dataId = '{!AWSDataId}'; | 
 |  |  |             let payloadForNewPIJson = JSON.stringify(obj); | 
 |  |  |             AWSService.update(staticResources.updateUrl, caseJson, payloadForNewPIJson, controllerSaveMethod, staticResources.token, staticResources.transactionUrl, false, insertOrUpdateBack, redirectCallBack); | 
 |  |  |             //zhj MEBG新方案改造 2022-11-29 start | 
 |  |  |             //AWSService.update(staticResources.updateUrl, caseJson, payloadForNewPIJson, controllerSaveMethod, staticResources.token, staticResources.transactionUrl, false, insertOrUpdateBack, redirectCallBack); | 
 |  |  |             AWSService.update(staticResourcesV2.updateUrl, caseJson, payloadForNewPIJson, controllerSaveMethod, staticResourcesV2.token, staticResources.transactionUrl, false, insertOrUpdateBack, redirectCallBack); | 
 |  |  |             //zhj MEBG新方案改造 2022-11-29 end | 
 |  |  |         } | 
 |  |  |         //insert to AWS | 
 |  |  |         function NewPIToAWS(caseJson, payloadForNewPI) { | 
 |  |  |             let controllerSaveMethod = '{!$RemoteAction.NewAndEditCaseController.saveCase}'; | 
 |  |  |             AWSService.insert(staticResources.newUrl, caseJson, payloadForNewPI, controllerSaveMethod, staticResources.token, staticResources.transactionUrl, true, insertOrUpdateBack, redirectCallBack); | 
 |  |  |             //zhj MEBG新方案改造 2022-11-29 start | 
 |  |  |             //AWSService.insert(staticResources.newUrl, caseJson, payloadForNewPI, controllerSaveMethod, staticResources.token, staticResources.transactionUrl, {!isNewMode}, insertOrUpdateBack, redirectCallBack); | 
 |  |  |             AWSService.insert(staticResourcesV2.newUrl, caseJson, payloadForNewPI, controllerSaveMethod, staticResourcesV2.token, staticResources.transactionUrl, {!isNewMode}, insertOrUpdateBack, redirectCallBack); | 
 |  |  |             //zhj MEBG新方案改造 2022-11-29 end | 
 |  |  |         } | 
 |  |  |         //必填字段 | 
 |  |  |         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 { | 
 |  |  |                     let fieldAPIValue = requiredFieldAPIList[i] | 
 |  |  | 
 |  |  |         } | 
 |  |  |         //按钮点击事件 | 
 |  |  |         function saveCaseProcess(saveMode) { | 
 |  |  |             EditButton(true); | 
 |  |  |  | 
 |  |  |             disableButtonStatus(); | 
 |  |  |             redirectMode = saveMode; | 
 |  |  |             console.log('redirectMode'+redirectMode); | 
 |  |  | 
 |  |  |             //1. Get Case Information from Form | 
 |  |  |             let caseJson = getCaseInformation(); | 
 |  |  |             //2. Validate the Case field value formate, for example the email formate or phone formate | 
 |  |  |             /* | 
 |  |  |             let validationResultMessage = validateFieldValueFormate(); | 
 |  |  |             console.log(validationResultMessage); | 
 |  |  |             if (!validationResultMessage) { | 
 |  |  | 
 |  |  |                 alertErrorMessage('手机格式输入有误,请重新输入!'); | 
 |  |  |                 return | 
 |  |  |             } | 
 |  |  |             */ | 
 |  |  |             // Check Required Field | 
 |  |  |             let checkRequiredFieldMsgResult = checkRequiredFieldMsg(caseJson); | 
 |  |  |             if (checkRequiredFieldMsgResult) { | 
 |  |  | 
 |  |  |             errorMsgNode.innerText = errorMsg; | 
 |  |  |             errorMsgNode.className = 'pbError'; | 
 |  |  |             unblockUI(); | 
 |  |  |             EditButton(false); | 
 |  |  |         } | 
 |  |  |         function hiddenErrorMsgNode() { | 
 |  |  |             let errorMsgNode = document.getElementById("page:form:block:msgContent"); | 
 |  |  | 
 |  |  |                                 <img src="/img/s.gif" alt="" class="minWidth" title="" width="1" height="1" /> | 
 |  |  |                                 <h2 class="mainTitle">CIC编辑</h2> | 
 |  |  |                             </td> | 
 |  |  |                             <td class="pbButton" id="topButtonRow"> | 
 |  |  |                             <td class="pbButton" id="topButtonRow" style="pointer-events: none; opacity: 0.4;"> | 
 |  |  |                                 <input class="btn" type="Button" value="保存" onclick="saveCaseProcess('Save')" /> | 
 |  |  |                                 <input class="btn" type="Button" value="保存并关闭" onclick="saveCaseProcess('SaveAndClose')" /> | 
 |  |  |                                 <input class="btn" type="Button" value="保存并新建" onclick="saveCaseProcess('SaveAndNew')" /> | 
 |  |  | 
 |  |  |                 <apex:pageBlockSection title="{!layoutSection.name}" showHeader="{!layoutSection.useHeader}" collapsible="{!layoutSection.allowCollapse}" columns="{!layoutSection.columns}"> | 
 |  |  |                     <!--Each section has layoutFields, let's iterate them as well--> | 
 |  |  |                     <apex:repeat value="{!layoutSection.layoutFields}" var="layoutField"> | 
 |  |  |                         <apex:inputField html-data-id="{!layoutField.fieldAPI}" value="{!Case[layoutField.fieldAPI]}" rendered="{!not(layoutField.isPlaceHOlder)}" | 
 |  |  |                             required="{!layoutField.isRequired}" /> | 
 |  |  |                         <apex:inputField html-data-id="{!layoutField.fieldAPI}" value="{!Case[layoutField.fieldAPI]}" rendered="{!not(layoutField.isPlaceHOlder)&&isNewMode}" required="{!layoutField.isRequired}" /> | 
 |  |  |                         <apex:inputField html-data-id="{!layoutField.fieldAPI}" value="{!Case[layoutField.fieldAPI]}" rendered="{!not(layoutField.isPlaceHOlder)&¬(isNewMode)&&layoutField.fieldAPI!='RecordTypeId'}" required="{!layoutField.isRequired}" /> | 
 |  |  |                         <apex:outputField html-data-id="{!layoutField.fieldAPI}" value="{!Case[layoutField.fieldAPI]}" rendered="{!not(layoutField.isPlaceHOlder)&¬(isNewMode)&&layoutField.fieldAPI=='RecordTypeId'}"  /> | 
 |  |  |                          | 
 |  |  |                         <apex:pageblocksectionitem rendered="{!layoutField.isPlaceHolder}"> | 
 |  |  |                         </apex:pageblocksectionitem> | 
 |  |  |                     </apex:repeat> | 
 |  |  | 
 |  |  |                         for (let n = 0; n < layoutSection.length; n++) { | 
 |  |  |                             let layoutField = layoutSection[n]; | 
 |  |  |                             if (layoutField.fieldAPI != '' && document.querySelector("[data-id='"+layoutField.fieldAPI+"']") != null) { | 
 |  |  |                                 document.querySelector("[data-id='"+layoutField.fieldAPI+"']").disabled = !(layoutField.editableField); | 
 |  |  |                                 let e = document.querySelector("[data-id='"+layoutField.fieldAPI+"']"); | 
 |  |  |                                 e.disabled = !(layoutField.editableField); | 
 |  |  |                                 // update 20220621 By Chen Yanan Start | 
 |  |  |                                 if(e.tagName == 'TEXTAREA' && layoutField.fieldAPI!= 'Staff_manual__c'){ | 
 |  |  |                                     console.log('add element'); | 
 |  |  |                                     e.cols = "75"; | 
 |  |  |                                     e.rows = "6"; | 
 |  |  |                                 } else if(e.tagName == 'TEXTAREA' && layoutField.fieldAPI == 'Staff_manual__c'){ | 
 |  |  |                                     console.log('add element'); | 
 |  |  |                                     e.cols = "40"; | 
 |  |  |                                     e.rows = "2"; | 
 |  |  |                                 } | 
 |  |  |                                 // update 20220621 By Chen Yanan End | 
 |  |  |                                 /* | 
 |  |  |                                 if (!(layoutField.editableField)) { | 
 |  |  |                                     if (e.getAttribute("multiple") && e.getAttribute("multiple") == 'multiple') { | 
 |  |  |                                         e.parentNode.classList.add("disabledbutton"); | 
 |  |  |                                     }else if (e.tagName == 'DIV') { | 
 |  |  |                                         e.classList.add("disabledbutton"); | 
 |  |  |                                     }else if (VLookUpFields.indexOf(layoutField.fieldAPI) >= 0) { | 
 |  |  |                                         e.parentNode.classList.add("disabledbutton"); | 
 |  |  |                                     } | 
 |  |  |                                 } | 
 |  |  |                                 */ | 
 |  |  |                             } | 
 |  |  |                         } | 
 |  |  |                     } | 
 |  |  | 
 |  |  |                     //3. Set Readonly Attribute | 
 |  |  |                     document.querySelector("[data-id='OwnerId']").classList.add("disabledbutton"); | 
 |  |  |                     document.querySelector("[data-id='RecordTypeId']").classList.add("disabledbutton"); | 
 |  |  |                      | 
 |  |  |                     document.getElementById('topButtonRow').style = ''; | 
 |  |  |                     document.getElementById('bottomButtonRow').style = ''; | 
 |  |  |                     //需要隐藏 | 
 |  |  |                     // document.querySelector("[data-id='SuppliedEmail']").classList.add("displayblock"); | 
 |  |  |                      | 
 |  |  | 
 |  |  |                     //     let id = jQuery("input[data-id='"+jQuery(this).attr("data-id")+ "']").attr("id"); | 
 |  |  |                     //     let input = document.getElementById(id); | 
 |  |  |                     //     if(input){ | 
 |  |  |                     //        input.value = ''; | 
 |  |  |                //       let hidden = document.getElementById(id+'_lkid'); | 
 |  |  |                     //      input.value = ''; | 
 |  |  |                     //      let hidden = document.getElementById(id+'_lkid'); | 
 |  |  |                     //         if(hidden){ | 
 |  |  |                     //            hidden.value = ''; | 
 |  |  |                     //          hidden.value = ''; | 
 |  |  |                     //         } | 
 |  |  |                     //     } | 
 |  |  |                     // }); | 
 |  |  | 
 |  |  |                         <tr> | 
 |  |  |                             <td class="pbTitle"> | 
 |  |  |                                 <img src="/img/s.gif" alt="" class="minWidth" title="" width="1" height="1" /> </td> | 
 |  |  |                             <td class="pbButton" id="bottomButtonRow"> | 
 |  |  |                             <td class="pbButton" id="bottomButtonRow" style="pointer-events: none; opacity: 0.4;"> | 
 |  |  |                                 <input class="btn" type="Button" value="保存" onclick="saveCaseProcess('Save')" /> | 
 |  |  |                                 <input class="btn" type="Button" value="保存并关闭" onclick="saveCaseProcess('SaveAndClose')" /> | 
 |  |  |                                 <input class="btn" type="Button" value="保存并新建" onclick="saveCaseProcess('SaveAndNew')" /> |