refactored JSEvents for easier server callbacks

This commit is contained in:
Peter Schojer
2008-06-09 09:09:02 +00:00
parent db640711d1
commit 515c64faea
15 changed files with 323 additions and 77 deletions

View File

@@ -479,6 +479,27 @@ bool Utility::writeJSEvent(std::ostream& out, const std::string& eventName, cons
}
bool Utility::writeJSEvent(std::ostream& out, const std::string& eventName, const std::list<JSDelegate>& delegates, const Poco::WebWidgets::JSDelegate& serverCallback, std::size_t serverCallPos)
{
// TODO: we can optimize here a bit by avoiding the copy
std::list<JSDelegate> dels;
std::list<JSDelegate>::const_iterator it = dels.begin();
bool written = false;
for (; it != dels.end(); ++it, --serverCallPos)
{
if (serverCallPos == 0)
{
dels.push_back(serverCallback);
written = true;
}
dels.push_back(*it);
}
if (!written)
dels.push_back(serverCallback);
return writeJSEvent(out, eventName, dels);
}
void Utility::writeFunction(std::ostream& out, const std::string& fctName, const std::vector<std::string> &params, const std::string& code)
{
out << fctName << "(";
@@ -583,6 +604,18 @@ std::string Utility::createCallbackFunctionCode(const std::string& signature, co
}
Poco::WebWidgets::JSDelegate Utility::createServerCallback(
const std::string& signature,
const std::map<std::string, std::string>& addServerParams,
Renderable::ID id,
const std::string& onSuccessJS,
const std::string& onFailureJS)
{
std::string code(createCallbackFunctionCode(signature, addServerParams, id, onSuccessJS, onFailureJS));
return (jsDelegate(code));
}
int Utility::detectMaxParamCount(const std::list<JSDelegate>& delegates)
{
int cnt = 0;