apache / royale-asjs

Apache Royale ASJS
Apache License 2.0
372 stars 116 forks source link

Attachment should be saved when Click on attachment file Popup Should be opened #867

Open pashminakazi opened 4 years ago

pashminakazi commented 4 years ago

Project Details are : https://paste.apache.org/cpo8y Test case is available on VDI. Go to Accounts Recieveable from Select in Menu Go to Sales Commission Scheme Setup from Setups in Menu File : com/dbz/modules/AR/dbzSalesCommissionScheme.mxml

Click on New Button then Plus (+) button,Popup will be opened and then click Plus (+) Buttonn and then attachment icon,attach any files

Whole row should be highlighted when we select a row.File Name is not highlighted in Royale image

and when we click on File Name the popup should be opened to save this File image

In Royale when we click on Attachment File Name nothing happens


frd = new mx.net.FileReference();
frd.addEventListener(org.apache.royale.events.Event.OPEN, openHandler); 
frd.save(file,name);

this functions doesn't triggered in Royale

aharui commented 4 years ago

You will have to use the DownloadButton as described in #838

pashminakazi commented 4 years ago

@aharui ok thanks But another issue is : when i click on row of attached file the row will be highlighted without the file name, filename should be highlighted as well as it is included in that row

aharui commented 4 years ago

I don't understand your last comment. Maybe open a new issue about it.

pashminakazi commented 4 years ago

@aharui I have replaced mx:LinkButton with

<mx:DownloadButton styleName="htmlLink" id="downloadButton"  
label="{data.at_Name}"
toolTip="Save File" 
click="btnDownload_clickHandler(data.at_Name,data.at_Bytes,data.at_Status)"/>
private function btnDownload_clickHandler(name:String,file:mx.utils.ByteArray,status:String):void {                     
    if(status!= "0") {
            downloadButton.defaultFileName = name;                                                           
    }
       else
        Alert.show("File has been Removed.");
    }

image

but it doesn't download the file

aharui commented 4 years ago

Run the test app in #838 to see if that works for you. Also read the discussion in #838. DownloadButton requires a slightly different workflow than FileReference.save. The information needs to be ready before the button is clicked. You may need a popup instead.

pashminakazi commented 4 years ago

@aharui I have replaced <mx:LinkButton styleName="htmlLink" label="{data.at_Name}" toolTip="Save File"
click="btnDownload_clickHandler(data.at_Name,data.at_Bytes,data.at_Status)"/>

private function btnDownload_clickHandler(name:String,file:mx.utils.ByteArray,status:String):void {
        if(status!= "0") {
            frd = new mx.net.FileReference();                                       
            frd.addEventListener(org.apache.royale.events.Event.OPEN, openHandler); 
            frd.save(file,name);
            }
           else
           Alert.show("File has been Removed.");
        }

With

<mx:DownloadButton styleName="htmlLink" id="downloadButton"  label="{data.at_Name}"
 toolTip="Save File"                                               
 click="btnDownload_clickHandler(data.at_Name,data.at_Bytes,data.at_Status)"/>
private function btnDownload_clickHandler(name:String,file:mx.utils.ByteArray,status:String):void {                     
    if(status!= "0") {
           downloadButton.defaultFileName = name;   
           downloadButton.data = menuDataXMLList.toString()                                      
        }
       else
       Alert.show("File has been Removed.");
    }

<fx:Declarations>
      <fx:XMLList id="menuDataXMLList">
        <menuitem label="label-1">          
            <menuitem label="label-1-1"/>           
            <menuitem label="label-1-2"/>           
        </menuitem>
        <menuitem label="Switch Locale" id="admin" >            
              <menuitem label="label-2-1"/>         
              <menuitem label="label-2-2"/>         
              <menuitem label="label-2-3" id="admin" />
        </menuitem>
          </fx:XMLList>
        </fx:Declarations>

if i remove downloadButton.data = menuDataXMLList.toString() then file Name is shown if i added downloadButton.data = menuDataXMLList.toString() file Name doesn't visible,in both situation file download doesn't work.

As discussed in (https://github.com/apache/royale-asjs/issues/838) I have added

COMPILE::JS {
  var saveData = (function () {
    var a = document.createElement("a");
    document.body.appendChild(a);
    a.style = "display: none";
    return function (data, fileName) {
    var json = JSON.stringify(data),
    blob = new Blob([json], {type: "octet/stream"}),
    url = window.URL.createObjectURL(blob);
    a.href = url;
       a.download = fileName;
       a.click();
       window.URL.revokeObjectURL(url);
      };
}());
var data = { x: 42, s: "hello, world", d: new Date() },
fileName = name;
saveData(data, fileName);
} 

But after this there's a compilation Error Implicit type coercion of blob from Object to etc Access of possibly undefined URL with reference window So i commented this part.

I am trying to fix this issue from last 2 to 3 days with multiple changes,nothing works for me, I you have time then please write a correct code for me,or instruct me to write code

aharui commented 4 years ago

The key difference is that in Royale, the data and defaultFileName must be set before the button is clicked. It cannot be setup in a click handler. Look at the example in #838 more carefully. If you don't have the data ready early enough, you may need to use a popup to give you a chance to prepare the data.

pashminakazi commented 4 years ago

Hi Alex,

I dont know how to prepare data before click and how to create a popup.I didn't understand the discussion in #838.

On Tue, Jun 23, 2020, 9:08 PM aharui notifications@github.com wrote:

The key difference is that in Royale, the data and defaultFileName must be set before the button is clicked. It cannot be setup in a click handler. Look at the example in #838 https://github.com/apache/royale-asjs/issues/838 more carefully. If you don't have the data ready early enough, you may need to use a popup to give you a chance to prepare the data.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/apache/royale-asjs/issues/867#issuecomment-648262960, or unsubscribe https://github.com/notifications/unsubscribe-auth/AKB67E7PJHVQZ4J6BGSGIVDRYDHRRANCNFSM4N6AN2UQ .

pashminakazi commented 4 years ago

Which things should i use? XMLList and json part is necessary for my attachment popup or not?

On Tue, Jun 23, 2020, 9:28 PM Pashmina Kazi pashminakazi@gmail.com wrote:

Hi Alex,

I dont know how to prepare data before click and how to create a popup.I didn't understand the discussion in #838.

On Tue, Jun 23, 2020, 9:08 PM aharui notifications@github.com wrote:

The key difference is that in Royale, the data and defaultFileName must be set before the button is clicked. It cannot be setup in a click handler. Look at the example in #838 https://github.com/apache/royale-asjs/issues/838 more carefully. If you don't have the data ready early enough, you may need to use a popup to give you a chance to prepare the data.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/apache/royale-asjs/issues/867#issuecomment-648262960, or unsubscribe https://github.com/notifications/unsubscribe-auth/AKB67E7PJHVQZ4J6BGSGIVDRYDHRRANCNFSM4N6AN2UQ .

aharui commented 4 years ago

In #838, the data was XML. Is your data XML? It looks like it is a regular ByteArray. The data.at_Bytes ByteArray would be assigned to the DownloadButton.data, and the DownloadButton.defaultFileName would be assigned data.at_Name.

In Flex, the LinkButton would be created at startup, and later the user would click on it, and the data.at_Bytes could have changed between startup and the click based on other things the user did, including other code that could run when the user clicked on the LinkButton.

In Royale, the DownloadButton is created at startup and the data and defaultFileName must be set before the DownloadButton sees the click event so it is harder to deal with changes to the ByteArray based on what the user did after startup.

I don't know when your code has made the ByteArray ready, but that is the point at which it need to be assigned to the DownloadButton's data property. It can't be done in the DownloadButton's clickHandler

pashminakazi commented 4 years ago

Ok,If I will create a separate function for preparing data before calling click handler Example In that function I will do private function PreparingData(name:String,file:mx.utils.ByteArray,status:String):void {
DownloadButton.data = data.at_Bytes; DownloadButton.defaultFileName = data.at_Name;
}

where i call PreparingData function? and then when i am doing everything in that function,what should i do in ClickHandler function?

pashminakazi commented 4 years ago

mx:DownloadButton and clickhandler function is inside these tags

aharui commented 4 years ago

As in the example in #838, you should no longer need a click handler.

I don't know when your application should set the DownloadButton.data. It all depends on when you know what that data is.