• ratu kucing
  • NEWBIE
  • 0 Points
  • Member since 2022

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 1
    Replies
I have a program that can update ppd schedule time.
the code that I made now if I make changes to ppd schedule time and does not give a time lag before checking or saving data, then the data list does not match the updated data.
for example: I make changes to 5 data lists, if I immediately press the check button, only 4 data will be displayed (the last data is not included in the list), but if I check in system.debug, the five data have been entered into the list .
I really don't know what to do.
I have tried to give a breaktime before the data is displayed when pressing the check button, but it doesn't work, and if I give it more than 10 seconds it will get a cpu limit error
but if I give a time lag (just press the check button after a few seconds) then the data in the list matches the one in system.debug
this is my vfp code:
<apex:pageBlock >
   <apex:commandButton value="Check" action="{!check}" />
   <br/>
   {!updateDeliveryScheduleList}
</apex:pageBlock>

<apex:pageMessages id="pageMessages" />
<body>
    <apex:actionStatus startStyleClass="loadingMessage" startText="loading..." id="loadStatus">
    </apex:actionStatus>
    <apex:tabPanel switchType="client" selectedTab="name2" id="theTabPanel">
        <apex:tab label="Validate" name="validate" id="tabValidate">
            <apex:outputPanel id="wrapSalesPlanTable">
                <script>
                    j$(document).ready( function () {
                    j$('[id$="salesPlanTable"]').DataTable({iDisplayLength: 50, searching: false, dom: 'lBfrtip', stateSave: true, order: [], buttons: ['excel']});
                    });
                </script>
                <table id="salesPlanTable" class="stripe row-border order-column" style="width:100%"> 
                    <thead>
                        <tr>                                
                            <th id="columnA">PPD Delivery Schedule</th>
                            <th id="columnB">Check Opex</th>
                        </tr>
                    </thead>
                    <tbody>
                        <apex:repeat value="{!dataSalesPlan}" var="i">
                            <tr>
                                <th id="columnA">
                                    <apex:input type="date" value="{!i.deliverySchedulePPD}">
                                        <apex:actionSupport event="onblur" action="{!updateDeliverySchedule}" reRender="">
                                            <apex:param name="salesPlanIndex" value="{!i.index}" assignTo="{!salesPlanIndex}"/>
                                        </apex:actionSupport>
                                    </apex:input>
                                </th>
                                <th id="columnB">
                                    <apex:inputCheckbox styleClass="checkOpex{!i.spd.ID} checkOpex {!i.spd.ID}" value="{!i.opex}">
                                        <apex:actionSupport event="onchange" action="{!updateOpex}" reRender="">
                                           <apex:param name="salesPlanIndex" value="{!i.index}" assignTo="{!salesPlanIndex}"/>
                                        </apex:actionSupport>
                                    </apex:inputCheckbox>
                                </th>
                             </tr>
                        </apex:repeat>
                    </tbody>
                </table>
            </apex:outputPanel>
        </apex:tab>
    </apex:tabPanel>
</body>
this is my apex code:
public List<Sales_Plan_Detail__c> getDataSalesPlan {get;set;}
    public List<SPDWrapper> dataSalesPlan {get;set;}
    public Id[] updateSPDIds {get;set;}
    public Map<Id, Date> updateDeliveryScheduleList {get;set;}
    public Integer salesPlanIndex {get; set;}
    
    public UT_Checklist_Sales_Plan() { //constractor
        updateDeliveryScheduleList = new Map<Id, Date>();
    } 
        
    public void updateDeliverySchedule() {
        SPDWrapper spdWrapper = dataSalesPlan[salesPlanIndex];
        updateDeliveryScheduleList.put(spdWrapper.spd.Id, spdWrapper.deliverySchedulePPD); 
        if(!updateSPDIds.contains(spdWrapper.spd.Id)){
            updateSPDIds.add(spdWrapper.spd.Id);
        }
    }
    
    public void check(){
        datetime start = System.now();
        while (System.now() < start.addseconds(5)){
            //just to reload page to show value of updateDeliveryScheduleList.put
        }
    }

this is debug value (5 data)User-added image

this is vfp value (4 data)User-added image
I tried to make an alert message after I click a checkbox. The alert message has a 2 seconds timeout. I tried to print start and end datetime with console.log to make sure it works perfectly and it shows the correct time, but it always needs extra time (10 seconds) to show the alert after end date when I click checkbox for the first time, and the alert message will running well (same as end date) after the first or start js.
And is it possible to disable the other checkbox when the alert message is still loading?
I don't know where my fault is and why this can happen? Do you have any idea?
This is my code:
<apex:inputCheckbox styleClass="checkOpex{!i.spd.ID} checkOpex {!i.spd.ID}" value="
{!i.opex}">
   <apex:actionSupport event="onchange" action="{!updateOpex}" reRender=""> 
   <apex:param name="salesPlanIndex" value="{!i.index}" assignTo="{!salesPlanIndex}"/>
   </apex:actionSupport>
</apex:inputCheckbox>

Javascript
<script type="text/javascript">
    document.documentElement.style.setProperty('--screen-width', (screen.width - 120)+'px');
j$ = jQuery.noConflict();
    
    j$(document).ready(function() {
        j$(document).on('change', '.checkOpex', function(e) {
            var today = new Date();
            var date = today.getHours() + ":" + today.getMinutes() + ":" + today.getSeconds();
            console.log('Start Date'+ date);
            setTimeout(function () {
                    var today2 = new Date();
                    var end = today2.getHours() + ":" + today2.getMinutes() + ":" + today2.getSeconds();
                    console.log('end Date'+ end);
                    alert('Successfully set data');
                }, 2000);
        });
    });

​​​​​​​
i have a program that can update multiple value, i wanted to give settimeout 2 second after click on spesific checkbox. when settimeout is loading the other checkbox in apex-repeat is disabled and when the settimeout is over the other checkbox will be enable again.
i tried so many ways and still not figure it out.
is it possible?
 
this is my code now:
<apex:repeat value="{!dataSalesPlan}" var="i">
<apex:inputCheckbox styleClass="checkOpex{!i.spd.ID} checkOpex {!i.spd.ID}" value="
{!i.opex}">
   <apex:actionSupport event="onchange" action="{!updateOpex}" reRender=""> 
   <apex:param name="salesPlanIndex" value="{!i.index}" assignTo="{!salesPlanIndex}"/>
   </apex:actionSupport>
</apex:inputCheckbox>
</apex:repeat>

Javascipt
<script type="text/javascript">
    document.documentElement.style.setProperty('--screen-width', (screen.width - 120)+'px');
    j$ = jQuery.noConflict();
    
    j$(document).ready(function() {
        j$(document).on('change', '.checkOpex', function(e) {
            var self = $(this);
            $(this).prop('disabled', true);
            setTimeout(function() {
            $(self).removeAttr('disabled');
            alert("Succesfully Set Data");
            }, 2000);
        });
    });

 
I have a program that can update ppd schedule time.
the code that I made now if I make changes to ppd schedule time and does not give a time lag before checking or saving data, then the data list does not match the updated data.
for example: I make changes to 5 data lists, if I immediately press the check button, only 4 data will be displayed (the last data is not included in the list), but if I check in system.debug, the five data have been entered into the list .
I really don't know what to do.
I have tried to give a breaktime before the data is displayed when pressing the check button, but it doesn't work, and if I give it more than 10 seconds it will get a cpu limit error
but if I give a time lag (just press the check button after a few seconds) then the data in the list matches the one in system.debug
this is my vfp code:
<apex:pageBlock >
   <apex:commandButton value="Check" action="{!check}" />
   <br/>
   {!updateDeliveryScheduleList}
</apex:pageBlock>

<apex:pageMessages id="pageMessages" />
<body>
    <apex:actionStatus startStyleClass="loadingMessage" startText="loading..." id="loadStatus">
    </apex:actionStatus>
    <apex:tabPanel switchType="client" selectedTab="name2" id="theTabPanel">
        <apex:tab label="Validate" name="validate" id="tabValidate">
            <apex:outputPanel id="wrapSalesPlanTable">
                <script>
                    j$(document).ready( function () {
                    j$('[id$="salesPlanTable"]').DataTable({iDisplayLength: 50, searching: false, dom: 'lBfrtip', stateSave: true, order: [], buttons: ['excel']});
                    });
                </script>
                <table id="salesPlanTable" class="stripe row-border order-column" style="width:100%"> 
                    <thead>
                        <tr>                                
                            <th id="columnA">PPD Delivery Schedule</th>
                            <th id="columnB">Check Opex</th>
                        </tr>
                    </thead>
                    <tbody>
                        <apex:repeat value="{!dataSalesPlan}" var="i">
                            <tr>
                                <th id="columnA">
                                    <apex:input type="date" value="{!i.deliverySchedulePPD}">
                                        <apex:actionSupport event="onblur" action="{!updateDeliverySchedule}" reRender="">
                                            <apex:param name="salesPlanIndex" value="{!i.index}" assignTo="{!salesPlanIndex}"/>
                                        </apex:actionSupport>
                                    </apex:input>
                                </th>
                                <th id="columnB">
                                    <apex:inputCheckbox styleClass="checkOpex{!i.spd.ID} checkOpex {!i.spd.ID}" value="{!i.opex}">
                                        <apex:actionSupport event="onchange" action="{!updateOpex}" reRender="">
                                           <apex:param name="salesPlanIndex" value="{!i.index}" assignTo="{!salesPlanIndex}"/>
                                        </apex:actionSupport>
                                    </apex:inputCheckbox>
                                </th>
                             </tr>
                        </apex:repeat>
                    </tbody>
                </table>
            </apex:outputPanel>
        </apex:tab>
    </apex:tabPanel>
</body>
this is my apex code:
public List<Sales_Plan_Detail__c> getDataSalesPlan {get;set;}
    public List<SPDWrapper> dataSalesPlan {get;set;}
    public Id[] updateSPDIds {get;set;}
    public Map<Id, Date> updateDeliveryScheduleList {get;set;}
    public Integer salesPlanIndex {get; set;}
    
    public UT_Checklist_Sales_Plan() { //constractor
        updateDeliveryScheduleList = new Map<Id, Date>();
    } 
        
    public void updateDeliverySchedule() {
        SPDWrapper spdWrapper = dataSalesPlan[salesPlanIndex];
        updateDeliveryScheduleList.put(spdWrapper.spd.Id, spdWrapper.deliverySchedulePPD); 
        if(!updateSPDIds.contains(spdWrapper.spd.Id)){
            updateSPDIds.add(spdWrapper.spd.Id);
        }
    }
    
    public void check(){
        datetime start = System.now();
        while (System.now() < start.addseconds(5)){
            //just to reload page to show value of updateDeliveryScheduleList.put
        }
    }

this is debug value (5 data)User-added image

this is vfp value (4 data)User-added image