mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-14 15:05:35 +02:00
fixes to events
This commit is contained in:
@@ -57,7 +57,7 @@ void CollapsibleRenderer::writeProperties(const Frame* pFrame, std::ostream& ost
|
||||
{
|
||||
const Collapsible* pC = static_cast<const Collapsible*>(pFrame);
|
||||
FrameRenderer::writeProperties(pFrame, ostr);
|
||||
ostr << ",collapsible:true,titleCollapse:true, header:true,collapsed:" << (pC->getCollapse()?"true":"false");
|
||||
ostr << ",collapsible:true,titleCollapse:true, collapsed:" << (pC->getCollapse()?"true":"false");
|
||||
}
|
||||
|
||||
|
||||
|
@@ -84,26 +84,40 @@ void TableRenderer::renderProperties(const Table* pTable, const RenderContext& c
|
||||
WebApplication& app = WebApplication::instance();
|
||||
Renderable::ID id = app.getCurrentPage()->id();
|
||||
Utility::writeRenderableProperties(pTable, ostr);
|
||||
static const std::string afterEdit("afterEdit");
|
||||
static const std::string afterEdit("afteredit");
|
||||
static const std::string cellClicked("cellclick");
|
||||
std::map<std::string, std::string> addParams;
|
||||
addParams.insert(std::make_pair(Table::FIELD_COL, "+obj.column"));
|
||||
addParams.insert(std::make_pair(Table::FIELD_ROW, "+obj.row"));
|
||||
addParams.insert(std::make_pair(Table::FIELD_VAL, "+obj.value"));
|
||||
addParams.insert(std::make_pair(RequestHandler::KEY_EVID, Table::EV_CELLVALUECHANGED));
|
||||
JavaScriptEvent<int> ev;
|
||||
ev.setJSDelegates(pTable->cellValueChanged.jsDelegates());
|
||||
ev.add(jsDelegate("function(obj){obj.grid.getStore().commitChanges();}"));
|
||||
ostr << ",listeners:{";
|
||||
Utility::writeJSEventPlusServerCallback(ostr, afterEdit, ev.jsDelegates(), addParams);
|
||||
ostr << "},";
|
||||
Utility::writeJSEventPlusServerCallback(ostr, afterEdit, ev.jsDelegates(), addParams, pTable->cellValueChanged.hasLocalHandlers());
|
||||
|
||||
//cellclick : ( Grid this, Number rowIndex, Number columnIndex, Ext.EventObject e )
|
||||
//hm, more than one param in the eventhanlder of cellclick, writeJSEvent creates a fucntion(obj) wrapper
|
||||
//FIXME: no support for custom javascript yet
|
||||
addParams.clear();
|
||||
addParams.insert(std::make_pair(Table::FIELD_COL, "+columnIndex"));
|
||||
addParams.insert(std::make_pair(Table::FIELD_ROW, "+rowIndex"));
|
||||
addParams.insert(std::make_pair(RequestHandler::KEY_EVID, Table::EV_CELLCLICKED));
|
||||
ostr << ",";
|
||||
Utility::writeServerCallback(ostr,cellClicked, "function(aGrid, rowIndex,columnIndex,e)",addParams, pTable->cellClicked.hasLocalHandlers());
|
||||
|
||||
ostr << "},"; //close listeners
|
||||
|
||||
renderColumns(pTable, context, ostr);
|
||||
ostr << ",clicksToEdit:1";
|
||||
ostr << ",clicksToEdit:1,stripeRows:true";
|
||||
if (pTable->getWidth() > 0)
|
||||
ostr << ",width:" << pTable->getWidth();
|
||||
if (pTable->getHeight() > 0)
|
||||
ostr << ",height:" << pTable->getHeight();
|
||||
ostr << ",store:";
|
||||
renderStore(pTable, ostr);
|
||||
WebApplication::instance().registerAjaxProcessor(Poco::NumberFormatter::format(pTable), const_cast<Table*>(pTable));
|
||||
WebApplication::instance().registerAjaxProcessor(Poco::NumberFormatter::format(id), const_cast<Table*>(pTable));
|
||||
}
|
||||
|
||||
|
||||
|
@@ -447,18 +447,20 @@ void Utility::writeCodeForDelegate(std::ostream& invoke, std::ostream& out, cons
|
||||
}
|
||||
|
||||
|
||||
bool Utility::writeJSEventPlusServerCallback(std::ostream& out, const std::string& eventName, const std::set<JSDelegate>& delegates, const std::map<std::string, std::string>& addServerParams)
|
||||
bool Utility::writeJSEventPlusServerCallback(std::ostream& out, const std::string& eventName, const std::set<JSDelegate>& delegates, const std::map<std::string, std::string>& addServerParams, bool reloadPage)
|
||||
{
|
||||
// rather simple way to support more than one delegate
|
||||
// TODO: there sure is a more efficient way to do this
|
||||
out << "'" << eventName << "':";
|
||||
|
||||
out << eventName << ":";
|
||||
static const std::string defSignature("function("+JS_EVENTARGNAME+")");
|
||||
|
||||
std::ostringstream invoke;
|
||||
invoke << "invoke:function(" << JS_EVENTARGNAME << "){";
|
||||
out << "{fn:function(" << JS_EVENTARGNAME << "){var all={";
|
||||
writeCodeForDelegate(invoke, out, delegates);
|
||||
//write server callback
|
||||
writeCodeForDelegate(invoke, out, jsDelegate(createFunctionCode(eventName, addServerParams)), static_cast<int>(delegates.size()));
|
||||
writeCodeForDelegate(invoke, out, jsDelegate(createCallbackFunctionCode(defSignature, addServerParams, reloadPage)), static_cast<int>(delegates.size()));
|
||||
invoke << "}";
|
||||
out << invoke.str() << "};"; //closes all
|
||||
|
||||
@@ -469,15 +471,23 @@ bool Utility::writeJSEventPlusServerCallback(std::ostream& out, const std::strin
|
||||
}
|
||||
|
||||
|
||||
std::string Utility::createFunctionCode(const std::string& eventName, const std::map<std::string, std::string>& addParams)
|
||||
bool Utility::writeServerCallback(std::ostream& out, const std::string& eventName, const std::string& signature, const std::map<std::string, std::string>& addServerParams, bool reloadPage)
|
||||
{
|
||||
std::string fctCode(createCallbackFunctionCode(signature, addServerParams, reloadPage));
|
||||
out << eventName << ":";
|
||||
out << fctCode;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
std::string Utility::createURI(const std::map<std::string, std::string>& addParams)
|
||||
{
|
||||
WebApplication& app = WebApplication::instance();
|
||||
Renderable::ID id = app.getCurrentPage()->id();
|
||||
std::ostringstream uri;
|
||||
uri << "'" << app.getURI().toString();
|
||||
uri << ";"; //mark as AJAX request
|
||||
uri << RequestHandler::KEY_ID << "=" << id << "&";
|
||||
uri << RequestHandler::KEY_EVID << "=" << eventName;
|
||||
uri << "'" << app.getURI().toString() << "?";
|
||||
uri << RequestHandler::KEY_TYPE << "=" << RequestHandler::VAL_AJAX; //mark as AJAX request
|
||||
uri << "&" << RequestHandler::KEY_ID << "=" << id;
|
||||
// add optional params
|
||||
bool commaAtEnd = false;
|
||||
std::size_t cnt(1);
|
||||
@@ -509,11 +519,29 @@ std::string Utility::createFunctionCode(const std::string& eventName, const std:
|
||||
}
|
||||
if (!commaAtEnd)
|
||||
uri << "'";
|
||||
return uri.str();
|
||||
|
||||
}
|
||||
|
||||
|
||||
std::string Utility::createCallbackFunctionCode(const std::string& signature, const std::map<std::string, std::string>& addParams, bool reloadPage)
|
||||
{
|
||||
poco_assert_dbg (!signature.empty());
|
||||
poco_assert_dbg(signature.find("function") != std::string::npos);
|
||||
poco_assert_dbg(signature.find("{") == std::string::npos);
|
||||
std::string uri(createURI(addParams));
|
||||
// now add the callback code
|
||||
std::ostringstream function;
|
||||
function << "function(" << JS_EVENTARGNAME << "){var uri=" << uri.str() << ";";
|
||||
function << signature;
|
||||
function << "{var uri=" << uri << ";";
|
||||
function << "Ext.Ajax.request({url:uri,";
|
||||
function << "failure:function(){Ext.MessageBox.alert('Status','Failed to write changes back to server.');}});}";
|
||||
if (reloadPage)
|
||||
{
|
||||
function << "success:function(){window.location.reload();},";
|
||||
function << "failure:function(){Ext.MessageBox.alert('Status','Failed to write changes back to server.');window.location.reload();}});}";
|
||||
}
|
||||
else
|
||||
function << "failure:function(){Ext.MessageBox.alert('Status','Failed to write changes back to server.');}});}";
|
||||
return function.str();
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user