Esempio n. 1
0
File: Home.C Progetto: GuLinux/wt
void Home::chatSetUser(const WString& userName)
{
  WApplication::instance()->doJavaScript
    ("if (window.chat && window.chat.emit) {"
     """try {"
     ""  "window.chat.emit(window.chat, 'login', "
     ""                    "" + userName.jsStringLiteral() + "); "
     """} catch (e) {"
     ""  "window.chatUser="******";"
     """}"
     "} else "
     """window.chatUser="******";");
}
Esempio n. 2
0
 void setText(const WString& text) {
   WApplication::instance()->doJavaScript
     (bufferText_->jsRef() + ".innerHTML="
      "'<pre class=\"prettyprint\">' + prettyPrintOne("
      + text.jsStringLiteral() + ", " + bufferText_->jsRef()
      + ") + '</pre>';");
 }
Esempio n. 3
0
void MessageBox::setText(const WString& text)
{
  text_ = text;
  if (!hidden_)
    WApplication::instance()
      ->doJavaScript(elRef() + ".updateText(" + text.jsStringLiteral() + ");");
}
Esempio n. 4
0
 /// Call this to push a server side validation result to the client side (complete with message)
 static void tellClient(WFormWidget* widget, const WString& value, Result validationResult) {
     widget->setJavaScriptMember("serverValidationResult",
      "{ value:" + value.jsStringLiteral() + ","
       "valid:" + (validationResult.state() == WValidator::Valid ? "true," : "false,") +
      "message:" + validationResult.message().jsStringLiteral() + "}");
     Wt::WApplication* app = Wt::WApplication::instance();
     app->doJavaScript( app->javaScriptClass() + ".WT.validate(" + widget->jsRef() + ");" );
 }
Esempio n. 5
0
void WFormWidget::setToolTip(const WString& text, TextFormat textFormat)
{
  WInteractWidget::setToolTip(text, textFormat);

  if (validator_ && textFormat == PlainText) {
    setJavaScriptMember("defaultTT", text.jsStringLiteral());
    validate();
  }
}
Esempio n. 6
0
std::string asJSLiteral(const boost::any& v, TextFormat textFormat)
{
  if (v.empty())
    return std::string("''");
  else if (v.type() == typeid(WString)) {
    WString s = boost::any_cast<WString>(v);

    bool plainText = false;
    if (textFormat == XHTMLText) {
      if (s.literal())
	plainText = !WWebWidget::removeScript(s);
    } else
      plainText = true;

    if (plainText && textFormat != XHTMLUnsafeText)
      s = WWebWidget::escapeText(s);

    return s.jsStringLiteral();
  } else if (v.type() == typeid(std::string)
	     || v.type() == typeid(const char *)) {
    WString s = v.type() == typeid(std::string) 
      ? WString::fromUTF8(boost::any_cast<std::string>(v))
      : WString::fromUTF8(boost::any_cast<const char *>(v));

    bool plainText;
    if (textFormat == XHTMLText)
      plainText = !WWebWidget::removeScript(s);
    else
      plainText = true;

    if (plainText && textFormat != XHTMLUnsafeText)
      s = WWebWidget::escapeText(s);

    return s.jsStringLiteral();
  } else if (v.type() == typeid(bool)) {
    bool b = boost::any_cast<bool>(v);
    return b ? "true" : "false";
  } else if (v.type() == typeid(WDate)) {
    const WDate& d = boost::any_cast<WDate>(v);

    return "new Date(" + boost::lexical_cast<std::string>(d.year())
      + ',' + boost::lexical_cast<std::string>(d.month() - 1)
      + ',' + boost::lexical_cast<std::string>(d.day())
      + ')';
  } else if (v.type() == typeid(WDateTime)) {
    const WDateTime& dt = boost::any_cast<WDateTime>(v);
    const WDate& d = dt.date();
    const WTime& t = dt.time();

    return "new Date(" + boost::lexical_cast<std::string>(d.year())
      + ',' + boost::lexical_cast<std::string>(d.month() - 1)
      + ',' + boost::lexical_cast<std::string>(d.day())
      + ',' + boost::lexical_cast<std::string>(t.hour())
      + ',' + boost::lexical_cast<std::string>(t.minute())
      + ',' + boost::lexical_cast<std::string>(t.second())
      + ',' + boost::lexical_cast<std::string>(t.msec())
      + ')';
  }

#define ELSE_LEXICAL_ANY(TYPE) \
  else if (v.type() == typeid(TYPE)) \
    return boost::lexical_cast<std::string>(boost::any_cast<TYPE>(v))

  ELSE_LEXICAL_ANY(short);
  ELSE_LEXICAL_ANY(unsigned short);
  ELSE_LEXICAL_ANY(int);
  ELSE_LEXICAL_ANY(unsigned int);
  ELSE_LEXICAL_ANY(long);
  ELSE_LEXICAL_ANY(unsigned long);
  ELSE_LEXICAL_ANY(::int64_t);
  ELSE_LEXICAL_ANY(::uint64_t);
  ELSE_LEXICAL_ANY(long long);
  ELSE_LEXICAL_ANY(unsigned long long);
  ELSE_LEXICAL_ANY(float);
  ELSE_LEXICAL_ANY(double);

#undef ELSE_LEXICAL_ANY

  else {