Exemple #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());
  }
Exemple #2
0
Wt::WString TopicWidget::reindent(const Wt::WString& text)
{
  std::vector<std::string> lines;
  std::string s = text.toUTF8();
  boost::split(lines, s, boost::is_any_of("\n"));

  std::string result;
  int indent = -1;
  int newlines = 0;
  for (unsigned i = 0; i < lines.size(); ++i) {
    const std::string& line = lines[i];

    if (line.empty()) {
      ++newlines;
    } else {
      if (indent == -1) {
        indent = countSpaces(line);
      } else {
        for (int j = 0; j < newlines; ++j)
          result += '\n';
      }

      newlines = 0;

      if (!result.empty())
        result += '\n';

      result += skipSpaces(line, indent);
    }
  }
  return Wt::WString::fromUTF8(result);
}
Exemple #3
0
 void set_query() {
     dbo::Transaction t(tApp->session());
     ULP::Q q;
     if (only_blocked_) {
         q = tApp->session().query<UserPtr>(
                 "select U from thechess_message_filter F "
                 "left join thechess_user U on F.bad_id = U.id");
         q.where("F.good_id = ?").bind(tApp->user());
     } else {
         q = tApp->session().find<User>();
     }
     if (not_removed_) {
         q.where("rights != ?").bind(NONE);
         q.where("vacation_until is null");
         q.where("last_online > ?").bind(now() - 10 * WEEK);
     }
     if (only_online_) {
         q.where("last_online >= ?");
         q.bind(now() - Options::instance()->away_timeout());
     }
     if (!name_like_.empty()) {
         q.where("(username like ? or id = ?)");
         q.bind("%" + name_like_ + "%");
         q.bind(Wt::Wc::str2int(name_like_.toUTF8()));
     }
     q.orderBy("games_stat_elo desc");
     setQuery(q, /* keep_columns */ true);
 }
Exemple #4
0
Wt::Auth::User RDAUserDatabase::findWithIdentity (const std::string &provider,
						  const Wt::WString &identity)
  const
{
	std::string i;
  /*
   * David: find the 'id' for a user with name _identity_, leave it
   * empty if no user with this name exists
   */

	if(SEC_USERS_FILENO==(-1))
	{
    		return Wt::Auth::User();
	}
	ZERNRD(SEC_USERS_FILENO);
	i=identity.toUTF8();
	USERLOGIN=stralloc(i.c_str());
	FINDFLDSETSTRING(SEC_USERS_FILENO,"USER IDENTIFICATION",USERLOGIN);
	if(EQLNRD(SEC_USERS_FILENO,1)) 
	{
		KEYNRD(SEC_USERS_FILENO,1);
    		return Wt::Auth::User();
	} else {
    		return Wt::Auth::User(i, *this);
	}
}
Exemple #5
0
void AbstractRPM::consoleAddData(const Wt::WString &computerName, const Wt::WString &data)
{
	Wt::WString date = Wt::WDate::currentServerDate().toString("yyyy/MM/dd");
	Wt::WString time = Wt::WTime::currentServerTime().toString("hh:mm:ss");
	std::string user = currentUser();
	Wt::WString header = date + "-" + time;
	if (!user.empty())
		header += ": " + user;
	Wt::WString entry = header + ": " + data + "\n";

	computerStateLock.lock();
	Wt::WString logs = entry + _computerLogs[computerName];
	logs = logs.toUTF8().substr(0, 1000);	/* limit to 1k */
	_computerLogs[computerName] = logs;
	computerStateLock.unlock();

	viewsLock.lock();
	std::map< std::string, View* >::iterator it;
	for (it = views.begin(); it != views.end(); ++it) {
		server->post((*it).first, boost::bind(&View::consoleDataAdded,
						      (*it).second, computerName,
						      entry));
	}
	viewsLock.unlock();
}
void CreatePostWidget::submitMessage()
{
    Wt::WString text = _messageTextArea->text();
    if(text == ""){
        // can use setEmptyText instead of this
        enterDefaultText();
    }else{
        PostMsg msg;
        uint32_t token;

        RsGxsId author = _idChooser->getSelectedId();
        if(author.isNull()){
            return;
        }
        msg.mMeta.mAuthorId = author;

        RsGxsGroupId targetWall = _wallChooser->getSelectedWallId();
        if(targetWall.isNull()){
            return;
        }
        // this is a trick:
        // use the group id to signal the wall the post should appear on
        msg.mMeta.mGroupId = targetWall;

        // todo: circle
        msg.mPostText = text.toUTF8();
        rsWall->createPost(token, msg);
    }
}
Exemple #7
0
 void Popup::doDelayedJavaScript(const Wt::WString & jscode) {
   if (isRendered()) {
     doJavaScript(jscode.toUTF8());
   }
   else {
     additions_.push_back(jscode);
   }
 }
Exemple #8
0
void ComputerView::consoleDataAdded(const Wt::WString &data)
{
	Wt::WString logs = data + _logs_edit->valueText();
	logs = logs.toUTF8().substr(0, 1000);	/* limit to 1k */
	_logs_edit->setValueText(logs);

	app->triggerUpdate();
}
Exemple #9
0
/* ****************************************************************************
 * asciidoc
 */
WString asciidoc(const Wt::WString& src)
{
    std::string srcFileName = tempFileName();
    std::string htmlFileName = tempFileName();

    {
        std::ofstream srcFile(srcFileName.c_str(), std::ios::out);
        std::string ssrc = src.toUTF8();
        srcFile.write(ssrc.c_str(), (std::streamsize)ssrc.length());
        srcFile.close();
    }

#if defined(ASCIIDOC_EXECUTABLE)
#define xstr(s) str(s)
#define str(s) #s
    std::string cmd = xstr(ASCIIDOC_EXECUTABLE);
#else
    std::string cmd = "asciidoc";
#endif
    std::string command = cmd + " -o " + htmlFileName + " -s " + srcFileName;

#ifndef WIN32
  /*
   * So, asciidoc apparently sends a SIGINT which is caught by its parent process..
   * So we have to temporarily ignore it.
   */
    struct sigaction newAction, oldAction;
    newAction.sa_handler = SIG_IGN;
    newAction.sa_flags = 0;
    sigemptyset(&newAction.sa_mask);
    sigaction(SIGINT, &newAction, &oldAction);
#endif
    bool ok = system(command.c_str()) == 0;
#ifndef WIN32
    sigaction(SIGINT, &oldAction, 0);
#endif

    WString result;

    if (ok)
    {
        result = WString::fromUTF8(readFileToString(htmlFileName));
    }
    else
    {
        result = WString::fromUTF8("<i>Could not execute asciidoc</i>");
    }
    unlink(srcFileName.c_str());
    unlink(htmlFileName.c_str());

    return result;
}
		Result validate(const Wt::WString& input) const
		{
			auto res = Wt::WValidator::validate(input);
			if (res.state() != Wt::ValidationState::Valid)
				return res;

			auto password = Config::instance().getString("upload-password", "");

			if (input.toUTF8() == password)
				return Result(Wt::ValidationState::Valid);

			return Result(Wt::ValidationState::Invalid, Wt::WString::tr("msg-bad-password"));
		}
Exemple #11
0
Wt::Json::Value saveFragments(MyTreeTableNode *root)
{ 
	Wt::Json::Value retVal = Wt::Json::Value(Wt::Json::ArrayType);
	Wt::Json::Array& ret = retVal; 
	Wt::WString name;
	name = root->text;	
	std::string str = name.toUTF8();
	str.erase(std::remove(str.begin(), str.end(), ' '), str.end()); //This removes whitespace
	if(str.length()<1)
	{
		name = Wt::WString("New Node");
	}
	if(root->childNodes().size()>0)
	{
		ret.push_back(Wt::Json::Value(Wt::WString("group")));
		ret.push_back(Wt::Json::Value(name));
		Wt::Json::Value out_children_value = Wt::Json::Value(Wt::Json::ArrayType);	
		Wt::Json::Array& out_children = out_children_value; 
		for(auto mynode:root->childNodes()) //I wonder, what order do we get these in?
		{
			out_children.push_back(saveFragments(dynamic_cast<MyTreeTableNode*>(mynode)));
		}

		ret.push_back(out_children_value);

	}
	else //TODO add room for annotations
	{
		ret.push_back(Wt::Json::Value(Wt::WString("fragment")));
		ret.push_back(Wt::Json::Value(name));
		long long start = root->startWidget->time();
		long long stop = root->stopWidget->time();
		//this->log("info")<< "Saving fragment "<<std::to_string(start) << "  "<<std::to_string(stop);
		ret.push_back(Wt::Json::Value(start));
		ret.push_back(Wt::Json::Value(stop));
	}
return retVal;
}