JavaScript dialogs for Sitemagic CMS

Dialogs are commonly used to ask the user to either confirm or supply information client side, without requiring the user to perform a post back. Sitemagic CMS ships with the SMMessageDialog class which supports the following types of dialogs:
  • Message dialog (alert box with information)
  • Confirm dialog (alert box with information and OK/Cancel buttons)
  • Input dialog (input box with information and OK/Cancel buttons)
  • Password dialog (input box with password field that hides the value entered)
The 3 first types of dialogs are based on standard JavaScript dialogs (alert, confirm, and prompt) while the password dialog is unique to Sitemagic CMS, as the default implementation of JavaScript does not provide a password dialog. The following code demonstrates how the 4 dialog types are used:
// Using the message dialog

SMMessageDialog.ShowMessageDialog("Please update your bookmark");

// Using the confirm dialog

if (SMMessageDialog.ShowConfirmDialog("Delete selected item?") === true)
{
    // User confirmed action (clicked OK) - do something here..
}

// Using the input dialog

var name = SMMessageDialog.ShowInputDialog("What is your name?", "Enter name here..");

if (name !== null) // name variable will be null if user canceled or closed the input dialog
{
    // User entered a value - do something here..
}

// Using the password dialog

SMMessageDialog.ShowPasswordDialog(function(pass)
{
    // This function executes when the password is either specified or the dialog is closed.

    if (pass !== null) // Password specified
    {
        // Do something with the password here..
    }
    else
    {
        // User canceled the password dialog
        SMMessageDialog.ShowMessageDialog("You must enter your password to log in!");
    }
}, "Enter password", "Please enter the password received by e-mail");