How to change url parameter openDocument to EditDocument from a client side link in XPages - xpages

I have a data source called "doc" and a link control on my xpage. The datasource is bound to a document using the url parameter
documentId=914A....&action=openDocument
When I click the link control I want to change the url parameter action to "editDocument" so that my data source goes into edit mode.
I would like this to be a client side solution, so I am thinking it can be done by constructing the url using EL, so something like this.
<xp:link escape="true" text="Edit Mode" id="link5" value="/documentID=#{doc.getUniversalID...}?action=editDocument"></xp:link>
any ideas?
Thanks
Thomas

What about simply changing the location.href by replacing "openDocument" with "editDocument"?
location.href = location.href.replace(\openDocument\g, "editdocument");

Related

xpages: how to simulate form's auto launch properties

Is there a quick and easy way to convert forms that have auto launch first attachment and/or launch URL?
I know it can be coded in SSJS but I was just wandering if someone had a quick way of doing this.
Thanks
The following Domino URL command will open an attachment ...
http://Host/DatabaseName/View/DocumentName/$File/fileattachmentname
... where the DocumentName is effectively the lookup value shown in the first column which is sorted.
Add an xp:link control and code it open the attachment (in this example in a new window). For example, the following is an xp:link that could be added in an xp:viewColumn or xp:repeat or any iterator control. In this example the var for the iterator is set to "rowData" and the name for the link is returned from the ListName column and the url to launch the attachment is in the cLinkUrl column.
<xp:link escape="true" id="link1" target="_blank">
<xp:this.text><![CDATA[#{javascript:rowData.getColumnValue("ListName");}]]></xp:this.text>
<xp:this.value><![CDATA[#{javascript:rowData.getColumnValue("cLinkUrl")}]]></xp:this.value>
</xp:link>
Since I wanted the code to be in the xpage, as it opens up either the document or the attachment depending on roles, I ended up adding this to the beforepageload event of the xpage (still need to add the role check to this though):
<xp:this.beforePageLoad>
<xp:executeScript>
<xp:this.script><![CDATA[#{javascript:var url = currentDocument.getDocument().getHttpURL();
var attachmentName = #AttachmentNames();
facesContext.getExternalContext().redirect(url.replace("?OpenDocument","/$File/"+attachmentName+"?OpenElement&target=_new"));}]]></xp:this.script>
</xp:executeScript>
</xp:this.beforePageLoad>

xpage: document1 is not defined

In the source of an xpage I have, RIGHT after the opening view tag...the following:
<xp:this.data>
<xp:dominoDocument
formName="myform"
var="document1"
</xp:this.data>
I need to be able to pull the value of any field for various functions. In a 'Server JavaScript' library I have this function, as a test:
function testThis(){
debugger;
var mystring = document1.getElementById("#{id:employeeTitle}");
console.log(mystring);
(...expecting everything in the element to be logged in the console.)
You can see I have the XPage bound to a DominoDocument with the variable name of 'document1'.
The function is called via a button, and stops for the debugger...so I can step through it.
In Firefox debugger, it is 'Paused at an exception' that says:
ReferenceError: document1 is not defined
I am sure this is something simple staring right at me, but I just don't get it. Any ideas?
Thank you.
I think you are mixing up ServerSide JS and client side. The Firefox debugger only knows about client side debugging (which is code that executes in the browser). For debugging server side JS I suggest the Debug Toolbar plugin that you can find at open NTF.https://www.openntf.org/main.nsf/project.xsp?r=project/XPage%20Debug%20Toolbar
You can also write to the server log with _dump, see https://xcellerant.net/2014/10/15/using_dump_to_write_to_server_console/
Finally, note in your code that if SSJS, you would use document1.getItemValueString("whatever") to access document values. The document object is of type NotesXSPDocument. See https://www.ibm.com/support/knowledgecenter/en/SSVRGU_9.0.1/reference/r_wpdr_xsp_xspdocument_r.html
You get the DOM element of the rendered field employeeTitle on client side in your CSJS code with
var element = document.getElementById("#{id:employeeTitle}");
and the content value with element.innerHTML.
Use document (entry point to web page loaded in the browser) instead of document1 (usually named XPage's data source on server side).
Your function testThis() has to be a part of the XPage, Custom Control or a SSJS library. This makes sure that #{id:employeeTitle} gets replaced with the real DOM id on server during rendering. If you want to put testThis() into a CSJS library you have to deliver the id as parameter to the function like
function testThis(id){
var element = document.getElementById(id);
...
and call the function in XPage like
testThis("#{id:employeeTitle}");

How to create in XPages a submit button to discard the current and create a new document?

I need to create a link on a XPage to refresh the panel with a new document.
The current document must not be saved.
Thank you!
Just create a link with the URL to the page where this link is on, e.g.
<xp:link text="Discard and start over" value="/thepage.xsp?action=newDocument"></xp:link>
you can reinstatiate a data source bound to a panel using the following code. Try running that before you submit.
var c = getComponent("mypanel");
var ds = c.getData();
ds.get(0).refresh();

Dynamically add custom control on Xpage

how can I add custom control on the basis of sessionScope variable. I try include page container control but no luck:
<xp:this.afterPageLoad><![CDATA[#{javascript:sessionScope.put("viewName","ccViewAll.xsp");}]]></xp:this.afterPageLoad>
<xp:text escape="true" id="computedField1">
<xp:this.value><![CDATA[#{javascript:sessionScope.get("viewName")}]]></xp:this.value>
</xp:text>
<xc:appLayout>
<xp:this.facets>
<xp:panel xp:key="facetMiddle">
<xp:include id="include1">
<xp:this.pageName><![CDATA[${javascript:sessionScope.get("viewName")}]]>
</xp:this.pageName>
</xp:include>
</xp:panel>
</xp:this.facets>
</xc:appLayout>
The above code give me error Error 404 HTTP Web Server: Item Not Found Exception. But when I hardcode the viewname that is ccViewAll.xsp instead of sessionScope.get("viewName"), its work fine.
-MAK
You can use the dynamic content control or the switchFacet control if you have the ExtLib for XPages. The Teamroom template (demo application that comes with the ExtLib) uses these in the "allDocuments" Xpage or the "allDocsAllTab" custom control, these are good examples to look at.
If you don't have the ExtLib you could use the loaded / rendered property of a custom control to decide which one gets loaded.
e.g.
<xp:panel key="MiddleColumn">
<xc:customControl1 loaded="${javascript: if(viewScope.control == "customControl1")}"></xc:customControl1>
<xc:customControl2 loaded="${javascript: if(viewScope.control == "customControl2")}"></xc:customControl2>
</xp:panel>
loaded = false means that nothing will be done for this control.
rendered = false means that the control will be created but hidden, you can change this later to show it.
use rendered if its going to change for example when a button is clicked and loaded when its decided at start up and won't change while the user is logged in.
If you are using this to show a different view in the domino database based on some other selection that I would suggest looking at the Extension Libraries 'Dynamic View Panel' control.
Using this control means you won't need to create different custom controls for each view that you want to use, just a single page with this control and point it to the correct view to display via a scope variable.
If you need to customize how each view displays you can create a viewControl bean to set additional properties based on the view that it is showing.
Something worth to mention is that if you don't use the ExtLib - If you're using Partial Refresh then you HAVE to use the rendered property, since the loaded property only can be calculated on pageLoad.
From my understanding this means that every custom control will be computed by the server and that's probably not something you want. (Added overhead, for one thing.)
/J

sharepoint list redirect with form data

Does anyone know the syntax, or the way to redirect a sharepoint "New Item Form" to a URL and pass values from the form as parameters in the URL?
So if the form as a "lastname" field, I would want the redirect to be something like http://path_to_other_page?name=lastname
I know I need to use something like:
onclick="javascript: {ddwrt:GenFireServerEvent(concat('__commit;__redirect={path_to_other_page.aspx?name=',/dsQueryResponse/Rows/Row/#LastName))}"
Except that's not working for me - I think the "/dsQueryResponse/Rows/Row/#LastName" is not correct - I was just trying to guess from other posts I had seen here...
Anyone?
That looks like something that would work on an edit form rather than a new form - that data is loaded when the page is loaded, not when it is submitted. To get the data in javascript you will need to access the textbox directly - jquery may be helpful.
I think you can use the SharePoint's build in Modal dialog (http://msdn.microsoft.com/en-us/library/ff410058(v=office.14).aspx). Within the modal dialog, you can callback function that will get the parameters from the form page.

Resources