Li Jun
2022-04-27 24fda5246494953a232b37547fb50bde77bd9886
force-app/main/default/pages/NewAndEditContact.page
@@ -4,6 +4,12 @@
    <apex:includeScript value="{!URLFOR($Resource.jquery183minjs)}"/>
    <apex:includeScript value="{!URLFOR($Resource.PleaseWaitDialog)}"/>
    <apex:includeScript value="{! URLFOR($Resource.AWSService, 'AWSService.js') }" />
    <style>
        .disabledbutton {
            pointer-events: none;
            opacity: 0.4;
        }
    </style>
    <script>
        
        var config = {};
@@ -61,8 +67,9 @@
                
                //payloadJson.AWS_Data_Id__c = r.object[0].dataId;
                payloadJson.AWS_Data_Id__c = '{!AWSDataId}';
                if (isNewMode) {
                if (isNewMode || {!isCloneMode}) {
                    payloadJson.AWS_Data_Id__c = r.object[0].dataId;
                    delete payloadJson.OwnerId;
                } else {
                    payloadJson.AWS_Data_Id__c = '{!AWSDataId}';
                }
@@ -132,9 +139,23 @@
        var fieldAPIToLabelMap = JSON.parse('{!fieldAPIToLabelMapStr}');
        console.log('{!staticResource}');
        var VLookUpFields = {! VLookUpFieldsJson};
        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 ProcessPI(sobjJson, payloadForNewPI) {
            blockme();
            if ({!isNewMode}) {
            if ({!isNewMode} || {!isCloneMode}) {
               NewPIToAWS(sobjJson, payloadForNewPI)
            }else {
                UpdatePIToAWS(sobjJson, payloadForNewPI)
@@ -174,34 +195,34 @@
        function validateFieldValueFormate() {
            let error_msg = '';
            let textEmail = "[data-id='Email']";
            let textPhone = "[data-id='Phone']";
            //Email
            let email = document.querySelector(textEmail);
            if(email ){
                if(email.value){
                    if(!/^[\w-]{3,12}@[\da-zA-Z]{2,16}\.[a-zA-Z]+$/.test(email.value)){
                       error_msg += ';邮件格式错误';
                    }
                }else{
                    if(email.previousSibling && email.previousSibling.className.indexOf('requiredBlock')>-1){
                        error_msg += ';邮件格式错误';
                    }
                }
            }
            let phone = document.querySelector(textPhone);
            // let textEmail = "[data-id='Email']";
            // let textPhone = "[data-id='Phone']";
            // //Email
            // let email = document.querySelector(textEmail);
            // if(email ){
            //     if(email.value){
            //         if(!/^[\w-]{3,12}@[\da-zA-Z]{2,16}\.[a-zA-Z]+$/.test(email.value)){
            //            error_msg += ';邮件格式错误';
            //         }
            //     }else{
            //         if(email.previousSibling && email.previousSibling.className.indexOf('requiredBlock')>-1){
            //             error_msg += ';邮件格式错误';
            //         }
            //     }
            // }
            // let phone = document.querySelector(textPhone);
            if(phone && false ){
                if(phone.value){
                    if(!/^1[3|5|8|7][0-9]\d{4,8}$/.test(phone.value)){
                       error_msg += ';电话号码错误';
                    }
                }else{
                    if(phone.previousSibling && phone.previousSibling.className.indexOf('requiredBlock')>-1){
                        error_msg += ';电话号码错误';
                    }
                }
            }
            // if(phone && false ){
            //     if(phone.value){
            //         if(!/^1[3|5|8|7][0-9]\d{4,8}$/.test(phone.value)){
            //            error_msg += ';电话号码错误';
            //         }
            //     }else{
            //         if(phone.previousSibling && phone.previousSibling.className.indexOf('requiredBlock')>-1){
            //             error_msg += ';电话号码错误';
            //         }
            //     }
            // }
            let es = document.getElementsByTagName('select')
            for(let ei in es){
@@ -302,7 +323,6 @@
                    window.open('/' + sfId, '_self');
                }
            }
        }
        function UpdatePIToAWS(sobjJson, payloadForNewPI) {
@@ -338,6 +358,8 @@
            return blankRequiredFields;
        }
        function saveSobjectProcess(save_and_new) {
            EditButton(true);
            if(save_and_new){
                config.SaveAndNew = true;
            }
@@ -377,6 +399,7 @@
            errorMsg = '错误:无效数据。' + '\n' + errorMsg;
            errorMsgNode.innerText = errorMsg;
            errorMsgNode.className = 'pbError';
            EditButton(false);
        }
        function hiddenErrorMsgNode() {
            let errorMsgNode = document.getElementById("page:form:block:msgContent");
@@ -388,10 +411,10 @@
        <div class="ptBody">
            <div class="content">
                <img src="/img/s.gif" alt="{! SobjectLabel}" class="pageTitleIcon" title="{! SobjectLabel}" />
                <h1 class="pageType">{! SobjectLabel}<apex:outputText rendered="{!isNewMode}">{!$Label.New}</apex:outputText><apex:outputText rendered="{!not(isNewMode)}">{!$Label.Edit}</apex:outputText>
                <h1 class="pageType">{! SobjectLabel}<apex:outputText rendered="{!isNewMode || isCloneMode}">{!$Label.New}</apex:outputText><apex:outputText rendered="{!not(isNewMode || isCloneMode)}">{!$Label.Edit}</apex:outputText>
                    <span class="titleSeparatingColon">:</span>
                </h1>
                <h2 class="pageDescription"> <apex:outputText rendered="{!isNewMode}">{!$Label.New}</apex:outputText><apex:outputText rendered="{!not(isNewMode)}">{!$Label.Edit}</apex:outputText>{! SobjectLabel}</h2>
                <h2 class="pageDescription"> <apex:outputText rendered="{!isNewMode || isCloneMode}">{!$Label.New}</apex:outputText><apex:outputText rendered="{!not(isNewMode || isCloneMode)}">{!$Label.Edit}</apex:outputText>{! SobjectLabel}</h2>
                <div class="blank">&nbsp;</div>
            </div>
            <div class="links">
@@ -413,9 +436,9 @@
                        <tr>
                            <td class="pbTitle">
                                <img src="/img/s.gif" alt="" class="minWidth" title="" width="1" height="1" />
                                <h2 class="mainTitle">{! SobjectLabel}<apex:outputText rendered="{!isNewMode}">{!$Label.New}</apex:outputText><apex:outputText rendered="{!not(isNewMode)}">{!$Label.Edit}</apex:outputText></h2>
                                <h2 class="mainTitle">{! SobjectLabel}<apex:outputText rendered="{!isNewMode || isCloneMode}">{!$Label.New}</apex:outputText><apex:outputText rendered="{!not(isNewMode || isCloneMode)}">{!$Label.Edit}</apex:outputText></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="{!$Label.Save}" onclick="saveSobjectProcess()" />
                                <input class="btn" type="Button" value="{!$Label.SaveAndNew}" onclick="saveSobjectProcess(1)" />
                                <apex:commandButton action="{!cancel}" value="{!$Label.Cancel}" />
@@ -437,8 +460,9 @@
                    
                    <!--Each section has layoutFields, let's iterate them as well-->
                    <apex:repeat value="{!layoutSection.layoutFields}" var="layoutField">
                        <apex:inputField styleClass="{!ApiPrefix} {!ApiPrefix}_{!layoutField.fieldAPI}" html-data-id="{!layoutField.fieldAPI}" value="{!Contact[layoutField.fieldAPI]}" rendered="{!not(layoutField.isPlaceHOlder)}"
                                         required="{!layoutField.isRequired}" />
                        <apex:inputField styleClass="{!ApiPrefix} {!ApiPrefix}_{!layoutField.fieldAPI}" html-data-id="{!layoutField.fieldAPI}" value="{!Contact[layoutField.fieldAPI]}" rendered="{!not(layoutField.isPlaceHOlder)&&isNewMode}" required="{!layoutField.isRequired}" />
                        <apex:inputField styleClass="{!ApiPrefix} {!ApiPrefix}_{!layoutField.fieldAPI}" html-data-id="{!layoutField.fieldAPI}" value="{!Contact[layoutField.fieldAPI]}" rendered="{!not(layoutField.isPlaceHOlder)&&not(isNewMode)&&layoutField.fieldAPI!='RecordTypeId'}" required="{!layoutField.isRequired}" />
                        <apex:outputField styleClass="{!ApiPrefix} {!ApiPrefix}_{!layoutField.fieldAPI}" html-data-id="{!layoutField.fieldAPI}" value="{!Contact[layoutField.fieldAPI]}" rendered="{!not(layoutField.isPlaceHOlder)&&not(isNewMode)&&layoutField.fieldAPI=='RecordTypeId'}" />
                        <apex:pageblocksectionitem rendered="{!layoutField.isPlaceHolder}">
                        </apex:pageblocksectionitem>
                    </apex:repeat>
@@ -486,38 +510,10 @@
                       oi.value = '{!CurrentUserId}'
                    }
                }
                document.getElementById('topButtonRow').style = '';
                document.getElementById('bottomButtonRow').style = '';
                jQuery('a[data-id="OwnerId"]').remove();
                /*
                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 = '';
                        }
                    }
                });*/
                var layoutSections = JSON.parse('{!layoutSectionsStr}');
                for (let m = 0; m < layoutSections.length; m++) {
@@ -538,7 +534,7 @@
                        <tr>
                            <td class="pbTitle">
                                <img src="/img/s.gif" alt="" class="minWidth" title="" width="1" height="1" />&nbsp;</td>
                            <td class="pbButtonb" id="bottomButtonRow">
                            <td class="pbButtonb" id="bottomButtonRow" style="pointer-events: none; opacity: 0.4;">
                                <input class="btn" type="Button" value="{!$Label.Save}" onclick="saveSobjectProcess()" />
                                <input class="btn" type="Button" value="{!$Label.SaveAndNew}" onclick="saveSobjectProcess()" />
                                <apex:commandButton action="{!cancel}" value="{!$Label.Cancel}" />