Ritu
Ritu

Reputation: 1095

ColdFusion.Window.create not refreshing the pop up window

I am opening a window for editing items through Coldfusion.Window.Create. When I click on different "edit" links, the window always shows the first item I edited, not the one I clicked. For some reason the pop up window is not getting refreshed in each call.

Here is the code of my cfm :

<cfoutput query="getSavedSelections">
<table class="mytableb" >
    <tr>
        <td class="mylistb" style="width:178px;" valign="top">
            #getSavedSelections.SavedSelectionExportName#
        </td>
        <td class="mylistb" style="width:130px;" valign="top">
            (<a onclick="EditSurveyExport(#getSavedSelections.SavedSelectionExportId#,'#scope#')" style="cursor: pointer;cursor:hand;">Edit</a> |  <a onclick="ConfirmExportDeletion('#scope#',#pgmid#,#getSavedSelections.SavedSelectionExportId#,'#surveyAliasname#','#getSavedSelections.SavedSelectionExportName#','csv');" style="cursor: pointer;cursor:hand;">Delete</a>)                            
        </td>
    </tr>
</table>
</cfoutput>

Here's the javascript code for opening and closing the window :

function EditSurveyExport(SavedSelectionID,passedScope)
{
    console.log(SavedSelectionID);
    ColdFusion.Window.create("SavedSelectionEditingWindow","Edit Saved selection","index.cfm?event=survey.editexportwithid&SavedSelectionID="+SavedSelectionID+"&passedscope="+passedScope,{modal:true,width:500,height:700,center:true,draggable:true})
    console.log('after create');
    document.getElementById(ColdFusion.Window.getWindowObject("SavedSelectionEditingWindow").header.id).className = "windowHdr";

}

function CloseExportEditingWindow()
{
    ColdFusion.Window.hide('SavedSelectionEditingWindow');
    console.log('after closing');
}

I observed the console. Only first time after page load this url gets called: "http://localhost/index.cfm?event=survey.editexportwithid&SavedSelectionID=1029&passedscope=individual&_cf_containerId=SavedSelectionEditingWindow-body&_cf_nodebug=true&_cf_nocache=true&_cf_clientid=8BF05647C531DF1C34380F471DE37721&_cf_rc=0".

Then I can see only id and 'after create' in the console.

I am unable to get the reason behind this. Can anyone please help me understand why this is happening?

Upvotes: 1

Views: 666

Answers (2)

Dan Short
Dan Short

Reputation: 9616

First off, I'll reiterate what Scott and Miguel said. Don't use it if you don't have to. That being said, in the interest of answering your question, you'll need to destroy the window before you recreate it in order to get the cfwindow code to reload the contents. Here's a function I've used to do that:

var windowCleanup = function(id) {
    try {
        //Destroy the window if it still exists
        ColdFusion.Window.destroy(id, true);
    } catch(e) { }
}

That will completely destroy the previous window, and then create your new one. Then, whenever you create a new window, run this after the create() statement:

ColdFusion.Window.onHide(id, windowCleanup);

Now, any time that window gets hidden, for whatever reason, it will be properly destroyed and you'll be ready for the new create() method call.

Upvotes: 2

Miguel-F
Miguel-F

Reputation: 13548

I agree with Scott's comment, you should try using the newer JavaScript libraries instead of relying on ColdFusion to do it for you. You will run into the limitations eventually.

Having said that, I think the problem is that each window you open must have a unique name. Otherwise the code will just open the existing window.

From the docs regarding the name parameter:

The name of the window. This attribute is required to interact with the window, including to dynamically show or hide it. If a window with the specified name exists, the function shows that window, and ignores the remaining parameters; otherwise, the name must be unique on the page.

All of the windows created in your code will have the same name; "SavedSelectionEditingWindow". You will need to create unique names for each different window that you would like opened. You could probably just append the SavedSelectionID argument to the name (assuming that is unique per item).

Upvotes: 2

Related Questions