Popup Class Reference
[Javascript - Wt interaction example]

A JavaScript based popup window, encapsulating the Javascript functions alert(), confirm(), and prompt(). More...

#include <Popup.h>

Inheritance diagram for Popup:

Inheritance graph
[legend]

List of all members.

Public Member Functions

void setMessage (const WString &message)
 Change the message.
void setDefaultValue (const std::string defaultValue)
 Change the default value for a prompt dialog.
const WMessage & message () const
 Get the current message.
const std::string & defaultValue () const
 Get the default value for a prompt dialog.

Static Public Member Functions

static PopupcreateConfirm (const WString &message, WObject *parent=0)
 Create a confirm dialog.
static PopupcreatePrompt (const WString &message, const std::string defaultValue, WObject *parent=0)
 Create a prompt dialog with the given default value.
static PopupcreateAlert (const WString &message, WObject *parent=0)
 Create an alert dialog.

Public Attributes

JSlot show
 Show the dialog.
JSignal< std::string > okPressed
 Signal emitted when ok pressed.
JSignal< void > cancelPressed
 Signal emitted when cancel is pressed.

Private Types

enum  Type { Confirm, Alert, Prompt }
 Popup type. More...

Private Member Functions

 Popup (Type t, const WString &message, const std::string defaultValue, WObject *parent)
 Popup constructor.
void setJavaScript ()
 Update the javascript code.

Private Attributes

Type t_
WString message_
std::string defaultValue_


Detailed Description

A JavaScript based popup window, encapsulating the Javascript functions alert(), confirm(), and prompt().

Use one of the create static methods to create a popup. This will not display the popup, until either the show slot is triggered from an event handler, or is executed using it's exec() method.

When the user closes the popup, either the okPressed or cancelPressed signal is emitted. For a prompt dialog, the value is passed as a parameter to the okPressed signal.

Definition at line 32 of file Popup.h.


Member Enumeration Documentation

enum Popup::Type [private]

Popup type.

Enumerator:
Confirm 
Alert 
Prompt 

Definition at line 83 of file Popup.h.

00083 { Confirm, Alert, Prompt };


Constructor & Destructor Documentation

Popup::Popup ( Type  t,
const WString message,
const std::string  defaultValue,
WObject parent 
) [private]

Popup constructor.

Definition at line 12 of file Popup.C.

00014   : WObject(parent),
00015     okPressed(this, "ok"),
00016     cancelPressed(this, "cancel"),
00017     t_(t),
00018     message_(message),
00019     defaultValue_(defaultValue)
00020 {
00021   setJavaScript();
00022 }


Member Function Documentation

Popup * Popup::createConfirm ( const WString message,
WObject parent = 0 
) [static]

Create a confirm dialog.

Definition at line 71 of file Popup.C.

00072 {
00073   return new Popup(Confirm, message, std::string(), parent);
00074 }

Popup * Popup::createPrompt ( const WString message,
const std::string  defaultValue,
WObject parent = 0 
) [static]

Create a prompt dialog with the given default value.

Definition at line 81 of file Popup.C.

00083 {
00084   return new Popup(Prompt, message, defaultValue, parent);
00085 }

Popup * Popup::createAlert ( const WString message,
WObject parent = 0 
) [static]

Create an alert dialog.

Definition at line 76 of file Popup.C.

00077 {
00078   return new Popup(Alert, message, std::string(), parent);
00079 }

void Popup::setMessage ( const WString message  ) 

Change the message.

Definition at line 59 of file Popup.C.

00060 {
00061   message_ = message;
00062   setJavaScript();
00063 }

void Popup::setDefaultValue ( const std::string  defaultValue  ) 

Change the default value for a prompt dialog.

Definition at line 65 of file Popup.C.

00066 {
00067   defaultValue_ = defaultValue;
00068   setJavaScript();
00069 }

const WMessage& Popup::message (  )  const [inline]

Get the current message.

Definition at line 59 of file Popup.h.

00059 { return message_; }

const std::string& Popup::defaultValue (  )  const [inline]

Get the default value for a prompt dialog.

Definition at line 63 of file Popup.h.

00063 { return defaultValue_; }

void Popup::setJavaScript (  )  [private]

Update the javascript code.

Definition at line 24 of file Popup.C.

00025 {
00026   /*
00027    * Sets the JavaScript code.
00028    *
00029    * Notice how Wt.emit() is used to emit the okPressed or cancelPressed
00030    * signal, and how arguments may be passed to it, matching the number and
00031    * type of arguments in the JSignal definition.
00032    */
00033   switch (t_) {
00034   case Confirm:
00035     show.setJavaScript
00036       ("function(){ if (confirm('" + message_.narrow() + "')) {"
00037        "  Wt.emit('" + id() + "','" + okPressed.name() + "', '');"
00038        "} else {"
00039        "  Wt.emit('" + id() + "','" + cancelPressed.name() + "');"
00040        "}}");
00041     break;
00042   case Alert:
00043     show.setJavaScript
00044       ("function(){ alert('" + message_.narrow() + "');"
00045        "Wt.emit('" + id() + "','" + okPressed.name() + "', '');}");
00046     break;
00047   case Prompt:
00048     show.setJavaScript
00049       ("function(){var n = prompt('" + message_.narrow() + "', '"
00050        + defaultValue_ + "');"
00051        "if (n != null) {"
00052        "  Wt.emit('" + id() + "','" + okPressed.name() + "', n);"
00053        "} else {"
00054        "  Wt.emit('" + id() + "','" + cancelPressed.name() + "');"
00055        "}}");
00056   }
00057 }


Member Data Documentation

Show the dialog.

Use show.exec() to show the dialog, or connect the slot to an EventSignal to directly show the dialog without a server round trip.

Definition at line 70 of file Popup.h.

JSignal<std::string> Popup::okPressed

Signal emitted when ok pressed.

Definition at line 74 of file Popup.h.

Signal emitted when cancel is pressed.

Definition at line 78 of file Popup.h.

Type Popup::t_ [private]

Definition at line 90 of file Popup.h.

Definition at line 91 of file Popup.h.

std::string Popup::defaultValue_ [private]

Definition at line 92 of file Popup.h.


The documentation for this class was generated from the following files:

Generated on Mon Jan 26 14:14:22 2009 for Wt by doxygen 1.5.6