added rowClicked event

This commit is contained in:
Peter Schojer
2008-06-05 13:10:18 +00:00
parent c7a3b3499d
commit 790a20ed20
5 changed files with 63 additions and 10 deletions

View File

@@ -63,6 +63,7 @@ class ExtJS_API TableRenderer: public Poco::WebWidgets::Renderer
{ {
public: public:
static const std::string EV_CELLCLICKED; static const std::string EV_CELLCLICKED;
static const std::string EV_ROWCLICKED;
static const std::string EV_AFTEREDIT; static const std::string EV_AFTEREDIT;
static const std::string EV_AFTERLOAD; static const std::string EV_AFTERLOAD;
static const std::string HIDDEN_INDEX_ROW; static const std::string HIDDEN_INDEX_ROW;
@@ -84,9 +85,15 @@ public:
/// The Extjs handler offers a method signature of "function(obj)" where obj is a complex element containing members (column, row, value) /// The Extjs handler offers a method signature of "function(obj)" where obj is a complex element containing members (column, row, value)
static void addCellClickedServerCallback(Table* pTable, const std::string& onSuccess=std::string(), const std::string& onFailure=std::string()); 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 /// 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 ) /// Method signature is cellclick : ( Grid this, Number rowIndex, Number columnIndex, Ext.EventObject e )
static void addRowClickedServerCallback(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 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 void addAfterLoadServerCallback(Table* pTable, const std::string& onSuccess=std::string(), const std::string& onFailure=std::string()); 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 /// 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 ) /// Method signature is ( Store this, Ext.data.Record[] records, Object options )

View File

@@ -89,14 +89,15 @@ void ButtonCellRenderer::renderProperties(const ButtonCell* pButtonCell, const s
{ {
ostr << "type:'submit',"; ostr << "type:'submit',";
Form::Ptr pForm = Utility::insideForm(pButtonCell); Form::Ptr pForm = Utility::insideForm(pButtonCell);
//ostr << "handler: function(){Ext.getCmp('" << pForm->id() << "').getForm().submit({url:'" << pForm->getURI().toString() << "',waitMsg:'Loading'});},";
ostr << "handler: function(){Ext.getCmp('" << pForm->id() << "').getForm().submit();},"; ostr << "handler: function(){Ext.getCmp('" << pForm->id() << "').getForm().submit();},";
} }
Button* pOwner = dynamic_cast<Button*>(pButtonCell->getOwner());
poco_check_ptr (pOwner);
if (writeId) if (writeId)
Utility::writeRenderableProperties(pButtonCell, ostr); Utility::writeRenderableProperties(pOwner, ostr);
if (!pButtonCell->isEnabled()) if (!pButtonCell->isEnabled())
ostr << ",disabled:true"; ostr << ",disabled:true";
Button* pOwner = dynamic_cast<Button*>(pButtonCell->getOwner());
if (pOwner) if (pOwner)
{ {
if (!pOwner->getName().empty()) if (!pOwner->getName().empty())

View File

@@ -55,6 +55,7 @@ namespace ExtJS {
const std::string TableRenderer::EV_CELLCLICKED("cellclick"); const std::string TableRenderer::EV_CELLCLICKED("cellclick");
const std::string TableRenderer::EV_ROWCLICKED("rowselect");
const std::string TableRenderer::EV_AFTEREDIT("afteredit"); const std::string TableRenderer::EV_AFTEREDIT("afteredit");
const std::string TableRenderer::EV_AFTERLOAD("load"); const std::string TableRenderer::EV_AFTERLOAD("load");
const std::string TableRenderer::HIDDEN_INDEX_ROW("hidIdx"); const std::string TableRenderer::HIDDEN_INDEX_ROW("hidIdx");
@@ -148,6 +149,25 @@ void TableRenderer::addCellClickedServerCallback(Table* pTable, const std::strin
} }
void TableRenderer::addRowClickedServerCallback(Table* pTable, const std::string& onSuccess, const std::string& onFailure)
{
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_ROWCLICKED));
Utility::addServerCallback(pTable->rowClicked, signature, addParams, pTable->id(), onSuccess, onFailure);
}
void TableRenderer::renderProperties(const Table* pTable, const RenderContext& context, std::ostream& ostr) void TableRenderer::renderProperties(const Table* pTable, const RenderContext& context, std::ostream& ostr)
{ {
WebApplication& app = WebApplication::instance(); WebApplication& app = WebApplication::instance();
@@ -167,7 +187,9 @@ void TableRenderer::renderProperties(const Table* pTable, const RenderContext& c
if (written) if (written)
ostr << ","; ostr << ",";
Utility::writeJSEvent(ostr, EV_CELLCLICKED, pTable->cellClicked.jsDelegates()); written = Utility::writeJSEvent(ostr, EV_CELLCLICKED, pTable->cellClicked.jsDelegates());
ostr << "},"; //close listeners ostr << "},"; //close listeners
@@ -175,10 +197,20 @@ void TableRenderer::renderProperties(const Table* pTable, const RenderContext& c
// forbid reordering of columns, otherwise col index will not match the col index at the server // forbid reordering of columns, otherwise col index will not match the col index at the server
// sorting is allowed though, i.e row matching is active // sorting is allowed though, i.e row matching is active
ostr << ",clicksToEdit:1,stripeRows:true,enableColumnHide:false,enableColumnMove:false,loadMask:true"; ostr << ",clicksToEdit:1,stripeRows:true,enableColumnHide:false,enableColumnMove:false,loadMask:true";
if (pTable->getSelectionModel() == Table::SM_SINGLEROW) if (pTable->getSelectionModel() != Table::SM_CELL)
ostr << ",selModel:new Ext.grid.RowSelectionModel({singleSelect:true})"; {
else if (pTable->getSelectionModel() == Table::SM_MULTIROW) if (pTable->getSelectionModel() == Table::SM_SINGLEROW)
ostr << ",selModel:new Ext.grid.RowSelectionModel({singleSelect:false})"; 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.jsDelegates().empty())
{
ostr << ",listeners:{";
Utility::writeJSEvent(ostr, EV_ROWCLICKED, pTable->rowClicked.jsDelegates());
ostr << "}";
}
ostr << "})"; //close selModel
}
if (pTable->getWidth() > 0) if (pTable->getWidth() > 0)
ostr << ",width:" << pTable->getWidth(); ostr << ",width:" << pTable->getWidth();
if (pTable->getHeight() > 0) if (pTable->getHeight() > 0)

View File

@@ -67,6 +67,7 @@ public:
static const std::string FIELD_VAL; static const std::string FIELD_VAL;
static const std::string FIELD_CNT; static const std::string FIELD_CNT;
static const std::string EV_CELLCLICKED; static const std::string EV_CELLCLICKED;
static const std::string EV_ROWCLICKED;
static const std::string EV_CELLVALUECHANGED; static const std::string EV_CELLVALUECHANGED;
static const std::string EV_LOADDATA; static const std::string EV_LOADDATA;
static const std::string EV_AFTERLOAD; static const std::string EV_AFTERLOAD;
@@ -98,7 +99,9 @@ public:
LoadData(Poco::Net::HTTPServerResponse* pResponse, Table* pTable, int firstRow, int rowCnt); LoadData(Poco::Net::HTTPServerResponse* pResponse, Table* pTable, int firstRow, int rowCnt);
}; };
JavaScriptEvent<Table::CellClick> cellClicked; JavaScriptEvent<std::size_t> rowClicked; /// fires the row clicked event
JavaScriptEvent<Table::CellClick> cellClicked; /// fires the cellClicked event
JavaScriptEvent<Table::CellValueChange> cellValueChanged; JavaScriptEvent<Table::CellValueChange> cellValueChanged;

View File

@@ -49,6 +49,7 @@ const std::string Table::FIELD_ROW("row");
const std::string Table::FIELD_VAL("val"); const std::string Table::FIELD_VAL("val");
const std::string Table::FIELD_CNT("cnt"); const std::string Table::FIELD_CNT("cnt");
const std::string Table::EV_CELLCLICKED("click"); const std::string Table::EV_CELLCLICKED("click");
const std::string Table::EV_ROWCLICKED("row");
const std::string Table::EV_CELLVALUECHANGED("edit"); const std::string Table::EV_CELLVALUECHANGED("edit");
const std::string Table::EV_LOADDATA("load"); const std::string Table::EV_LOADDATA("load");
const std::string Table::EV_AFTERLOAD("afterload"); const std::string Table::EV_AFTERLOAD("afterload");
@@ -157,6 +158,15 @@ void Table::handleAjaxRequest(const Poco::Net::NameValueCollection& args, Poco::
cellClicked(this, ev); cellClicked(this, ev);
response.send(); response.send();
} }
else if (ev == EV_ROWCLICKED)
{
if (row < 0 )
throw InvalidArgumentException("row out of range");
std::size_t theRow(row);
rowClicked(this, theRow);
response.send();
}
else if (ev == EV_CELLVALUECHANGED) else if (ev == EV_CELLVALUECHANGED)
{ {
if (col < 0 || row < 0 || col >= getColumnCount()) if (col < 0 || row < 0 || col >= getColumnCount())