|  |  | 
 |  |  | <apex:page standardController="On_Call__c" extensions="OnCallController" id="page"> | 
 |  |  | <apex:page standardController="On_Call__c" extensions="OnCallController" id="page" lightningStylesheets="true"> | 
 |  |  |     <apex:includeScript value="{! URLFOR($Resource.AWSService, 'AWSService.js') }" /> | 
 |  |  |     <apex:stylesheet value="{!URLFOR($Resource.blockUIcss)}"/> | 
 |  |  |     <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 { | 
 |  |  |             pointer-events: none; | 
 |  |  | 
 |  |  |         //Initial Required Information | 
 |  |  |         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 requiredFieldAPIList = JSON.parse('{!requiredFieldAPIListStr}'); | 
 |  |  |         var fieldAPIToLabelMap = JSON.parse('{!fieldAPIToLabelMapStr}'); | 
 |  |  |         var VLookUpFields = new Set(['segment__c','Hospital__c','Oncall_Equipment__c','OwnerId']); | 
 |  |  | 
 |  |  |         //Query Required Parameter | 
 |  |  |         var queryBack = function queryBack(data) { | 
 |  |  |             console.log('data = ' + data); | 
 |  |  |             document.querySelector("[id='page:form:pageBlock:pageBlockSection:j_id1:0:j_id2']").value = data.object.callerPhone; | 
 |  |  |             document.querySelector("[data-id='Responsible_Person_HP__c']").value = data.object.responsiblePersonHP; | 
 |  |  |             //document.querySelector("[id='page:form:pageBlock:pageBlockSection:j_id1:0:j_id2']").value = data.object.callerPhone; | 
 |  |  |             if(document.getElementById(api_id_map['Caller_phone__c'])) | 
 |  |  |                 document.getElementById(api_id_map['Caller_phone__c']).value = data.object.callerPhone;    //20220404  By Chen Yanan | 
 |  |  |             if(document.querySelector("[data-id='Responsible_Person_HP__c']")) | 
 |  |  |                 document.querySelector("[data-id='Responsible_Person_HP__c']").value = data.object.responsiblePersonHP; | 
 |  |  |             unblockUI(); | 
 |  |  |         }; | 
 |  |  |  | 
 |  |  | 
 |  |  |             console.log('payloadJson=' + JSON.stringify(payloadJson)); | 
 |  |  |             payloadJson.Caller_phone__c = r.object[0].callerPhone; | 
 |  |  |             payloadJson.Responsible_Person_HP__c = r.object[0].responsiblePersonHP; | 
 |  |  |             payloadJson.Caller_Phone_Encrypt__c = r.object[0].callerPhoneEncrypt; | 
 |  |  |             payloadJson.Responsible_PersonHP_Encrypt__c = r.object[0].responsiblePersonHPEncrypt; | 
 |  |  |             //zhj MEBG新方案改造 2022-11-29 start | 
 |  |  |             // payloadJson.Caller_Phone_Encrypt__c = r.object[0].callerPhoneEncrypt; | 
 |  |  |             // payloadJson.Responsible_PersonHP_Encrypt__c = r.object[0].responsiblePersonHPEncrypt; | 
 |  |  |             //zhj MEBG新方案改造 2022-11-29 end | 
 |  |  |             payloadJson.AWS_Data_Id__c = '{!AWSDataId}'; | 
 |  |  |             if (isNewMode) { | 
 |  |  |             if (isNewMode|| {!isCloneMode} ||!'{!AWSDataId}') {//Add by Li Jun for PIPL 20220413 | 
 |  |  |                 payloadJson.AWS_Data_Id__c = r.object[0].dataId; | 
 |  |  |                 delete payloadJson.OwnerId; | 
 |  |  |             } else { | 
 |  |  |                 payloadJson.AWS_Data_Id__c = '{!AWSDataId}'; | 
 |  |  |             } | 
 |  |  |             debugger | 
 |  |  |             if('{!sfRecordIdForEdit}'){ | 
 |  |  |                 payloadJson.Id = '{!sfRecordIdForEdit}'; | 
 |  |  |             } | 
 |  |  |             if('{!rtTypeId}'){ | 
 |  |  |                 payloadJson.RecordTypeId = '{!rtTypeId}';//Add by zhj for Record Type Issue 20220421 | 
 |  |  |             } | 
 |  |  |             return payloadJson; | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         // New Or Edit | 
 |  |  |         function ProcessPI(onCallJson, payloadForNewPI) { | 
 |  |  |             blockme(); | 
 |  |  |             if ({!isNewMode | 
 |  |  |             }) { | 
 |  |  |             if ({!isNewMode} || {!isCloneMode} ||!'{!AWSDataId}') {//Add by Li Jun for PIPL 20220413 | 
 |  |  |                 NewPIToAWS(onCallJson, payloadForNewPI) | 
 |  |  |             }else { | 
 |  |  |                 UpdatePIToAWS(onCallJson, payloadForNewPI) | 
 |  |  | 
 |  |  |                     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; | 
 |  |  |                         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; | 
 |  |  | 
 |  |  |             let obj = JSON.parse(payloadForNewPI); | 
 |  |  |             obj[0].dataId = '{!AWSDataId}'; | 
 |  |  |             let payloadForNewPIJson = JSON.stringify(obj); | 
 |  |  |             AWSService.update(staticResources.updateUrl, onCallJson, payloadForNewPIJson, controllerSaveMethod, staticResources.token, staticResources.transactionUrl, false, insertOrUpdateBack, redirectCallBack); | 
 |  |  |             //zhj MEBG新方案改造 2022-11-29 start | 
 |  |  |             //AWSService.update(staticResources.updateUrl, onCallJson, payloadForNewPIJson, controllerSaveMethod, staticResources.token, staticResources.transactionUrl, false, insertOrUpdateBack, redirectCallBack); | 
 |  |  |             AWSService.update(staticResourcesV2.updateUrl, onCallJson, payloadForNewPIJson, controllerSaveMethod, staticResources.token, staticResourcesV2.transactionUrl, false, insertOrUpdateBack, redirectCallBack); | 
 |  |  |             //zhj MEBG新方案改造 2022-11-29 end | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         //Insert Sensitive Information to AWS | 
 |  |  |         function NewPIToAWS(onCallJson, payloadForNewPI) { | 
 |  |  |             let controllerSaveMethod = '{!$RemoteAction.OnCallController.saveOnCall}'; | 
 |  |  |             AWSService.insert(staticResources.newUrl, onCallJson, payloadForNewPI, controllerSaveMethod, staticResources.token, staticResources.transactionUrl, true, insertOrUpdateBack, redirectCallBack); | 
 |  |  |             //zhj MEBG新方案改造 2022-11-29 start | 
 |  |  |             //AWSService.insert(staticResources.newUrl, onCallJson, payloadForNewPI, controllerSaveMethod, staticResources.token, staticResources.transactionUrl,{!isNewMode}, insertOrUpdateBack, redirectCallBack); | 
 |  |  |             AWSService.insert(staticResourcesV2.newUrl, onCallJson, payloadForNewPI, controllerSaveMethod, staticResourcesV2.token, staticResources.transactionUrl,{!isNewMode}, insertOrUpdateBack, redirectCallBack); | 
 |  |  |             //zhj MEBG新方案改造 2022-11-29 end | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         //Check Required Fields | 
 |  |  |         function checkRequiredFieldMsg(formData) { | 
 |  |  |             let blankRequiredFields = ''; | 
 |  |  |             for (i = 0; i < requiredFieldAPIList.length; i++) { | 
 |  |  |                 if (formData[requiredFieldAPIList[i]]) { | 
 |  |  |                 if (formData[requiredFieldAPIList[i]] && !VLookUpFields.has(requiredFieldAPIList[i])) { | 
 |  |  |                     continue; | 
 |  |  |                 }else if(VLookUpFields.has(requiredFieldAPIList[i]) && formData[requiredFieldAPIList[i]] != '000000000000000'){ | 
 |  |  |                     continue; | 
 |  |  |                 } else { | 
 |  |  |                     if (blankRequiredFields == '') { | 
 |  |  | 
 |  |  |             } | 
 |  |  |             return blankRequiredFields; | 
 |  |  |         } | 
 |  |  |         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"); | 
 |  |  |             } | 
 |  |  |         } | 
 |  |  |         //Base Process | 
 |  |  |         function saveOnCallProcess(saveMode) { | 
 |  |  |             EditButton(true); | 
 |  |  |             redirectMode = saveMode; | 
 |  |  |             console.log('redirectMode' + redirectMode); | 
 |  |  |             hiddenErrorMsgNode(); | 
 |  |  | 
 |  |  |  | 
 |  |  |         //Alert Error Message | 
 |  |  |         function alertErrorMessage(errorMsg) { | 
 |  |  |             let errorMsgNode = document.getElementById("page:form:msgContent"); | 
 |  |  |             let errorMsgNode = document.getElementById("page:form:block:msgContent"); | 
 |  |  |             errorMsg = '错误:无效数据。' + '\n' + errorMsg; | 
 |  |  |             errorMsgNode.innerText = errorMsg; | 
 |  |  |             errorMsgNode.className = 'pbError'; | 
 |  |  |             unblockUI(); | 
 |  |  |             EditButton(false); | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         //Hide Error Message | 
 |  |  |         function hiddenErrorMsgNode() { | 
 |  |  |             let errorMsgNode = document.getElementById("page:form:msgContent"); | 
 |  |  |             let errorMsgNode = document.getElementById("page:form:block:msgContent"); | 
 |  |  |             errorMsgNode.innerText = ''; | 
 |  |  |             errorMsgNode.className = ''; | 
 |  |  |         } | 
 |  |  |         var GetEleApiName = function(ele){ | 
 |  |  |             for(let ci in ele.classList){ | 
 |  |  |                 let c = ele.classList[ci]; | 
 |  |  |                 if(c.indexOf('PIBackApi'+'_')>-1){ | 
 |  |  |                     return c.replace('PIBackApi'+'_',''); | 
 |  |  |                 } | 
 |  |  |             } | 
 |  |  |             return ''; | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         function IsFormTag(tag_name){ | 
 |  |  |             if (!tag_name) { | 
 |  |  |                 return false; | 
 |  |  |             } | 
 |  |  |             return ['input','select','textarea'].indexOf(tag_name.toLowerCase())>-1; | 
 |  |  |         } | 
 |  |  |          | 
 |  |  |         function IsFormElement(e){ | 
 |  |  |             return IsFormTag(e.tagName); | 
 |  |  |         } | 
 |  |  |     </script> | 
 |  |  |     <div class="bPageTitle"> | 
 |  |  | 
 |  |  |         <div class="ptBreadcrumb"></div> | 
 |  |  |     </div> | 
 |  |  |     <apex:form id="form"> | 
 |  |  |         <!-- Error Msg--> | 
 |  |  |         <apex:outputPanel id="errorMsg"> | 
 |  |  |             <apex:pageMessages id="msgContent" escape="false" /> | 
 |  |  |         </apex:outputPanel> | 
 |  |  |         <apex:pageblock > | 
 |  |  |         <apex:pageblock id="block" > | 
 |  |  |             <div class="pbHeader"> | 
 |  |  |                 <table cellspacing="0" cellpadding="0" border="0"> | 
 |  |  |                     <tbody> | 
 |  |  | 
 |  |  |                                 <img src="/img/s.gif" alt="" class="minWidth" title="" width="1" height="1" /> | 
 |  |  |                                 <h2 class="mainTitle">OnCall编辑</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="saveOnCallProcess('Save')" /> | 
 |  |  |                                 <input class="btn" type="Button" value="保存并新建" onclick="saveOnCallProcess('SaveAndNew')" /> | 
 |  |  |                                 <apex:commandButton action="{!cancel}" value="取消" /> | 
 |  |  | 
 |  |  |                     </tbody> | 
 |  |  |                 </table> | 
 |  |  |             </div> | 
 |  |  |             <!-- Error Msg--> | 
 |  |  |             <div style="text-align: center;"> | 
 |  |  |                 <apex:outputPanel id="errorMsg"> | 
 |  |  |                     <apex:pageMessages id="msgContent" escape="false" /> | 
 |  |  |                 </apex:outputPanel> | 
 |  |  |             </div> | 
 |  |  |             <!-- Iterate the layoutSections, which is a list of sections --> | 
 |  |  |             <apex:repeat value="{!layoutSections}" var="layoutSection"> | 
 |  |  |                 <apex:pageBlockSection title="{!layoutSection.name}" 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="{!On_Call__c[layoutField.fieldAPI]}" rendered="{!not(layoutField.isPlaceHOlder)}" | 
 |  |  |                        <apex:inputField styleClass="PIBackApi PIBackApi_{!layoutField.fieldAPI}" html-data-id="{!layoutField.fieldAPI}" value="{!On_Call__c[layoutField.fieldAPI]}" rendered="{!not(layoutField.isPlaceHOlder)&&isNewMode}" | 
 |  |  |                             required="{!layoutField.isRequired}" /> | 
 |  |  |                         <apex:inputField styleClass="PIBackApi PIBackApi_{!layoutField.fieldAPI}" html-data-id="{!layoutField.fieldAPI}" value="{!On_Call__c[layoutField.fieldAPI]}" rendered="{!not(layoutField.isPlaceHOlder)&¬(isNewMode)&&layoutField.fieldAPI!='RecordTypeId'}" | 
 |  |  |                             required="{!layoutField.isRequired}" /> | 
 |  |  |                         <apex:outputField styleClass="PIBackApi PIBackApi_{!layoutField.fieldAPI}" html-data-id="{!layoutField.fieldAPI}" value="{!On_Call__c[layoutField.fieldAPI]}" rendered="{!not(layoutField.isPlaceHOlder)&¬(isNewMode)&&layoutField.fieldAPI=='RecordTypeId'}" | 
 |  |  |                        /> | 
 |  |  |                         <apex:pageblocksectionitem rendered="{!layoutField.isPlaceHolder}"> | 
 |  |  |                         </apex:pageblocksectionitem> | 
 |  |  |                     </apex:repeat> | 
 |  |  | 
 |  |  |                 </apex:pageBlockSection> | 
 |  |  |             </apex:repeat> | 
 |  |  |             <script> | 
 |  |  |                 var init_nodes = document.getElementsByClassName("PIBackApi"); | 
 |  |  |                 var api_id_map={}; | 
 |  |  |                 for(let ei in init_nodes){ | 
 |  |  |                     let e = init_nodes[ei]; | 
 |  |  |                     if(IsFormElement(e)){ | 
 |  |  |                         if(e.getAttribute("multiple") != 'multiple' || e.style.display == 'none' && e.id.indexOf('selected') < 0){ | 
 |  |  |                             api_id_map[GetEleApiName(e)] = e.id; | 
 |  |  |                         } | 
 |  |  |                          | 
 |  |  |                     } | 
 |  |  |                 } | 
 |  |  |                 //Append Page | 
 |  |  |                 sfdcPage.appendToOnloadQueue(function () { | 
 |  |  |                     var layoutSections = JSON.parse('{!layoutSectionsStr}'); | 
 |  |  |                     for (let m = 0; m < layoutSections.length; m++) { | 
 |  |  |                         let layoutSection = layoutSections[m].layoutFields; | 
 |  |  |                         for (let n = 0; n < layoutSection.length; n++) { | 
 |  |  |                             let layoutField = layoutSection[n]; | 
 |  |  |                             if (layoutField.fieldAPI != '' && document.querySelector("[data-id='"+layoutField.fieldAPI+"']") != null) { | 
 |  |  |                                 let e = document.querySelector("[data-id='"+layoutField.fieldAPI+"']"); | 
 |  |  |                                 e.disabled = !(layoutField.editableField); | 
 |  |  |                                 if (!(layoutField.editableField)) { | 
 |  |  |                                     if (e.getAttribute("multiple") && e.getAttribute("multiple") == 'multiple') { | 
 |  |  |                                         e.parentNode.classList.add("disabledbutton"); | 
 |  |  |                                     } | 
 |  |  |                                     if (e.tagName == 'DIV') { | 
 |  |  |                                         e.classList.add("disabledbutton"); | 
 |  |  |                                     } | 
 |  |  |                                 } | 
 |  |  |                             } | 
 |  |  |                         } | 
 |  |  |                     } | 
 |  |  |                     //2. Query AWS Data by dataId  | 
 |  |  |                     console.log('Mode for onCall Page:' + {!isNewMode}); | 
 |  |  |                     if (!{!isNewMode}) { | 
 |  |  | 
 |  |  |                         QueryOnCallFromAWS(); | 
 |  |  |                     }; | 
 |  |  |                     document.querySelector("[data-id='OwnerId']").classList.add("disabledbutton"); | 
 |  |  |  | 
 |  |  |                     document.getElementById('topButtonRow').style = ''; | 
 |  |  |                document.getElementById('bottomButtonRow').style = ''; | 
 |  |  |  | 
 |  |  |                     jQuery(".lookupInput").each(function(i,e){ | 
 |  |  |                         let je =jQuery(e).find('input'); | 
 |  |  |                         je.attr("readonly",""); | 
 |  |  |                         je.css("background","unset"); | 
 |  |  |                          | 
 |  |  |                         let dataid = je.attr('data-id'); | 
 |  |  |                         if(['Hospital_Name__c','Department_Class__c','OwnerId'].indexOf(dataid) > -1) return; | 
 |  |  |                         jQuery(e).children(":last-child").before('<img class="closeIcon" data-id="'+dataid+'" generate="" alt="Clear" src="/s.gif" style="display: inline-block;">'); | 
 |  |  |                     }) | 
 |  |  |                      | 
 |  |  |                     jQuery(".lookupInput").on("mouseenter","img[generate]",function(e){ | 
 |  |  |                         this.className = "closeIconOn"; | 
 |  |  |                     }); | 
 |  |  |                      | 
 |  |  |                     jQuery(".lookupInput").on("mouseleave","img[generate]",function(e){ | 
 |  |  |                         this.className = "closeIcon" | 
 |  |  |                     }); | 
 |  |  |                      | 
 |  |  |                     jQuery(".lookupInput").on("click","img[generate]",function(e){ | 
 |  |  |                         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'); | 
 |  |  |                             if(hidden){ | 
 |  |  |                                 hidden.value = ''; | 
 |  |  |                             } | 
 |  |  |                         } | 
 |  |  |                     }); | 
 |  |  |                 }); | 
 |  |  |             </script> | 
 |  |  |             <div class="pbBottomButtons"> | 
 |  |  | 
 |  |  |                         <tr> | 
 |  |  |                             <td class="pbTitle"> | 
 |  |  |                                 <img src="/img/s.gif" alt="" class="minWidth" title="" width="1" height="1" /> </td> | 
 |  |  |                             <td class="pbButtonb" id="bottomButtonRow"> | 
 |  |  |                             <td class="pbButtonb" id="bottomButtonRow" style="pointer-events: none; opacity: 0.4;"> | 
 |  |  |                                 <input class="btn" type="Button" value="保存" onclick="saveOnCallProcess('Save')" /> | 
 |  |  |                                 <input class="btn" type="Button" value="保存并新建" onclick="saveOnCallProcess('SaveAndNew')" /> | 
 |  |  |                                 <apex:commandButton action="{!cancel}" value="取消" /> |