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 " Wt.emit('" + id() + "','" + okPressed.name() + "', '');"
00038 "} else {"
00039 " Wt.emit('" + id() + "','" + cancelPressed.name() + "');"
00040 "}}");
00041 break;
00042 case Alert:
00043 show.setJavaScript
00044 ("function(){ alert('" + message_.narrow() + "');"
00045 "Wt.emit('" + id() + "','" + okPressed.name() + "', '');}");
00046 break;
00047 case Prompt:
00048 show.setJavaScript
00049 ("function(){var n = prompt('" + message_.narrow() + "', '"
00050 + defaultValue_ + "');"
00051 "if (n != null) {"
00052 " Wt.emit('" + id() + "','" + okPressed.name() + "', n);"
00053 "} else {"
00054 " Wt.emit('" + id() + "','" + cancelPressed.name() + "');"
00055 "}}");
00056 }
00057 }
00058
00059 void Popup::setMessage(const WString& message)
00060 {
00061 message_ = message;
00062 setJavaScript();
00063 }
00064
00065 void Popup::setDefaultValue(const std::string defaultValue)
00066 {
00067 defaultValue_ = defaultValue;
00068 setJavaScript();
00069 }
00070
00071 Popup *Popup::createConfirm(const WString& message, WObject *parent)
00072 {
00073 return new Popup(Confirm, message, std::string(), parent);
00074 }
00075
00076 Popup *Popup::createAlert(const WString& message, WObject *parent)
00077 {
00078 return new Popup(Alert, message, std::string(), parent);
00079 }
00080
00081 Popup *Popup::createPrompt(const WString& message,
00082 const std::string defaultValue, WObject *parent)
00083 {
00084 return new Popup(Prompt, message, defaultValue, parent);
00085 }