freedowsRoO Posted May 19, 2020 Posted May 19, 2020 Hello! How can i have sure that ajaxEvent finish the execution? I need to use a function after the ajaxEvent are processed. I'm triyng to use 'UniSession.SendFile()' in the event ajaxEvent but the application send more than one file to the client side, The first time that i click the button the application send 1 file per time, if i click the second time the application send 2 files and so on.... Is difficult to explain.... Quote
Sherzod Posted May 19, 2020 Posted May 19, 2020 Hello, OK, but do you have a simple testcase to check first?.. Quote
freedowsRoO Posted May 23, 2020 Author Posted May 23, 2020 On 5/19/2020 at 4:29 PM, Sherzod said: Hello, OK, but do you have a simple testcase to check first?.. Sorry, i did not manage to reproduce them. The error occurs only in my application, i made a video to try to explain better. Note in the video that the application stops at breakpoint only once, but on the client appears to save the file many times. Video_1590223862_Trim.wmv Quote
Sherzod Posted May 23, 2020 Posted May 23, 2020 5 hours ago, freedowsRoO said: Note in the video that the application stops at breakpoint only once, but on the client appears to save the file many times. Sorry, is not very clear... 1 Quote
andyhill Posted May 23, 2020 Posted May 23, 2020 AjaxEvent ONE Inside AjaxEvent ONE at end of event call AjaxEvent TWO 1 Quote
freedowsRoO Posted May 24, 2020 Author Posted May 24, 2020 On 5/23/2020 at 4:53 PM, andyhill said: AjaxEvent ONE Inside AjaxEvent ONE at end of event call AjaxEvent TWO Thanks for reply but i have only one ajaxevent. The server trigger the unissession.sendfile many times.. Quote
freedowsRoO Posted May 25, 2020 Author Posted May 25, 2020 On 5/23/2020 at 2:16 PM, Sherzod said: Sorry, is not very clear... I managed to reproduce the problem. The problem is when i call the html2canvas function but i don´t know how to fix it. To reproduce the problem, just click to 'send file' button more than one time. SendFile.rar Quote
Sherzod Posted May 25, 2020 Posted May 25, 2020 19 minutes ago, freedowsRoO said: To reproduce the problem, just click to 'send file' button more than one time. Well, right, how many clicks, as many request. Quote
freedowsRoO Posted May 25, 2020 Author Posted May 25, 2020 11 minutes ago, Sherzod said: Well, right, how many clicks, as many request. Just click, wait the download finish and click again and reapeat. In the first time that you click the application will send 1 file to save, the second time the application will send two, the third time three and etc... Quote
Sherzod Posted May 25, 2020 Posted May 25, 2020 8 minutes ago, freedowsRoO said: Just click, wait the download finish and click again and reapeat. I understood you, there are several ways to achieve this, I will try to give you a solution. Quote
Sherzod Posted May 25, 2020 Posted May 25, 2020 Also, your code seems to be "incomplete" function click(sender, e, eOpts) { ajaxRequest('#1', "getData", ["base64Data=teste"]) } ajaxRequest('#1', "getData", ["base64Data="+canvas.toDataURL("image/jpeg,1.0")]) procedure TMainForm.UniButton1AjaxEvent(Sender: TComponent; EventName: string; Params: TUniStrings); begin if EventName='getData' then Begin UniSession.SendFile(UniServerModule.FilesFolderPath+ 'unipdf.pdf'); End; end; Quote
freedowsRoO Posted May 25, 2020 Author Posted May 25, 2020 18 hours ago, Sherzod said: Also, your code seems to be "incomplete" function click(sender, e, eOpts) { ajaxRequest('#1', "getData", ["base64Data=teste"]) } ajaxRequest('#1', "getData", ["base64Data="+canvas.toDataURL("image/jpeg,1.0")]) procedure TMainForm.UniButton1AjaxEvent(Sender: TComponent; EventName: string; Params: TUniStrings); begin if EventName='getData' then Begin UniSession.SendFile(UniServerModule.FilesFolderPath+ 'unipdf.pdf'); End; end; Yeh it is incomplete, i just made the example using the html2cavas with the ajaxrequest because the problem only show when i call de html2canvas function. In my main application i convert the base64 image and save on a PDF, after that i send the 'unisession.sendFile'. Just focus on the problem, i click one time in the button and the server send me 2 files do download just it. Thanks in advanced... Quote
Sherzod Posted May 26, 2020 Posted May 26, 2020 4 hours ago, freedowsRoO said: up Hello, Sorry for the late response. One possible solution...: 1. Remove "JSInterface.JSCode..." from OnClick event procedure TMainForm.UniButton1Click(Sender: TObject); begin end; 2. You need to move the logic to ClientEvents.ExtEvents... function click(sender, e, eOpts) { sender.setDisabled(true); ajaxRequest(sender, "getData", ["base64Data=teste"]); } 3. ClientEvents.UniEvents... function ajaxCallback(sender, response) { sender.setDisabled(false); } 1 Quote
freedowsRoO Posted May 26, 2020 Author Posted May 26, 2020 1 hour ago, Sherzod said: Hello, Sorry for the late response. One possible solution...: 1. Remove "JSInterface.JSCode..." from OnClick event procedure TMainForm.UniButton1Click(Sender: TObject); begin end; 2. You need to move the logic to ClientEvents.ExtEvents... function click(sender, e, eOpts) { sender.setDisabled(true); ajaxRequest(sender, "getData", ["base64Data=teste"]); } 3. ClientEvents.UniEvents... function ajaxCallback(sender, response) { sender.setDisabled(false); } Nice, I'm already trying to do that but without success... function click(sender, e, eOpts) { html2canvas(document.getElementById(PanelCentral.jsID) , { dpi: 144 } ).then( function(canvas) { '+ var ctx = canvas.getContext("2d"); ctx.webkitImageSmoothingEnabled = false; ctx.mozImageSmoothingEnabled = false; ctx.imageSmoothingEnabled = false; var myImage = canvas.toDataURL("image/jpeg,1.0"); ajaxRequest('#1', "getData", ["base64Data="+myImage]); } ); } Quote
Sherzod Posted May 27, 2020 Posted May 27, 2020 14 hours ago, freedowsRoO said: ajaxRequest('#1', "getData", ["base64Data="+myImage]); ajaxRequest(sender, "getData", ["base64Data="+myImage]); 1 Quote
freedowsRoO Posted May 27, 2020 Author Posted May 27, 2020 11 minutes ago, Sherzod said: ajaxRequest(sender, "getData", ["base64Data="+myImage]); A little question: Is this line correct? html2canvas(document.getElementById(PanelCentral.jsID) , { dpi: 144 } ) If i need to use another component there i just call de name of the component? Quote
Sherzod Posted May 27, 2020 Posted May 27, 2020 5 minutes ago, freedowsRoO said: PanelCentral.jsID It seems not, what kind of object? Quote
freedowsRoO Posted May 27, 2020 Author Posted May 27, 2020 2 minutes ago, Sherzod said: It seems not, what kind of object? Any object, i need to set there the object that i want to take the screeshot. How it works ? When the function was in the delphi click event i just use the code like: MyPanel.JsID or MyButton.JsID. How it workd now that i change my function to ClientEvents? Quote
Sherzod Posted May 27, 2020 Posted May 27, 2020 7 minutes ago, freedowsRoO said: Any object, i need to set there the object that i want to take the screeshot. Where and how will you set this object? Quote
freedowsRoO Posted May 27, 2020 Author Posted May 27, 2020 6 minutes ago, Sherzod said: Where and how will you set this object? When i click the button i need to send to the clientEvents the JSID of the component that i want. Quote
Sherzod Posted May 27, 2020 Posted May 27, 2020 14 hours ago, freedowsRoO said: function click(sender, e, eOpts) { html2canvas(document.getElementById(PanelCentral.jsID) , { dpi: 144 } ).then( function(canvas) { '+ var ctx = canvas.getContext("2d"); ctx.webkitImageSmoothingEnabled = false; ctx.mozImageSmoothingEnabled = false; ctx.imageSmoothingEnabled = false; var myImage = canvas.toDataURL("image/jpeg,1.0"); ajaxRequest('#1', "getData", ["base64Data="+myImage]); } ); } function click(sender, e, eOpts) { html2canvas(document.getElementById(sender.id), { dpi: 144 }).then(function(canvas) { var ctx = canvas.getContext("2d"); ctx.webkitImageSmoothingEnabled = false; ctx.mozImageSmoothingEnabled = false; ctx.imageSmoothingEnabled = false; var myImage = canvas.toDataURL("image/jpeg,1.0"); ajaxRequest(sender, "getData", ["base64Data= " + myImage]); }); } Quote
freedowsRoO Posted May 27, 2020 Author Posted May 27, 2020 8 minutes ago, Sherzod said: function click(sender, e, eOpts) { html2canvas(document.getElementById(sender.id), { dpi: 144 }).then(function(canvas) { var ctx = canvas.getContext("2d"); ctx.webkitImageSmoothingEnabled = false; ctx.mozImageSmoothingEnabled = false; ctx.imageSmoothingEnabled = false; var myImage = canvas.toDataURL("image/jpeg,1.0"); ajaxRequest(sender, "getData", ["base64Data= " + myImage]); }); } Ok, almost there... What if i need to change the 'sender.id' for another component? I need to take a screenshot of a panel not of my button(sender). Quote
Sherzod Posted May 27, 2020 Posted May 27, 2020 3 minutes ago, freedowsRoO said: What if i need to change the 'sender.id' for another component? I need to take a screenshot of a panel not of my button(sender). In this case. And with our solution, you can use it like this. 1. For example, you can use a combobox for select the another component id. ... YourMainButton.JSInterface.JSAssign('screenshotObjId', [YourCustomComponent.JsID]); ... 2. function click(sender, e, eOpts) { html2canvas(document.getElementById(sender.screenshotObjId), { dpi: 144 }).then(function(canvas) { var ctx = canvas.getContext("2d"); ctx.webkitImageSmoothingEnabled = false; ctx.mozImageSmoothingEnabled = false; ctx.imageSmoothingEnabled = false; var myImage = canvas.toDataURL("image/jpeg,1.0"); ajaxRequest(sender, "getData", ["base64Data= " + myImage]); }); } 1 Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.