Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008 #include "Popup.h"
00009
00010 using namespace Wt;
00011
00012 Popup::Popup(Type t, const WString& message, std::string defaultValue,
00013 WObject *parent)
00014 : WObject(parent),
00015 okPressed_(this, "ok"),
00016 cancelPressed_(this, "cancel"),
00017 t_(t),
00018 message_(message),
00019 defaultValue_(defaultValue)
00020 {
00021 setJavaScript();
00022 }
00023
00024 void Popup::setJavaScript()
00025 {
00026
00027
00028
00029
00030
00031
00032
00033 switch (t_) {
00034 case Confirm:
00035 show.setJavaScript
00036 ("function(){ if (confirm('" + message_.narrow() + "')) {"
00037 + okPressed_.createCall("''") +
00038 "} else {"
00039 + cancelPressed_.createCall() +
00040 "}}");
00041 break;
00042 case Alert:
00043 show.setJavaScript
00044 ("function(){ alert('" + message_.narrow() + "');"
00045 + okPressed_.createCall("''") +
00046 "}");
00047 break;
00048 case Prompt:
00049 show.setJavaScript
00050 ("function(){var n = prompt('" + message_.narrow() + "', '"
00051 + defaultValue_ + "');"
00052 "if (n != null) {"
00053 + okPressed_.createCall("n") +
00054 "} else {"
00055 + cancelPressed_.createCall() +
00056 "}}");
00057 }
00058 }
00059
00060 void Popup::setMessage(const WString& message)
00061 {
00062 message_ = message;
00063 setJavaScript();
00064 }
00065
00066 void Popup::setDefaultValue(const std::string defaultValue)
00067 {
00068 defaultValue_ = defaultValue;
00069 setJavaScript();
00070 }
00071
00072 Popup *Popup::createConfirm(const WString& message, WObject *parent)
00073 {
00074 return new Popup(Confirm, message, std::string(), parent);
00075 }
00076
00077 Popup *Popup::createAlert(const WString& message, WObject *parent)
00078 {
00079 return new Popup(Alert, message, std::string(), parent);
00080 }
00081
00082 Popup *Popup::createPrompt(const WString& message,
00083 const std::string defaultValue, WObject *parent)
00084 {
00085 return new Popup(Prompt, message, defaultValue, parent);
00086 }