Posts that Alon is monitoring

Subscribe to Posts that Alon is monitoring 3 post(s) found

May 28, 2007
Avatar Kira 2 post(s)

Topic: Windows.close()

Thank you for your reply!

I’ve encountered another problem with Windows.close() function. It works fine in Firefox but not with IE :(
The error message in IE is ‘Object doesn’t support this property or method’. I’ve narrowed down my code and found that the problem lies on the Windows.close() in stopSaving function. I’m using the latest prototype v1.5.1, latest scriptaculous 1.7.1_beta3, and latest windows v1.3

AIM.AjaxFormSave = Class.create(); Object.extend(AIM.AjaxFormSave.prototype, { initialize: function(formId, button, checks, redirect){ this.form = $(formId); this.checks = checks; this.redirect = redirect; this.callback = null; this.events = $H({ onSave: [], onSuccess: [] }); var count = 0, node = $('AjaxFormSaveTarget'+count); while(node){ count++; node = $('AjaxFormSaveTarget'+count); } this.target = document.createElement('iframe'); this.target.id = 'AjaxFormSaveTarget'+count; this.target.name = 'AjaxFormSaveTarget'+count; this.target.style.display = 'none'; document.body.appendChild(this.target); this.form.target = 'AjaxFormSaveTarget'+count; Event.observe($(button), 'click', this.doSave.bind(this)); Event.observe(this.target, 'load', this.finishSave.bind(this)); }, registerEvent: function(event, handler){ if(this.events.keys().member(event)) this.events[event].push(handler); }, fireEvent: function(){ var args = $A(arguments); var event = args.shift(); if(this.events.keys().member(event)){ return this.events[event].all(function(value, index){ return value.apply(null, args); }); } return true; }, doSave: function(){ if(this.saving) return; this.startSaving(); this.callback = null; if(arguments.length > 0 && typeof arguments[0] == 'function') this.callback = arguments[0]; var result; for(var i = 0; i < this.checks.length; i++){ result = this.checks[i](); if(result !== true){ Dialog.alert(result, AIM.Control.dialogOptions()); this.stopSaving(); return false; } } if(!this.fireEvent('onSave')){ Dialog.alert('An error occurred while preparing to save!', AIM.Control.dialogOptions()); this.stopSaving(); return false; } this.form.submit(); }, startSaving: function(){ this.saving = true; Dialog.info("Saving...", Object.extend(AIM.Control.dialogOptions(), { showProgress: true, id: 'savingMsg' })); }, stopSaving: function(){ this.saving = false; Windows.close('savingMsg'); }, finishSave: function(){ if(!this.saving) return; var retVal, responseText; try { var responseTexts = this.target.contentWindow.document.getElementsByTagName('textarea'); if(responseTexts.length > 0){ responseText = responseTexts[0].value; } else { Dialog.alert("ERROR: There was an error in processing the request!", AIM.Control.dialogOptions()); this.target.style.display = 'block'; //DEBUGGING ONLY!!! retVal = false; responseText = null; } if(responseText){ var response = eval("("+responseText+")"); if(response.result == 0){ Dialog.info("Saved Successfully", AIM.Control.dialogOptions()); if(this.redirect){ window.location.href = this.redirect; } else { setTimeout(function(){ Dialog.closeInfo(); }, 1000); this.fireEvent('onSuccess'); } retVal = true; } else { Dialog.alert("ERROR: "+response.errorMsg, AIM.Control.dialogOptions()); retVal = false; } } } catch(e){ if(console) console.log(e); retVal = false; } this.stopSaving(); if(this.callback) this.callback(retVal); } });
 
May 21, 2007
Avatar Sebastien Gr... 198 post(s)

Topic: Windows.close()

You have to do top.Windows.close(“window_id”);

See http://pwc-forum.xilinus.com/forums/1/topics/1

 
May 21, 2007
Avatar Kira 2 post(s)

Topic: Windows.close()

Hi,

I’m a novice in javascript and trying to use prototype window however I encountered a problem.
I’ve created a page and when you click on a button on the parent window, it will pop up a new window (media_lib.php) that listed all of images that you can use (created by prototype window) using mac os x style, my code for that is:

On the parent page (template1.php):
<img src="media/placeholder.jpg" id="0:760x1004" onClick="javascript:changeImage(this);" style="border: 2px dashed #ffa200;">

Oh the javascript page (brochure.js):
function changeImage(image_obj){ var image_id = image_obj.id.split(':'); var win = new Window('window_id', {className: "mac_os_x", title: "Media Library", width:580, height:450, url: "emarketing_medialib.php"}); win.showCenter(); win.setDestroyOnClose(); }

What the code should do is when you click on the image link in (media_lib.php, i.e the pop up window), the parent should load that image and the pop up window will close.

On the media_lib.php,
<a href='#' onClick='Windows.close("window_id", event);'><?=$images[$i][0]?></a> <—At the moment I’m only trying to close the pop up window if you clicked on the link.

I have also included the necessary files
<head> <style type="text/css"> @import url(stylesheets/brochure.css); @import url(stylesheets/default.css); @import url(stylesheets/mac_os_x.css); </style> <script language="javascript" type="text/javascript" src="javascript/prototype.js"></script> <script language="javascript" type="text/javascript" src="javascript/scriptaculous.js"></script> <script language="javascript" type="text/javascript" src="javascript/window.js"></script> <script language="javascript" type="text/javascript" src="javascript/brochure.js"></script> </head>
But Windows.close doesn’t seem to work at all, i.e the window doesn’t close and there’s no error

Can anyone help? I’ve spent one whole day trying to figure out what’s wrong and no luck so far :(