예제 #1
0
파일: Main.cpp 프로젝트: runya-v/run
        /*!
         * \brief Конструктор класса сайта.
         * \param[in] Класс хранения окружения сайта
         */
        CompanyesApplication(const Wt::WEnvironment& env)
            : Wt::WApplication(env)
        {
            this->messageResourceBundle().use(this->appRoot() + "rus_locale");
            this->useStyleSheet(this->appRoot() + "main.css");
            this->setTitle(Wt::WString::tr("Title"));

            Wt::WApplication *app = Wt::WApplication::instance();
            app->setLoadingIndicator(new Wt::WOverlayLoadingIndicator());
            app->styleSheet().addRule("body", "margin: 0px");

            Wt::WStackedWidget* contents = new Wt::WStackedWidget();
            contents->setOverflow(Wt::WContainerWidget::OverflowAuto);
            contents->setPositionScheme(Wt::Relative);

            Wt::WMenu* menu = new Wt::WMenu(contents, Wt::Vertical, 0);
            menu->setRenderAsList(true);
            menu->setStyleClass("menu");

            std::string absolute_path = boost::filesystem::system_complete(boost::filesystem::path(".")).string();
            new RegionsCreator(absolute_path, contents, menu);

            Wt::WHBoxLayout* hlayout = new Wt::WHBoxLayout();
            hlayout->addWidget(menu, 0);
            hlayout->addWidget(contents, 1);

            Wt::WVBoxLayout* vlayout = new Wt::WVBoxLayout(this->root());
            vlayout->addWidget(new Wt::WText(Wt::WString::tr("Header")), 0);
            vlayout->addLayout(hlayout, 1);
        }
예제 #2
0
파일: SocketNotifier.C 프로젝트: DTidd/wt
Wt::WApplication *createApplication(const Wt::WEnvironment& env)
{
  Wt::WApplication *app = new Wt::WApplication(env);
  new RssReader(app->root());

  return app;
}
예제 #3
0
void Extension::handleURLChange() {
    // Find the page
    IGui* gui = IGui::instance();
    Wt::WApplication* app = Wt::WApplication::instance();
    std::string pageName = "/";
    std::string action = "view";
    if (app->internalPathMatches("/page/")) {
        pageName = app->internalPathNextPart("/page/");
        std::string pagePath = "/page/" + pageName + "/";
        if (app->internalPathMatches(pagePath))
            action = app->internalPathNextPart(pagePath);
    }
    dbo::Session& s = dbSession();
    dbo::Transaction t(s);
    dbo::ptr<Model> page = s.find<Model>().where("name=?").bind(pageName);
    // Use it
    if (page) {
        ActionMap::const_iterator found = actionMap.find(action);
        if (found != actionMap.end()) {
            ((this)->*(found->second))(*page); // Call the action .. view/edit etc..
        } else {
            Wt::WApplication::instance()->log("ERROR") <<
                    "No valid action for page " << page->getName() << " - " <<
                    "Action name " << action;
            // Default to view maybe ?
            gui->setBody("ERROR: No such action " + action );
        }
    } else {
        gui->setBody("PAGE NOT FOUND: " + pageName);
    }
    t.commit();
}
예제 #4
0
파일: Popup.cpp 프로젝트: yvanvds/wtMapbox
  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());
  }
예제 #5
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() + ");" );
 }
void SurveySelector::startSurvey() {
	std::cout << "Hello " << user_->text() << ", please fill in " << surveys_->currentText() << std::endl;
	Wt::WApplication *app = Wt::WApplication::instance();
	std::string path("/fill/");
	path.append(user_->text().toUTF8());
	path.append("/");
	path.append(surveys_->currentText().toUTF8());
	app->setInternalPath(path, true);
}
예제 #7
0
파일: core.cpp 프로젝트: Beliaf/leechcraft
Wt::WApplication* Core::CreateApplication (const Wt::WEnvironment& e)
{
	Wt::WApplication *result = new Wt::WApplication (e);
	result->setTitle ("LeechCraft");

	Interface *interface = new Interface (result, e);

	return result;
}
예제 #8
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()");
}
예제 #9
0
YahooStockHistory::GotCSVSignal& YahooStockHistory::query(const std::string& query)
{
     std::string url = "http://ichart.yahoo.com/table.csv?";
     url += query;
     Wt::WApplication* app = Wt::WApplication::instance();
     app->log("info") << "Sending query: " << url << "\n";
     if (http->get(url)) {
          return http->done();
     }
     throw std::runtime_error("Couldn't connect to http");
};
예제 #10
0
void Table::sendToAll() {
    // TODO: Mutex lock?
    std::cout << "sending " << test << " to " << clients.length() << std::endl;
    Wt::WApplication *app = Wt::WApplication::instance();

    foreach(TableView* i, clients) {
        if (app && app->sessionId() == i->sessionId())
            i->updateNumber(test);
        else
            m_server.post(i->sessionId(), boost::bind(&TableView::updateNumber, i, test));
    }
}
예제 #11
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();
     }
 }
예제 #12
0
/* ****************************************************************************
 * Set Cookie
 */
void SetCookie(std::string name, std::string myValue)
{
    Wt::WApplication *app = Wt::WApplication::instance();
    try
    {
        app->setCookie(name, myValue, 150000, "", "/", false);
    }
    catch (std::exception& e)
    {
        std::cerr << e.what() << std::endl;
        std::cerr << "WittyWizard::SetCookie: Failed writting cookie: " << name;
        Wt::log("error") << "WittyWizard::SetCookie()  Failed writting cookie: " << name;
    }
} // end void WittyWizard::SetCookie
예제 #13
0
/* ****************************************************************************
 * Menu Manager Session
 * appPath:
 * useDb:
 * lang: FIXME: default|lang1|lang2|lang3
 * connectionPool:
 */
MenuManSession::MenuManSession(const std::string& appPath, const std::string& useDb, const std::string& lang, Wt::Dbo::SqlConnectionPool& connectionPool) : appPath_(appPath), useDb_(useDb), lang_(lang), connectionPool_(connectionPool)
{
    if (useDb == "1")
    {
        setConnectionPool(connectionPool_);
        mapClass<MenuMan>("menuman"); // table name menuman
        Wt::WApplication* app = Wt::WApplication::instance();
        std::string path = app->internalPath(); // /lang/menuman/
        bool doXmlUpdate = false;
        // FIXME add security for logon or certificate
        // hard code /admin/menuman/updatexml for admin work
        if (path.find("/admin/menuman/updatexml") != std::string::npos) { doXmlUpdate = true; }
        //Wt::log("start") << " *** MenuManSession::MenuManSession() useDb | path = " << path << " | doXmlUpdate = " << doXmlUpdate << " *** ";
        if (CrystalBall::InitDb || doXmlUpdate)
        {
            try
            {
                Wt::Dbo::Transaction t(*this);
                // Note: you must drop table to do update
                if (doXmlUpdate)
                {
                    Wt::log("warning") << "MenuManSession::MenuManSession() SQL Drop Table menuman";
                    dropTables();
                }
                createTables();
                Wt::log("warning") << "Created database: menuman ";
                if (!ImportXML())
                {
                    Wt::log("error") << " *** MenuManSession::MenuManSession() ImportXML failed! *** ";
                    return;
                }
                t.commit();
            }
            catch (std::exception& e)
            {
                Wt::log("warning") << " *** MenuManSession::MenuManSession()  Using existing menuman database = " << e.what();
            }
        }
    } // end if (useDb == "1")
    //Wt::log("end") << " *** MenuManSession::MenuManSession() *** ";
} // end MenuManSession
예제 #14
0
/* ****************************************************************************
 * Get Hits
 */
std::string HitCounterManImpl::GetHits()
{
    // Create an instance of app to access Internal Paths
    Wt::WApplication* app = Wt::WApplication::instance();
    try
    {
        // Start a Transaction
        Wt::Dbo::Transaction t(session_);

        hits = session_.query<int>("select count(*) from hitcounterman").where("page = ?").bind(app->internalPath());
        //Wt::log("notice") << "HitCounterManImpl::GetHits()  hits = " << hits << " | page = " << app->internalPath();

        // Commit Transaction
        t.commit();    }
    catch (std::exception& e)
    {
        std::cerr << e.what() << std::endl;
        //Wt::log("error") << "HitCounterManImpl::GetHits()  Failed reading from hitcounterman database.";
        hits = 0;
    }

    try
    {
        Wt::WLocale myString = Wt::WLocale(theLocale.c_str());
        // Note: this only works if you set the Separator, use case to set it
        myString.setGroupSeparator(",");
        std::string myReturn = myString.toString(hits).toUTF8();
        return myReturn;
        /*
         * This requires locale to be installed and configured on server
        std::stringstream ss;
        ss.imbue(std::locale(theLocale.c_str()));
        ss << std::fixed << hits;
        return ss.str();
        */
    }
    catch (std::exception& e)
    {
        std::cerr << e.what() << std::endl;
        std::cerr << "HitCounterManImpl::GetHits: Failed local not installed";
        Wt::log("error") << "HitCounterManImpl::GetHits() Failed local not installed";
    }

    return std::to_string(hits);
} // end GetHits
예제 #15
0
/* ****************************************************************************
 * Set
 */
void HitCounterManImpl::Set()
{
    // Create an instance of app to access Internal Paths
    Wt::WApplication* app = Wt::WApplication::instance();
    try
    {
        // Start a Transaction
        Wt::Dbo::Transaction t(session_);
        HitCounterMans myHitCounterMan = session_.find<HitCounterMan>();
        //
        hits = myHitCounterMan.size();
        //
        // Commit Transaction
        t.commit();
    }
    catch (std::exception& e)
    {
        std::cerr << e.what() << std::endl;
        std::cerr << "HitCounterManImpl::Update: Failed reading from hitcounterman database";
        Wt::log("error") << "HitCounterManImpl::Update()  Failed reading from hitcounterman database";
    }

    try
    {
        // Start a Transaction
        Wt::Dbo::Transaction t(session_);
        //
        uniqueHits = session_.query<int>("select COUNT(distinct ipaddress) from hitcounterman").where("page = ?").bind(app->internalPath());;
        // Commit Transaction
        t.commit();
    }
    catch (std::exception& e)
    {
        std::cerr << e.what() << std::endl;
        std::cerr << "HitCounterManImpl::Update: Failed reading from hitcounterman database";
        Wt::log("error") << "HitCounterManImpl::Update()  Failed reading from hitcounterman database";
    }

} // end
예제 #16
0
파일: main.C 프로젝트: GuLinux/wt
Wt::WApplication *createApplication(const Wt::WEnvironment& env)
{
  Wt::WApplication* app = new Wt::WApplication(env);

  if (app->appRoot().empty()) {
    std::cerr << "!!!!!!!!!!" << std::endl
	      << "!! Warning: read the README.md file for hints on deployment,"
	      << " the approot looks suspect!" << std::endl
	      << "!!!!!!!!!!" << std::endl;
  }

  // Choice of theme: defaults to bootstrap3 but can be overridden using
  // a theme parameter (for testing)
  const std::string *themePtr = env.getParameter("theme");
  std::string theme;
  if (!themePtr)
    theme = "bootstrap3";
  else
    theme = *themePtr;

  if (theme == "bootstrap3") {
    Wt::WBootstrapTheme *bootstrapTheme = new Wt::WBootstrapTheme(app);
    bootstrapTheme->setVersion(Wt::WBootstrapTheme::Version3);
    app->setTheme(bootstrapTheme);

    // load the default bootstrap3 (sub-)theme
    app->useStyleSheet("resources/themes/bootstrap/3/bootstrap-theme.min.css");
  } else if (theme == "bootstrap2") {
    Wt::WBootstrapTheme *bootstrapTheme = new Wt::WBootstrapTheme(app);
    app->setTheme(bootstrapTheme);
  } else
    app->setTheme(new Wt::WCssTheme(theme));


  // load text bundles (for the tr() function)
  app->messageResourceBundle().use(app->appRoot() + "report");
  app->messageResourceBundle().use(app->appRoot() + "text");
  app->messageResourceBundle().use(app->appRoot() + "src");
 
  Wt::WHBoxLayout *layout = new Wt::WHBoxLayout(app->root());
  layout->setContentsMargins(0, 0, 0, 0);
  layout->addWidget(new WidgetGallery());

  app->setTitle("Wt Widget Gallery");

  app->useStyleSheet("style/everywidget.css");
  app->useStyleSheet("style/dragdrop.css");
  app->useStyleSheet("style/combostyle.css");
  app->useStyleSheet("style/pygments.css");

  return app;
}
예제 #17
0
void WCssDecorationStyle::updateDomElement(DomElement& element, bool all)
{
  /*
   * set cursor
   */
  if (cursorChanged_ || all) {
    switch (cursor_) {
    case AutoCursor:
      if (cursorChanged_)
	element.setProperty(PropertyStyleCursor, "auto");
      break;
    case ArrowCursor:
      element.setProperty(PropertyStyleCursor, "default"); break;
    case CrossCursor:
      element.setProperty(PropertyStyleCursor, "crosshair"); break;
    case PointingHandCursor:
      element.setProperty(PropertyStyleCursor, "pointer"); break;
    case OpenHandCursor:
      element.setProperty(PropertyStyleCursor, "move"); break;
    case WaitCursor:
      element.setProperty(PropertyStyleCursor, "wait"); break;
    case IBeamCursor:
      element.setProperty(PropertyStyleCursor, "text"); break;
    case WhatsThisCursor:
      element.setProperty(PropertyStyleCursor, "help"); break;
    }

    if (!cursorImage_.empty()) {
      element.setProperty(PropertyStyleCursor, 
			  "url(" + cursorImage_ + "),"
			  + element.getProperty(PropertyStyleCursor));
    }

    cursorChanged_ = false;
  }

  /*
   * set font
   */
  font_.updateDomElement(element, fontChanged_, all);
  fontChanged_ = false;

  /*
   * set border
   */
  Property properties[4] 
    = { PropertyStyleBorderTop,
	PropertyStyleBorderRight,
	PropertyStyleBorderBottom,
	PropertyStyleBorderLeft };

  if (borderChanged_ || all) {
    for (unsigned i = 0; i < 4; ++i) {
      if (border_[i])
	element.setProperty(properties[i], border_[i]->cssText());
      else if (borderChanged_)
	element.setProperty(properties[i], "");
    }

    borderChanged_ = false;
  }

  /*
   * set colors
   */
  if (foregroundColorChanged_ || all) {
    if ((all && !foregroundColor_.isDefault())
	|| foregroundColorChanged_)
      element.setProperty(PropertyStyleColor, foregroundColor_.cssText());
    foregroundColorChanged_ = false;
  }

  if (backgroundColorChanged_ || all) {
    if ((all && !backgroundColor_.isDefault()) ||
	backgroundColorChanged_)
      element.setProperty(PropertyStyleBackgroundColor,
			  backgroundColor_.cssText());
    backgroundColorChanged_ = false;
  }

  if (backgroundImageChanged_ || all) {
    if (!backgroundImage_.isNull() || backgroundImageChanged_) {
      if (backgroundImage_.isNull())
	element.setProperty(PropertyStyleBackgroundImage, "none");
      else {
	Wt::WApplication *app = Wt::WApplication::instance();

	std::string url = app->encodeUntrustedUrl
	  (app->resolveRelativeUrl(backgroundImage_.url()));

	element.setProperty(PropertyStyleBackgroundImage,
			    "url(" + WWebWidget::jsStringLiteral(url, '"')
			    + ")");
      }

      if (backgroundImageRepeat_ != RepeatXY ||
	  backgroundImageLocation_ != 0) {
	switch (backgroundImageRepeat_) {
	case RepeatXY:
	  element.setProperty(PropertyStyleBackgroundRepeat, "repeat");
	  break;
	case RepeatX:
	  element.setProperty(PropertyStyleBackgroundRepeat, "repeat-x");
	  break;
	case RepeatY:
	  element.setProperty(PropertyStyleBackgroundRepeat, "repeat-y");
	  break;
	case NoRepeat:
	  element.setProperty(PropertyStyleBackgroundRepeat, "no-repeat");
	  break;
	}

	if (backgroundImageLocation_) {
	  // www3schools claims this is needed for mozilla -- but not true ?
	  //element.setProperty(PropertyStyleBackgroundAttachment, "fixed");

	  std::string location;
	  if (backgroundImageLocation_ & CenterY)
	    location += " center";
	  else if (backgroundImageLocation_ & Bottom)
	    location += " bottom";
	  else
	    location += " top";

	  if (backgroundImageLocation_ & CenterX)
	    location += " center";
	  else if (backgroundImageLocation_ & Right)
	    location += " right";
	  else 
	    location += " left";

	  element.setProperty(PropertyStyleBackgroundPosition, location);
	}
      }
    }

    backgroundImageChanged_ = false;
  }

  if (textDecorationChanged_ ||  all) {
    std::string options;

    if (textDecoration_ & Underline)
      options += " underline";
    if (textDecoration_ & Overline)
      options += " overline";
    if (textDecoration_ & LineThrough)
      options += " line-through";
    if (textDecoration_ & Blink)
      options += " blink";

    if (!options.empty() || textDecorationChanged_)
      element.setProperty(PropertyStyleTextDecoration, options);

    textDecorationChanged_ = false;
  }
}