// // JavaScript code for the management of nice dialog boxes under any web browser. // // Author: OrdinaSoft // Patrick Lanz // Lausanne // info@ordinasoft.ch // // First version: May 1st, 2007 // // (c) 2007, OrdinaSoft, all rights reserved //----------------------------------------------------------------------------------------------- // Namespace initialization. if (typeof OrdinaSoft == 'undefined') OrdinaSoft = new Object (); if (typeof OrdinaSoft.DialogBox == 'undefined') OrdinaSoft.DialogBox = new Object (); //----------------------------------------------------------------------------------------------- // Global variables. OrdinaSoft.DialogBox._PageMask = null; OrdinaSoft.DialogBox._Stack = []; OrdinaSoft.DialogBox.TitleClass = ''; // CSS class for title OrdinaSoft.DialogBox.ContentClass = ''; // CSS class for content OrdinaSoft.DialogBox.ImageRoot = 'Images/DialogBox'; // base URL for images OrdinaSoft.DialogBox.Opacity = 0.25; // opacity for the mask OrdinaSoft.DialogBox.BtnClass = ''; // CSS class for the buttons OrdinaSoft.DialogBox.OkBtnText = 'OK'; // Text for 'OK' button OrdinaSoft.DialogBox.CancelBtnText = 'Cancel'; // Text for 'Cancel' button OrdinaSoft.DialogBox.YesBtnText = 'Yes'; // Text for 'Yes' button OrdinaSoft.DialogBox.NoBtnText = 'No'; // Text for 'No' button //----------------------------------------------------------------------------------------------- // Dialog box constructor. // Creates a dialog box, without displaying it. // - Content is the content of the dialog box. // - Title is the optional title of the dialog box. OrdinaSoft.DialogBox.DialogBox = function () { this.Content = ' '; this.Title = ' '; this.FocusElmt = null; return true; } // OrdinaSoft.DialogBox.DialogBox //----------------------------------------------------------------------------------------------- // Format of the dialog box. // Formats the dialog box and returns a
element with the content of the dialog box. OrdinaSoft.DialogBox.DialogBox.prototype._Format = function () { var Box = OrdinaSoft.Base.GetClientDiv (); var s = []; var Dir = OrdinaSoft.DialogBox.ImageRoot + '/'; s [s.length] = ''; s [s.length] = ' '; s [s.length] = ' '; s [s.length] = ' '; s [s.length] = '
' + ' '; s [s.length] = ' '; s [s.length] = ' '; s [s.length] = ' '; s [s.length] = ' '; s [s.length] = ' '; s [s.length] = ' '; s [s.length] = ' '; s [s.length] = ' '; s [s.length] = ' '; s [s.length] = ' '; s [s.length] = ' '; s [s.length] = ' '; s [s.length] = ' '; s [s.length] = ' '; s [s.length] = ' '; s [s.length] = ' '; s [s.length] = ' '; s [s.length] = ' '; s [s.length] = ' '; s [s.length] = ' '; s [s.length] = '
' + this.Title + '
'; s [s.length] = ' '; s [s.length] = ' '; s [s.length] = ' '; s [s.length] = ' '; s [s.length] = ' '; s [s.length] = ' '; s [s.length] = ' '; s [s.length] = ' '; s [s.length] = ' '; s [s.length] = ' '; s [s.length] = ' '; s [s.length] = ' '; s [s.length] = ' '; s [s.length] = ' '; s [s.length] = ' '; s [s.length] = '
' + this.Content + '
' + '
'; Box.innerHTML = s.join ('\r\n'); return Box; } // OrdinaSoft.DialogBox.DialogBox.prototype._Format //----------------------------------------------------------------------------------------------- // Buttons. // Returns HTML code with an OK button. // - idOK is the identifier of the OK button. Its default value is dlg_OK. // - fOK is the name of the function to call when the OK button is pressed. Its default value is // to close the dialog box. OrdinaSoft.DialogBox.GetOK = function (idOK, fOK) { if (idOK == null) idOK = 'dlg_OK'; if (fOK == null) fOK = 'OrdinaSoft.DialogBox.Close ()'; var s = []; s [s.length] = '
 
'; s [s.length] = '
'; s [s.length] = ' '; s [s.length] = '
'; return s.join ('\r\n'); } // OrdinaSoft.DialogBox.GetOK // Returns HTML code for 1 button. // - idFirst is the identifier of the button. // - TxtFirst is the text for the button. // - fFirst is the name of the function to call when the button is pressed. Its default value is // to close the dialog box. OrdinaSoft.DialogBox.Get1Button = function (idFirst, TxtFirst, fFirst) { if (fFirst == null) fFirst = 'OrdinaSoft.DialogBox.Close ()'; var ClassTxt = (OrdinaSoft.DialogBox.BtnClass == '') ? '' : 'class="' + OrdinaSoft.DialogBox.BtnClass + '" '; var s = []; s [s.length] = '
 
'; s [s.length] = '
'; s [s.length] = ' '; s [s.length] = '
'; return s.join ('\r\n'); } // OrdinaSoft.DialogBox.Get1Button // Returns HTML code for 2 buttons. // - idFirst is the identifier of the first button. // - TxtFirst is the text for the first button. // - fFirst is the name of the function to call when the first button is pressed. Its default // value is to close the dialog box. // - idSecond is the identifier of the second button. // - TxtSecond is the text for the second button. // - fSecond is the name of the function to call when the second button is pressed. Its default // value is to close the dialog box. OrdinaSoft.DialogBox.Get2Buttons = function (idFirst, TxtFirst, fFirst, idSecond, TxtSecond, fSecond) { if (fFirst == null) fFirst = 'OrdinaSoft.DialogBox.Close ()'; if (fSecond == null) fSecond = 'OrdinaSoft.DialogBox.Close ()'; var ClassTxt = (OrdinaSoft.DialogBox.BtnClass == '') ? '' : 'class="' + OrdinaSoft.DialogBox.BtnClass + '" '; var s = []; s [s.length] = '
 
'; s [s.length] = '
'; s [s.length] = ' '; s [s.length] = '   '; s [s.length] = ' '; s [s.length] = '
'; return s.join ('\r\n'); } // OrdinaSoft.DialogBox.Get2Buttons // Returns HTML code for 3 buttons. // - idFirst is the identifier of the first button. // - TxtFirst is the text for the first button. // - fFirst is the name of the function to call when the first button is pressed. Its default // value is to close the dialog box. // - idSecond is the identifier of the second button. // - TxtSecond is the text for the second button. // - fSecond is the name of the function to call when the second button is pressed. Its default // value is to close the dialog box. // - idThird is the identifier of the third button. // - TxtThird is the text for the third button. // - fThird is the name of the function to call when the third button is pressed. Its default // value is to close the dialog box. OrdinaSoft.DialogBox.Get3Buttons = function (idFirst, TxtFirst, fFirst, idSecond, TxtSecond, fSecond, idThird, TxtThird, fThird) { if (fFirst == null) fFirst = 'OrdinaSoft.DialogBox.Close ()'; if (fSecond == null) fSecond = 'OrdinaSoft.DialogBox.Close ()'; if (fThird == null) fThird = 'OrdinaSoft.DialogBox.Close ()'; var ClassTxt = (OrdinaSoft.DialogBox.BtnClass == '') ? '' : 'class="' + OrdinaSoft.DialogBox.BtnClass + '" '; var s = []; s [s.length] = '
 
'; s [s.length] = '
'; s [s.length] = ' '; s [s.length] = '   '; s [s.length] = ' '; s [s.length] = '   '; s [s.length] = ' '; s [s.length] = '
'; return s.join ('\r\n'); } // OrdinaSoft.DialogBox.Get3Buttons // Returns HTML code with an OK and a Cancel button. // - idOK is the identifier of the OK button. Its default value is dlg_OK. // - fOK is the name of the function to call when the OK button is pressed. Its default value is // to close the dialog box. // - idCancel is the identifier of the Cancel button. Its default value is dlg_Cancel. // - fCancel is the name of the function to call when the Cancel button is pressed. Its default // value is to close the dialog box. OrdinaSoft.DialogBox.GetOKCancel = function (idOK, fOK, idCancel, fCancel) { if (idOK == null) idOK = 'dlg_OK'; if (idCancel == null) idCancel = 'dlg_Cancel'; return OrdinaSoft.DialogBox.Get2Buttons (idOK, OrdinaSoft.DialogBox.OkBtnText, fOK, idCancel, OrdinaSoft.DialogBox.CancelBtnText, fCancel); } // OrdinaSoft.DialogBox.GetOKCancel // Returns HTML code with a Yes and a No button. // - idYes is the identifier of the Yes button. Its default value is dlg_Yes. // - fYes is the name of the function to call when the Yes button is pressed. Its default value // is to close the dialog box. // - idNo is the identifier of the No button. Its default value is dlg_No. // - fNo is the name of the function to call when the No button is pressed. Its default value is // to close the dialog box. OrdinaSoft.DialogBox.GetYesNo = function (idYes, fYes, idNo, fNo) { if (idYes == null) idYes = 'dlg_Yes'; if (idNo == null) idNo = 'dlg_No'; return OrdinaSoft.DialogBox.Get2Buttons (idYes, OrdinaSoft.DialogBox.YesBtnText, fYes, idNo, OrdinaSoft.DialogBox.NoBtnText, fNo); } // OrdinaSoft.DialogBox.GetYesNo //----------------------------------------------------------------------------------------------- // Showing and closing the dialog box. // Shows the dialog box. OrdinaSoft.DialogBox.DialogBox.prototype.Show = function () { OrdinaSoft.DialogBox._ShowMask (); this.Box = this._Format (); OrdinaSoft.DialogBox._Stack [OrdinaSoft.DialogBox._Stack.length] = this; document.forms [0].appendChild (this.Box); if (this.FocusElmt != null) { var FocusElmt = document.getElementById (this.FocusElmt); if (FocusElmt != null) FocusElmt.focus (); } // this.FocusElmt != null return true; } // OrdinaSoft.DialogBox.DialogBox.prototype.Show // Closes the last opened dialog box. OrdinaSoft.DialogBox.Close = function () { var Stack = OrdinaSoft.DialogBox._Stack; if (Stack.length != 0) { var Obj = Stack [Stack.length - 1]; if (Obj != null) { var Dlg = Obj.Box; if (Dlg != null) { OrdinaSoft.Base.StopClientDivTracking (Dlg); Dlg.parentNode.removeChild (Dlg); } // Dlg != null if (typeof Obj.OnClose == 'function') Obj.OnClose (); } // Obj != null Stack.length = Stack.length - 1; if (Stack.length == 0) OrdinaSoft.DialogBox._HideMask (); } // OrdinaSoft.DialogBox._Stack.length != 0 return true; } // OrdinaSoft.DialogBox.Close OrdinaSoft.DialogBox.DialogBox.prototype.Close = function () { return OrdinaSoft.DialogBox.Close (); } // OrdinaSoft.DialogBox.DialogBox.prototype.Close //----------------------------------------------------------------------------------------------- // Dialog box tools. // Indicates if a dialog box is actually displayed. // - The return value is true if a dialog box is displayed and false otherwise. OrdinaSoft.DialogBox.IsDialogBoxDisplayed = function () { return OrdinaSoft.DialogBox._Stack.length != 0; } // OrdinaSoft.DialogBox.IsDialogBoxDisplayed //----------------------------------------------------------------------------------------------- // Message boxes. // Message Box constructor. // - Message is the message to display. // - Title is the title of the message box. Its default value is an empty text. // - Button is the HTML code for the button(s). Its default value is to have only an OK button. // - Icon is the icon to display in the message box. Its default value is to display no icon. OrdinaSoft.DialogBox.MessageBox = function (Message, Title, Button, Icon) { // Gets the content var s = []; s [s.length] = ''; s [s.length] = ' '; if (Icon != null) { // we have an icon s [s.length] = ' '; s [s.length] = ' '; } // typeof Icon != 'undefined' s [s.length] = ' '; s [s.length] = ' '; s [s.length] = '
' + '' + ' ' + Message + '
'; if (Button == null) { // default button Button = OrdinaSoft.DialogBox.GetOK ('mb_OK'); this.FocusElmt = 'mb_OK'; } // Button == null s [s.length] = Button; this.Content = s.join ('\r\n'); // Title this.Title = Title; return true; } // OrdinaSoft.DialogBox.MessageBox OrdinaSoft.DialogBox.MessageBox.prototype = new OrdinaSoft.DialogBox.DialogBox (); // Displays an information message box, with a 'Question' icon. // - Message is the message to display in the message box. // - Title is the optional title of the message box. // - fYes is the function to call if the result is 'Yes'. // - fNo is the function to call if the result is 'No'. // - The result is the message box just displayed. OrdinaSoft.DialogBox.MessageBox.Question = function (Message, Title, fYes, fNo) { var Dlg = new OrdinaSoft.DialogBox.MessageBox (Message, Title, OrdinaSoft.DialogBox.GetYesNo ('mb_Yes', fYes, 'mb_No', fNo), 'Question'); Dlg.Show (); return Dlg; } // OrdinaSoft.DialogBox.MessageBox.Question // Displays an information message box, with an 'Info' icon. // - Message is the message to display in the message box. // - Title is the optional title of the message box. // - The result is the message box just displayed. OrdinaSoft.DialogBox.MessageBox.Info = function (Message, Title) { var Dlg = new OrdinaSoft.DialogBox.MessageBox (Message, Title, null, 'Info'); Dlg.Show (); return Dlg; } // OrdinaSoft.DialogBox.MessageBox.Info // Displays a warning message box, with a 'Warning' icon. // - Message is the message to display in the message box. // - Title is the optional title of the message box. // - The result is the message box just displayed. OrdinaSoft.DialogBox.MessageBox.Warning = function (Message, Title) { var Dlg = new OrdinaSoft.DialogBox.MessageBox (Message, Title, null, 'Warning'); Dlg.Show (); return Dlg; } // OrdinaSoft.DialogBox.MessageBox.Warning // Displays an error message box, with an 'Error' icon. // - Message is the message to display in the message box. // - Title is the optional title of the message box. // - The result is the message box just displayed. OrdinaSoft.DialogBox.MessageBox.Error = function (Message, Title) { var Dlg = new OrdinaSoft.DialogBox.MessageBox (Message, Title, null, 'Error') Dlg.Show (); return Dlg; } // OrdinaSoft.DialogBox.MessageBox.Info //----------------------------------------------------------------------------------------------- // Displaying and hiding the mask. // Private function to display the mask on top of the user page. OrdinaSoft.DialogBox._ShowMask = function () { if (OrdinaSoft.DialogBox._PageMask != null) return true; // have already a mask var Mask = OrdinaSoft.Base.GetClientDiv (); var Style = Mask.style; Style.backgroundColor = '#000000'; Style.filter = 'alpha(opacity=' + (100 * OrdinaSoft.DialogBox.Opacity).toString () + ')'; Style.opacity = OrdinaSoft.DialogBox.Opacity; document.forms [0].appendChild (Mask); OrdinaSoft.DialogBox._PageMask = Mask return true; } // OrdinaSoft.DialogBox._ShowMask // Private function to hide the mask on top of the user page. OrdinaSoft.DialogBox._HideMask = function () { var Elmt = OrdinaSoft.DialogBox._PageMask; if (Elmt != null) { OrdinaSoft.Base.StopClientDivTracking (Elmt); Elmt.parentNode.removeChild (Elmt); OrdinaSoft.DialogBox._PageMask = null; } // Elmt != null return true; } // OrdinaSoft.DialogBox._HideMask //----------------------------------------------------------------------------------------------- OrdinaSoft_DialogBox_Initialized = true; // indicates that the library is initialized