1. #1
    Ext User
    Join Date
    Aug 2008
    Posts
    5
    Vote Rating
    0
    rosalyne is on a distinguished road

      0  

    Default How to close an Ext window when save in "Open Save Cancel" dialog box is clicked

    How to close an Ext window when save in "Open Save Cancel" dialog box is clicked


    I'm using following code for opening a .doc or xls file in an Ext js window through manageIframe. I'm getting "Open Save Cancel" dialog box as soon as the window's
    show() method is called. When I clicked Save button the file gets downloaded but the window still keeps open. I want to close the Ext window as soon as Save button is clicked. Please someone help me to acheive this ?


    var
    gcDocWin = new Ext.Window({
    layout:'fit',
    title:
    'View Document',
    width:850,
    height:580,
    draggable:
    true,
    closable:
    true,
    resizable:
    true,
    closeAction:
    'destroy',
    plain:
    true,
    modal:
    true,
    items:[
    { xtype : 'iframepanel',
    layout:
    'fit',
    defaultSrc :
    test.doc'
    }],

    buttons: [
    { text: 'Close',
    handler:
    function(){
    gcDocWin.destroy();}
    }
    ]
    });

    gcDocWin.show();

    Thanks in Advance

    Rosalyne

  2. #2
    Sencha - Community Support Team mankz's Avatar
    Join Date
    Nov 2007
    Location
    Stockholm, Sweden
    Posts
    2,752
    Vote Rating
    106
    mankz is a name known to all mankz is a name known to all mankz is a name known to all mankz is a name known to all mankz is a name known to all mankz is a name known to all

      0  

    Default


    1. Post code in [CODE] tags
    2. It cannot be done, you cannot listen to events of a save-popup button click
    3. You don't need a window to download a file. What you want to do is generate an iframe on the fly. For example, I have a method defined in my Ext override file which I use throughout my application. Something like this:

    Code:
    // Utility function for downloading files through an iframe
    Ext.util.FileOps = function(obj, name){
           alert('This code was posted in \[CODE\] tags');
    };
    
    Ext.util.FileOps.downloadFile = function(url) {
    	    // create hidden target iframe
    	    var id = Ext.id();
    	    var frame = document.createElement('iframe');
    	    frame.id = id;
    	    frame.name = id;
    	    frame.className = 'x-hidden';
    	    if(Ext.isIE) {
    		    frame.src = Ext.SSL_SECURE_URL;
    	    }
    
    	    document.body.appendChild(frame);
    
    	    if(Ext.isIE) {
    		    document.frames[id].name = id;
    	    }
    
    	    var form = Ext.DomHelper.append(document.body, {
    		    tag:'form',
    		    method:'post',
    		    action:url,
    		    target:id
    	    });
    
    	    document.body.appendChild(form);
    
    	    var callback = function() {
    		    Ext.EventManager.removeListener(frame, 'load', callback, this);
    		    setTimeout(function() {document.body.removeChild(form);}, 100);
    		    setTimeout(function() {document.body.removeChild(frame);}, 110);
    	    };
        	
    	    Ext.EventManager.on(frame, 'load', callback, this);
    	    form.submit();
    };

  3. #3
    Ext User
    Join Date
    Aug 2008
    Posts
    5
    Vote Rating
    0
    rosalyne is on a distinguished road

      0  

    Default


    Thanks for your response...
    It works fine with .doc and .xls file. But if we try to download a file with extensions .jpg, .gif, .txt etc it doesnot show up the "Open Save "dialog....

  4. #4
    Sencha - Community Support Team mankz's Avatar
    Join Date
    Nov 2007
    Location
    Stockholm, Sweden
    Posts
    2,752
    Vote Rating
    106
    mankz is a name known to all mankz is a name known to all mankz is a name known to all mankz is a name known to all mankz is a name known to all mankz is a name known to all

      0  

    Default


    Ok, I don't set the file to download directly in the src. I use a server page to post the files, something like:

    Ext.util.FileOps.downloadFile('PostFilePage.aspx?file=theFileToDownload.doc');

    Then in my server page I can serve the files any way I want, setting response headers and so on...

  5. #5
    Sencha Premium Member lorezyra's Avatar
    Join Date
    Dec 2007
    Location
    Japan -- 日本
    Posts
    636
    Vote Rating
    15
    lorezyra will become famous soon enough lorezyra will become famous soon enough

      0  

    Arrow Checkout "Content-Disposition" header attribute

    Checkout "Content-Disposition" header attribute


    Below is a snipplet of code I use to deliever my images (from my online Image Editor):

    PHP Code:
    $dl $_REQUEST['dl'];

            
    $contentType="image/jpeg";
            
    $output imagecreatefromjpeg($editDirectory.$imageName);
            
    ob_start(); // start a new output buffer
               
    imagejpeg($output""100);
               
    $imageData ob_get_contents();
               
    $imageDataLength ob_get_length();
            
    ob_end_clean(); // stop this output buffer


    $dl=($dl==1"attachment":"inline"); //download or just view?
    header("Content-Type: $contentType");
    header("Content-Length: $imageDataLength");
    header("Content-Disposition: $dl; filename=$imageName"); //
    header("Content-Description: Image Editor 3.0 file");
    echo 
    $imageData
    If you want your file to be downloaded to the browser, use "attachment"... Most web servers default to "inline" when serving images...
    Perfection as a goal is a nice idea that can point one in a specific direction. However, since "perfection" is an ever changing (evolving?) and moving target, one must admit that perfection can never be obtained...

    When in doubt, check the d4mn source code!
    ================================================
    And here are my terms...
    1. I don't care if you use my source code. (Known as "Code.")
    2. I don't care if I get any monetary compensation.
    3. I do care to receive credit for Code provided. So, please keep my name in the comments for Code provided.
    4. Code is provided without warranty "AS-IS" and I claim absolutely no warranty nor liability to the quality, security, and run-ability on any platform.
    5. By using Code, you accept all risk inherit with Code regardless if Code has known and yet to be discovered bugs.
    6. You are welcome to change and improve the Code to best meet your needs.
    7. I don't care if you use the Code in a commercial or open-source project.
    8. You are not required to contact me prior to using the Code.
    ================================================
    Simple. Enjoy.

Thread Participants: 2