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

  1. /* -*- Mode: Java; tab-width: 4; c-basic-offset: 4; -*-
  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 WizardManager( string frame_id, string tagURLPrefix, 
  23.  *                       string tagURLPostfix, object wizardMap ) ;
  24.  *  purpose: class for managing the state of a generic wizard
  25.  *  in:  string frame_id content frame id/name 
  26.  *       string tagURLPrefix prefix root of wizard pages
  27.  *       string tagURLPostfix extension suffix of wizard pages (e.g. ".xul")
  28.  *       object wizardMap navigation map object
  29.  *  out: nothing.
  30.  **/
  31. function WizardManager( frame_id, tagURLPrefix, tagURLPostfix, wizardMap )
  32. {
  33.   // current page
  34.   this.currentPageTag       = null;
  35.   // data grid of navigable pages
  36.   this.wizardMap            = ( wizardMap ) ? wizardMap : null;
  37.   // current page
  38.   this.currentPageNumber    = 0;
  39.   // flag to signify no page-change occurred.
  40.   this.firstTime            = true;   // was false, let's see what this does. o_O
  41.   // frame which holds data
  42.   this.content_frame        = document.getElementById( frame_id );
  43.   // wizard state manager 
  44.   this.WSM                  = new WidgetStateManager( frame_id );
  45.   // wizard button handler set
  46.   this.WHANDLER             = new WizardHandlerSet( this.WSM, this );
  47.   
  48.   // url handling
  49.   this.URL_PagePrefix       = ( tagURLPrefix  ) ? tagURLPrefix : null;
  50.   this.URL_PagePostfix      = ( tagURLPostfix ) ? tagURLPrefix : null; 
  51.  
  52.   // string bundle  
  53.   this.bundle               = srGetStrBundle("chrome://global/locale/wizardManager.properties");
  54.  
  55.   this.LoadPage             = WM_LoadPage;
  56.   this.GetURLFromTag        = WM_GetURLFromTag;
  57.   this.GetTagFromURL        = WM_GetTagFromURL;
  58.   this.SetHandlers          = WM_SetHandlers;
  59.   this.SetPageData          = WM_SetPageData;
  60.   this.SavePageData         = WM_SavePageData;
  61.   this.ProgressUpdate       = WM_ProgressUpdate;
  62.   this.GetMapLength         = WM_GetMapLength;
  63.  
  64.   // set up handlers from wizard overlay
  65.   // #include chrome://global/content/wizardOverlay.js
  66.   doSetWizardButtons( this );
  67. }
  68.  
  69. /** void LoadPage( string page ) ;
  70.  *  purpose: loads a page into the content frame
  71.  *  in:  string page tag referring to the complete file name of the current page
  72.  *       string frame_id optional supply of page frame, if content_frame is not 
  73.  *                       defined
  74.  *  out: boolean success indicator.
  75.  **/
  76. function WM_LoadPage( pageURL, absolute )
  77. {
  78.     if( pageURL != "" )
  79.     {
  80.     if ( this.firstTime && !absolute )
  81.       this.ProgressUpdate( this.currentPageNumber );
  82.  
  83.     // 1.1: REMOVED to fix no-field-page-JS error bug. reintroduce if needed.
  84.     // if ( !this.firstTime )
  85.     //   this.WSM.SavePageData( this.content_frame );
  86.  
  87.     // build a url from a tag, or use an absolute url
  88.     if( !absolute ) {
  89.             var src = this.GetURLFromTag( pageURL );
  90.     } else {
  91.       src = pageURL;
  92.     }
  93.     if( this.content_frame )
  94.             this.content_frame.setAttribute("src", src);
  95.     else 
  96.       return false;
  97.  
  98.       this.firstTime = false;
  99.     return true;
  100.     }
  101.   return false;
  102. }
  103. /** string GetUrlFromTag( string tag ) ;
  104.  *  - purpose: creates a complete URL based on a tag.
  105.  *  - in:  string tag representing the specific page to be loaded
  106.  *  - out: string url representing the complete location of the page.
  107.  **/               
  108. function WM_GetURLFromTag( tag ) 
  109. {
  110.   return this.URL_PagePrefix + tag + this.URL_PagePostfix;
  111. }
  112. /** string GetTagFromURL( string tag ) ;
  113.  *  - purpose: fetches a tag from a URL
  114.  *  - in:   string url representing the complete location of the page.
  115.  *  - out:  string tag representing the specific page to be loaded
  116.  **/               
  117. function WM_GetTagFromURL( url )
  118. {
  119.   return url.substring(this.URL_PagePrefix.length, this.URL_PagePostfix.length);
  120. }
  121.  
  122. // SetHandlers pass-through for setting wizard button handlers easily
  123. function WM_SetHandlers( onNext, onBack, onFinish, onCancel, onPageLoad, enablingFunc )
  124. {
  125.   this.WHANDLER.SetHandlers( onNext, onBack, onFinish, onCancel, onPageLoad, enablingFunc );
  126. }
  127. // SetPageData pass-through
  128. function WM_SetPageData()
  129. {
  130.   this.WSM.SetPageData();
  131. }
  132. // SavePageData pass-through
  133. function WM_SavePageData()
  134. {
  135.   this.WSM.SavePageData();
  136. }
  137.  
  138. /** int GetMapLength()
  139.  *  - purpose: returns the number of pages in the wizardMap
  140.  *  - in:   nothing
  141.  *  - out:  integer number of pages in wizardMap
  142.  **/               
  143. function WM_GetMapLength()
  144. {
  145.   var count = 0;
  146.   for ( i in this.wizardMap )
  147.     count++;
  148.   return count;
  149. }
  150.  
  151. /** void ProgressUpdate ( int currentPageNumber );
  152.  *  - purpose: updates the "page x of y" display if available
  153.  *  - in:   integer representing current page number. 
  154.  *  - out:  nothing
  155.  **/               
  156. function WM_ProgressUpdate( currentPageNumber )
  157. {
  158.   var statusbar = document.getElementById ( "status" );
  159.   if ( statusbar ) {
  160.       var string;
  161.       try {
  162.           dump("mapLength = " + this.GetMapLength() + "\n");
  163.           string = this.bundle.formatStringFromName("oflabel",
  164.                                                     [currentPageNumber+1,
  165.                                                     this.GetMapLength()], 2);
  166.       } catch (e) {
  167.           string = "";
  168.       }
  169.     statusbar.setAttribute( "progress", string );
  170.   }
  171. }
  172.  
  173.