Wt examples
4.10.4
Loading...
Searching...
No Matches
javascript
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 bv, Herent, Belgium.
4
*
5
* See the LICENSE file for terms of use.
6
*/
7
8
#include <Wt/WAny.h>
9
10
#include "
Popup.h
"
11
12
using namespace
Wt
;
13
14
Popup::Popup
(
Type
t
,
const
WString
& message, std::string defaultValue)
15
: WObject(),
16
okPressed_(
this
,
"ok"
),
17
cancelPressed_(
this
,
"cancel"
),
18
t_(
t
),
19
message_(message),
20
defaultValue_(defaultValue)
21
{
22
setJavaScript
();
23
}
24
25
void
Popup::setJavaScript
()
26
{
27
/*
28
* Sets the JavaScript code.
29
*
30
* Notice how Wt.emit() is used to emit the okPressed or cancelPressed
31
* signal, and how arguments may be passed to it, matching the number and
32
* type of arguments in the JSignal definition.
33
*/
34
switch
(
t_
) {
35
case
Confirm
:
36
show
.setJavaScript
37
(
"function(){ if (confirm('"
+
message_
.narrow() +
"')) {"
38
+
okPressed_
.createCall({
"''"
}) +
39
"} else {"
40
+
cancelPressed_
.createCall({}) +
41
"}}"
);
42
break
;
43
case
Alert
:
44
show
.setJavaScript
45
(
"function(){ alert('"
+
message_
.narrow() +
"');"
46
+
okPressed_
.createCall({
"''"
}) +
47
"}"
);
48
break
;
49
case
Prompt
:
50
show
.setJavaScript
51
(
"function(){var n = prompt('"
+
message_
.narrow() +
"', '"
52
+
defaultValue_
+
"');"
53
"if (n != null) {"
54
+
okPressed_
.createCall({
"n"
}) +
55
"} else {"
56
+
cancelPressed_
.createCall({}) +
57
"}}"
);
58
}
59
}
60
61
void
Popup::setMessage
(
const
WString
& message)
62
{
63
message_
=
message
;
64
setJavaScript
();
65
}
66
67
void
Popup::setDefaultValue
(
const
std::string defaultValue)
68
{
69
defaultValue_
=
defaultValue
;
70
setJavaScript
();
71
}
72
73
std::unique_ptr<Popup>
Popup::createConfirm
(
const
WString
& message)
74
{
75
return
std::make_unique<Popup>(
Type::Confirm
,
message
, std::string());
76
}
77
78
std::unique_ptr<Popup>
Popup::createAlert
(
const
WString
& message)
79
{
80
return
std::make_unique<Popup>(
Type::Alert
,
message
, std::string());
81
}
82
83
std::unique_ptr<Popup>
Popup::createPrompt
(
const
WString
& message,
84
const
std::string defaultValue)
85
{
86
return
std::make_unique<Popup>(
Type::Prompt
,
message
,
defaultValue
);
87
}
Popup.h
UserDatabase
Wt::Auth::Dbo::UserDatabase< AuthInfo > UserDatabase
Definition
Session.h:22
Popup::setMessage
void setMessage(const WString &message)
Change the message.
Definition
Popup.C:61
Popup::cancelPressed_
JSignal cancelPressed_
Definition
Popup.h:89
Popup::createConfirm
static std::unique_ptr< Popup > createConfirm(const WString &message)
Create a confirm dialog.
Definition
Popup.C:73
Popup::defaultValue
const std::string & defaultValue() const
Get the default value for a prompt dialog.
Definition
Popup.h:70
Popup::show
JSlot show
Show the dialog.
Definition
Popup.h:77
Popup::Popup
Popup(Type t, const WString &message, const std::string defaultValue)
Popup constructor.
Definition
Popup.C:14
Popup::t_
Type t_
Definition
Popup.h:91
Popup::createAlert
static std::unique_ptr< Popup > createAlert(const WString &message)
Create an alert dialog.
Definition
Popup.C:78
Popup::message_
WString message_
Definition
Popup.h:92
Popup::setDefaultValue
void setDefaultValue(const std::string defaultValue)
Change the default value for a prompt dialog.
Definition
Popup.C:67
Popup::message
const WString & message() const
Get the current message.
Definition
Popup.h:66
Popup::createPrompt
static std::unique_ptr< Popup > createPrompt(const WString &message, const std::string defaultValue)
Create a prompt dialog with the given default value.
Definition
Popup.C:83
Popup::defaultValue_
std::string defaultValue_
Definition
Popup.h:93
Popup::Type
Type
Popup type.
Definition
Popup.h:37
Popup::Alert
@ Alert
Definition
Popup.h:37
Popup::Prompt
@ Prompt
Definition
Popup.h:37
Popup::Confirm
@ Confirm
Definition
Popup.h:37
Popup::okPressed_
JSignal< std::string > okPressed_
Definition
Popup.h:88
Popup::setJavaScript
void setJavaScript()
Update the javascript code.
Definition
Popup.C:25
Wt
Definition
AddresseeEdit.h:16
Generated on Tue Mar 26 2024 for
the C++ Web Toolkit (Wt)
by
1.10.0