FUYU
2023-05-19 559771a80cf779dc13a84ecd2f178e6ca5a8353a
force-app/main/default/pages/NewRentalApply.page
@@ -1,16 +1,9 @@
<!--
  @description       :
  @author            : Dennis
  @group             :
  @last modified on  : 04-01-2022
  @last modified by  : ChangeMeIn@UserSettingsUnder.SFDoc
-->
<apex:page standardController="Rental_Apply__c" extensions="RentalApplyController" id="page">
    <apex:stylesheet value="{!URLFOR($Resource.blockUIcss)}"/>
    <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 {
            pointer-events: none;
@@ -20,6 +13,12 @@
    <script>
        //Initial Required Information
        var staticResources = JSON.parse('{!staticResource}');
        //zhj MEBG新方案改造 2022-11-29 start
        var staticResourcesV2 = JSON.parse('{!staticResourceV2}');
        var isEdit = JSON.parse('{!isEdit}');
        var phoneNumber = '';
        var directShippmentAddress = '';
        //zhj MEBG新方案改造 2022-11-29 end
        var staticResourcesContact = JSON.parse('{!staticResourceContact}');
        var requiredFieldAPIList = JSON.parse('{!requiredFieldAPIListStr}');
        var fieldAPIToLabelMap = JSON.parse('{!fieldAPIToLabelMapStr}');
@@ -46,9 +45,21 @@
        //Query Required Parameter
        var queryBack = function queryBack(data) {
            console.log('data = ' + data);
            document.querySelector("[data-id='Phone_number__c']").value = data.object.phoneNumber;
            document.querySelector("[data-id='direct_shippment_address__c']").value = data.object.directShippmentAddress;
            // document.querySelector("[data-id='Phone_number__c']").value = data.object.phoneNumber;
            // document.querySelector("[data-id='direct_shippment_address__c']").value = data.object.directShippmentAddress;
            //zhj MEBG新方案改造 2022-11-29 start
            if(document.querySelector("[data-id='Phone_number__c']")){
                document.querySelector("[data-id='Phone_number__c']").value = data.object.phoneNumber;
                phoneNumber = data.object.phoneNumber == null ? '': data.object.phoneNumber;
            }
            if(document.querySelector("[data-id='direct_shippment_address__c']")){
                document.querySelector("[data-id='direct_shippment_address__c']").value = data.object.directShippmentAddress;
                directShippmentAddress = data.object.directShippmentAddress == null ? '' : data.object.directShippmentAddress;
            }
            //zhj MEBG新方案改造 2022-11-29 end
            unblockUI();
            enableButtonStatus();//Add by Li Jun 20220418
        };
        //Check If Insert Or Update
@@ -60,23 +71,67 @@
            console.log('payloadJson=' + JSON.stringify(payloadJson));
            payloadJson.Phone_number__c = r.object[0].phoneNumber;
            payloadJson.direct_shippment_address__c = r.object[0].directShippmentAddress;
            payloadJson.Phone_Number_Encrypt__c = r.object[0].phoneNumberEncrypt;
            payloadJson.Direct_Shippment_Address_Encrypt__c = r.object[0].directShippmentAddressEncrypt;
            //zhj MEBG新方案改造 2022-11-29 start
            // payloadJson.Phone_Number_Encrypt__c = r.object[0].phoneNumberEncrypt;
            // payloadJson.Direct_Shippment_Address_Encrypt__c = r.object[0].directShippmentAddressEncrypt;
            //zhj MEBG新方案改造 2022-11-29 end
            payloadJson.AWS_Data_Id__c = '{!AWSDataId}';
            if (isNewMode) {
            if('{!rtTypeId}'){
                payloadJson.RecordTypeId = '{!rtTypeId}';//Add by Li Jun for Record Type Issue 20220419
            }
            if (isNewMode || {!isCloneMode}) {
                payloadJson.AWS_Data_Id__c = r.object[0].dataId;
                delete payloadJson.OwnerId;
            } else {
                payloadJson.AWS_Data_Id__c = '{!AWSDataId}';
            }
            debugger
            if('{!rtTypeId}'){
                payloadJson.RecordTypeId = '{!rtTypeId}';//Add by zhj for Record Type Issue 20220421
            }
            return payloadJson;
        }
        //Add Button status start 20220418
        function enableButton(obj) {
            obj.classList.remove("btnDisabled");
        }
        function disableButton(obj) {
            obj.classList.add("btnDisabled");
        }
        function disableButtonStatus() {
            let btnList = document.getElementsByClassName('btn');
            for (let i = 0; i < btnList.length; i++) {
                disableButton(btnList[i]);
            }
        }
        function enableButtonStatus() {
            let btnList = document.getElementsByClassName('btn');
            for (let i = 0; i < btnList.length; i++) {
                enableButton(btnList[i]);
            }
        }
        disableButtonStatus();
        //Add Button status end 20220418
        // New Or Edit
        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(rentalApplyJson, payloadForNewPI) {
            blockme();
            if ({!isNewMode
            }) {
            if ({!isNewMode} || {!isCloneMode}) {
                NewPIToAWS(rentalApplyJson, payloadForNewPI)
            }else {
                UpdatePIToAWS(rentalApplyJson, payloadForNewPI)
@@ -105,8 +160,8 @@
            }
            return ['input','select','textarea'].indexOf(tag_name.toLowerCase())>-1;
        }
       function IsFormElement(e){
        function IsFormElement(e){
            return IsFormTag(e.tagName);
        }
@@ -149,15 +204,17 @@
            // }
            // result.HP_received_sign_rich__c = CKEDITOR.instances["page:form:block:j_id34:12:j_id35:j_id36:1:j_id37:textAreaDelegate_HP_received_sign_rich__c"].getData();
            // if(document.querySelector("[aria-describedby = 'cke_71']")){
            //     result.   Extension_List_RentalApply__c = document.querySelector("[aria-describedby = 'cke_71']").contentWindow.document.getElementsByTagName('body')[0].innerHTML
            //     result.  Extension_List_RentalApply__c = document.querySelector("[aria-describedby = 'cke_71']").contentWindow.document.getElementsByTagName('body')[0].innerHTML
            // }
            for (let index = 0; index < nodelist.length; index++) {
                if (VLookUpFields.has(nodelist[index].getAttribute("data-id"))) {
                    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(document.getElementById(vlookUpNodeId)){
                            let vlookUpNodeValue = document.getElementById(vlookUpNodeId).value;
                            result[nodelist[index].getAttribute("data-id")] = vlookUpNodeValue;
                        }
                    }
                } else if (nodelist[index].type == 'checkbox') {
                    result[nodelist[index].getAttribute("data-id")] = nodelist[index].checked;
@@ -185,20 +242,21 @@
                    }
                }             
            }
            if(document.querySelector("[id='page:form:block:j_id34:2:j_id35:j_id36:2:j_id37']")!=null){
                result.demo_purpose2__c = document.querySelector("[id='page:form:block:j_id34:2:j_id35:j_id36:2:j_id37']").value;
            if(api_id_map['demo_purpose2__c']){
                result.demo_purpose2__c = document.getElementById(api_id_map['demo_purpose2__c']).value!='_\x01_'?document.getElementById(api_id_map['demo_purpose2__c']).value:'';
            }            
            if(document.querySelector("[id='page:form:block:j_id34:0:j_id35:j_id36:18:j_id37']")!=null){
                result.ToAgency__c = document.querySelector("[id='page:form:block:j_id34:0:j_id35:j_id36:18:j_id37']").value;
            if(api_id_map['ToAgency__c']){
                result.ToAgency__c = document.getElementById(api_id_map['ToAgency__c']).value!='_\x01_'?document.getElementById(api_id_map['ToAgency__c']).value:'';
            }            
            //document.querySelector("[id='page:form:block:j_id34:0:j_id35:j_id36:18:j_id37']").disabled =true; // Commented By Li Jun 20220304
            if(document.querySelector("[id='page:form:block:j_id34:13:j_id35:j_id36:1:j_id37']")!=null){
                result.Loaner_cancel_reason__c = document.querySelector("[id='page:form:block:j_id34:13:j_id35:j_id36:1:j_id37']").value;
            }else{
                if(document.querySelector("[id='page:form:block:j_id34:11:j_id35:j_id36:1:j_id37']")!=null){
                    result.Loaner_cancel_reason__c = document.querySelector("[id='page:form:block:j_id34:11:j_id35:j_id36:1:j_id37']").value;
                }
            if(api_id_map['Loaner_cancel_reason__c']){
                result.Loaner_cancel_reason__c = document.getElementById(api_id_map['Loaner_cancel_reason__c']).value!='_\x01_'?document.getElementById(api_id_map['Loaner_cancel_reason__c']).value:'';
            }
            // else{
            //     if(document.querySelector("[id='page:form:block:j_id34:11:j_id35:j_id36:1:j_id37']")!=null){
            //         result.Loaner_cancel_reason__c = document.querySelector("[id='page:form:block:j_id34:11:j_id35:j_id36:1:j_id37']").value;
            //     }
            // }
            // //格式化时间
            // if(result.HP_received_sign_day__c){
            //     result.HP_received_sign_day__c = result.HP_received_sign_day__c.replace(/\//g, '-')+':00';
@@ -211,9 +269,13 @@
            if(e){
                    result.Extension_List_RentalApply__c = e.getData();
                }
            if(document.getElementById('page:form:block:j_id34:0:j_id35:j_id36:13:j_id37' + '_lkid')!=null){
            if(document.getElementById(api_id_map['Office_Assistant1__c'] + '_lkid')!=null){
                // result.ToAgency__c = document.getElementById('page:form:block:j_id34:0:j_id35:j_id36:18:j_id37').value;
                result.Office_Assistant1__c = document.getElementById('page:form:block:j_id34:0:j_id35:j_id36:13:j_id37' + '_lkid').value;
                result.Office_Assistant1__c = document.getElementById(api_id_map['Office_Assistant1__c'] + '_lkid').value;
            }
            if(document.getElementById(api_id_map['Office_Assistant2__c'] + '_lkid')!=null){
                // result.ToAgency__c = document.getElementById('page:form:block:j_id34:0:j_id35:j_id36:18:j_id37').value;
                result.Office_Assistant2__c = document.getElementById(api_id_map['Office_Assistant2__c'] + '_lkid').value;
            }
            console.log(JSON.stringify(result));
            return result;
@@ -230,20 +292,30 @@
            let obj = JSON.parse(payloadForNewPI);
            obj[0].dataId = '{!AWSDataId}';
            let payloadForNewPIJson = JSON.stringify(obj);
            AWSService.update(staticResources.updateUrl, rentalApplyJson, payloadForNewPIJson, controllerSaveMethod, staticResources.token, staticResources.transactionUrl, false, insertOrUpdateBack, redirectCallBack);
            //zhj MEBG新方案改造 2022-11-29 start
            //AWSService.update(staticResources.updateUrl, rentalApplyJson, payloadForNewPIJson, controllerSaveMethod, staticResources.token, staticResources.transactionUrl, false, insertOrUpdateBack, redirectCallBack);
            AWSService.update(staticResourcesV2.updateUrl, rentalApplyJson, payloadForNewPIJson, controllerSaveMethod, staticResources.token, staticResourcesV2.transactionUrl, false, insertOrUpdateBack, redirectCallBack);
            //zhj MEBG新方案改造 2022-11-29 end
        }
        //Insert Sensitive Information to AWS
        function NewPIToAWS(rentalApplyJson, payloadForNewPI) {
            let controllerSaveMethod = '{!$RemoteAction.RentalApplyController.saveRentalApply}';
            AWSService.insert(staticResources.newUrl, rentalApplyJson, payloadForNewPI, controllerSaveMethod, staticResources.token, staticResources.transactionUrl, true, insertOrUpdateBack, redirectCallBack);
            //zhj MEBG新方案改造 2022-11-29 start
            //AWSService.insert(staticResources.newUrl, rentalApplyJson, payloadForNewPI, controllerSaveMethod, staticResources.token, staticResources.transactionUrl, true, insertOrUpdateBack, redirectCallBack);
            debugger
            console.log('staticResourcesV2.newUrl = ' + staticResourcesV2.newUrl);
            AWSService.insert(staticResourcesV2.newUrl, rentalApplyJson, payloadForNewPI, controllerSaveMethod, staticResources.token, staticResourcesV2.transactionUrl, true, 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 == '') {
@@ -259,6 +331,7 @@
        //Base Process
        function saveRentalApplyProcess(saveMode) {
            EditButton(true);
            redirectMode = saveMode;
            console.log('redirectMode' + redirectMode);
            hiddenErrorMsgNode();
@@ -281,6 +354,14 @@
            //3. Prepare the payload for New PI API To AWS - To Do
            let payloadForNewPI = getPIPayload(rentalApplyJson);
            //zhj MEBG新方案改造 2022-11-29 start
            debugger
            if(isEdit == true && (rentalApplyJson.Phone_number__c != phoneNumber || rentalApplyJson.direct_shippment_address__c != directShippmentAddress)){
                alertErrorMessage('申请单批准后,不能编辑备品借用信息');
                return
            }
            //zhj MEBG新方案改造 2022-11-29 end
            //4. rentalApply to AWS 
            ProcessPI(rentalApplyJson, payloadForNewPI);
        }
@@ -292,6 +373,7 @@
            errorMsgNode.innerText = errorMsg;
            errorMsgNode.className = 'pbError';
            unblockUI();
            EditButton(false);
        }
        //Hide Error Message
@@ -399,7 +481,7 @@
                                <img src="/img/s.gif" alt="" class="minWidth" title="" width="1" height="1" />
                                <h2 class="mainTitle">备品借出申请编辑</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="saveRentalApplyProcess('Save')" />
                                <input class="btn" type="Button" value="保存并新建" onclick="saveRentalApplyProcess('SaveAndNew')" />
                                <apex:commandButton action="{!cancel}" value="取消" />
@@ -420,8 +502,12 @@
                    <!--Each section has layoutFields, let's iterate them as well-->
                    <apex:repeat value="{!layoutSection.layoutFields}" var="layoutField">
                        <apex:inputField styleClass="PIBackApi PIBackApi_{!layoutField.fieldAPI}" html-data-id="{!layoutField.fieldAPI}" value="{!Rental_Apply__c[layoutField.fieldAPI]}" rendered="{!not(layoutField.isPlaceHOlder)}"
                        <apex:inputField styleClass="PIBackApi PIBackApi_{!layoutField.fieldAPI}" html-data-id="{!layoutField.fieldAPI}" value="{!Rental_Apply__c[layoutField.fieldAPI]}" rendered="{!not(layoutField.isPlaceHOlder)&&isNewMode}"
                            required="{!layoutField.isRequired}" />
                        <apex:inputField styleClass="PIBackApi PIBackApi_{!layoutField.fieldAPI}" html-data-id="{!layoutField.fieldAPI}" value="{!Rental_Apply__c[layoutField.fieldAPI]}" rendered="{!not(layoutField.isPlaceHOlder)&&not(isNewMode)&&layoutField.fieldAPI!='RecordTypeId'}"
                            required="{!layoutField.isRequired}" />
                        <apex:outputField styleClass="PIBackApi PIBackApi_{!layoutField.fieldAPI}" html-data-id="{!layoutField.fieldAPI}" value="{!Rental_Apply__c[layoutField.fieldAPI]}" rendered="{!not(layoutField.isPlaceHOlder)&&not(isNewMode)&&layoutField.fieldAPI=='RecordTypeId'}"
                       />
                        <apex:pageblocksectionitem rendered="{!layoutField.isPlaceHolder}">
                        </apex:pageblocksectionitem>
                    </apex:repeat>
@@ -429,6 +515,7 @@
                </apex:pageBlockSection>
            </apex:repeat>
            <script>
                blockme(); //zhj 2022-12-28 improve
               var init_nodes = document.getElementsByClassName("PIBackApi");
                var api_id_map={};
                for(let ei in init_nodes){
@@ -437,7 +524,14 @@
                        if(e.getAttribute("multiple") != 'multiple' || e.style.display == 'none' && e.id.indexOf('selected') < 0){
                            api_id_map[GetEleApiName(e)] = e.id;
                        }
                    }else{
                        let eid = jQuery(e).find(".lookupInput input").attr("id")
                        if(eid){
                            eid += '_lkid';
                            if(document.getElementById(eid)){
                                api_id_map[GetEleApiName(e)] = eid;
                            }
                        }
                    }
                }
                console.log(api_id_map);
@@ -471,19 +565,25 @@
                    var onlyReadFields = ['ExtensionStatus__c','ExtensionApplicationTime_Initial__c','ExtensionApprovalTime_Initial__c','ExtensionApplicationTime_Final__c','ExtensionApprovalTime_Final__c','ExtensionSuccessTimes__c','ZongjianApprovalManager__c','BuchangApprovalManager__c','JingliApprovalManager__c','BuchangApprovalManagerSales__c','SalesManager__c'];
                    console.log(onlyReadFields);
                    for(let i=0;i<onlyReadFields.length;i++){
                        document.querySelector('[data-id='+onlyReadFields[i]+']').parentNode.remove();
                        if(document.querySelector('[data-id='+onlyReadFields[i]+']')){
                            document.querySelector('[data-id='+onlyReadFields[i]+']').parentNode.remove();
                        }
                    }
                    
                    //2. Query AWS Data by dataId 
                    console.log('Mode for rentalApply Page:' + {!isNewMode});
                    if (!{!isNewMode}) {
                        blockme();
                        QueryRentalApplyFromAWS();
                    }else{
                        enableButtonStatus();//Add by Li Jun 20220418
                    };
                    //Replace Vlookup Field
                    replaceSearchContactLookup();
                    document.querySelector("[data-id='OwnerId']").classList.add("disabledbutton");
                    document.getElementById('topButtonRow').style = '';
             document.getElementById('bottomButtonRow').style = '';
                    let previous_value = {};
                    jQuery(".lookupInput input").each(function(i,e){
                        let je =jQuery(e);
@@ -501,6 +601,8 @@
                            }
                        })
                    });
                    unblockUI();
                                        
@@ -543,7 +645,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="保存" onclick="saveRentalApplyProcess('Save')" />
                                <input class="btn" type="Button" value="保存并新建" onclick="saveRentalApplyProcess('SaveAndNew')" />
                                <apex:commandButton action="{!cancel}" value="取消" />