I built a Dialog in InDesign script that has any options.
I want to save the settings the user selects in a file (For example in a file named setting.ini) to do not require a re-adjustment in the next run and the same settings are enabled for the Dialog.
Is there such a possibility?
Yes, you can use the label functionality to save any information to any InDesign objects. To save things from dialogs that you want to access the next time that a script is run, it would make most sense to save the info into the app object directly, that way it will be available even after closing and re-starting InDesign (as opposed to saving it into a Document which might not be open the next time the users uses the script).
The general workflow would be something like this:
// after the user closes the dialog, save the settings they made to an object
var userChoice = {
// save any info from the dialog, for example some settings about underlines
underline: checkbox3.value,
underlineWeight: edittext6.text,
underlineOffset: edittext7.text,
// etc. ...
};
// insert the given information into a script label, pick any arbitrary name
// use .toSource() to stringify the object in the process, labels can only save strings
app.insertLabel("ha_a_usersettings", userChoice.toSource());
Now the info is saved in the app itself. Next time you run the script, you can retrieve the information from the label like this:
var savedSettings = eval(app.extractLabel("ha_a_usersettings"));
Now you can proceed and pre-populate the dialog with the properties you have in the savedSettings variable.
Related
It seems the only way to open a client-side dialog is from within an embedded control which doesn't work for me. Most of my coding to populate the dialogs is contained in an external script library, yet when I try to XSP.openDialog(id) I receive a jumbled javascript error on Firebug.
I have tried
Accessing the object (an extension library dialog) directly from a button on the xpages. It opens without a problem
Calling a script function from an embedded button and passing the id of the dialog. Error.
Created a global variable containing the id of the dialog and called directly from a button. WORKS
Same global variable, but called in a javascript function. ERROR
from within script created variable with dojo.byId. ERROR
Is there something else I need to configure? Many of the buttons I will be using are also dynamically generated from a JSON-supplied feed.
This is a rather strange one I think, and I'm sure I made a mistake here myself:
in one of my applications I'm showing a fileDownload control bound to a Richtext field in my underlying NotesDocument. The control's properties a are set to Hide if no attachments, show size, type and created as well as allow delete. The control itself sits inside a custom control, being part of another custom control, similar to this:
Xpage.xsp
- ccContainer
- - ccInnerDoc
Document datasources for both the container and the "inner" doc are defined at the root of ccContainer and passed into the inner doc.
The inner doc's datasource is comnputed based on a document selection, and it's igenoreRequestParams property is set to false so that I can display the contents of the selected datasource in a given panel etc.
The selected doc is first opened in read mode, and I can set it to edit mode using a button.
Problem now is that my file download control always is showing the delete icon (trashcan) no matter which mode the doc is opened in. And it's not only the icon showing, it also pretends to work by asking me whether I really want to delete and then really removes the file attachment. Only that this change of course cannot be stored into the datasource because it's only open in read mode.
I'm sure that this behaviour is some side-effect of something else in my application (to a certain extent I rebuilt this in a plain new db and until now cannot reproduce it), but I'm at the end of my knowledge of what this could be.
Any hint of what could be causing this is more than welcome.
In place of #Frantisek Kossuth I answer this myself: see compute dynamically the allowDelete property of file download xpages
Thanks again, Frantisek!
I am sure this is related to my question here
Null value for fileData:com.ibm.xsp.http.UploadedFile in dialog box?
Which I am still not 100% clear why the file upload control does not work directly in an extension pages dialog box.
But anyway I came up with my own solution using the file update control inside of a hidden panel. I need to set the button that uses the control to full update.
I have a button does an import of data. The button gets the file via a file upload control. This data is displayed in a view on the xpage.
The view is not being updated even though the Import button has Full Update. I am guessing that the full update actually get executed before the import actually completes?
Is there anyway to update my view after the import completes?
My understanding is that a File Upload requires a full refresh of the XPage to push the file up to the temporary folder on the server. At this point, the attachment is just stored in that temporary folder. It's not stored in the NSF. A subsequent function needs to be run to save that to a document.
Is your button doing the upload of the file to the temporary folder, or is it saving a Notes Document / directly accessing the temporary file and processing it via the back-end? If it's just performing the upload, the view won't upload.
The other thing I've come across is View Panels not immediately updating with new documents that have been created. In that scenario, a repeat control bound to NotesView.getDocumentsByKey() did immediately update.
I solved the issue by causing the button that uploads the file to display an extension pages dialog box. This dialog box has an OK button to close the message box but also refreshes the required part of the form.
I've created an XAgent to export Notes data to Excel along the lines of the following:
http://www.dominoguru.com/pages/developer2010_xpagexlsexport.html
http://xpageswiki.com/web/youatnotes/wiki-xpages.nsf/dx/How_to_export_to_Excel_or_other_formats
The agent works fine the first time I run it in the Notes client. However, the second time I trigger the XAgent, I get the Location chooser letting me determine where to save the file, but nothing is ever downloaded. Worst of all, my Notes client locks up. I need to completely reboot my PC to get the XAgent to work again. I'm using Notes 8.5.3
When I run the agent within IE, it works fine every time.
Has anyone else experienced this behavior when exporting data via an XAgent running in XPiNC?
I wouldn't recommend to use file emitting XAgents in XPiNC. You do have access to the file system after all. So it is easier to directly write to a file and then just display the link. If you follow my XAgent advise all your worker code would be in a class which you pass the Stream object, so you only have slightly different wrapper code around it.
So you would (pseudo-code)
OutputStream out;
if(runningInXPiNC()) {
out = new FileOutputStream(new File(determineLocalFileName()));
} else {
out = getOutputStreamFromContextandResponseObject();
}
renderThatExelFile(out);
The rendered property of the page would be true for XPiNC, so you can display "Open the file" URL that points to "file://"+determineLocalFileName()
I'm writing a chrome extension and have a question.
My extension has some .html page in it, let it be 'popup.html'. I inject a content script into some page and this script opens a 'popup.html' in a new tab with something like 'var p = window.open(chrome.extension.getURL('/popup.html'), "popup")', which works perfectly. Next, I need to pass some data to this window and I can't figure how to do it in a simple way.
For some reason I can't call child window's function from a content script with
var p = window.open(chrome.extension.getURL('/popup.html'), "popup");
p.foo(data);
In the console I see Uncaught TypeError: Cannot call method 'foo' of undefined message.
I can't pass data in a query string, because the data is simply too big.
Is there an elegant and simple way to pass data to such kind of window? I thought about messaging, but how do I effectively get tab ID of a newly opened window w/out using a background page?
Thanks a lot in advance.
UPD:
I tried to inverse the logic and get a data from parent window with 'window.opener.foo()' but in a newly opened tab window.opener returns null.
Ok, I found two solutions to my problem.
1) Add a background page, which opens a popup with chrome.tabs.create(). Then send a message from a content script to a background page, which re-sends it to a corresponding tab via chrome.tabs.sendMessage(). It looks a little ugly, but works.
2) A better one, w/out background page. Extension (popup) page creates a listener for long-lived connection. Then content script sends a message to this connection. A problem here is that a listener is not created right after the page is opened, so there should be a mechanism for a content script to wait until popup is loaded. It can be a simple setTimeout or a notification from popup via same long-lived connection.
If anyone has a better solution I'd gladly check it out as well.