#include <JavascriptExample.h>
Public Member Functions | |
JavascriptExample (const WEnvironment &env) | |
Create the example application. | |
Private Member Functions | |
void | confirmed () |
The user has confirmed the payment. | |
void | setAmount (std::string amount) |
Set the amount to be payed. | |
Private Attributes | |
Popup * | promptAmount_ |
Popup for changing the amount. | |
Popup * | confirmPay_ |
Popup for paying. | |
WText * | currentAmount_ |
WText for showing the current amount. |
Definition at line 24 of file JavascriptExample.h.
JavascriptExample::JavascriptExample | ( | const WEnvironment & | env | ) |
Create the example application.
Definition at line 19 of file JavascriptExample.C.
00020 : WApplication(env) 00021 { 00022 setTitle("Javascript example"); 00023 00024 // Create a popup for prompting the amount of money, and connect the 00025 // okPressed button to the slot for setting the amount of money. 00026 // 00027 // Note that the input provided by the user in the prompt box is passed as 00028 // an argument to the slot. 00029 promptAmount_ = Popup::createPrompt("How much do you want to pay?", "", 00030 this); 00031 promptAmount_->okPressed().connect(SLOT(this, JavascriptExample::setAmount)); 00032 00033 // Create a popup for confirming the payment. 00034 // 00035 // Since a confirm popup does not allow input, we ignore the 00036 // argument carrying the input (which will be empty anyway). 00037 confirmPay_ = Popup::createConfirm("", this); 00038 confirmPay_->okPressed().connect(SLOT(this, JavascriptExample::confirmed)); 00039 00040 new WText("<h2>Wt Javascript example</h2>" 00041 "<p>Wt makes abstraction of Javascript, and therefore allows you" 00042 " to develop web applications without any knowledge of Javascript," 00043 " and which are not dependent on Javascript." 00044 " However, Wt does allow you to add custom Javascript code:</p>" 00045 " <ul>" 00046 " <li>To call custom JavaScript code from an event handler, " 00047 "connect the Wt::EventSignal to a Wt::JSlot.</li>" 00048 " <li>To call C++ code from custom JavaScript, use " 00049 "Wt.emit() to emit a Wt::JSignal.</li>" 00050 " <li>To call custom JavaScript code from C++, use " 00051 "WApplication::doJavascript() or Wt::JSlot::exec().</li>" 00052 " </ul>" 00053 "<p>This simple application shows how to interact between C++ and" 00054 " JavaScript using the JSlot and JSignal classes.</p>", root()); 00055 00056 currentAmount_ 00057 = new WText("Current amount: $" + promptAmount_->defaultValue(), root()); 00058 00059 WPushButton *amountButton = new WPushButton("Change ...", root()); 00060 amountButton->setMargin(10, Left | Right); 00061 00062 new WBreak(root()); 00063 00064 WPushButton *confirmButton = new WPushButton("Pay now.", root()); 00065 confirmButton->setMargin(10, Top | Bottom); 00066 00067 // Connect the event handlers to a JSlot: this will execute the JavaScript 00068 // immediately, without a server round trip. 00069 amountButton->clicked().connect(promptAmount_->show); 00070 confirmButton->clicked().connect(confirmPay_->show); 00071 00072 // Set the initial amount 00073 setAmount("1000"); 00074 }
void JavascriptExample::confirmed | ( | ) | [private] |
The user has confirmed the payment.
Definition at line 88 of file JavascriptExample.C.
00089 { 00090 new WText("<br/>Just payed $" + promptAmount_->defaultValue() + ".", root()); 00091 }
void JavascriptExample::setAmount | ( | std::string | amount | ) | [private] |
Set the amount to be payed.
Definition at line 76 of file JavascriptExample.C.
00077 { 00078 // Change the confirmation message to include the amount. 00079 confirmPay_->setMessage("Are you sure you want to pay $" + amount + " ?"); 00080 00081 // Change the default value for the prompt. 00082 promptAmount_->setDefaultValue(amount); 00083 00084 // Change the text that shows the current amount. 00085 currentAmount_->setText("Current amount: $" + promptAmount_->defaultValue()); 00086 }
Popup* JavascriptExample::promptAmount_ [private] |
Popup* JavascriptExample::confirmPay_ [private] |
WText* JavascriptExample::currentAmount_ [private] |