diff --git a/WebWidgets/ExtJS/include/Poco/WebWidgets/ExtJS/TableRenderer.h b/WebWidgets/ExtJS/include/Poco/WebWidgets/ExtJS/TableRenderer.h index 6579ce4ab..c09e086cc 100644 --- a/WebWidgets/ExtJS/include/Poco/WebWidgets/ExtJS/TableRenderer.h +++ b/WebWidgets/ExtJS/include/Poco/WebWidgets/ExtJS/TableRenderer.h @@ -67,6 +67,7 @@ public: static const std::string EV_BEFORECELLCLICKED; static const std::string EV_BEFOREROWCLICKED; static const std::string EV_AFTEREDIT; + static const std::string EV_BEFORECELLVALUECHANGED; static const std::string EV_AFTERLOAD; static const std::string EV_RENDER; static const std::string EV_MOUSEUP; @@ -89,6 +90,12 @@ public: /// Adds a javascript callback to inform the WebServer that the client has changed a value in the Table /// The Extjs handler offers a method signature of "function(obj)" where obj is a complex element containing members (column, row, value) + static Poco::WebWidgets::JSDelegate createBeforeCellValueChangedServerCallback(const Table* pTable); + /// Adds a javascript callback to inform the WebServer that the client has changed a value in the Table + /// The Extjs handler offers a method signature of "function(obj)" where obj is a complex element + /// containing members (grid, record, column, row, value, cancel)! + /// obj.cancel must be set to false to forbid the edit + static Poco::WebWidgets::JSDelegate createCellClickedServerCallback(const Table* pTable); /// Adds a javascript callback to inform the WebServer that the client has clicked on a cell in the Table /// Method signature is cellclick : ( Grid this, Number rowIndex, Number columnIndex, Ext.EventObject e ) diff --git a/WebWidgets/ExtJS/src/TableRenderer.cpp b/WebWidgets/ExtJS/src/TableRenderer.cpp index 160f056f2..5aa56c52c 100644 --- a/WebWidgets/ExtJS/src/TableRenderer.cpp +++ b/WebWidgets/ExtJS/src/TableRenderer.cpp @@ -58,6 +58,7 @@ const std::string TableRenderer::EV_CELLCLICKED("cellclick"); const std::string TableRenderer::EV_ROWCLICKED("rowselect"); const std::string TableRenderer::EV_BEFORECELLCLICKED("cellmousedown"); const std::string TableRenderer::EV_BEFOREROWCLICKED("rowmousedown"); +const std::string TableRenderer::EV_BEFORECELLVALUECHANGED("validateedit"); const std::string TableRenderer::EV_AFTEREDIT("afteredit"); const std::string TableRenderer::EV_AFTERLOAD("load"); const std::string TableRenderer::EV_RENDER("render"); @@ -122,7 +123,29 @@ Poco::WebWidgets::JSDelegate TableRenderer::createCellValueChangedServerCallback addParams.insert(std::make_pair(RequestHandler::KEY_EVID, Table::EV_CELLVALUECHANGED)); const std::string& success = pTable->cellValueChanged.getOnSuccess(); - return Utility::createServerCallback(signature, addParams, pTable->id(), pTable->cellValueChanged.getOnSuccess(), pTable->cellValueChanged.getOnFailure()); + return Utility::createServerCallback(signature, addParams, pTable->id(), success, pTable->cellValueChanged.getOnFailure()); +} + + + +Poco::WebWidgets::JSDelegate TableRenderer::createBeforeCellValueChangedServerCallback(const Table* pTable) +{static const std::string signature("function(obj)"); + //extract the true row index from the last column! + std::string origRow("+obj.record.get('"); + origRow.append(Poco::NumberFormatter::format(static_cast(pTable->getColumnCount()))); + origRow.append("')"); + std::map addParams; + addParams.insert(std::make_pair(Table::FIELD_COL, "+obj.column")); + addParams.insert(std::make_pair(Table::FIELD_ROW, origRow)); + //problem: I need the displayed string from teh renderer, not the value! + // date fields cause problems here, and I only habe one cellclick event per table not per column! + // from the table get the TableColumn, from this get the renderer for the given col and render obj.value + // {(var r=obj.grid.getColumnModel().getRenderer(obj.column))?r(obj.value);:obj.value;}, hm renderer exists for everthing + addParams.insert(std::make_pair(Table::FIELD_VAL, "+obj.grid.getColumnModel().getRenderer(obj.column)(obj.value)")); + addParams.insert(std::make_pair(RequestHandler::KEY_EVID, Table::EV_BEFORECELLVALUECHANGED)); + const std::string& success = pTable->beforeCellValueChanged.getOnSuccess(); + + return Utility::createServerCallback(signature, addParams, pTable->id(), success, pTable->beforeCellValueChanged.getOnFailure()); } @@ -260,6 +283,14 @@ void TableRenderer::renderProperties(const Table* pTable, const RenderContext& c pTable->cellValueChanged.getServerCallbackPos()); else written = Utility::writeJSEvent(ostr, EV_AFTEREDIT, modList); + if (written) + ostr << ","; + if (pTable->beforeCellValueChanged.willDoServerCallback()) + written = Utility::writeJSEvent(ostr, EV_BEFORECELLVALUECHANGED, modList, + TableRenderer::createBeforeCellValueChangedServerCallback(pTable), + pTable->beforeCellValueChanged.getServerCallbackPos()); + else + written = Utility::writeJSEvent(ostr, EV_AFTEREDIT, modList); } if (pTable->cellClicked.hasJavaScriptCode()) diff --git a/WebWidgets/include/Poco/WebWidgets/Table.h b/WebWidgets/include/Poco/WebWidgets/Table.h index 1ea9b3c30..d405db227 100644 --- a/WebWidgets/include/Poco/WebWidgets/Table.h +++ b/WebWidgets/include/Poco/WebWidgets/Table.h @@ -71,6 +71,7 @@ public: static const std::string EV_ROWCLICKED; static const std::string EV_BEFOREROWCLICKED; static const std::string EV_CELLVALUECHANGED; + static const std::string EV_BEFORECELLVALUECHANGED; static const std::string EV_LOADDATA; static const std::string EV_AFTERLOAD; static const std::string EV_RENDER; @@ -114,6 +115,8 @@ public: JavaScriptEvent cellValueChanged; + JavaScriptEvent beforeCellValueChanged; + JavaScriptEvent afterLoad; // thrown after data was loaded JavaScriptEvent afterRender; // thrown after rendering diff --git a/WebWidgets/src/Table.cpp b/WebWidgets/src/Table.cpp index a6da01df0..c45fd01a3 100644 --- a/WebWidgets/src/Table.cpp +++ b/WebWidgets/src/Table.cpp @@ -53,6 +53,7 @@ const std::string Table::EV_BEFORECELLCLICKED("beforeclick"); const std::string Table::EV_ROWCLICKED("row"); const std::string Table::EV_BEFOREROWCLICKED("beforerow"); const std::string Table::EV_CELLVALUECHANGED("edit"); +const std::string Table::EV_BEFORECELLVALUECHANGED("beforeedit"); const std::string Table::EV_LOADDATA("load"); const std::string Table::EV_AFTERLOAD("afterload"); const std::string Table::EV_RENDER("render");