Change file name before a save

Stimulsoft Reports.JS discussion
Post Reply
PaPy
Posts: 34
Joined: Fri May 19, 2017 1:51 pm

Change file name before a save

Post by PaPy »

Hi,

I want to use a prompt to allow the user to change his report fileName. For example, when I click on save, I want to pop a prompt to allow him to change the filename.

Is it possible to use the same prompt that you used when we click on "save as" ?
Attachments
What I want to use
What I want to use
Capture.PNG (5.62 KiB) Viewed 5924 times
harryf75
Posts: 20
Joined: Sun Jun 11, 2017 9:59 pm

Re: Change file name before a save

Post by harryf75 »

You can add a onSave/onSaveAs Hook:

https://admin.stimulsoft.com/documentat ... savereport

var designer = new Stimulsoft.Designer.StiDesigner(options, "StiDesigner", false);
designer.onSaveAsReport = function (e) { // or onSaveReport
this.designer.report.reportName="My Cool Name"; // sets the report name...
};


I didn't figure out a method to use then the default Stimulsoft JS Messagebox - so I added SweetAlert2

https://www.npmjs.com/package/sweetalert2

or the angular2 version

https://www.npmjs.com/package/ng2-sweetalert2
PaPy
Posts: 34
Joined: Fri May 19, 2017 1:51 pm

Re: Change file name before a save

Post by PaPy »

Thanks for your answer harryf75,

I know I could use the onSave hook, but I wanted to use the default Stimulsoft JS Messagebox to get the user's text.

But nevermind, if it is impossible I will use something else, even it's a pity. :?
harryf75
Posts: 20
Joined: Sun Jun 11, 2017 9:59 pm

Re: Change file name before a save

Post by harryf75 »

At last from my knowlege only this works.

Did you try saving the hook and calling it? This might works...

var old = designer.onSaveAsReport;
designer.onSaveAsReport = function (e) { // or onSaveReport
this.designer.report.reportName="My Cool Name"; // sets the report name...
old();
};
PaPy
Posts: 34
Joined: Fri May 19, 2017 1:51 pm

Re: Change file name before a save

Post by PaPy »

In this way, it is the Developer who set the name I wanted the user to set himself the name of the document in a onSaveReport only if the user use one of my documents, to save this report in an other file.

Here is my function if it could help to understand :

Code: Select all

designer.onSaveReport = function (e) {
    var jsonString = e.report.saveToJsonString();
    var today = new Date();
    var date = today.getDate() + '_' + parseInt(today.getMonth()+1) + '_' + today.getFullYear();
    var defaultName = 'document_' + date;
    e.fileName = defaultName;
    if (iscustom() == 1){
        e.fileName = getFileName();
    }else{
        //A MessageBox will open and the user have to tape his own fileName. 
    }
}
harryf75
Posts: 20
Joined: Sun Jun 11, 2017 9:59 pm

Re: Change file name before a save

Post by harryf75 »

I wrapped the whole Designer into my own panel.

In my software I have system default report. The user can have a "Copy of..." report and also rename the report. And I have a rename method.
Attachments
designer.png
designer.png (25.35 KiB) Viewed 5905 times
PaPy
Posts: 34
Joined: Fri May 19, 2017 1:51 pm

Re: Change file name before a save

Post by PaPy »

That is a possibility, maybe I will do something like this.

A message popup would have been better for me but nevermind.

Thanks for your answer.
joaquinsuarez69
Posts: 4
Joined: Tue Feb 27, 2018 5:23 pm

Re: Change file name before a save

Post by joaquinsuarez69 »

hi
PaPy wrote:That is a possibility, maybe I will do something like this.

A message popup would have been better for me but nevermind.

Thanks for your answer.
were you able to use the stimulsoft's pop up ?
Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

Re: Change file name before a save

Post by Alex K. »

Hello,

Please try to use the following code:

Code: Select all

var designer = new Stimulsoft.Designer.StiDesigner(null, "StiDesigner", false);
            designer.renderHtml("content");
            
            designer.jsObject.InitializeSaveReportForm(function (saveReportForm) {
                saveReportForm.action = function () {
                    this.changeVisibleState(false);
                    var fileName = this.reportNameTextBox.value;
                    //write your code here
                    alert(fileName);
                    if (this.nextFunc) this.nextFunc();
                }
            });
Thank you.
Post Reply