home *** CD-ROM | disk | FTP | other *** search
/ ftp.swcp.com / ftp.swcp.com.zip / ftp.swcp.com / mac / mozilla-macos9-1.3.1.sea.bin / Mozilla1.3.1 / Chrome / comm.jar / content / communicator / profile / createProfileWizard.js < prev    next >
Text File  |  2003-06-08  |  6KB  |  178 lines

  1. /*
  2.  * The contents of this file are subject to the Netscape Public
  3.  * License Version 1.1 (the "License"); you may not use this file
  4.  * except in compliance with the License. You may obtain a copy of
  5.  * the License at http://www.mozilla.org/NPL/
  6.  *
  7.  * Software distributed under the License is distributed on an "AS
  8.  * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
  9.  * implied. See the License for the specific language governing
  10.  * rights and limitations under the License.
  11.  *
  12.  * The Original Code is Mozilla Communicator client code, released
  13.  * March 31, 1998.
  14.  *
  15.  * The Initial Developer of the Original Code is Netscape
  16.  * Communications Corporation. Portions created by Netscape are
  17.  * Copyright (C) 1998-1999 Netscape Communications Corporation. All
  18.  * Rights Reserved.
  19.  *
  20.  * Contributor(s):
  21.  *   Ben Goodger (30/09/99)
  22.  */ 
  23.  
  24. // The WIZARD of GORE
  25.  
  26. var profile = Components.classes["@mozilla.org/profile/manager;1"].getService();
  27. profile = profile.QueryInterface(Components.interfaces.nsIProfileInternal); 
  28. var gCreateProfileWizardBundle;
  29. var gProfileManagerBundle;
  30.  
  31. // Navigation Set for pages contained in wizard 
  32. var wizardMap = {
  33.   newProfile1_1: { previous: null,              next: "newProfile1_2",    finish: false },
  34.   newProfile1_2: { previous: "newProfile1_1",   next: null,               finish: true },
  35. }
  36.  
  37. // page specific variables
  38. var profName      = "";
  39. var profDir       = "";
  40. var wizardManager = null;
  41.  
  42. // startup procedure
  43. function Startup( startPage, frame_id )
  44. {
  45.   if( frame_id == "" ) {
  46.     dump("Please supply a content_frame ID!");
  47.     return false;
  48.   }
  49.   gCreateProfileWizardBundle = document.getElementById("bundle_createProfileWizard");
  50.   gProfileManagerBundle = document.getElementById("bundle_profileManager");
  51.   
  52.   // instantiate the Wizard Manager
  53.   wizardManager                   = new WizardManager( frame_id, null, null, wizardMap );
  54.   wizardManager.URL_PagePrefix    = "chrome://communicator/content/profile/";
  55.   wizardManager.URL_PagePostfix   = ".xul";
  56.  
  57.   // set the button handler functions
  58.   wizardManager.SetHandlers( null, null, onFinish, onCancel, null, null );
  59.   // load the start page
  60.   wizardManager.LoadPage (startPage, false);
  61.   // move to center of screen if no opener, otherwise, to center of opener
  62.   if( window.opener )
  63.     moveToAlertPosition();
  64.   else
  65.     centerWindowOnScreen();
  66. }
  67.  
  68. function onCancel()
  69. {
  70.   if( top.window.opener )
  71.     window.close();
  72.   else { 
  73.     try {
  74.       profile.forgetCurrentProfile();
  75.     }
  76.     catch (ex) {
  77.       dump("failed to forget current profile.\n");
  78.     }
  79.     window.close();
  80.   }
  81. }
  82.  
  83. function onFinish()
  84. {
  85.  
  86.   // check if we're at final stage 
  87.   if( !wizardManager.wizardMap[wizardManager.currentPageTag].finish )
  88.     return;
  89.  
  90.   var tag =  wizardManager.WSM.GetTagFromURL( wizardManager.content_frame.src, "/", ".xul" );
  91.   wizardManager.WSM.SavePageData( tag, null, null, null );
  92.  
  93.   var profName = wizardManager.WSM.PageData["newProfile1_2"].ProfileName.value;
  94.   var profDir = wizardManager.WSM.PageData["newProfile1_2"].ProfileDir.value;
  95.   var profLang = wizardManager.WSM.PageData["newProfile1_2"].ProfileLanguage.value;
  96.   var profRegion = wizardManager.WSM.PageData["newProfile1_2"].ProfileRegion.value;
  97.  
  98.   // Get & select langcode
  99.   proceed = processCreateProfileData(profName, profDir, profLang, profRegion); 
  100.   
  101.   if( proceed ) {
  102.     if( window.opener ) {
  103.       window.opener.CreateProfile(profName, profDir);
  104.     }
  105.     else {
  106.       profile.currentProfile = profName;
  107.     }
  108.     window.close();
  109.   }
  110.   else
  111.     return;
  112. }
  113.  
  114. /** void processCreateProfileData( void ) ;
  115.  *  - purpose: 
  116.  *  - in:  nothing
  117.  *  - out: nothing
  118.  **/               
  119. function processCreateProfileData( aProfName, aProfDir, langcode, regioncode)
  120. {
  121.   try {
  122.     // note: deleted check for empty profName string here as this should be
  123.     //       done by panel. -bmg (31/10/99)
  124.     // todo: move this check into the panel itself, activated ontyping :P
  125.     //       this should definetly be moved to that page.. but how about providing
  126.     //       user with some feedback about what's wrong. .. TOOLTIP! o_O
  127.     //       or.. some sort of onblur notification. like a dialog then, or a 
  128.     //       dropout layery thing. yeah. something like that to tell them when 
  129.     //       it happens, not when the whole wizard is complete. blah. 
  130.     if (profile.profileExists(aProfName)) {
  131.       alert(gCreateProfileWizardBundle.getString("profileExists"));
  132.       // this is a bad but probably acceptable solution for now. 
  133.       // when we add more panels, we will want a better solution. 
  134.       window.frames["content"].document.getElementById("ProfileName").focus();
  135.       return false;
  136.     }
  137.     var invalidChars = ["/", "\\", "*", ":"];
  138.     for( var i = 0; i < invalidChars.length; i++ )
  139.     {
  140.       if( aProfName.indexOf( invalidChars[i] ) != -1 ) {
  141.         var aString = gProfileManagerBundle.getString("invalidCharA");
  142.         var bString = gProfileManagerBundle.getString("invalidCharB");
  143.         bString = bString.replace(/\s*<html:br\/>/g,"\n");
  144.         var lString = aString + invalidChars[i] + bString;
  145.         alert( lString );
  146.         window.frames["content"].document.getElementById("ProfileName").focus();
  147.         return false;
  148.       }
  149.     }
  150.  
  151.     // Adding code to see if the profile directory already exists....
  152.     // XXXX - Further modifications like adding propmt dialog are required - XXXX
  153.     var useExistingDir = false;
  154.     var fileSpec = Components.classes["@mozilla.org/file/local;1"].createInstance();
  155.     if ( fileSpec )
  156.         fileSpec = fileSpec.QueryInterface( Components.interfaces.nsILocalFile );
  157.  
  158.     if (aProfDir == null)
  159.         fileSpec.initWithPath(profile.defaultProfileParentDir.path);
  160.     else
  161.         fileSpec.initWithPath(aProfDir);
  162.  
  163.     fileSpec.append(aProfName);
  164.  
  165.     if (fileSpec != null && fileSpec.exists())
  166.       useExistingDir = true;
  167.  
  168.     dump("*** going to create a new profile called " + aProfName + " in folder: " + aProfDir + "\n");
  169.     profile.createNewProfileWithLocales(aProfName, aProfDir, langcode, regioncode, useExistingDir);
  170.  
  171.     return true;
  172.   }
  173.   catch(e) {
  174.     dump("*** Failed to create a profile\n");
  175.   }
  176. }
  177.  
  178.