Wt examples 3.3.12
Popup.C
Go to the documentation of this file.
1// This may look like C code, but it's really -*- C++ -*-
2/*
3 * Copyright (C) 2008 Emweb bvba, Kessel-Lo, Belgium.
4 *
5 * See the LICENSE file for terms of use.
6 */
7
8#include "Popup.h"
9
10using namespace Wt;
11
12Popup::Popup(Type t, const WString& message, std::string defaultValue,
13 WObject *parent)
14 : WObject(parent),
15 okPressed_(this, "ok"),
16 cancelPressed_(this, "cancel"),
17 t_(t),
18 message_(message),
19 defaultValue_(defaultValue)
20{
22}
23
25{
26 /*
27 * Sets the JavaScript code.
28 *
29 * Notice how Wt.emit() is used to emit the okPressed or cancelPressed
30 * signal, and how arguments may be passed to it, matching the number and
31 * type of arguments in the JSignal definition.
32 */
33 switch (t_) {
34 case Confirm:
36 ("function(){ if (confirm('" + message_.narrow() + "')) {"
37 + okPressed_.createCall("''") +
38 "} else {"
40 "}}");
41 break;
42 case Alert:
44 ("function(){ alert('" + message_.narrow() + "');"
45 + okPressed_.createCall("''") +
46 "}");
47 break;
48 case Prompt:
50 ("function(){var n = prompt('" + message_.narrow() + "', '"
51 + defaultValue_ + "');"
52 "if (n != null) {"
53 + okPressed_.createCall("n") +
54 "} else {"
56 "}}");
57 }
58}
59
60void Popup::setMessage(const WString& message)
61{
64}
65
66void Popup::setDefaultValue(const std::string defaultValue)
67{
70}
71
72Popup *Popup::createConfirm(const WString& message, WObject *parent)
73{
74 return new Popup(Confirm, message, std::string(), parent);
75}
76
77Popup *Popup::createAlert(const WString& message, WObject *parent)
78{
79 return new Popup(Alert, message, std::string(), parent);
80}
81
83 const std::string defaultValue, WObject *parent)
84{
85 return new Popup(Prompt, message, defaultValue, parent);
86}
A JavaScript based popup window, encapsulating the Javascript functions alert(), confirm(),...
Definition Popup.h:33
void setMessage(const WString &message)
Change the message.
Definition Popup.C:60
static Popup * createConfirm(const WString &message, WObject *parent=0)
Create a confirm dialog.
Definition Popup.C:72
const std::string & defaultValue() const
Get the default value for a prompt dialog.
Definition Popup.h:63
JSlot show
Show the dialog.
Definition Popup.h:70
Type t_
Definition Popup.h:93
WString message_
Definition Popup.h:94
void setDefaultValue(const std::string defaultValue)
Change the default value for a prompt dialog.
Definition Popup.C:66
const WString & message() const
Get the current message.
Definition Popup.h:59
JSignal< void > cancelPressed_
Definition Popup.h:91
std::string defaultValue_
Definition Popup.h:95
Popup(Type t, const WString &message, const std::string defaultValue, WObject *parent)
Popup constructor.
Definition Popup.C:12
Type
Popup type.
Definition Popup.h:83
@ Alert
Definition Popup.h:83
@ Prompt
Definition Popup.h:83
@ Confirm
Definition Popup.h:83
static Popup * createAlert(const WString &message, WObject *parent=0)
Create an alert dialog.
Definition Popup.C:77
JSignal< std::string > okPressed_
Definition Popup.h:90
static Popup * createPrompt(const WString &message, const std::string defaultValue, WObject *parent=0)
Create a prompt dialog with the given default value.
Definition Popup.C:82
void setJavaScript()
Update the javascript code.
Definition Popup.C:24
const std::string createCall(const std::string &arg1=std::string(), const std::string &arg2=std::string(), const std::string &arg3=std::string(), const std::string &arg4=std::string(), const std::string &arg5=std::string(), const std::string &arg6=std::string()) const
void setJavaScript(const std::string &javaScript, int nbArgs=0)
WObject * parent() const
std::string narrow(const std::locale &loc=std::locale()) const

Generated on Fri May 17 2024 for the C++ Web Toolkit (Wt) by doxygen 1.9.8