home *** CD-ROM | disk | FTP | other *** search
/ CD Actual Thematic 7: Programming / CDAT7.iso / Share / Java / ScriptBuilder / NOSB30_TRIAL.exe / data1.cab / Program_Files / CompLib / Dialog / Dialog.js < prev    next >
Encoding:
JavaScript  |  1998-10-05  |  3.3 KB  |  96 lines

  1. /* ======================================================================
  2. OBJECT:        com_netobjects_Dialog
  3.                 
  4. DESC:            This control allows developers to render 3 different kinds of 
  5.                 dialogs from one simple object: alert, prompt and confirm.
  6.  
  7. TESTED
  8. PLATFORMS:    Netscape Navigator 4.05, 
  9.                 Microsoft Internet Explorer 4.01
  10. ====================================================================== */
  11. function com_netobjects_Dialog(params) {
  12.  
  13.    // Public Properties    
  14.     this.name                 = (params.name != null) ? params.name : ""; 
  15.     if ((params.dlgType.toLowerCase() != "prompt") && (params.dlgType.toLowerCase() != "confirm"))
  16.         {this.dlgType = "alert"} else {this.dlgType = params.dlgType.toLowerCase()};
  17.     this.message             = (params.message != null) ? params.message : "";
  18.     this.value                 = (params.value != null) ? params.value : "";
  19.  
  20.     this.testMode            = (params.testMode != null) ? params.testMode : "none"
  21.     
  22.     // Private Properties
  23.     this.validateProperties = _dialog_validateProperties;
  24.  
  25.     // Public Methods
  26.     this.open             = _dialog_open;
  27.  
  28.     // Public Events
  29.     this.onOpen              = _dialog_onOpen;
  30.  
  31.     // Validate object properties
  32.     this.validateProperties();
  33.  
  34.     // Public Methods ----------------------------------------
  35.     /* ======================================================================
  36.     
  37.    METHOD: _dialog_open.  Opens the JavaScript dialog box of the type indicated
  38.     by this.dlgType.
  39.  
  40.     ====================================================================== */
  41.     function _dialog_open() {
  42.  
  43.         if (this.dlgType == "alert") {
  44.            eval("alert(\"" + this.message + "\")");
  45.         } else if (this.dlgType == "prompt") {
  46.            eval("this.value = prompt(\"" + this.message + "\",\""+ this.value + "\")");
  47.         } else if (this.dlgType == "confirm") {
  48.            eval("this.value = confirm(\"" + this.message + "\")");
  49.         }
  50.  
  51.         // Fire public events
  52.         this.onOpen(); 
  53.     
  54.     } // END _dialog_open
  55.  
  56.  
  57.     // Private Methods ----------------------------------------
  58.     /* ======================================================================
  59.     
  60.    METHOD: _dialog_validateProperties.  If the test mode is set,
  61.     generate error and/or warning messages if required or recommended properties
  62.     are set with invalid property values or are not set at all.
  63.  
  64.     ====================================================================== */
  65.     function _dialog_validateProperties() {
  66.         if ((this.testMode.toLowerCase() == "text") || (this.testMode.toLowerCase() == "alerts")) {
  67.             var errors = new Array()
  68.           iIndex = 0;  
  69.          
  70.             // Check for errors
  71.             if (this.name == "") 
  72.                 errors[iIndex++] = "Name is a required property.";  
  73.          if (params.dlgType == "")
  74.                 errors[iIndex++] = "dlgType is a required property.";  
  75.  
  76.             // Display errors
  77.             for (var i=0; i<errors.length; i++)  {
  78.                 if (this.testMode.toLowerCase()    == "text") 
  79.                       document.write( "<BR><HR><B><FONT COLOR=RED>TEST MODE, com_netobjects_Dialog, '" + this.name + "' : </FONT> " + errors[i] + "</B><HR>\n");
  80.                 else
  81.                       alert("TEST MODE, com_netobjects_Dialog, '" + this.name + "' : " + errors[i]);
  82.  
  83.             }            
  84.         } 
  85.     } // END _dialog_validateProperties
  86.  
  87.     
  88.     
  89.     
  90.     // Public Event Handlers ----------------------------------------
  91.     function _dialog_onOpen() {
  92.     }
  93.   
  94. } // END CONSTRUCTOR com_netobjects_Dialog
  95.  
  96.