FORUM PLAN UPDATE
Date revision: This forum will remain open to new posts and responses until December 1, 2018. (After that date, you will still be able to view and search the forum.) Also, we're taking a second look at the best place to host future conversation. For now, keep using this forum, and stay tuned for more news.



Mar 18, 2013, 7:43 PM
90 Posts

Simple autosave for an xpage?

  • Category: Other
  • Platform: Other
  • Release: 8.5.3
  • Role:
  • Tags:
  • Replies: 6
 Does anyone know of a simple autosave function to attach to an xpage page being worked on through a web browser?
 
The one here looked simple and promising at first -- 
 
http://stackoverflow.com/questions/12971605/autosave-function-in-ajax-mode
 
but it doesn't say what triggers it -- i.e. there's no timer attached to it. I guess I'm looking for something that sets off an autosave every xx seconds, unless there's another way.
 
 
Many thanks, Randal
 
 
Mar 19, 2013, 11:07 PM
366 Posts
Re: Simple autosave for an xpage?
 Can you provide the use case?  I'm assuming the document would be saved in some kind of "draft" mode and then deleted if never completed by the user.


What is the timing of the save?  after how long. 


Is this an issue of users loosing input data?   


Have you thought about adding a simple "save as draft" action button? 
Mar 20, 2013, 12:29 PM
90 Posts
Re: Simple autosave for an xpage?
 Users are filling in a detailed questionnaire online. The same users do this each year.
 
This year, we're converting the form to be an xPage.
  

In the previous, regular, "notes form on the web", we had both autosave and "save as draft".

Why the autosave was needed in addition to the "save as draft" button is that a user would be working wirelessly at home, or from somewhere, take an hour to fill in one question for whatever reason, then go to hit "save as draft" only to find out that their wireless had hiccuped in the meantime, their connection / session was lost, and bye bye work, hello screaming user blaming us.   
 
Re the timing of the save, presumably that would be a variable that could simply be set and adjusted over time??

 
Mar 20, 2013, 1:15 PM
90 Posts
Re: Simple autosave for an xpage?
 Sven Hasselbach posted this elsewhere....
 
<xp:eventHandler event="autoSaveEvent" id="autoSaveDoc" submit="false">
   <xp:this.action>
      <xp:saveDocument />
   </xp:this.action>
</xp:eventHandler>

  

The event handler can now be called from CSJS with this code:

executeOnServer('autoSaveDoc',null,{ 'valmode': 0 })
 I think the missing piece is some kind of timer to set off the line:  
executeOnServer('autoSaveDoc',null,{ 'valmode': 0 })
 
Mar 20, 2013, 4:31 PM
366 Posts
Re: Simple autosave for an xpage?
 I can't really say that I think this is a good idea, but it works


Here is the complete xsp source of  a simple timer that saves the "document" ever 10-20 seconds 

It uses Jeremy Hodges csjs eventHandler routine in combination with a dojo timer 

I tested it in FF and Chrome and worked fine. 

<?xml version="1.0" encoding="UTF-8"?>

<xp:view

xmlns:xp="http://www.ibm.com/xsp/core">


<xp:this.resources>

<xp:dojoModule

name="dojox.timing"></xp:dojoModule>

</xp:this.resources>

<xp:this.data>

<xp:dominoDocument

var="document1"

formName="StoredFormData">

</xp:dominoDocument>

</xp:this.data>


         <xp:eventHandler event="onfubar" id="autoSaveDoc" submit="false">

             <xp:this.action>

                 <xp:saveDocument></xp:saveDocument>

             </xp:this.action>

         </xp:eventHandler>


         <xp:eventHandler

         event="onClientLoad"

         submit="false">

         <xp:this.script><![CDATA[var executeOnServer = function () {

    // must supply event handler id or we're outta here....

    if (!arguments[0])

        return false;

    // the ID of the event handler we want to execute

    var functionName = arguments[0];


    // OPTIONAL - The Client Side ID that you want to partial refresh after executing the event handler

    var refreshId = (arguments[1]) ? arguments[1] : "@none";

    var form = (arguments[1]) ? XSP.findForm(arguments[1]) : dojo.query('form')[0];


    // OPTIONAL - Options object contianing onStart, onComplete and onError functions for the call to the 

    // handler and subsequent partial refresh

    var options = (arguments[2]) ? arguments[2] : {};


    // Set the ID in $$xspsubmitid of the event handler to execute

    dojo.query('[name="$$xspsubmitid"]')[0].value = form.id + ':' + functionName;

    XSP._partialRefresh("post", form, refreshId, options);

}

var x = 0;

var form = document.forms[0];

t = new dojox.timing.Timer(3600);

t.onTick = function() {

 x+=1;

 console.info(x);

 if(x > 10){

 x = 0;

 console.info(x);

 console.info("reset");

 executeOnServer('autoSaveDoc');

 }

}

t.onStart = function() {

 console.info("Starting timer");

}

t.start();]]></xp:this.script>


         </xp:eventHandler>

         

<xp:panel id="dataFields"><xp:table>

<xp:tr>

<xp:td>

<xp:label value="First name:" id="firstName_Label1" for="firstName1">

</xp:label>

</xp:td>

<xp:td>

<xp:inputText value="#{document1.FirstName}" id="firstName1" defaultValue="Bob">

</xp:inputText>

</xp:td>

</xp:tr>

<xp:tr>

<xp:td>

<xp:label value="Last name:" id="lastName_Label1" for="lastName1">

</xp:label>

</xp:td>

<xp:td>

<xp:inputText value="#{document1.LastName}" id="lastName1" defaultValue="Maher">

</xp:inputText>

</xp:td>

</xp:tr>

<xp:tr>

<xp:td></xp:td>

<xp:td>

<xp:button value="Submit" id="button1">

<xp:eventHandler event="onclick" submit="true" refreshMode="complete" immediate="false" save="true" id="eventHandler1">

</xp:eventHandler>

</xp:button>

</xp:td>

</xp:tr>

</xp:table></xp:panel><xp:this.navigationRules><xp:navigationRule outcome="xsp-success" viewId="/StoredFormView.xsp"></xp:navigationRule></xp:this.navigationRules></xp:view> 
Mar 21, 2013, 1:46 PM
90 Posts
Re: Simple autosave for an xpage?
Paul, ha! I just typed out a long response to you, but it got LOST cause there was a blip and NO autosave here lol.


NO WAY I gonna retype everything I lost, I'll just say thanks and this forum itself just proved how valuable it would be here LOL.


Randal   
Jun 18, 2018, 2:56 PM
3 Posts
How to get Code to Work with querySaveDocument event entry?

I need to have my xPage automatically save silently and without refreshing anything.  I'm trying to use the above code posted by Paul Calhoun.  The code works by itself, but when I put it into my xPage it does not because I have code in the querySaveDocument event.  What I'm doing in that event is looking to see if a submission field is set to "Yes" (which would mean that the Submit button has been clicked) and if it is NOT, then no additional code should be executed.

How can I allow the silent interval save to work with code in the querySaveDocument event?


FORUM PLAN UPDATE
Date revision: This forum will remain open to new posts and responses until December 1, 2018. (After that date, you will still be able to view and search the forum.) Also, we're taking a second look at the best place to host future conversation. For now, keep using this forum, and stay tuned for more news.