mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-23 08:31:43 +02:00
added editmode support
This commit is contained in:
@@ -76,6 +76,7 @@ public:
|
||||
static const std::string EV_KEYPRESSED;
|
||||
static const std::string EV_ROWSELECTED;
|
||||
static const std::string EV_CELLSELECTED;
|
||||
static const std::string EV_STARTCELLVALUECHANGE;
|
||||
static const std::string HIDDEN_INDEX_ROW;
|
||||
|
||||
TableRenderer();
|
||||
@@ -100,6 +101,11 @@ public:
|
||||
/// containing members (grid, record, column, row, value, cancel)!
|
||||
/// obj.cancel must be set to false to forbid the edit
|
||||
|
||||
static Poco::WebWidgets::JSDelegate createStartCellValueChangeServerCallback(const Table* pTable);
|
||||
/// Adds a javascript callback to inform the WebServer that the client has entered edit mode 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)!
|
||||
|
||||
static Poco::WebWidgets::JSDelegate createCellSelectedServerCallback(const Table* pTable);
|
||||
/// Adds a javascript callback to inform the WebServer that the client has selected a cell
|
||||
/// The Extjs handler offers a method signature of
|
||||
|
@@ -59,6 +59,7 @@ const std::string TableRenderer::EV_ROWCLICKED("rowclick");
|
||||
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_STARTCELLVALUECHANGE("beforeedit");
|
||||
const std::string TableRenderer::EV_AFTEREDIT("afteredit");
|
||||
const std::string TableRenderer::EV_AFTERLOAD("load");
|
||||
const std::string TableRenderer::EV_RENDER("render");
|
||||
@@ -316,6 +317,31 @@ Poco::WebWidgets::JSDelegate TableRenderer::createKeyPressedServerCallback(const
|
||||
}
|
||||
|
||||
|
||||
Poco::WebWidgets::JSDelegate TableRenderer::createStartCellValueChangeServerCallback(const Table* pTable)
|
||||
{
|
||||
// beforeedit : ( Object e )
|
||||
// * grid - This grid
|
||||
// * record - The record being edited
|
||||
// * field - The field name being edited
|
||||
// * value - The value for the field being edited.
|
||||
// * row - The grid row index
|
||||
// * column - The grid column index
|
||||
// * cancel - Set this to true to cancel the edit or return false from your handler.
|
||||
|
||||
poco_check_ptr (pTable);
|
||||
static const std::string signature("function(e)");
|
||||
//extract the true row index from the last column!
|
||||
std::string origRow("+e.grid.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_STARTCELLVALUECHANGE));
|
||||
return Utility::createServerCallback(signature, addParams, pTable->id(), pTable->startCellValueChange.getOnSuccess(), pTable->startCellValueChange.getOnFailure());
|
||||
}
|
||||
|
||||
|
||||
void TableRenderer::renderProperties(const Table* pTable, const RenderContext& context, std::ostream& ostr)
|
||||
{
|
||||
WebApplication& app = WebApplication::instance();
|
||||
@@ -341,6 +367,13 @@ void TableRenderer::renderProperties(const Table* pTable, const RenderContext& c
|
||||
written = Utility::writeJSEvent(ostr, EV_BEFORECELLVALUECHANGED, pTable->beforeCellValueChanged,
|
||||
&TableRenderer::createBeforeCellValueChangedServerCallback, pTable);
|
||||
}
|
||||
|
||||
if (pTable->startCellValueChange.hasJavaScriptCode())
|
||||
{
|
||||
if (written) ostr << ",";
|
||||
written = Utility::writeJSEvent(ostr, EV_STARTCELLVALUECHANGE, pTable->startCellValueChange,
|
||||
&TableRenderer::createStartCellValueChangeServerCallback, pTable);
|
||||
}
|
||||
}
|
||||
|
||||
if (pTable->keyDown.hasJavaScriptCode())
|
||||
|
@@ -82,7 +82,7 @@ void TextFieldCellRenderer::renderBody(const Renderable* pRenderable, const Rend
|
||||
void TextFieldCellRenderer::writeCellProperties(const TextFieldCell* pCell, std::ostream& ostr, bool writeValue, bool writeListeners)
|
||||
{
|
||||
Utility::writeCellProperties(pCell, ostr);
|
||||
|
||||
if (pCell->getEditMode() == Cell::EM_SELECTCONTENT)
|
||||
ostr << ",selectOnFocus:true";
|
||||
|
||||
if (writeValue&& !pCell->getValue().empty())
|
||||
|
@@ -66,6 +66,13 @@ class WebWidgets_API Cell: public Renderable, public RequestProcessor
|
||||
public:
|
||||
typedef Poco::AutoPtr<Cell> Ptr;
|
||||
|
||||
enum EditMode
|
||||
/// Confgures edit mode for cells
|
||||
{
|
||||
EM_SELECTCONTENT = 0,
|
||||
EM_CURSORATENDOFVALUE
|
||||
};
|
||||
|
||||
void enable(bool enabled = true);
|
||||
/// Enables (if enabled == true) or disables the Cell.
|
||||
|
||||
@@ -155,6 +162,12 @@ public:
|
||||
bool isEditable() const;
|
||||
/// Returns true iff the Cell is editable.
|
||||
|
||||
void setEditMode(Cell::EditMode em);
|
||||
/// Sets the edit mode
|
||||
|
||||
Cell::EditMode getEditMode() const;
|
||||
/// Returns the edit mode
|
||||
|
||||
// RequestProcessor
|
||||
virtual void handleForm(const std::string& field, const std::string& value);
|
||||
/// Handles a form field submitted by the client.
|
||||
@@ -180,6 +193,7 @@ protected:
|
||||
/// Returns the owner of this Cell.
|
||||
|
||||
private:
|
||||
EditMode _em;
|
||||
View* _pOwner;
|
||||
bool _enabled;
|
||||
bool _editable;
|
||||
@@ -255,6 +269,18 @@ inline int Cell::getRowIndex() const
|
||||
}
|
||||
|
||||
|
||||
inline void Cell::setEditMode(Cell::EditMode em)
|
||||
{
|
||||
_em = em;
|
||||
}
|
||||
|
||||
|
||||
inline Cell::EditMode Cell::getEditMode() const
|
||||
{
|
||||
return _em;
|
||||
}
|
||||
|
||||
|
||||
} } // namespace Poco::WebWidgets
|
||||
|
||||
|
||||
|
@@ -81,6 +81,7 @@ public:
|
||||
static const std::string EV_KEYPRESSED;
|
||||
static const std::string EV_ROWSELECTED;
|
||||
static const std::string EV_CELLSELECTED;
|
||||
static const std::string EV_STARTCELLVALUECHANGE;
|
||||
|
||||
struct WebWidgets_API CellClick
|
||||
{
|
||||
@@ -121,9 +122,11 @@ public:
|
||||
|
||||
JavaScriptEvent<Table::CellClick> beforeCellClicked; /// fires when the mouse is pressed down on a cell
|
||||
|
||||
JavaScriptEvent<Table::CellValueChange> cellValueChanged;
|
||||
JavaScriptEvent<Table::CellValueChange> cellValueChanged; /// triggered after data is written to the table
|
||||
|
||||
JavaScriptEvent<Table::CellValueChange> beforeCellValueChanged;
|
||||
JavaScriptEvent<Table::CellValueChange> beforeCellValueChanged; /// triggered before data is written to the table
|
||||
|
||||
JavaScriptEvent<Table::CellClick> startCellValueChange; /// triggered before a beforeCellValueChanged
|
||||
|
||||
JavaScriptEvent<Table*> afterLoad; // thrown after data was loaded
|
||||
|
||||
|
@@ -89,6 +89,12 @@ public:
|
||||
bool isEditable() const;
|
||||
/// Returns true iff the Cell is editable.
|
||||
|
||||
void setEditMode(Cell::EditMode em);
|
||||
/// Sets the edit mode of the cell
|
||||
|
||||
Cell::EditMode getEditMode() const;
|
||||
/// Returns the edit mode of the cell
|
||||
|
||||
void setCustomRenderer(const std::string& jsCode);
|
||||
/// Allows to set custom JavaScript code that renders the values of the columns
|
||||
/// This code depends on the rendering library used during run-time!
|
||||
@@ -174,6 +180,19 @@ inline bool TableColumn::isEditable() const
|
||||
}
|
||||
|
||||
|
||||
inline void TableColumn::setEditMode(Cell::EditMode em)
|
||||
{
|
||||
_pCell->setEditMode(em);
|
||||
}
|
||||
|
||||
|
||||
inline Cell::EditMode TableColumn::getEditMode() const
|
||||
|
||||
{
|
||||
return _pCell->getEditMode();
|
||||
}
|
||||
|
||||
|
||||
inline void TableColumn::setCustomRenderer(const std::string& jsCode)
|
||||
{
|
||||
_customRenderer = jsCode;
|
||||
|
@@ -45,6 +45,7 @@ namespace WebWidgets {
|
||||
|
||||
Cell::Cell(View* pOwner, const std::type_info& type):
|
||||
Renderable(type),
|
||||
_em(EM_SELECTCONTENT),
|
||||
_pOwner(pOwner),
|
||||
_enabled(true),
|
||||
_editable(true),
|
||||
@@ -58,6 +59,7 @@ Cell::Cell(View* pOwner, const std::type_info& type):
|
||||
|
||||
Cell::Cell(const std::type_info& type):
|
||||
Renderable(type),
|
||||
_em(EM_SELECTCONTENT),
|
||||
_pOwner(0),
|
||||
_enabled(true),
|
||||
_editable(true),
|
||||
|
@@ -63,6 +63,7 @@ const std::string Table::EV_KEYDOWN("keydown");
|
||||
const std::string Table::EV_KEYPRESSED("keypressed");
|
||||
const std::string Table::EV_ROWSELECTED("rowselected");
|
||||
const std::string Table::EV_CELLSELECTED("cellselected");
|
||||
const std::string Table::EV_STARTCELLVALUECHANGE("startedit");
|
||||
|
||||
|
||||
Table::Table(const TableColumns& tc, TableModel::Ptr pModel):
|
||||
@@ -301,6 +302,15 @@ void Table::handleAjaxRequest(const Poco::Net::NameValueCollection& args, Poco::
|
||||
rowSelected(this, theRow);
|
||||
response.send();
|
||||
}
|
||||
else if (ev == EV_STARTCELLVALUECHANGE)
|
||||
{
|
||||
if (col < 0 || row < 0 || col >= getColumnCount())
|
||||
throw InvalidArgumentException("col/row out of range");
|
||||
|
||||
CellClick ev(row, col);
|
||||
startCellValueChange(this, ev);
|
||||
response.send();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user