form1.#variables[0].controller - (JavaScript, client)
var im;
var pageName;
var currentPageNum;
var dataStore;
var logLevel;
var history;
/*
*
* ADOBE SYSTEMS INCORPORATED
* Copyright 2005 Adobe Systems Incorporated
* All Rights Reserved
*
* NOTICE: Adobe permits you to use, modify, and distribute
* this file in accordance with the terms of the Adobe license
* agreement accompanying it. If you have received this file
* from a source other than Adobe, then your use, modification,
* or distribution of it requires the prior written permission
* of Adobe.
*
* MVC Model 2 XFA Sample Implementation
*
* Created on Feb 22, 2005
*
* Author Herve Dupriez
* Email hdupriez@adobe.com
* Version 1.0
*
*/
/*
*
* Main Action Controller
*
* For the simplicity of this controller, actions are coded within this main function.
* For more complex frameworks, this function could simply act as a switch to other functions.
*
*/
function executeAction( action )
{
debugLog("executeAction " + action );
var pnum = getPageNum(action);
debugLog("history size " + history.length );
if ( action == "back" )
{
if ( history.length > 1 )
{
// Restore previous page
debugLog("back to page " + history[history.length - 2] );
im[currentPageNum].removeInstance(0);
currentPageNum = history[history.length - 2];
loadPage( currentPageNum );
im[currentPageNum].addInstance();
}
else
{
forward(1);
}
}
else if ( action == "first" )
{
forward(1);
}
else if ( action == "last" )
{
forward(9);
}
else if ( action == "previous" )
{
var prev = currentPageNum-1;
if ( prev > 0 && prev < pageName.length )
forward(prev);
}
else if ( action == "next" )
{
var next = currentPageNum+1;
if ( next > 0 && next < pageName.length -2 )
forward(next);
}
else if ( pnum == -1 )
{
showErrorPage(404, "Page Not Found");
}
else
forward(pnum);
}
/*
*
* Initialization of the controller
*
* For debugging purposes increase the logLevel variable below
*
*/
function init()
{
console.println("init");
// Init log level
// 0: error
// 1: warning
// 2: info
// 3: debug
// 4: trace
logLevel = 0;
// Initialize instance managers and page names
if ( im == null )
{
scanPages();
}
// Initialize "page number"
if ( currentPageNum == null )
{
currentPageNum = 0;
var dataNodes = xfa.data.form1.nodes;
debugLog( xfa.data.form1.saveXML() );
if ( dataNodes != null )
{
var intNumElements = dataNodes.length;
for(var j=0; j < intNumElements; j++)
{
var currentElement = dataNodes.item(j);
debugLog("listNodes found " + currentElement.name );
if ( currentElement.name.substr(0,5) == "page_" ) {
var action = currentElement.name.substr(5) ;
setCurrentPage( getPageNum( action ) );
break;
}
}
}
/*
* Show last page viewed when document was saved
* or the Welcome Page if document opened for the first time
*
*/
if ( currentPageNum == 0 )
im[currentPageNum].addInstance();
}
// Initialize a simple data store
if ( dataStore == null )
{
retrieveDataStore();
}
// History
if ( history == null )
{
history = new Array();
history[0] = currentPageNum;
debugLog("history[0]= 0");
}
executeAction("1");
}
/*
*
* Save page data to the in-memory data store
*
*/
function savePage( pageNum )
{
debugLog("savePage " + pageNum);
var pageObj = xfa.resolveNode(pageName[pageNum]);
if (pageObj != null)
{
var sXML = xfa.data.form1.saveXML();
dataStore[pageNum] = sXML;
}
}
/*
*
* Load page data from the in-memory data store
*
*/
function loadPage( pageNum )
{
debugLog("loadPage " + pageNum);
if ( pageNum > 0 && pageNum < pageName.length )
{
if ( dataStore[pageNum] != null && dataStore[pageNum] != "" )
{
xfa.data.form1.loadXML( dataStore[pageNum], true, true );
traceLog( xfa.data.saveXML() );
}
debugLog("history[" + history.length + "]=" + pageNum);
history[history.length] = pageNum;
}
}