Wt examples  3.2.1
Public Member Functions | Private Member Functions | Private Attributes | List of all members
JavascriptExample Class Reference

An example showing how to interact custom JavaScript with Wt stuff. More...

#include <JavascriptExample.h>

Inheritance diagram for JavascriptExample:
Inheritance graph
[legend]

Public Member Functions

 JavascriptExample (const WEnvironment &env)
 Create the example application.
- Public Member Functions inherited from Wt::WApplication
 WApplication (const WEnvironment &environment)
 ~WApplication ()
const WEnvironmentenvironment () const
WContainerWidgetroot () const
WWidgetfindWidget (const std::string &name)
void setTitle (const WString &title)
const WStringtitle () const
const WStringcloseMessage () const
WLocalizedStringslocalizedStrings ()
void setLocalizedStrings (WLocalizedStrings *stringResolver)
WMessageResourceBundlemessageResourceBundle ()
void setLocale (const std::string &locale)
std::string locale () const
virtual void refresh ()
void bindWidget (WWidget *widget, const std::string &domId)
std::string docRoot () const
std::string sessionId () const
void changeSessionId ()
void processEvents ()
void setAjaxMethod (AjaxMethod method)
AjaxMethod ajaxMethod () const
virtual void initialize ()
virtual void finalize ()
void setTwoPhaseRenderingThreshold (int size)
void setCookie (const std::string &name, const std::string &value, int maxAge, const std::string &domain="", const std::string &path="", bool secure=false)
void addMetaLink (const std::string &href, const std::string &rel, const std::string &media, const std::string &hreflang, const std::string &type, const std::string &sizes, bool disabled)
void removeMetaLink (const std::string &href)
void addMetaHeader (const std::string &name, const WString &content, const std::string &lang="")
void addMetaHeader (MetaHeaderType type, const std::string &name, const WString &content, const std::string &lang="")
void removeMetaHeader (MetaHeaderType type, const std::string &name="")
WLogEntry log (const std::string &type) const
void setLoadingIndicator (WLoadingIndicator *indicator)
WLoadingIndicatorloadingIndicator () const
void quit ()
bool isQuited () const
::int64_t maximumRequestSize () const
Signal< ::int64_t > & requestTooLarge ()
void setConfirmCloseMessage (const WString &message)
void deferRendering ()
void resumeRendering ()
boost::function< void()> bind (const F &f)
WCssStyleSheetstyleSheet ()
void useStyleSheet (const std::string &url)
void useStyleSheet (const std::string &url, const std::string &condition, const std::string &media="all")
void setCssTheme (const std::string &theme)
std::string cssTheme () const
void setLayoutDirection (LayoutDirection direction)
LayoutDirection layoutDirection () const
void setBodyClass (const std::string &styleClass)
std::string bodyClass () const
void setHtmlClass (const std::string &styleClass)
std::string htmlClass () const
std::string url (const std::string &internalPath=std::string()) const
virtual std::string makeAbsoluteUrl (const std::string &url) const
std::string resolveRelativeUrl (const std::string &url) const
std::string bookmarkUrl () const
std::string bookmarkUrl (const std::string &internalPath) const
void setInternalPath (const std::string &path, bool emitChange=false)
std::string internalPath () const
std::string internalPathNextPart (const std::string &path) const
std::string internalSubPath (const std::string &path) const
bool internalPathMatches (const std::string &path) const
Signal< std::string > & internalPathChanged ()
void redirect (const std::string &url)
void enableUpdates (bool enabled=true)
bool updatesEnabled () const
void triggerUpdate ()
UpdateLock getUpdateLock ()
void attachThread (bool attach=true)
void doJavaScript (const std::string &javascript, bool afterLoaded=true)
void addAutoJavaScript (const std::string &javascript)
void declareJavaScriptFunction (const std::string &name, const std::string &function)
bool require (const std::string &url, const std::string &symbol=std::string())
void setJavaScriptClass (const std::string &className)
std::string javaScriptClass ()
EventSignal< WKeyEvent > & globalKeyWentDown ()
EventSignal< WKeyEvent > & globalKeyPressed ()
EventSignal< WKeyEvent > & globalKeyWentUp ()
EventSignalglobalEnterPressed ()
EventSignalglobalEscapePressed ()
 WObject (WObject *parent=0)
virtual ~WObject ()
virtual const std::string id () const
void setObjectName (const std::string &name)
virtual std::string objectName () const
void resetLearnedSlots ()
void resetLearnedSlot (void(T::*method)())
WStatelessSlot * implementStateless (void(T::*method)())
WStatelessSlot * implementStateless (void(T::*method)(), void(T::*undoMethod)())
WStatelessSlot * implementJavaScript (void(T::*method)(), const std::string &jsCode)
void addChild (WObject *child)
virtual void removeChild (WObject *child)
const std::vector< WObject * > & children () const
WObjectparent () const

Private Member Functions

void confirmed ()
 The user has confirmed the payment.
void setAmount (std::string amount)
 Set the amount to be payed.

Private Attributes

PopuppromptAmount_
 Popup for changing the amount.
PopupconfirmPay_
 Popup for paying.
WTextcurrentAmount_
 WText for showing the current amount.

Additional Inherited Members

- Public Types inherited from Wt::WApplication
enum  AjaxMethod
typedef Wt::ApplicationCreator ApplicationCreator
typedef void(WObject::* Method )()
typedef boost::function
< WApplication *(const
WEnvironment &)> 
ApplicationCreator
- Static Public Member Functions inherited from Wt::WApplication
static WApplicationinstance ()
static std::string resourcesUrl ()
static std::string appRoot ()
static bool readConfigurationProperty (const std::string &name, std::string &value)
- Public Attributes inherited from Wt::WApplication
 XMLHttpRequest
 DynamicScriptTag
- Protected Member Functions inherited from Wt::WApplication
virtual void notify (const WEvent &e)
virtual bool isExposed (WWidget *w) const
virtual void enableAjax ()
virtual void unload ()
virtual WStatelessSlot * getStateless (Method method)
- Static Protected Member Functions inherited from Wt::WApplication
static WObjectsender ()

Detailed Description

An example showing how to interact custom JavaScript with Wt stuff.

Definition at line 24 of file JavascriptExample.h.

Constructor & Destructor Documentation

JavascriptExample::JavascriptExample ( const WEnvironment env)

Create the example application.

Definition at line 19 of file JavascriptExample.C.

: WApplication(env)
{
setTitle("Javascript example");
// Create a popup for prompting the amount of money, and connect the
// okPressed button to the slot for setting the amount of money.
//
// Note that the input provided by the user in the prompt box is passed as
// an argument to the slot.
promptAmount_ = Popup::createPrompt("How much do you want to pay?", "",
this);
// Create a popup for confirming the payment.
//
// Since a confirm popup does not allow input, we ignore the
// argument carrying the input (which will be empty anyway).
new WText("<h2>Wt Javascript example</h2>"
"<p>Wt makes abstraction of Javascript, and therefore allows you"
" to develop web applications without any knowledge of Javascript,"
" and which are not dependent on Javascript."
" However, Wt does allow you to add custom Javascript code:</p>"
" <ul>"
" <li>To call custom JavaScript code from an event handler, "
"connect the Wt::EventSignal to a Wt::JSlot.</li>"
" <li>To call C++ code from custom JavaScript, use "
"Wt.emit() to emit a Wt::JSignal.</li>"
" <li>To call custom JavaScript code from C++, use "
"WApplication::doJavascript() or Wt::JSlot::exec().</li>"
" </ul>"
"<p>This simple application shows how to interact between C++ and"
" JavaScript using the JSlot and JSignal classes.</p>", root());
= new WText("Current amount: $" + promptAmount_->defaultValue(), root());
WPushButton *amountButton = new WPushButton("Change ...", root());
amountButton->setMargin(10, Left | Right);
new WBreak(root());
WPushButton *confirmButton = new WPushButton("Pay now.", root());
confirmButton->setMargin(10, Top | Bottom);
// Connect the event handlers to a JSlot: this will execute the JavaScript
// immediately, without a server round trip.
amountButton->clicked().connect(promptAmount_->show);
confirmButton->clicked().connect(confirmPay_->show);
// Set the initial amount
setAmount("1000");
}

Member Function Documentation

void JavascriptExample::confirmed ( )
private

The user has confirmed the payment.

Definition at line 88 of file JavascriptExample.C.

{
new WText("<br/>Just payed $" + promptAmount_->defaultValue() + ".", root());
}
void JavascriptExample::setAmount ( std::string  amount)
private

Set the amount to be payed.

Definition at line 76 of file JavascriptExample.C.

{
// Change the confirmation message to include the amount.
confirmPay_->setMessage("Are you sure you want to pay $" + amount + " ?");
// Change the default value for the prompt.
// Change the text that shows the current amount.
currentAmount_->setText("Current amount: $" + promptAmount_->defaultValue());
}

Member Data Documentation

Popup* JavascriptExample::confirmPay_
private

Popup for paying.

Definition at line 46 of file JavascriptExample.h.

WText* JavascriptExample::currentAmount_
private

WText for showing the current amount.

Definition at line 50 of file JavascriptExample.h.

Popup* JavascriptExample::promptAmount_
private

Popup for changing the amount.

Definition at line 42 of file JavascriptExample.h.


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

Generated on Sat Oct 18 2014 for the C++ Web Toolkit (Wt) by doxygen 1.8.1.2