mirror of
https://github.com/pocoproject/poco.git
synced 2025-04-23 00:48:52 +02:00
fixed Imagebutton click event
This commit is contained in:
parent
6b3b3e852f
commit
5bd23e62b3
@ -168,7 +168,32 @@ public:
|
|||||||
const std::string& onSuccessJS,
|
const std::string& onSuccessJS,
|
||||||
const std::string& onFailureJS);
|
const std::string& onFailureJS);
|
||||||
|
|
||||||
|
template <typename T, typename CreateServerCallbackFct, typename Param>
|
||||||
|
static bool writeFunctionCode(std::ostream& out, const std::string& varName, const JavaScriptEvent<T>& ev, CreateServerCallbackFct fct, const Param* p)
|
||||||
|
{
|
||||||
|
if (!ev.hasJavaScriptCode())
|
||||||
|
return false;
|
||||||
|
if (ev.willDoServerCallback())
|
||||||
|
return writeFunctionCode(out, varName, ev.jsDelegates(), (*fct)(p), ev.getServerCallbackPos());
|
||||||
|
return writeFunctionCode(out, varName, ev.jsDelegates());
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
static bool writeFunctionCode(std::ostream& out,
|
||||||
|
const std::string& varName,
|
||||||
|
const std::list<JSDelegate>& delegates,
|
||||||
|
const Poco::WebWidgets::JSDelegate& serverCallback,
|
||||||
|
std::size_t serverCallPos);
|
||||||
|
|
||||||
|
static bool writeFunctionCode(std::ostream& out,
|
||||||
|
const std::string& varName,
|
||||||
|
const std::list<JSDelegate>& delegates);
|
||||||
|
|
||||||
|
static std::list<JSDelegate> Utility::insertServerCallback(const std::list<JSDelegate>& delegates,
|
||||||
|
const Poco::WebWidgets::JSDelegate& serverCallback,
|
||||||
|
std::size_t serverCallPos);
|
||||||
|
|
||||||
|
|
||||||
static void convertPocoDateToPHPDate(char in, std::string& result);
|
static void convertPocoDateToPHPDate(char in, std::string& result);
|
||||||
static void convertPHPDateToPocoDate(char in, std::string& result);
|
static void convertPHPDateToPocoDate(char in, std::string& result);
|
||||||
static void escapeCharForPHP(char in, std::string& result);
|
static void escapeCharForPHP(char in, std::string& result);
|
||||||
|
@ -38,6 +38,7 @@
|
|||||||
#include "Poco/WebWidgets/ExtJS/FormRenderer.h"
|
#include "Poco/WebWidgets/ExtJS/FormRenderer.h"
|
||||||
#include "Poco/WebWidgets/ExtJS/Utility.h"
|
#include "Poco/WebWidgets/ExtJS/Utility.h"
|
||||||
#include "Poco/WebWidgets/ImageButtonCell.h"
|
#include "Poco/WebWidgets/ImageButtonCell.h"
|
||||||
|
#include "Poco/WebWidgets/ImageButton.h"
|
||||||
|
|
||||||
|
|
||||||
namespace Poco {
|
namespace Poco {
|
||||||
@ -95,11 +96,20 @@ void ImageButtonCellRenderer::writeHTML(const ImageButtonCell* pButtonCell, bool
|
|||||||
std::string tooltip = ptrImg->getToolTip();
|
std::string tooltip = ptrImg->getToolTip();
|
||||||
if (!tooltip.empty())
|
if (!tooltip.empty())
|
||||||
ostr << " alt=\"" << Utility::safe(tooltip) << "\"";
|
ostr << " alt=\"" << Utility::safe(tooltip) << "\"";
|
||||||
|
const Poco::WebWidgets::ImageButton* pOwner = static_cast<const Poco::WebWidgets::ImageButton*>(pButtonCell->getOwner());
|
||||||
|
poco_check_ptr (pOwner);
|
||||||
|
if (pOwner->buttonClicked.hasJavaScriptCode())
|
||||||
|
{
|
||||||
|
ostr << " onclick=\"";
|
||||||
|
//FIXME: this will only work without params!
|
||||||
|
Utility::writeFunctionCode(ostr, "fct", pOwner->buttonClicked, &ButtonCellRenderer::createClickServerCallback, pOwner);
|
||||||
|
ostr << "\"";
|
||||||
|
}
|
||||||
ostr << " type=\"image\"/>";
|
ostr << " type=\"image\"/>";
|
||||||
ostr << "</div>";
|
ostr << "</div>";
|
||||||
std::string txt(pButtonCell->getOwner()->getText());
|
std::string txt(pOwner->getText());
|
||||||
if (showTxt && !txt.empty())
|
if (showTxt && !txt.empty())
|
||||||
ostr << "<div>" << Utility::safe(pButtonCell->getOwner()->getText()) << "</div>";
|
ostr << "<div><center>" << Utility::safe(pButtonCell->getOwner()->getText()) << "</center></div>";
|
||||||
ostr << "</div>'";
|
ostr << "</div>'";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -428,15 +428,59 @@ bool Utility::writeJSEvent(std::ostream& out, const std::string& eventName, cons
|
|||||||
out << "'" << eventName << "':{";
|
out << "'" << eventName << "':{";
|
||||||
|
|
||||||
if (delegates.size() == 1)
|
if (delegates.size() == 1)
|
||||||
out << "fn:" << delegates.begin()->jsCode() << "";
|
out << "fn:" << delegates.begin()->jsCode();
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// rather simple way to support more than one delegate
|
// rather simple way to support more than one delegate
|
||||||
std::ostringstream invoke;
|
std::ostringstream invoke;
|
||||||
int maxParams = detectMaxParamCount(delegates);
|
int maxParams = detectMaxParamCount(delegates);
|
||||||
std::string fct(createFunctionSignature(maxParams));
|
std::string fct(createFunctionSignature(maxParams));
|
||||||
out << "fn:" << fct << "{var all={";
|
out << "fn:" << fct << "{";
|
||||||
|
writeFunctionCode(out, "all", delegates);
|
||||||
|
out << "}"; //closes fn
|
||||||
|
|
||||||
|
}
|
||||||
|
if (delayTime > 0)
|
||||||
|
{
|
||||||
|
if (!group)
|
||||||
|
out << ",delay:" << delayTime;
|
||||||
|
else
|
||||||
|
out << ",buffer:" << delayTime;
|
||||||
|
}
|
||||||
|
out << "}"; //closes outer fn
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool Utility::writeFunctionCode(std::ostream& out,
|
||||||
|
const std::string& varName,
|
||||||
|
const std::list<JSDelegate>& delegates,
|
||||||
|
const Poco::WebWidgets::JSDelegate& serverCallback,
|
||||||
|
std::size_t serverCallPos)
|
||||||
|
{
|
||||||
|
return writeFunctionCode(out, varName, insertServerCallback(delegates, serverCallback, serverCallPos));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool Utility::writeFunctionCode(std::ostream& out,
|
||||||
|
const std::string& varName,
|
||||||
|
const std::list<JSDelegate>& delegates)
|
||||||
|
{
|
||||||
|
if (delegates.empty())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (delegates.size() == 1)
|
||||||
|
{
|
||||||
|
out << delegates.begin()->jsCode();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// rather simple way to support more than one delegate
|
||||||
|
std::ostringstream invoke;
|
||||||
|
int maxParams = detectMaxParamCount(delegates);
|
||||||
|
out << "var " << varName << "={";
|
||||||
// the invoke function calls all the other functions sequentially
|
// the invoke function calls all the other functions sequentially
|
||||||
|
std::string fct(createFunctionSignature(maxParams));
|
||||||
invoke << "invoke:" << fct <<"{";
|
invoke << "invoke:" << fct <<"{";
|
||||||
std::list<JSDelegate>::const_iterator it = delegates.begin();
|
std::list<JSDelegate>::const_iterator it = delegates.begin();
|
||||||
int cnt(0);
|
int cnt(0);
|
||||||
@ -464,7 +508,14 @@ bool Utility::writeJSEvent(std::ostream& out, const std::string& eventName, cons
|
|||||||
{
|
{
|
||||||
// a reference to another js function
|
// a reference to another js function
|
||||||
//maybe the user defined params too -> ignore them
|
//maybe the user defined params too -> ignore them
|
||||||
|
// more likely the user defined constant values!
|
||||||
|
if (params.empty())
|
||||||
out << fctName;
|
out << fctName;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
params.clear();
|
||||||
|
writeFunction(out, "function", params, it->jsCode());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -477,20 +528,9 @@ bool Utility::writeJSEvent(std::ostream& out, const std::string& eventName, cons
|
|||||||
}
|
}
|
||||||
|
|
||||||
invoke << "}";
|
invoke << "}";
|
||||||
out << invoke.str() << "};"; //closes all
|
out << invoke.str() << "};"; //closes varName
|
||||||
|
//FIXME: this will only work with no args when not called from writeJSEvent
|
||||||
out << "all." << createFunctionSignature("invoke", maxParams) << ";";
|
out << varName << "." << createFunctionSignature("invoke", maxParams) << ";";
|
||||||
out << "}"; //closes fn
|
|
||||||
|
|
||||||
}
|
|
||||||
if (delayTime > 0)
|
|
||||||
{
|
|
||||||
if (!group)
|
|
||||||
out << ",delay:" << delayTime;
|
|
||||||
else
|
|
||||||
out << ",buffer:" << delayTime;
|
|
||||||
}
|
|
||||||
out << "}"; //closes outer fn
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -502,6 +542,14 @@ bool Utility::writeJSEvent(std::ostream& out,
|
|||||||
std::size_t serverCallPos,
|
std::size_t serverCallPos,
|
||||||
int delayTime,
|
int delayTime,
|
||||||
bool group)
|
bool group)
|
||||||
|
{
|
||||||
|
return writeJSEvent(out, eventName, insertServerCallback(delegates, serverCallback, serverCallPos), delayTime, group);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
std::list<JSDelegate> Utility::insertServerCallback(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
|
// TODO: we can optimize here a bit by avoiding the copy
|
||||||
std::list<JSDelegate> dels;
|
std::list<JSDelegate> dels;
|
||||||
@ -518,7 +566,8 @@ bool Utility::writeJSEvent(std::ostream& out,
|
|||||||
}
|
}
|
||||||
if (!written)
|
if (!written)
|
||||||
dels.push_back(serverCallback);
|
dels.push_back(serverCallback);
|
||||||
return writeJSEvent(out, eventName, dels, delayTime, group);
|
|
||||||
|
return dels;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user