Example #1
0
  void Popup::render(Wt::WFlags<Wt::RenderFlag> flags) {
    Wt::WApplication * app = Wt::WApplication::instance();
    Wt::WString initFunction = app->javaScriptClass() + ".init_popup_" + id();

    Wt::WStringStream stream;
    stream
      << "{" << initFunction.toUTF8() << " = function() {"
      << "  var self = " << jsRef() << ";"
      << "  if (!self) {"
      << "    setTimeout(" << initFunction.toUTF8() << ", 0);"
      << "  }";

    stream
      << "  self.popup = new mapboxgl.Popup( {"
      << "    closeButton: " << ToScript(closeButton_).toUTF8() << ", "
      << "    closeOnClick: " << ToScript(closeOnClick_).toUTF8() << ", "
      << "    anchor: " << ToScript(anchor_).toUTF8()
      << "  });";

    for (unsigned int i = 0; i < additions_.size(); i++) {
      stream << additions_[i].toUTF8();
    }
    additions_.clear();

    stream
      << "  setTimeout(function(){ delete " << initFunction.toUTF8() << ";}, 0)};\n"
      << "}\n"
      << initFunction.toUTF8() << "();\n";

    app->doJavaScript(stream.str());
  }
Example #2
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() + ");" );
 }
Example #3
0
void MainWindow::toggleTheme() {
    Wt::WApplication* app = Wt::WApplication::instance(); // Get the Wt::WApplication intstance for our thread
    std::string oldTheme = app->cssTheme();
    std::string newTheme = oldTheme == "default" ? "polished" : "default";
    app->setCssTheme(newTheme); // Toggle the theme between 'default' and 'polished'
    _btnToggleTheme->setText("Change to " + oldTheme);
    // Make the client reload the css
    app->doJavaScript(app->javaScriptClass() + ".updateStyles()");
}
Example #4
0
 /// Validates the widget and passes the message on to the browser
 static Result validateWidgetAndTellBrowser(WFormWidget* widget) {
     ServerSideValidator* validator = dynamic_cast<ServerSideValidator*>(widget->validator());
     if (validator != 0) {
         WString value = getValue(widget);
         Result result = validator->validate(value);
         tellClient(widget, value, result);
         return result;
     } else {
         Wt::WApplication* app = Wt::WApplication::instance();
         app->doJavaScript( app->javaScriptClass() + ".WT.validate(" + widget->jsRef() + ");" );
         return widget->validate();
     }
 }