Friday, April 4, 2014

Autosave ePerfromance Take III

Since we are working on our tools upgrade to 8.53, I was forced to readdress the auto save functionality that I had previously blogged about.  In my initial posting I was auto saving when the user navigated to the EP_APPR_EDIT5 or EP_APPR_M_EDIT5 pages.  The auto save functionality was no matching buffer issues if the document did not already have a goal attached.  I also attempted to auto save from the two pages above, but it to generated the same error messages.  For now I am leaving them out, and commenting out the JavaScript that calls the save prior to navigating to these pages.  You are welcome to uncomment this code out and play around at your own risk as always. Back to the method I went with:

First, create a derived work record and add the fields HTMLAREA and EP_STORE_PB





Second,  add the fields from step one to the EP_APPR_MAIN1 and EP_APPR_BASE1.




 *Make sure you set the EP_STORE_PB to invisible and modifiable via JavaScript and give it a page field name of ZZ_EP_STORE.

Third, add the following PeopleCode to the work records.



Add some FieldChange PeopleCode to the EP_STORE_PB to save the Document.  This can be copied from the Delivered Save Logic.



/*******************************************
RITM0054746 8.53 TOOLS UPGRADE 
UMBMOD
KCW002

Autosave code changed to for new timout logic
in 8.53
*****************************************/

import EP_FUNCTIONS:EP_Utilities;

Declare Function TransferToDocumentSelection PeopleCode FUNCLIB_EP.EP_APPRAISAL_ID FieldFormula;

Global Record &EP_GBLKEYS_WRK;
Component string &PushButton;



Evaluate %Component
When = Component.EP_APPR_BASE
   &ReturnCode = "RETURN_EST_SAVE";
   &TransferPg = "Page.EP_APPR_BASE1";
   Break;
When = Component.EP_APPR_MAIN
   &ReturnCode = "RETURN_EVL_SAVE";
   &TransferPg = "Page.EP_APPR_MAIN1";
   Break;
When-Other
   Exit;
   Break;
End-Evaluate;

/* Clear error messages, if any, and Save */
EP_BTN_LINK_WRK.EP_HTMLAREA_ERROR1.SetDefault();
EP_BTN_LINK_WRK.EP_HTMLAREA_ERROR2.SetDefault();
EP_BTN_LINK_WRK.EP_HTMLAREA_ERROR1.Visible = False;
EP_BTN_LINK_WRK.EP_HTMLAREA_ERROR2.Visible = False;
&PushButton = "STORE";
DoSaveNow();

Rem: Set Return Status to display a confirmation message;
&EP_GBLKEYS_WRK.EP_RETURN_STATUS.Value = &ReturnCode;
Rem: Set the Return Status HTML Area;
Local EP_FUNCTIONS:EP_Utilities &EP_Utilities = create EP_FUNCTIONS:EP_Utilities();
&EP_Utilities.SetReturnStatusHtmlArea();
Rem: Set focus to the top of the page for the return status message;

If ZZ_DERIVED_EP.EP_STORE_PB.Value = "T" Then
   
   REM DO TIMEOUT;
   ZZ_DERIVED_EP.HTMLAREA.Value = GetHTMLText(HTML.ZZ_EP_TIMEOUT);
Else
   
   ZZ_DERIVED_EP.EP_STORE_PB.Value = "";
   
End-If;

Also add some PeopleCode to the RowInit of the HTMLAREA.

/*******************************************
RITM0054746 8.53 TOOLS UPGRADE 
UMBMOD
KCW002

Autosave code changed to for new timout logic
in 8.53

Setup JavaScript for UMB Autosave timeout
*****************************************/

ZZ_DERIVED_EP.HTMLAREA.Value = GetHTMLText(HTML.ZZ_EP_AUTOSAVE);
 

Fourth, create two HTML Objects.

HTML.ZZ_EP_AUTOSAVE below:
<input type="hidden" name="ZZ_EP_STORE" id="ZZ_EP_STORE" value=""/>

<script type="text/javascript">

threadLock = false;
var xStore = document.getElementById("ZZ_EP_STORE");

function user_function()
{
//alert('starting process');
//debugger;

 if (!threadLock)
  {
   threadLock = true;
   if ("%page" == "EP_APPR_MAIN1" || "%page" == "EP_APPR_BASE1" )
   {


    xStore.value = 'T';
    //alert(xStore.value);
    document.%formname.submit();

   }
  }
}

</script>
<script type="text/javascript" language="javascript">

window.onbeforeunload = function(e) { 
var changes = checkFormChanged(document.%formname);
if (changes && !threadLock)
{
 threadLock = true; 
 if ("%page" == "EP_APPR_MAIN1" || "%page" == "EP_APPR_BASE1" )
 {
            return "You have unsaved changes, please save them."
    };
}
}
</script>

<script type="text/javascript">
function adaptLinks() {
    var links = document.getElementsByTagName('a');
    for (i = 0; i != links.length; i++) {
        links[i].onclick = (function () {
            var origOnClick = links[i].onclick;
            return function (e) { 
                 //add logic to save if the user is adding and item to the document                
                 //linkId = this.id.split('$');                 
                 //if (linkId[0] == 'EP_BTN_LINK_WRK_EP_ADD_ITEM_PB')
                 // {
                 //   xStore.value = 'Z'; 
                 // }
                 //end mod to auto save if the user is adding an item to the document
                 window.onbeforeunload = function(){};
                if (origOnClick != null && !origOnClick()) {
                    return false;
                }                
            }
        })();
    }
}
(function() {
  var originaldisplayTimeoutMsg = displayTimeoutMsg2;
  displayTimeoutMsg2 = function() {
    window.onbeforeunload = function(){};
    
    user_function();
  
  }
})();

adaptLinks();

</script> 
 
 
HTML.ZZ_EP_TIMEOUT below:
<input type="hidden" name="TIMEOUT" value=""/>

<script type="text/javascript">

self.location=timeOutURL; ;

</script> 
 
 

Test it out.

 When the user timesout, the user function will be called instead of the delivered timout logic, this will set the hidden ZZ_EP_STORE field value to 'T'.  This will trigger the fieldchange Peoplecode to trigger and this will save the document and set the HTMLAREA to the ZZ_EP_TIMEOUT.  This will inject JavaScript into the page that will log the user out and present them with the timeout message.  The adaptLinks function will prevent the user from navigating away from the current page when the form is changed and will prompt them to stay and save the information, for example when the user hits the Back button.  But it will also change the value of the hidden ZZ_EP_STORE to 'Z' if the link clicked is one to navigate the user to add something to the document, this will also trigger the FieldChange PeopleCode and it will save the document, but it won't timeout the user.    

No comments:

Post a Comment