Wt examples  3.3.0
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 
10 using namespace Wt;
11 
12 Popup::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 {
21  setJavaScript();
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 
60 void Popup::setMessage(const WString& message)
61 {
62  message_ = message;
63  setJavaScript();
64 }
65 
66 void Popup::setDefaultValue(const std::string defaultValue)
67 {
69  setJavaScript();
70 }
71 
72 Popup *Popup::createConfirm(const WString& message, WObject *parent)
73 {
74  return new Popup(Confirm, message, std::string(), parent);
75 }
76 
77 Popup *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 }

Generated on Fri May 31 2013 for the C++ Web Toolkit (Wt) by doxygen 1.8.3.1