home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / mozil06.zip / bin / chrome / toolkit.jar / content / global / wizardHandlerSet.js < prev    next >
Text File  |  2001-02-14  |  8KB  |  197 lines

  1. /* -*- Mode: Java; tab-width: 2; c-basic-offset: 2; -*-
  2.  * 
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  *
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  *
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  *
  18.  * Contributor(s):
  19.  *   Ben "Count XULula" Goodger <rgoodger@ihug.co.nz>
  20.  */
  21.  
  22. /** class WizardHandlerSet( WidgetStateManager sMgr, WizardManager wMgr ) ;
  23.  *  purpose: class for managing wizard navigation functions
  24.  *  in:  WidgetStateManager sMgr WSM object created by WizardManager
  25.  *       WizardManager wMgr WM object created by WizardManager
  26.  *  out: nothing.
  27.  **/
  28. function WizardHandlerSet( sMgr, wMgr )
  29. {
  30.   // data mambers
  31.   // wizard buttons
  32.   this.backButton         = document.getElementById("wiz-back-button");
  33.   this.nextButton         = document.getElementById("wiz-next-button");
  34.   this.finishButton       = document.getElementById("wiz-finish-button");
  35.   this.cancelButton       = document.getElementById("wiz-cancel-button");
  36.   // wizard handlers
  37.   this.nextButtonFunc     = null;
  38.   this.backButtonFunc     = null;
  39.   this.cancelButtonFunc   = null;
  40.   this.finishButtonFunc   = null;
  41.   this.pageLoadFunc       = null;
  42.   this.enablingFunc       = null;
  43.     
  44.   this.SM                 = sMgr;
  45.   this.WM                 = wMgr;
  46.  
  47.   // member functions
  48.   this.SetHandlers        = WHS_SetHandlers;
  49.  
  50.   // construction (points member functions to right functions)
  51.   this.SetHandlers( this.nextButtonFunc, this.backButtonFunc, this.finishButtonFunc, 
  52.                     this.cancelButtonFunc, this.pageLoadFunc, this.enablingFunc );
  53. }
  54.   
  55. // default handler for next page in page sequence
  56. function DEF_onNext()
  57. {
  58.   var oParent = this.WHANDLER;
  59.   if( oParent.nextButton.getAttribute("disabled") == "true" )
  60.     return;
  61.  
  62.   // make sure page is valid!
  63.   if (!oParent.SM.PageIsValid())
  64.       return;
  65.   
  66.     oParent.SM.SavePageData( this.currentPageTag, null, null, null );      // persist data
  67.   if (this.wizardMap[this.currentPageTag]) {
  68.     var nextPageTag = this.wizardMap[this.currentPageTag].next;
  69.     this.LoadPage( nextPageTag, false );     // load the next page
  70.     this.ProgressUpdate( ++this.currentPageNumber );
  71.   } else {
  72.     dump("Error: Missing an entry in the wizard map for " +
  73.          this.currentPageTag + "\n");
  74.   }
  75. }
  76. // default handler for previous page in sequence
  77. function DEF_onBack()
  78. {
  79.   var oParent = this.WHANDLER;
  80.     if( oParent.backButton.getAttribute("disabled") == "true" )
  81.        return;
  82.     oParent.SM.SavePageData( this.currentPageTag, null, null, null );      // persist data
  83.     previousPageTag = this.wizardMap[this.currentPageTag].previous;
  84.   this.LoadPage( previousPageTag, false ); // load the preivous page
  85.   this.ProgressUpdate( --this.currentPageNumber );
  86. }
  87. // default handler for cancelling wizard
  88. function DEF_onCancel()
  89. {
  90.   if( top.window.opener )
  91.     window.close();
  92. }
  93. // default finish handler
  94. function DEF_onFinish()
  95. {
  96.   var oParent = this.WHANDLER;
  97.   if( !this.wizardMap[this.currentPageTag].finish )
  98.     return;
  99.   oParent.SM.SavePageData( this.currentPageTag, null, null, null );
  100.   dump("WizardButtonHandlerSet Warning:\n");
  101.   dump("===============================\n");
  102.   dump("You must provide implementation for onFinish, or else your data will be lost!\n");
  103. }
  104.  
  105. // default button enabling ** depends on map, see doc
  106. function DEF_DoEnabling( nextButton, backButton, finishButton )
  107. {
  108.   var oParent = this.WHANDLER;
  109.   // make sure we're on a valid page
  110.     if( !this.currentPageTag ) 
  111.     return;
  112.   // "next" button enabling
  113.   var nextTag = this.wizardMap[this.currentPageTag].next;
  114.   if( nextTag && oParent.nextButton.getAttribute("disabled") ) {
  115.     oParent.nextButton.removeAttribute( "disabled" );
  116.   }
  117.   else if( !nextTag && !oParent.nextButton.getAttribute("disabled") ) {
  118.     oParent.nextButton.setAttribute( "disabled", "true" );
  119.   }
  120.   // "finish" button enabling
  121.   var finishTag = this.wizardMap[this.currentPageTag].finish;
  122.   if( finishTag && oParent.finishButton.getAttribute("disabled") ) {
  123.     oParent.finishButton.removeAttribute( "disabled" );
  124.   }
  125.   else if( !finishTag && !oParent.finishButton.getAttribute("disabled") ) {
  126.     oParent.finishButton.setAttribute( "disabled", "true" );
  127.   }
  128.   // "back" button enabling
  129.   var prevTag = this.wizardMap[this.currentPageTag].previous;
  130.     if( prevTag && oParent.backButton.getAttribute("disabled") ) {
  131.        oParent.backButton.removeAttribute("disabled");
  132.   }
  133.     else if( !prevTag && !oParent.backButton.getAttribute("disabled") ) {
  134.        oParent.backButton.setAttribute("disabled", "true"); 
  135.   }
  136. }
  137.  
  138. /** void PageLoaded( string tag, string frame_id ) ;
  139.  *  purpose: perform initial button enabling and call Startup routines.
  140.  *  in:  string page tag referring to the file name of the current page
  141.  *       string frame_id optional supply of page frame, if content_frame is not 
  142.  *                       defined
  143.  *  out: nothing.
  144.  **/
  145. function DEF_onPageLoad( tag ) 
  146. {
  147.   var oParent = this.WHANDLER;
  148.     this.currentPageTag = tag;
  149.   if( this.DoButtonEnabling )              // if provided, call user-defined button
  150.     this.DoButtonEnabling();               // enabling function
  151.   if( this.content_frame ) {
  152.     oParent.SM.SetPageData( tag, true );  // set page data in content frame
  153.  
  154.     // set the focus to the first focusable element
  155.     var doc = window.frames[0].document;
  156.     var controls = doc.controls;
  157.     for (var i=0; i< controls.length; i++) {
  158.       if (controls[i].focus) {
  159.         controls[i].focus();
  160.         break;                  // stop when focus has been set
  161.       }
  162.     }
  163.   }
  164.   else {
  165.     dump("Widget Data Manager Error:\n"); 
  166.     dump("==========================\n");
  167.     dump("content_frame variable not defined. Please specify one as an argument to Startup();\n");
  168.     return;
  169.   }
  170. }
  171.  
  172. /** void SetHandlers( string nextFunc, string backFunc, string finishFunc, string cancelFunc,
  173.  *                    string pageLoadFunc, string enablingFunc ) ;
  174.  *  purpose: allow user to assign button handler function names
  175.  *  in:  strings referring to the names of the functions for each button
  176.  *  out: nothing.
  177.  **/
  178. function WHS_SetHandlers( nextFunc, backFunc, finishFunc, cancelFunc, pageLoadFunc, enablingFunc )
  179. {
  180.   // var oParent = this.WHANDLER;
  181.   this.nextButtonFunc   = nextFunc      ;
  182.   this.backButtonFunc   = backFunc      ;
  183.   this.cancelButtonFunc = cancelFunc    ;
  184.   this.finishButtonFunc = finishFunc    ;
  185.   this.pageLoadFunc     = pageLoadFunc  ;
  186.   this.enablingFunc     = enablingFunc  ;
  187.   
  188.   // assign handlers to parent object
  189.   // (handler functions are assigned to parent object) 
  190.   this.WM.onNext             = ( !this.nextButtonFunc   ) ? DEF_onNext     : nextFunc ;
  191.   this.WM.onBack             = ( !this.backButtonFunc   ) ? DEF_onBack     : backFunc ;
  192.   this.WM.onCancel           = ( !this.cancelButtonFunc ) ? DEF_onCancel   : cancelFunc ;
  193.   this.WM.onFinish           = ( !this.finishButtonFunc ) ? DEF_onFinish   : finishFunc ;
  194.   this.WM.onPageLoad         = ( !this.pageLoadFunc     ) ? DEF_onPageLoad : pageLoadFunc ;
  195.   this.WM.DoButtonEnabling   = ( !this.enablingFunc     ) ? DEF_DoEnabling : enablingFunc ;
  196. }
  197.