• ballu j
  • NEWBIE
  • 0 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 0
    Replies
Hi,

when i try to click Cancel button here its cancelled at the same time page also refreshing and then  modal popup is closed ,but i want to close the modal popup without page refresh.i am new with modal popup can you please help me
here my code

Javascreept button code
-----------------------------------------
{!REQUIRESCRIPT("https://code.jquery.com/jquery-1.10.2.js")} 
{!REQUIRESCRIPT("https://code.jquery.com/ui/1.10.4/jquery-ui.js")} 
{!REQUIRESCRIPT("/resource/SoldHour_JS4")} 
var permissionsetName='GSD_SRM_Edit_Sold_Hour'; 
var ptask=''; 
var ptid='{!pse__Project_Task__c.Id}'; 
var projecttask = sforce.connection.query("Select id,PSA_Project_Task_Creation__c,GSD_Task_Type__c,PSA_Sold_Estimated_Hours__c,pse__Status__c,pse__Project__c from pse__Project_Task__c where id = '"+ptid+"' limit 1"); 
ptask=projecttask.getArray('records'); 
var projectid=ptask[0].pse__Project__c; 
var taskcreation=ptask[0].PSA_Project_Task_Creation__c; 
var taskType =ptask[0].GSD_Task_Type__c; 
var soldHours =ptask[0].PSA_Sold_Estimated_Hours__c; 
var custSetting="{!$Setup.GSDSRM_Settings__c.GSD_Project_Splitting_Active_Statuses__c}"; 
var status =ptask[0].pse__Status__c; 
var userid=sforce.connection.getUserInfo().userId; 
var manageAccess = sforce.apex.execute("GSDSRMValidateProjectAccess", "checkOwnerAccess",{projectId : projectid,ProjectOwnerId: userid}); 
var permissionsetaccess =sforce.apex.execute("GSDSRMValidateProjectAccess", "checkPermissionsetAccess",{permissionsetName: permissionsetName}); 

console.log('manageAccess'+manageAccess ); 
if(manageAccess=='False' ) { 
alert('{!$Label.GSD_Edit_Sold_Hour}'); 

else if(permissionsetaccess=='False' ) { 
alert('{!$Label.GSD_Edit_Sold_Hour}'); 

else if(taskcreation!='Manual with PG Templates' ) { 
alert('{!$Label.GSD_Validate_Status_for_Edit_Sold_Hour}'); 

else if(custSetting.indexOf(status) < 0){ 
alert('{!$Label.GSD_Validate_Status_for_Edit_Sold_Hour}'); 

else { 
j$("#modalDiv").dialog('option','title','{!pse__Project_Task__c.Name}').dialog('open'); 
}

ModalDialog popup code
-----------------------------------
/*@description: This script will insert a modal div in the standard page.
                the modal will contain a VF page. This file should be located in static resource.*/
var j$ = jQuery.noConflict();
var currentUrl = window.location.href;
var hostIndex = currentUrl.indexOf(window.location.host+'/')+(window.location.host+'/').length;
var objectId = currentUrl.substring(hostIndex,hostIndex+15); 
j$(function(){
    /*Insert the jQuery style sheets in the Head.*/
    /*Insert the Modal dialog along with the VF as an iframe inside the div.*/
    j$("head").after(
        j$("<link>",{rel:"stylesheet",
                    href:"https://code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css"}));
    j$("body").after(
        j$("<div>",{id:"modalDiv",
                    style:"display:none;"
           }).append(
            j$("<iframe>",{id:"vfFrame",
                         src:"/apex/GSDSRMEditSoldHourPage?id="+objectId,
                         height:200,
                         width:550,
                         frameBorder:0})
           ));
    /*Initialize the Dialog window.*/
    j$("#modalDiv").dialog({
        autoOpen: false,
        height: 275,
        width: 620,
        modal:true
    });
});


VF page
-------------------------


<apex:page showHeader="false"  sidebar="false" standardController="pse__Project_Task__c" extensions="GSDSRMSoldHourExtension">
    <style type="text/css">
body {
    margin:0;
    padding:0;
    font: 70%/1.3 arial,helvetica,sans-serif;
    background:#e6e6ff;
}
</style>
    <apex:form >
            
            <apex:pageblock id="pageBlock">
            <div align="Center">
            <br></br>
            <br></br>
            <b>Sold Hours</b>&nbsp;&nbsp;&nbsp;<apex:inputField value="{!pse__Project_Task__c.PSA_Sold_Estimated_Hours__c}"/>
                <br></br>        
             <apex:outputPanel >
            <br></br>
            <apex:commandButton action="{!saveAndReturn}" value="Save" onComplete="closeAndRefresh();" status="actionStatus" reRender="pageBlock"/>&nbsp;&nbsp;
            <apex:commandButton value="Cancel" onclick="window.close();"/>
            
            <apex:actionStatus id="actionStatus">
                <apex:facet name="start"> 
                    <img src="/img/loading.gif"/>
                </apex:facet>
            </apex:actionStatus>
            </apex:outputPanel>
            </div>
            </apex:pageblock>
            
           
            
    </apex:form>
    <script>
        function closeAndRefresh(){
            console.log('clicked on the button');
            window.top.location = '/{!$CurrentPage.parameters.id}';
        }
        
    
    </script>
</apex:page>

Modal Dialog popup