Widget state persistence for multi-pane dialogs, generic wizard architecture and wizard buttons. r=alecf
This commit is contained in:
Родитель
2d2e9a623c
Коммит
6e5eea144b
|
@ -13,3 +13,10 @@ charsetOverlay.xul
|
|||
charsetOverlay.js
|
||||
charsetDetectorsOverlay.js
|
||||
charsetDetectorsOverlay.xul
|
||||
widgetStateManager.js
|
||||
wizardHandlerSet.js
|
||||
wizardManager.js
|
||||
wizardOverlay.js
|
||||
wizardOverlay.xul
|
||||
|
||||
|
||||
|
|
|
@ -45,6 +45,11 @@ EXPORT_RESOURCE_CONTENT = \
|
|||
$(srcdir)/about.html \
|
||||
$(srcdir)/charsetDetectorsOverlay.js \
|
||||
$(srcdir)/charsetDetectorsOverlay.xul \
|
||||
$(srcdir)/widgetStateManager.js \
|
||||
$(srcdir)/wizardHandlerSet.js \
|
||||
$(srcdir)/wizardManager.js \
|
||||
$(srcdir)/wizardOverlay.js \
|
||||
$(srcdir)/wizardOverlay.xul \
|
||||
$(NULL)
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
|
|
@ -44,6 +44,11 @@ install::
|
|||
$(MAKE_INSTALL) charsetOverlay.js $(DISTBROWSER)
|
||||
$(MAKE_INSTALL) charsetDetectorsOverlay.js $(DISTBROWSER)
|
||||
$(MAKE_INSTALL) charsetDetectorsOverlay.xul $(DISTBROWSER)
|
||||
|
||||
$(MAKE_INSTALL) widgetStateManager.js $(DISTBROWSER)
|
||||
$(MAKE_INSTALL) wizardHandlerSet.js $(DISTBROWSER)
|
||||
$(MAKE_INSTALL) wizardManager.js $(DISTBROWSER)
|
||||
$(MAKE_INSTALL) wizardOverlay.js $(DISTBROWSER)
|
||||
$(MAKE_INSTALL) wizardOverlay.xul $(DISTBROWSER)
|
||||
|
||||
clobber::
|
||||
rm -f $(DIST)\bin\chrome\global\content\default\*.*
|
||||
|
|
|
@ -0,0 +1,244 @@
|
|||
/* -*- Mode: Java; tab-width: 4; c-basic-offset: 4; -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Ben "Count XULula" Goodger <rgoodger@ihug.co.nz>
|
||||
* Alec Flett <alecf@netscape.com>
|
||||
*/
|
||||
|
||||
|
||||
/** class WizardStateManager ( string frame_id, object pageMap )
|
||||
* - purpose: object for managing data in iframe multi-panel dialogs.
|
||||
* - in: string frame id/name set of iframe, pageMap showing navigation of wizard
|
||||
* - out: nothing (object)
|
||||
**/
|
||||
function WidgetStateManager( frame_id )
|
||||
{
|
||||
// data members
|
||||
/**
|
||||
* hash table for data values:
|
||||
* page1 => id1 => value1
|
||||
* page1 => id2 => value2
|
||||
* page2 => id1 => value1
|
||||
* page2 => id2 => value2
|
||||
**/
|
||||
this.PageData = [];
|
||||
this.content_frame = window.frames[frame_id];
|
||||
|
||||
// member functions
|
||||
this.SavePageData = WSM_SavePageData;
|
||||
this.SetPageData = WSM_SetPageData;
|
||||
this.GetTagFromURL = WSM_GetTagFromURL;
|
||||
this.GetURLFromTag = WSM_GetURLFromTag;
|
||||
this.toString = WSM_toString;
|
||||
this.ConvertToArray = WSM_ConvertToArray;
|
||||
}
|
||||
|
||||
/** void SavePageData() ;
|
||||
* - purpose: retrieves form/widget data from a generic page stored in a frame.
|
||||
* - useful for retrieving and persisting wizard/prefs page data that
|
||||
* - has not been added to permanent storage.
|
||||
* - for full reference, please refer to user manual at:
|
||||
* - http://www.mozilla.org/xpapps/ui/wizards.html
|
||||
* - in: nothing
|
||||
* - out: nothing
|
||||
**/
|
||||
function WSM_SavePageData( currentPageTag )
|
||||
{
|
||||
var doc = this.content_frame.document;
|
||||
if( this.content_frame.GetFields ) {
|
||||
// data user-provided from GetFields function
|
||||
var data = this.content_frame.GetFields();
|
||||
}
|
||||
else {
|
||||
// autosave data from form fields in the document
|
||||
var fields = doc.getElementsByTagName("FORM")[0].elements;
|
||||
var data = [];
|
||||
for( var i = 0; i < fields.length; i++ )
|
||||
{
|
||||
data[i] = [];
|
||||
var formElement = fields[i];
|
||||
data[i][0] = formElement.id;
|
||||
if( formElement.nodeName.toLowerCase() == "select" ) { // select & combo
|
||||
// data[i][0] = formElement.getAttribute("id");
|
||||
// here's a bug. this gives errors, even though this style of thing works
|
||||
// in 4.x
|
||||
// data[i][1] = formElement.options[formElement.options.selectedIndex].value;
|
||||
// dump("*** CURRSELECT:: VALUE: " + data[i][1] + "\n");
|
||||
}
|
||||
else if( formElement.nodeName.toLowerCase() == "textarea" ) { // textarea
|
||||
data[i][0] = currTextArea.getAttribute("id");
|
||||
data[i][1] = currTextArea.value;
|
||||
}
|
||||
else if( formElement.type == "checkbox" || formElement.type == "radio" ) {
|
||||
// form element is a checkbox or a radio group item
|
||||
data[i][1] = formElement.checked;
|
||||
}
|
||||
else if( formElement.type == "text" &&
|
||||
formElement.getAttribute( "datatype" ) == "nsIFileSpec" ) {
|
||||
if( formElement.value ) {
|
||||
var progId = "component://netscape/filespec";
|
||||
var filespec = Components.classes[progId].createInstance( Components.interfaces.nsIFileSpec );
|
||||
filespec.nativePath = formElement.value;
|
||||
data[i][1] = filespec;
|
||||
} else
|
||||
data[i][1] = null;
|
||||
}
|
||||
else {
|
||||
// generic form element: text, password field, buttons, textareas, etc
|
||||
data[i][1] = formElement.value;
|
||||
}
|
||||
}
|
||||
// trees are not supported here as they are too complex and customisable
|
||||
// to provide default handling for.
|
||||
}
|
||||
this.PageData[currentPageTag] = [];
|
||||
if( data.length ) {
|
||||
for( var i = 0; i < data.length; i++ ) {
|
||||
this.PageData[currentPageTag][data[i][0]] = data[i][1];
|
||||
}
|
||||
}
|
||||
else
|
||||
this.PageData[currentPageTag]["nodata"] = true; // no fields or functions
|
||||
}
|
||||
|
||||
/** void SetPageData() ;
|
||||
* - purpose: populates the loaded page with appropriate data from the data
|
||||
* - table.
|
||||
* - for full reference, please refer to user manual at:
|
||||
* - http://www.mozilla.org/xpapps/ui/wizards.html
|
||||
* - in: nothing.
|
||||
* - out: nothing.
|
||||
**/
|
||||
function WSM_SetPageData( currentPageTag )
|
||||
{
|
||||
var doc = this.content_frame.document;
|
||||
if ( this.PageData[currentPageTag] != undefined ) {
|
||||
if ( !this.PageData[currentPageTag]["nodata"] ) {
|
||||
for( var i in this.PageData[currentPageTag] ) {
|
||||
var value = this.PageData[currentPageTag][i];
|
||||
if( this.content_frame.SetFields ) {
|
||||
// user-provided SetFields function
|
||||
this.content_frame.SetFields( i, this.PageData[currentPageTag][i] );
|
||||
}
|
||||
else {
|
||||
// automated data provision
|
||||
// plundering code liberally from AccountManager.js
|
||||
var formElement = doc.getElementById( i );
|
||||
if( formElement && formElement.nodeName.toLowerCase() == "input" ) {
|
||||
if( formElement.type == "checkbox" || formElement.type == "radio" ) {
|
||||
// formElement is something interesting like a checkbox or radio
|
||||
if( value == undefined )
|
||||
formElement.checked = formElement.defaultChecked;
|
||||
else {
|
||||
if( formElement.getAttribute( "reversed" ) )
|
||||
formElement.checked = !value;
|
||||
else
|
||||
formElement.checked = value;
|
||||
}
|
||||
}
|
||||
else if( formElement.type == "text" &&
|
||||
formElement.getAttribute( "datatype" ) == "nsIFileSpec" ) {
|
||||
// formElement has something to do with fileSpec. looked important
|
||||
if( value ) {
|
||||
var filespec = value.QueryInterface( Components.interfaces.nsIFileSpec );
|
||||
try {
|
||||
formElement.value = filespec.nativePath;
|
||||
}
|
||||
catch( ex ) {
|
||||
dump("Still need to fix uninitialized filespec problem!\n");
|
||||
}
|
||||
}
|
||||
else
|
||||
formElement.value = formElement.defaultValue;
|
||||
}
|
||||
else {
|
||||
// some other type of form element
|
||||
if( value == undefined )
|
||||
formElement.value = formElement.defaultValue;
|
||||
else
|
||||
formElement.value = value;
|
||||
}
|
||||
}
|
||||
else if( formElement && formElement.nodeName.toLowerCase() == "select" ) {
|
||||
// select the option element that has the value that matches data[i][1]
|
||||
/* commenting out while select widgets appear to be broken
|
||||
if( formElement.hasChildNodes() ) {
|
||||
for( var j = 0; j < formElement.childNodes.length; j++ ) {
|
||||
var currNode = formElement.childNodes[i];
|
||||
if( currNode.nodeName.toLowerCase() == "option" ) {
|
||||
if( currNode.getAttribute("value") == value )
|
||||
currNode.selected = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
else if( formElement && formElement.nodeName.toLowerCase() == "textarea" ) {
|
||||
formElement.value = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** string GetTagFromURL( string tag, string prefix, string postfix ) ;
|
||||
* - purpose: fetches a tag from a URL
|
||||
* - in: string url representing the complete location of the page.
|
||||
* - out: string tag representing the specific page to be loaded
|
||||
**/
|
||||
function WSM_GetTagFromURL( url, prefix, suffix )
|
||||
{
|
||||
return url.substring( prefix.length, url.lastIndexOf(suffix) );
|
||||
}
|
||||
|
||||
/** string GetUrlFromTag( string tag, string prefix, string postfix ) ;
|
||||
* - purpose: creates a complete URL based on a tag.
|
||||
* - in: string tag representing the specific page to be loaded
|
||||
* - out: string url representing the complete location of the page.
|
||||
**/
|
||||
function WSM_GetURLFromTag( tag, prefix, postfix )
|
||||
{
|
||||
return prefix + tag + postfix;
|
||||
}
|
||||
|
||||
/** string toString() ;
|
||||
* - purpose: returns a string representation of the object
|
||||
* - in: nothing;
|
||||
* - out: nothing;
|
||||
**/
|
||||
function WSM_toString()
|
||||
{
|
||||
var string = "";
|
||||
for( var i in this.PageData ) {
|
||||
for( var k in this.PageData[i] ) {
|
||||
string += "WSM.PageData[" + i + "][" + k + "] : " + this.PageData[i][k] + ";\n";
|
||||
}
|
||||
}
|
||||
return string;
|
||||
}
|
||||
|
||||
function WSM_ConvertToArray( nodeList )
|
||||
{
|
||||
var retArray = [];
|
||||
for( var i = 0; i < nodeList.length; i++ )
|
||||
{
|
||||
retArray[i] = nodeList[i];
|
||||
}
|
||||
return retArray;
|
||||
}
|
|
@ -0,0 +1,169 @@
|
|||
/* -*- Mode: Java; tab-width: 4; c-basic-offset: 4; -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Ben "Count XULula" Goodger <rgoodger@ihug.co.nz>
|
||||
*/
|
||||
|
||||
/** class WizardHandlerSet( WidgetStateManager sMgr, WizardManager wMgr ) ;
|
||||
* purpose: class for managing wizard navigation functions
|
||||
* in: WidgetStateManager sMgr WSM object created by WizardManager
|
||||
* WizardManager wMgr WM object created by WizardManager
|
||||
* out: nothing.
|
||||
**/
|
||||
function WizardHandlerSet( sMgr, wMgr )
|
||||
{
|
||||
// data mambers
|
||||
// wizard buttons
|
||||
this.backButton = document.getElementById("wiz.back.button");
|
||||
this.nextButton = document.getElementById("wiz.next.button");
|
||||
this.finishButton = document.getElementById("wiz.finish.button");
|
||||
this.cancelButton = document.getElementById("wiz.cancel.button");
|
||||
// wizard handlers
|
||||
this.nextButtonFunc = null;
|
||||
this.backButtonFunc = null;
|
||||
this.cancelButtonFunc = null;
|
||||
this.finishButtonFunc = null;
|
||||
this.pageLoadFunc = null;
|
||||
this.enablingFunc = null;
|
||||
|
||||
this.SM = sMgr;
|
||||
this.WM = wMgr;
|
||||
|
||||
// member functions
|
||||
this.SetHandlers = WHS_SetHandlers;
|
||||
|
||||
// construction (points member functions to right functions)
|
||||
this.SetHandlers( this.nextButtonFunc, this.backButtonFunc, this.finishButtonFunc,
|
||||
this.cancelButtonFunc, this.pageLoadFunc, this.enablingFunc );
|
||||
}
|
||||
|
||||
// default handler for next page in page sequence
|
||||
function DEF_onNext()
|
||||
{
|
||||
var oParent = this.WHANDLER;
|
||||
if( oParent.nextButton.getAttribute("disabled") == "true" )
|
||||
return;
|
||||
oParent.SM.SavePageData( this.currentPageTag ); // persist data
|
||||
var nextPageTag = this.wizardMap[this.currentPageTag].next;
|
||||
this.LoadPage( nextPageTag, false ); // load the next page
|
||||
this.ProgressUpdate( ++this.currentPageNumber );
|
||||
}
|
||||
// default handler for previous page in sequence
|
||||
function DEF_onBack()
|
||||
{
|
||||
var oParent = this.WHANDLER;
|
||||
if( oParent.backButton.getAttribute("disabled") == "true" )
|
||||
return;
|
||||
oParent.SM.SavePageData( this.currentPageTag ); // persist data
|
||||
previousPageTag = this.wizardMap[this.currentPageTag].previous;
|
||||
this.LoadPage( previousPageTag, false ); // load the preivous page
|
||||
this.ProgressUpdate( --this.currentPageNumber );
|
||||
}
|
||||
// default handler for cancelling wizard
|
||||
function DEF_onCancel()
|
||||
{
|
||||
if( top.window.opener )
|
||||
window.close();
|
||||
}
|
||||
// default finish handler
|
||||
function DEF_onFinish()
|
||||
{
|
||||
var oParent = this.WHANDLER;
|
||||
if( !this.wizardMap[this.currentPageTag].finish )
|
||||
return;
|
||||
oParent.SM.SavePageData( this.currentPageTag );
|
||||
dump("WizardButtonHandlerSet Warning:\n");
|
||||
dump("===============================\n");
|
||||
dump("You must provide implementation for onFinish, or else your data will be lost!\n");
|
||||
}
|
||||
|
||||
// default button enabling ** depends on map, see doc
|
||||
function DEF_DoEnabling()
|
||||
{
|
||||
var oParent = this.WHANDLER;
|
||||
// make sure we're on a valid page
|
||||
if( !this.currentPageTag )
|
||||
return;
|
||||
// "next" button enabling
|
||||
nextTag = this.wizardMap[this.currentPageTag].next;
|
||||
if( nextTag && oParent.nextButton.getAttribute("disabled") )
|
||||
oParent.nextButton.removeAttribute( "disabled" );
|
||||
else if( !nextTag && !oParent.nextButton.getAttribute("disabled"))
|
||||
oParent.nextButton.setAttribute( "disabled", "true" );
|
||||
// "finish" button enabling
|
||||
finishTag = this.wizardMap[this.currentPageTag].finish;
|
||||
if( finishTag && oParent.finishButton.getAttribute("disabled") )
|
||||
oParent.finishButton.removeAttribute( "disabled" );
|
||||
else if(!finishTag && !oParent.finishButton.getAttribute("disabled") )
|
||||
oParent.finishButton.setAttribute( "disabled", "true" );
|
||||
// "back" button enabling
|
||||
prevTag = this.wizardMap[this.currentPageTag].previous;
|
||||
if( prevTag && oParent.backButton.getAttribute("disabled") )
|
||||
oParent.backButton.removeAttribute("disabled");
|
||||
else if( !prevTag && !oParent.backButton.getAttribute("disabled") )
|
||||
oParent.backButton.setAttribute("disabled", "true");
|
||||
}
|
||||
|
||||
/** void PageLoaded( string tag, string frame_id ) ;
|
||||
* purpose: perform initial button enabling and call Startup routines.
|
||||
* in: string page tag referring to the file name of the current page
|
||||
* string frame_id optional supply of page frame, if content_frame is not
|
||||
* defined
|
||||
* out: nothing.
|
||||
**/
|
||||
function DEF_onPageLoad( tag )
|
||||
{
|
||||
var oParent = this.WHANDLER;
|
||||
this.currentPageTag = tag;
|
||||
if( this.DoButtonEnabling ) // if provided, call user-defined button
|
||||
this.DoButtonEnabling(); // enabling function
|
||||
if( this.content_frame )
|
||||
oParent.SM.SetPageData( tag ); // set page data in content frame
|
||||
else {
|
||||
dump("Widget Data Manager Error:\n");
|
||||
dump("==========================\n");
|
||||
dump("content_frame variable not defined. Please specify one as an argument to Startup();\n");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/** void SetHandlers( string nextFunc, string backFunc, string finishFunc, string cancelFunc,
|
||||
* string pageLoadFunc, string enablingFunc ) ;
|
||||
* purpose: allow user to assign button handler function names
|
||||
* in: strings referring to the names of the functions for each button
|
||||
* out: nothing.
|
||||
**/
|
||||
function WHS_SetHandlers( nextFunc, backFunc, finishFunc, cancelFunc, pageLoadFunc, enablingFunc )
|
||||
{
|
||||
// var oParent = this.WHANDLER;
|
||||
this.nextButtonFunc = nextFunc ;
|
||||
this.backButtonFunc = backFunc ;
|
||||
this.cancelButtonFunc = cancelFunc ;
|
||||
this.finishButtonFunc = finishFunc ;
|
||||
this.pageLoadFunc = pageLoadFunc ;
|
||||
this.enablingFunc = enablingFunc ;
|
||||
|
||||
// assign handlers to parent object
|
||||
// (handler functions are assigned to parent object)
|
||||
this.WM.onNext = ( !this.nextButtonFunc ) ? DEF_onNext : nextFunc ;
|
||||
this.WM.onBack = ( !this.backButtonFunc ) ? DEF_onBack : backFunc ;
|
||||
this.WM.onCancel = ( !this.cancelButtonFunc ) ? DEF_onCancel : cancelFunc ;
|
||||
this.WM.onFinish = ( !this.finishButtonFunc ) ? DEF_onFinish : finishFunc ;
|
||||
this.WM.onPageLoad = ( !this.pageLoadFunc ) ? DEF_onPageLoad : pageLoadFunc ;
|
||||
this.WM.DoButtonEnabling = ( !this.enablingFunc ) ? DEF_DoEnabling : enablingFunc ;
|
||||
}
|
|
@ -0,0 +1,173 @@
|
|||
/* -*- Mode: Java; tab-width: 4; c-basic-offset: 4; -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Ben "Count XULula" Goodger <rgoodger@ihug.co.nz>
|
||||
*/
|
||||
|
||||
/** class WizardManager( string frame_id, string tagURLPrefix,
|
||||
* string tagURLPostfix, object wizardMap ) ;
|
||||
* purpose: class for managing the state of a generic wizard
|
||||
* in: string frame_id content frame id/name
|
||||
* string tagURLPrefix prefix root of wizard pages
|
||||
* string tagURLPostfix extension suffix of wizard pages (e.g. ".xul")
|
||||
* object wizardMap navigation map object
|
||||
* out: nothing.
|
||||
**/
|
||||
function WizardManager( frame_id, tagURLPrefix, tagURLPostfix, wizardMap )
|
||||
{
|
||||
// current page
|
||||
this.currentPageTag = null;
|
||||
// data grid of navigable pages
|
||||
this.wizardMap = ( wizardMap ) ? wizardMap : null;
|
||||
// current page
|
||||
this.currentPageNumber = 0;
|
||||
// flag to signify no page-change occurred.
|
||||
this.firstTime = true; // was false, let's see what this does. o_O
|
||||
// frame which holds data
|
||||
this.content_frame = document.getElementById( frame_id );
|
||||
// wizard state manager
|
||||
this.WSM = new WidgetStateManager( frame_id );
|
||||
// wizard button handler set
|
||||
this.WHANDLER = new WizardHandlerSet( this.WSM, this );
|
||||
|
||||
// url handling
|
||||
this.URL_PagePrefix = ( tagURLPrefix ) ? tagURLPrefix : null;
|
||||
this.URL_PagePostfix = ( tagURLPostfix ) ? tagURLPrefix : null;
|
||||
|
||||
// string bundle
|
||||
this.bundle = srGetStrBundle("chrome://global/locale/wizardManager.properties");
|
||||
|
||||
this.LoadPage = WM_LoadPage;
|
||||
this.GetURLFromTag = WM_GetURLFromTag;
|
||||
this.GetTagFromURL = WM_GetTagFromURL;
|
||||
this.SetHandlers = WM_SetHandlers;
|
||||
this.SetPageData = WM_SetPageData;
|
||||
this.SavePageData = WM_SavePageData;
|
||||
this.ProgressUpdate = WM_ProgressUpdate;
|
||||
this.GetMapLength = WM_GetMapLength;
|
||||
|
||||
// set up handlers from wizard overlay
|
||||
// #include chrome://global/content/wizardOverlay.js
|
||||
doSetWizardButtons( this );
|
||||
}
|
||||
|
||||
/** void LoadPage( string page ) ;
|
||||
* purpose: loads a page into the content frame
|
||||
* in: string page tag referring to the complete file name of the current page
|
||||
* string frame_id optional supply of page frame, if content_frame is not
|
||||
* defined
|
||||
* out: boolean success indicator.
|
||||
**/
|
||||
function WM_LoadPage( pageURL, absolute )
|
||||
{
|
||||
if( pageURL != "" )
|
||||
{
|
||||
if ( this.firstTime && !absolute )
|
||||
this.ProgressUpdate( this.currentPageNumber );
|
||||
|
||||
// 1.1: REMOVED to fix no-field-page-JS error bug. reintroduce if needed.
|
||||
// if ( !this.firstTime )
|
||||
// this.WSM.SavePageData( this.content_frame );
|
||||
|
||||
// build a url from a tag, or use an absolute url
|
||||
if( !absolute ) {
|
||||
src = this.GetURLFromTag( pageURL );
|
||||
} else {
|
||||
src = pageURL;
|
||||
}
|
||||
if( this.content_frame )
|
||||
this.content_frame.setAttribute("src", src);
|
||||
else
|
||||
return false;
|
||||
|
||||
this.firstTime = false;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
/** string GetUrlFromTag( string tag ) ;
|
||||
* - purpose: creates a complete URL based on a tag.
|
||||
* - in: string tag representing the specific page to be loaded
|
||||
* - out: string url representing the complete location of the page.
|
||||
**/
|
||||
function WM_GetURLFromTag( tag )
|
||||
{
|
||||
return this.URL_PagePrefix + tag + this.URL_PagePostfix;
|
||||
}
|
||||
/** string GetTagFromURL( string tag ) ;
|
||||
* - purpose: fetches a tag from a URL
|
||||
* - in: string url representing the complete location of the page.
|
||||
* - out: string tag representing the specific page to be loaded
|
||||
**/
|
||||
function WM_GetTagFromURL( url )
|
||||
{
|
||||
return url.substring(this.URL_PagePrefix.length, this.URL_PagePostfix.length);
|
||||
}
|
||||
|
||||
// SetHandlers pass-through for setting wizard button handlers easily
|
||||
function WM_SetHandlers( onNext, onBack, onFinish, onCancel, onPageLoad, enablingFunc )
|
||||
{
|
||||
this.WHANDLER.SetHandlers( onNext, onBack, onFinish, onCancel, onPageLoad, enablingFunc );
|
||||
}
|
||||
// SetPageData pass-through
|
||||
function WM_SetPageData()
|
||||
{
|
||||
this.WSM.SetPageData();
|
||||
}
|
||||
// SavePageData pass-through
|
||||
function WM_SavePageData()
|
||||
{
|
||||
this.WSM.SavePageData();
|
||||
}
|
||||
|
||||
/** int GetMapLength()
|
||||
* - purpose: returns the number of pages in the wizardMap
|
||||
* - in: nothing
|
||||
* - out: integer number of pages in wizardMap
|
||||
**/
|
||||
function WM_GetMapLength()
|
||||
{
|
||||
var count = 0;
|
||||
for ( i in this.wizardMap )
|
||||
count++;
|
||||
return count;
|
||||
}
|
||||
|
||||
/** void ProgressUpdate ( int currentPageNumber );
|
||||
* - purpose: updates the "page x of y" display if available
|
||||
* - in: integer representing current page number.
|
||||
* - out: nothing
|
||||
**/
|
||||
function WM_ProgressUpdate( currentPageNumber )
|
||||
{
|
||||
var div = document.getElementById ( "progress" );
|
||||
if ( div ) {
|
||||
if ( div.hasChildNodes() ) {
|
||||
for ( var i = 0; i < div.childNodes.length; i++ ) {
|
||||
div.removeChild ( div.childNodes[i] ); // kill old childnodes
|
||||
}
|
||||
}
|
||||
var string = "";
|
||||
string += (currentPageNumber + 1);
|
||||
string += ( " " + this.bundle.GetStringFromName("oflabel") + " " );
|
||||
string += this.GetMapLength();
|
||||
var textNode = document.createTextNode ( string );
|
||||
div.appendChild ( textNode );
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,69 @@
|
|||
/**
|
||||
* Wizard button controllers.
|
||||
* - Note:
|
||||
* - less infrastructure is provided here than for dialog buttons, as
|
||||
* - closing is not automatically desirable for many wizards (e.g. profile
|
||||
* - creation) where proper application shutdown is required. thus these
|
||||
* - functions simply pass this responsibility on to the wizard designer.
|
||||
* -
|
||||
* - Use: Include this JS file in your wizard XUL and the accompanying
|
||||
* - wizardOverlay.xul file as an overlay. Then set the overlay handlers
|
||||
* - with doSetWizardButtons(). It is recommended you use this overlay
|
||||
* - with the WizardManager wizard infrastructure. If you do that, you
|
||||
* - don't need to do anything here. Otherwise, use doSetWizardButtons()
|
||||
* - with false or null passed in as the first parameter, and the names
|
||||
* - of your functions passed in as the remaining parameters, see below.
|
||||
* -
|
||||
* - Ben Goodger (04/11/99)
|
||||
**/
|
||||
|
||||
var doNextFunction = null;
|
||||
var doBackFunction = null;
|
||||
var doFinishFunction = null;
|
||||
var doCancelFunction = null;
|
||||
|
||||
// call this from dialog onload() to allow buttons to call your code.
|
||||
function doSetWizardButtons( wizardManager, nextFunc, backFunc, finishFunc, cancelFunc )
|
||||
{
|
||||
if(wizardManager) {
|
||||
doNextFunction = wizardManager.onNext;
|
||||
doBackFunction = wizardManager.onBack;
|
||||
doFinishFunction = wizardManager.onFinish;
|
||||
doCancelFunction = wizardManager.onCancel;
|
||||
} else {
|
||||
doNextFunction = nextFunc;
|
||||
doBackFunction = backFunc;
|
||||
doFinishFunction = finishFunc;
|
||||
doCancelFunction = cancelFunc;
|
||||
}
|
||||
}
|
||||
|
||||
// calls function specified for "next" button click.
|
||||
function doNextButton()
|
||||
{
|
||||
if ( doNextFunction )
|
||||
doNextFunction();
|
||||
}
|
||||
|
||||
// calls function specified for "back" button click.
|
||||
function doBackButton()
|
||||
{
|
||||
if ( doBackFunction )
|
||||
doBackFunction();
|
||||
}
|
||||
|
||||
// calls function specified for "finish" button click.
|
||||
function doFinishButton()
|
||||
{
|
||||
if ( doFinishFunction )
|
||||
doFinishFunction();
|
||||
}
|
||||
|
||||
// calls function specified for "cancel" button click.
|
||||
function doCancelButton()
|
||||
{
|
||||
if ( doCancelFunction )
|
||||
doCancelFunction();
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
<?xml version="1.0"?>
|
||||
|
||||
<!DOCTYPE window SYSTEM "chrome://global/locale/wizardOverlay.dtd">
|
||||
|
||||
<?xml-stylesheet href="chrome://global/skin/wizardOverlay.css" type="text/css"?>
|
||||
|
||||
<overlay id="wizardOverlay"
|
||||
xmlns:html="http://www.w3.org/TR/REC-html40"
|
||||
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
|
||||
|
||||
<!-- Wizard Buttons -->
|
||||
<box id="wizardButtons" align="horizontal" style="margin-top: 0.5em">
|
||||
<spring flex="100%"/>
|
||||
<titledbutton id="wiz.cancel.button" value="&cancelButton.label;" onclick="wizardManager.onCancel()" align="left" style=" margin-top: 1em;"/>
|
||||
<spring flex="20%"/>
|
||||
<titledbutton id="wiz.back.button" value="&backButton.label;" onclick="wizardManager.onBack()" align="left" style="margin-top: 1em;"/>
|
||||
<titledbutton id="wiz.next.button" value="&nextButton.label;" onclick="wizardManager.onNext()" align="right" style="margin-top: 1em;"/>
|
||||
<spring flex="5%"/>
|
||||
<titledbutton id="wiz.finish.button" value="&finishButton.label;" onclick="wizardManager.onFinish()" align="right" style="margin-top: 1em;"/>
|
||||
<spring flex="5%"/>
|
||||
</box>
|
||||
|
||||
</overlay>
|
Загрузка…
Ссылка в новой задаче