diff --git a/WebWidgets/ExtJS/include/Poco/WebWidgets/ExtJS/TableRenderer.h b/WebWidgets/ExtJS/include/Poco/WebWidgets/ExtJS/TableRenderer.h index 502771c79..5e7809da6 100644 --- a/WebWidgets/ExtJS/include/Poco/WebWidgets/ExtJS/TableRenderer.h +++ b/WebWidgets/ExtJS/include/Poco/WebWidgets/ExtJS/TableRenderer.h @@ -64,6 +64,7 @@ class ExtJS_API TableRenderer: public Poco::WebWidgets::Renderer public: static const std::string EV_CELLCLICKED; static const std::string EV_AFTEREDIT; + static const std::string EV_AFTERLOAD; static const std::string HIDDEN_INDEX_ROW; TableRenderer(); @@ -85,6 +86,10 @@ public: static void addCellClickedServerCallback(Table* pTable, const std::string& onSuccess=std::string(), const std::string& onFailure=std::string()); /// Adds a javascript callback to inform the WebServer that the client has changed a value in the Table /// Method signature is cellclick : ( Grid this, Number rowIndex, Number columnIndex, Ext.EventObject e ) + + static void addAfterLoadServerCallback(Table* pTable, const std::string& onSuccess=std::string(), const std::string& onFailure=std::string()); + /// Adds a javascript callback to inform the WebServer that the client has finished loading data + /// Method signature is ( Store this, Ext.data.Record[] records, Object options ) protected: static void renderProperties(const Table* pTable, const RenderContext& context, std::ostream& ostr); diff --git a/WebWidgets/ExtJS/src/PageRenderer.cpp b/WebWidgets/ExtJS/src/PageRenderer.cpp index a340b6434..a6385fb3d 100644 --- a/WebWidgets/ExtJS/src/PageRenderer.cpp +++ b/WebWidgets/ExtJS/src/PageRenderer.cpp @@ -48,7 +48,7 @@ namespace ExtJS { const std::string PageRenderer::EV_BEFORERENDER("beforerender"); -const std::string PageRenderer::EV_AFTERRENDER("afterrender"); +const std::string PageRenderer::EV_AFTERRENDER("show"); //don't use afterrender which fires before all the children are rendered! PageRenderer::PageRenderer() @@ -97,6 +97,7 @@ void PageRenderer::renderHead(const Renderable* pRenderable, const RenderContext { ostr << ",listeners:{"; bool written = Utility::writeJSEvent(ostr, EV_BEFORERENDER, pPage->beforeRender.jsDelegates()); + //auto-show all windows JavaScriptEvent::JSDelegates js = pPage->afterRender.jsDelegates(); js.push_front(jsDelegate("function(){Ext.WindowMgr.each( function(w) {w.show(this);});}")); if (written && !js.empty()) @@ -129,8 +130,7 @@ void PageRenderer::renderHead(const Renderable* pRenderable, const RenderContext } //close the panel ostr << "]});"; - //auto-show all windows - //ostr << "Ext.WindowMgr.each( function(w) {w.show(this);});"; + //close onReady ostr << "});"; //close inline JS block diff --git a/WebWidgets/ExtJS/src/TableRenderer.cpp b/WebWidgets/ExtJS/src/TableRenderer.cpp index 63b5f25a5..28fd2fd9f 100644 --- a/WebWidgets/ExtJS/src/TableRenderer.cpp +++ b/WebWidgets/ExtJS/src/TableRenderer.cpp @@ -43,8 +43,10 @@ #include "Poco/WebWidgets/WebApplication.h" #include "Poco/WebWidgets/RequestHandler.h" #include "Poco/WebWidgets/DateFormatter.h" +#include "Poco/WebWidgets/JSDelegate.h" #include "Poco/Delegate.h" #include +#include namespace Poco { @@ -54,6 +56,7 @@ namespace ExtJS { const std::string TableRenderer::EV_CELLCLICKED("cellclick"); const std::string TableRenderer::EV_AFTEREDIT("afteredit"); +const std::string TableRenderer::EV_AFTERLOAD("load"); const std::string TableRenderer::HIDDEN_INDEX_ROW("hidIdx"); @@ -117,6 +120,16 @@ void TableRenderer::addCellValueChangedServerCallback(Table* pTable, const std:: +void TableRenderer::addAfterLoadServerCallback(Table* pTable, const std::string& onSuccess, const std::string& onFailure) +{ + poco_check_ptr (pTable); + static const std::string signature("function(aStore, recs, op)"); + std::map addParams; + addParams.insert(std::make_pair(RequestHandler::KEY_EVID, Table::EV_AFTERLOAD)); + Utility::addServerCallback(pTable->afterLoad, signature, addParams, pTable->id(), onSuccess, onFailure); +} + + void TableRenderer::addCellClickedServerCallback(Table* pTable, const std::string& onSuccess, const std::string& onFailure) { @@ -152,7 +165,6 @@ void TableRenderer::renderProperties(const Table* pTable, const RenderContext& c if (written) ostr << ","; - Utility::writeJSEvent(ostr, EV_CELLCLICKED, pTable->cellClicked.jsDelegates()); ostr << "},"; //close listeners @@ -282,12 +294,13 @@ void TableRenderer::renderStore(const Table* pTable, std::ostream& ostr) std::map addParams; addParams.insert(std::make_pair(RequestHandler::KEY_EVID,Table::EV_LOADDATA)); + std::string url(Utility::createURI(addParams, pTable->id())); ostr << url << "}),"; ostr << "reader:new Ext.data.ArrayReader()"; - //Write data - /*ostr << "data:"; - renderDataModel(pTable, ostr);*/ + ostr << ",listeners:{"; + Utility::writeJSEvent(ostr, EV_AFTERLOAD, pTable->afterLoad.jsDelegates()); + ostr << "}"; ostr << "})"; } diff --git a/WebWidgets/include/Poco/WebWidgets/Table.h b/WebWidgets/include/Poco/WebWidgets/Table.h index 20390b9de..601a55aac 100644 --- a/WebWidgets/include/Poco/WebWidgets/Table.h +++ b/WebWidgets/include/Poco/WebWidgets/Table.h @@ -69,8 +69,9 @@ public: static const std::string EV_CELLCLICKED; static const std::string EV_CELLVALUECHANGED; static const std::string EV_LOADDATA; + static const std::string EV_AFTERLOAD; - struct CellClick + struct WebWidgets_API CellClick { std::size_t row; std::size_t col; @@ -78,7 +79,7 @@ public: CellClick(std::size_t row, std::size_t col); }; - struct CellValueChange + struct WebWidgets_API CellValueChange /// Data sent with a cellValueChanged event. { std::size_t row; @@ -101,6 +102,8 @@ public: JavaScriptEvent cellValueChanged; + JavaScriptEvent afterLoad; // thrown after data was loaded + FIFOEvent beforeLoad; /// thrown whenever a load is requested, internal event to which the TableRenderer must register enum SelectionModel @@ -151,7 +154,7 @@ public: void handleAjaxRequest(const Poco::Net::NameValueCollection& args, Poco::Net::HTTPServerResponse& response); /// Handles a complete AJAX request submitted by the client. - + protected: Table(const std::string& name, const std::type_info& type, const TableColumns& tc, TableModel::Ptr pModel); /// Creates a Table and assigns it the given name. @@ -223,6 +226,7 @@ inline Table::SelectionModel Table::getSelectionModel() const } + } } // namespace Poco::WebWidgets diff --git a/WebWidgets/src/Table.cpp b/WebWidgets/src/Table.cpp index c6da708d2..f4dbb13f7 100644 --- a/WebWidgets/src/Table.cpp +++ b/WebWidgets/src/Table.cpp @@ -51,6 +51,7 @@ const std::string Table::FIELD_CNT("cnt"); const std::string Table::EV_CELLCLICKED("click"); const std::string Table::EV_CELLVALUECHANGED("edit"); const std::string Table::EV_LOADDATA("load"); +const std::string Table::EV_AFTERLOAD("afterload"); Table::Table(const TableColumns& tc, TableModel::Ptr pModel): @@ -174,6 +175,11 @@ void Table::handleAjaxRequest(const Poco::Net::NameValueCollection& args, Poco:: setValue(Poco::Any(val), row, col); response.send(); } + else if (ev == EV_AFTERLOAD) + { + Table* pTable = this; + afterLoad(this, pTable); + } }