Log in

View Full Version : Opening a modal by closing another



mclerojb58
08-06-2012, 06:47 PM
I have a application that is opening a dhtmlmodal window and based on the action chosen it will close and do nothing; do something backend and then close; close and then open a new modal shortly after.

This last one i am having trouble as I am assigning trying to open the new modal from a custom onclose function. I have attached the code below, the onclose is triggered by a function in the auditpop modal by calling parent.auditpop.close();

If anyone had any ideas or advise i would very much appreciate it.



function auditPopup(){
var map = {"userid" : temp_user,"edit" : "false"};
jQuery.ajax({
type: "GET",
url: '/auditwizard-portlet/checkInProgress.jsp',
dataType: "html",
data: map,
global: true,
success: function(responseHTML){
var audit_war = "/auditwizard-portlet/view.jsp?userid="+temp_user;
auditpop = dhtmlmodal.open("auditbox","iframe",audit_war,"Athena Audit Wizard","width=600px,height=280px,scrolling=1,center=0,top=5px,left=5px");
auditpop.onclose = function(){
audit_type = this.contentDoc.getElementById("prog_audited_type").innerHTML;
audit_app = this.contentDoc.getElementById("prog_audited_app").innerHTML;
audit_time = this.contentDoc.getElementById("prog_audited_timestamp").innerHTML;
audit_grace = this.contentDoc.getElementById("prog_audited_gracePer").innerHTML;
audit_save = this.contentDoc.getElementById("prog_audited_saveDate").innerHTML;
audit_last = this.contentDoc.getElementById("prog_audited_lastDate").innerHTML;
audit_auditee = this.contentDoc.getElementById("prog_audited_auditee").innerHTML;
audit_assigner = this.contentDoc.getElementById("prog_audited_assigner").innerHTML;
audit_ressignee = this.contentDoc.getElementById("prog_audited_reassignee").innerHTML;
audit_user = temp_user;
audit_params = "type="+audit_type+"&app="+audit_app+"&timestamp="+audit_time+"&graceper="+audit_grace+"&savedate="+audit_save+"&lastdate"+audit_last+"&auditee="+audit_auditee+"&assigner="+audit_assigner+"&reassignee="+audit_reassignee+"&userid="+audit_user;
alert(audit_params);
auditWizPop();
};

},
error: function(xhr, status, e){
if(xhr.status ==500){
alert("Please Contact Athena with error descript");
}else if(xhr.status == 404){
}else{
alert("Error has occured with "+xhr.status);
}
}
});
}

function auditWizPopup(){

var auditwizURL = "/auditwizard-portlet/application_audit_wizard.jsp?"+audit_params;
audit_wizard = dhtmlmodal.open("audit_wiz","iframe",auditwizURL,"Athena Audit Wizard (In Progress...)","width=1180px,height=700px,scrolling=1,center=0,top=5px,left=5px");
audit_wizard.onclose = function(){var audit_data = this.contentDoc.getElementById("audit_main_div").innerHTML;
var audit_app = this.contentDoc.getElementById("wiz_audited_app").innerHTML;
var audit_time = this.contentDoc.getElementById("wiz_audit_timestamp").innerHTML;

var map = {"random" : Math.floor(Math.random()*1000)
, "app" : audit_app
, "user" : "<%out.print(users);%>"
, "time" : audit_time
, "data" : audit_data};

jQuery.ajax({
type: "POST",
async: false,
url: '/auditwizard-portlet/SaveAuditToDB.jsp',
dataType: "html",
data: map,
global: true,
success: function(responseHTML){
alert("Save Successful");
audit_wizard.hide();
},
error: function(xhr, status, e){
if(xhr.status ==500){
alert("Please Contact Athena with error description");
}else if(xhr.status == 404){
}else{
alert("Error has occured with "+xhr.status);
}
}

});
};

jscheuer1
08-06-2012, 07:26 PM
There's a lot you're not showing us, a link to the page might be required. But since AJAX is involved, that might not be enough. It might be something simple though -

I'm assuming this alert fires:



alert(audit_params);
auditWizPop();
};

That would be what's telling you that auditWizPop should fire, but from what you say, it doesn't. The obvious reason would be that there is no function named auditWizPop. There is one named auditWizPopup, try that and see if it works:


alert(audit_params);
auditWizPopup();
};

mclerojb58
08-06-2012, 07:44 PM
Unfortunately I cannot post a link to the page as it is exists within my company's intranet.

I did fix the auditWizPopup() function call. The alert did execute and so did the new window open, but now oddly enough the auditpop.onclose function is no longer doing anything not oddly enough it is not, which is driving me crazy.

jscheuer1
08-06-2012, 08:37 PM
Oddly enough, I'm not sure I understand what you're saying here.

Looks like we solved the first problem though.

And it sounds like those other things were working before and that they aren't now. If that stuff was happening before, my guess would be that they depended upon the time and/or environment alloted to them due to the previous error.

Like if the now functioning callback (auditWizPopup) overwrites one or more things that the onclose function needs and/or produces, that would mess things up.

It would still probably help if you could put up a demo of this somewhere live.

It doesn't have to give away any company secrets. It just has to demonstrate the problem(s) you're having. Make it as simple as possible, while still showing the problem(s).

Often just setting up something like that will cause the insight you need to see where the current code is going wrong.

mclerojb58
08-06-2012, 10:00 PM
Sorry i didn't correct my grammar last post. The problem I am experiencing now is that in the auditpop.onclose function it is catching a error that shouldn't exist and is closing the window before the variable can be set.

SO

audit_type = this.contentDoc.getElementById("prog_audited_type").innerHTML;


in the auditpop.onclose function is caught as an errorin the catch statement in the dhtmlwindow.close function, which it shouldn't as the element exists in the modal window at the time the onclose function is called, and i am using IE and the catch is for non IE browsers. Then the dhtml close function proceeds to forget the rest of the onclose function and close the auditpop modal, and call the auditWizPopup function which gets stuck in an infinite loop looking for values, or something.

mclerojb58
08-06-2012, 10:01 PM
My only guess is that it is not liking the this.contentDoc which has worked in the past for me, and i haven't changed anything to prevent it from working in the js files.

jscheuer1
08-07-2012, 12:31 AM
Now I am confused. I thought you said everything else was working before you fixed the error with auditWizPop/auditWizPopup.

Now it seems there were problems before that was fixed.

In any case, this.contentDoc is non-standard. Unless you've defined it elsewhere, it's undefined. It looks like this.contentDocument, which can refer to the document object in a window. I've only ever seen this used in reference to an iframe's content document. But I suppose it could have other uses. However, in my experience it's not very cross browser.

If you're using AJAX though, everything should be in either the responseText or responseXML, whichever you're fetching*, there and of course (for the page that is doing the fetching) in the document object itself.


*If using jQuery.ajax as it appears you are, whichever of these that's fetched is the first argument of the success function - what you're calling the responseHTML.

mclerojb58
08-07-2012, 02:58 PM
You gave me an ephiphany originally the jQuery.ajax method was just in place as a check to proceed with audits however it made me look closer and see that the return is same as when it is called again in the modal window that is opened. it will take some restructuring but it may just fix this entire issue.

mclerojb58
08-07-2012, 07:45 PM
Ok i cleared the issue of this.contentDoc by eliminating it. Thank you know i am back to my original issue. Only the window opens but during the opening process it fails to do so.

Is there a way to modify the modal's contents and attributes (width, height, etc) without closing. Such if i clicked a button, it would go from 500px by 400px (w by h);displaying a couple button, it would display a different page and would now be 1180px by 700px (w by h)?

mclerojb58
08-07-2012, 07:47 PM
Ok i cleared the issue of this.contentDoc by eliminating it. Thank you know i am back to my original issue. Only the window opens but during the opening process it fails to do so.

By this I meant that, that grabbing data is no longer an issue but now the new modal will appear but fail half-way through and not display what it should.

jscheuer1
08-08-2012, 04:19 AM
I don't know what the new modal's code looks like at this point. In your original post you had its success function like so:



success: function(responseHTML){
alert("Save Successful");
audit_wizard.hide();
},

That's not going to display anything.

mclerojb58
08-09-2012, 02:34 PM
I am embarassed to have posted the last few since i figured out how to manipuliate the window within a few minutes of posting. For those who want to know if you are using the dhtmlmodal files offered by this site then really look at the dhtmlwindow demos it helps explain a lot.

The last bit of fun i have is to figure out how to prevent the minimize and close buttons in the title from showing up for just my application; since there are other apps that use these files, and will need them. Anyone have ideas?

I would be modifying the init and/or open methods of dhtmlwindow to specifically look for my window and then not show the specific icons. So i understand it would be an if-else statement around the html that add these buttons but i have tried it using the title variable that is passed to no avail.

mclerojb58
08-09-2012, 02:43 PM
jscheuer1: I want to say thanks for your help. Even though I wasn't able to solve the problem directly your input helped me see alternative simple workarounds to my over-thought complex problems.

The issue was that I was opening a window while closing another so even after it did all the work of setting up for the new window the close function would still try to clear and close the modal space which led to the error in closing the first modal and caused an infinite hang on opening the new window.

Short story cannot open a new modal while closing an old one.

I fixed this by rewriting the code to use the .load and .setSize functions to do what i needed from inside the modal.