added beforeCellChangeEvent

This commit is contained in:
Peter Schojer 2008-07-03 11:14:41 +00:00
parent 4e2a3f7013
commit b2f8d6abdf
4 changed files with 43 additions and 1 deletions

View File

@ -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 )

View File

@ -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<Poco::UInt32>(pTable->getColumnCount())));
origRow.append("')");
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, 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())

View File

@ -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<Table::CellValueChange> cellValueChanged;
JavaScriptEvent<Table::CellValueChange> beforeCellValueChanged;
JavaScriptEvent<Table*> afterLoad; // thrown after data was loaded
JavaScriptEvent<Table*> afterRender; // thrown after rendering

View File

@ -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");