mirror of
https://github.com/pocoproject/poco.git
synced 2025-01-29 21:30:04 +01:00
more Table events
This commit is contained in:
parent
3ca6a9775c
commit
e0bb9c162b
@ -64,6 +64,8 @@ class ExtJS_API TableRenderer: public Poco::WebWidgets::Renderer
|
||||
public:
|
||||
static const std::string EV_CELLCLICKED;
|
||||
static const std::string EV_ROWCLICKED;
|
||||
static const std::string EV_BEFORECELLCLICKED;
|
||||
static const std::string EV_BEFOREROWCLICKED;
|
||||
static const std::string EV_AFTEREDIT;
|
||||
static const std::string EV_AFTERLOAD;
|
||||
static const std::string EV_RENDER;
|
||||
@ -97,6 +99,16 @@ public:
|
||||
/// Single cell selection will trigger an exception!
|
||||
/// Method signature is rowselect : ( SelectionModel this, Number rowIndex, Ext.Data.Record r )
|
||||
|
||||
static Poco::WebWidgets::JSDelegate createBeforeCellClickedServerCallback(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 )
|
||||
|
||||
static Poco::WebWidgets::JSDelegate createBeforeRowClickedServerCallback(const Table* pTable);
|
||||
/// Adds a javascript callback to inform the WebServer that the client has clicke don a row
|
||||
/// This event will only be added if the Table uses a Row selection model!
|
||||
/// Single cell selection will trigger an exception!
|
||||
/// Method signature is rowselect : ( SelectionModel this, Number rowIndex, Ext.Data.Record r )
|
||||
|
||||
static Poco::WebWidgets::JSDelegate createAfterLoadServerCallback(const Table* pTable);
|
||||
/// 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 )
|
||||
|
@ -56,6 +56,8 @@ namespace ExtJS {
|
||||
|
||||
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_AFTEREDIT("afteredit");
|
||||
const std::string TableRenderer::EV_AFTERLOAD("load");
|
||||
const std::string TableRenderer::EV_RENDER("render");
|
||||
@ -161,6 +163,22 @@ Poco::WebWidgets::JSDelegate TableRenderer::createCellClickedServerCallback(cons
|
||||
}
|
||||
|
||||
|
||||
Poco::WebWidgets::JSDelegate TableRenderer::createBeforeCellClickedServerCallback(const Table* pTable)
|
||||
{
|
||||
poco_check_ptr (pTable);
|
||||
static const std::string signature("function(theGrid,row,col,e)");
|
||||
//extract the true row index from the last column!
|
||||
std::string origRow("+theGrid.getStore().getAt(row).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, "+col"));
|
||||
addParams.insert(std::make_pair(Table::FIELD_ROW, origRow));
|
||||
addParams.insert(std::make_pair(RequestHandler::KEY_EVID, Table::EV_BEFORECELLCLICKED));
|
||||
return Utility::createServerCallback(signature, addParams, pTable->id(), pTable->beforeCellClicked.getOnSuccess(), pTable->beforeCellClicked.getOnFailure());
|
||||
}
|
||||
|
||||
|
||||
Poco::WebWidgets::JSDelegate TableRenderer::createRowClickedServerCallback(const Table* pTable)
|
||||
{
|
||||
poco_check_ptr (pTable);
|
||||
@ -179,6 +197,24 @@ Poco::WebWidgets::JSDelegate TableRenderer::createRowClickedServerCallback(const
|
||||
}
|
||||
|
||||
|
||||
Poco::WebWidgets::JSDelegate TableRenderer::createBeforeRowClickedServerCallback(const Table* pTable)
|
||||
{
|
||||
poco_check_ptr (pTable);
|
||||
poco_assert (pTable->getSelectionModel() != Table::SM_CELL);
|
||||
|
||||
/// Method signature is rowselect : ( SelectionModel this, Number rowIndex, Ext.Data.Record r )
|
||||
static const std::string signature("function(sm,row,r)");
|
||||
//extract the true row index from the last column!
|
||||
std::string origRow("+r.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_ROW, origRow));
|
||||
addParams.insert(std::make_pair(RequestHandler::KEY_EVID, Table::EV_BEFOREROWCLICKED));
|
||||
return Utility::createServerCallback(signature, addParams, pTable->id(), pTable->beforeRowClicked.getOnSuccess(), pTable->beforeRowClicked.getOnFailure());
|
||||
}
|
||||
|
||||
|
||||
Poco::WebWidgets::JSDelegate TableRenderer::createMouseUpServerCallback(const Table* pTable)
|
||||
{
|
||||
poco_check_ptr (pTable);
|
||||
@ -238,6 +274,18 @@ void TableRenderer::renderProperties(const Table* pTable, const RenderContext& c
|
||||
written = Utility::writeJSEvent(ostr, EV_CELLCLICKED, pTable->cellClicked.jsDelegates());
|
||||
}
|
||||
|
||||
if (pTable->beforeCellClicked.hasJavaScriptCode())
|
||||
{
|
||||
if (written)
|
||||
ostr << ",";
|
||||
if (pTable->beforeCellClicked.willDoServerCallback())
|
||||
written = Utility::writeJSEvent(ostr, EV_BEFORECELLCLICKED, pTable->beforeCellClicked.jsDelegates(),
|
||||
TableRenderer::createBeforeCellClickedServerCallback(pTable),
|
||||
pTable->beforeCellClicked.getServerCallbackPos());
|
||||
else
|
||||
written = Utility::writeJSEvent(ostr, EV_BEFORECELLCLICKED, pTable->beforeCellClicked.jsDelegates());
|
||||
}
|
||||
|
||||
if (pTable->afterRender.hasJavaScriptCode())
|
||||
{
|
||||
if (written)
|
||||
@ -289,15 +337,27 @@ void TableRenderer::renderProperties(const Table* pTable, const RenderContext& c
|
||||
ostr << ",selModel:new Ext.grid.RowSelectionModel({singleSelect:true";
|
||||
else if (pTable->getSelectionModel() == Table::SM_MULTIROW)
|
||||
ostr << ",selModel:new Ext.grid.RowSelectionModel({singleSelect:false";
|
||||
if (pTable->rowClicked.hasJavaScriptCode())
|
||||
if (pTable->rowClicked.hasJavaScriptCode() || pTable->beforeRowClicked.hasJavaScriptCode())
|
||||
{
|
||||
ostr << ",listeners:{";
|
||||
if (pTable->rowClicked.willDoServerCallback())
|
||||
Utility::writeJSEvent(ostr, EV_ROWCLICKED, pTable->rowClicked.jsDelegates(),
|
||||
written = Utility::writeJSEvent(ostr, EV_ROWCLICKED, pTable->rowClicked.jsDelegates(),
|
||||
TableRenderer::createRowClickedServerCallback(pTable),
|
||||
pTable->rowClicked.getServerCallbackPos());
|
||||
else
|
||||
Utility::writeJSEvent(ostr, EV_ROWCLICKED, pTable->rowClicked.jsDelegates());
|
||||
written = Utility::writeJSEvent(ostr, EV_ROWCLICKED, pTable->rowClicked.jsDelegates());
|
||||
|
||||
if (pTable->beforeRowClicked.hasJavaScriptCode())
|
||||
{
|
||||
if (written)
|
||||
ostr << ",";
|
||||
if (pTable->beforeRowClicked.willDoServerCallback())
|
||||
written = Utility::writeJSEvent(ostr, EV_BEFOREROWCLICKED, pTable->beforeRowClicked.jsDelegates(),
|
||||
TableRenderer::createBeforeRowClickedServerCallback(pTable),
|
||||
pTable->beforeRowClicked.getServerCallbackPos());
|
||||
else
|
||||
written = Utility::writeJSEvent(ostr, EV_BEFOREROWCLICKED, pTable->beforeRowClicked.jsDelegates());
|
||||
}
|
||||
ostr << "}";
|
||||
}
|
||||
ostr << "})"; //close selModel
|
||||
|
@ -67,7 +67,9 @@ public:
|
||||
static const std::string FIELD_VAL;
|
||||
static const std::string FIELD_CNT;
|
||||
static const std::string EV_CELLCLICKED;
|
||||
static const std::string EV_BEFORECELLCLICKED;
|
||||
static const std::string EV_ROWCLICKED;
|
||||
static const std::string EV_BEFOREROWCLICKED;
|
||||
static const std::string EV_CELLVALUECHANGED;
|
||||
static const std::string EV_LOADDATA;
|
||||
static const std::string EV_AFTERLOAD;
|
||||
@ -104,8 +106,12 @@ public:
|
||||
|
||||
JavaScriptEvent<std::size_t> rowClicked; /// fires the row clicked event
|
||||
|
||||
JavaScriptEvent<std::size_t> beforeRowClicked; /// fires the before row clicked event
|
||||
|
||||
JavaScriptEvent<Table::CellClick> cellClicked; /// fires the cellClicked event
|
||||
|
||||
JavaScriptEvent<Table::CellClick> beforeCellClicked; /// fires when the mouse is pressed down on a cell
|
||||
|
||||
JavaScriptEvent<Table::CellValueChange> cellValueChanged;
|
||||
|
||||
JavaScriptEvent<Table*> afterLoad; // thrown after data was loaded
|
||||
|
@ -49,7 +49,9 @@ const std::string Table::FIELD_ROW("row");
|
||||
const std::string Table::FIELD_VAL("val");
|
||||
const std::string Table::FIELD_CNT("cnt");
|
||||
const std::string Table::EV_CELLCLICKED("click");
|
||||
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_LOADDATA("load");
|
||||
const std::string Table::EV_AFTERLOAD("afterload");
|
||||
@ -169,6 +171,15 @@ void Table::handleAjaxRequest(const Poco::Net::NameValueCollection& args, Poco::
|
||||
cellClicked(this, ev);
|
||||
response.send();
|
||||
}
|
||||
else if (ev == EV_BEFORECELLCLICKED)
|
||||
{
|
||||
if (col < 0 || row < 0 || col >= getColumnCount())
|
||||
throw InvalidArgumentException("col/row out of range");
|
||||
|
||||
CellClick ev(row, col);
|
||||
beforeCellClicked(this, ev);
|
||||
response.send();
|
||||
}
|
||||
else if (ev == EV_ROWCLICKED)
|
||||
{
|
||||
if (row < 0 )
|
||||
@ -178,6 +189,15 @@ void Table::handleAjaxRequest(const Poco::Net::NameValueCollection& args, Poco::
|
||||
rowClicked(this, theRow);
|
||||
response.send();
|
||||
}
|
||||
else if (ev == EV_BEFOREROWCLICKED)
|
||||
{
|
||||
if (row < 0 )
|
||||
throw InvalidArgumentException("row out of range");
|
||||
|
||||
std::size_t theRow(row);
|
||||
beforeRowClicked(this, theRow);
|
||||
response.send();
|
||||
}
|
||||
else if (ev == EV_CELLVALUECHANGED)
|
||||
{
|
||||
if (col < 0 || row < 0 || col >= getColumnCount())
|
||||
|
Loading…
x
Reference in New Issue
Block a user