added beforeselect event

This commit is contained in:
Peter Schojer
2008-09-04 13:02:54 +00:00
parent 3e3ff2766c
commit 9778ea9f5e
6 changed files with 60 additions and 8 deletions

View File

@@ -60,6 +60,7 @@ class ExtJS_API ComboBoxCellRenderer: public Poco::WebWidgets::Renderer
{
public:
static const std::string EV_SELECTED;
static const std::string EV_BEFORESELECT;
static const std::string EV_AFTERLOAD;
ComboBoxCellRenderer();
@@ -76,13 +77,18 @@ public:
private:
static void onLoad(void* pSender, Poco::Net::HTTPServerResponse* &pResponse);
static void serialize(const ComboBoxCell* pCell, std::ostream& out);
static Poco::WebWidgets::JSDelegate createSelectedServerCallback(const ComboBox* pCombo);
/// Adds a server callback for the selected event. The method signature for select is
/// select : ( Ext.form.ComboBox combo, Ext.data.Record record, Number index )
static Poco::WebWidgets::JSDelegate createBeforeSelectServerCallback(const ComboBox* pCombo);
/// Adds a server callback for the beforeselect event. The method signature is
/// beforeselect : ( Ext.form.ComboBox combo, Ext.data.Record record, Number index )
/// return false to forbid it
static Poco::WebWidgets::JSDelegate createAfterLoadServerCallback(const ComboBox* pCombo);
/// Create a server callback for afterLoad of ComboBox list
};

View File

@@ -53,6 +53,7 @@ namespace ExtJS {
const std::string ComboBoxCellRenderer::EV_SELECTED("select");
const std::string ComboBoxCellRenderer::EV_BEFORESELECT("beforeselect");
const std::string ComboBoxCellRenderer::EV_AFTERLOAD("load");
@@ -77,6 +78,18 @@ JSDelegate ComboBoxCellRenderer::createSelectedServerCallback(const ComboBox* pC
}
Poco::WebWidgets::JSDelegate ComboBoxCellRenderer::createBeforeSelectServerCallback(const ComboBox* pCombo)
{
// beforeselect : ( Ext.form.ComboBox combo, Ext.data.Record record, Number index )
// return false to forbid it
static const std::string signature("function(combo,rec,idx)");
std::map<std::string, std::string> addParams;
addParams.insert(std::make_pair(ComboBoxCell::FIELD_VAL, "+rec.get('d')"));
addParams.insert(std::make_pair(RequestHandler::KEY_EVID, ComboBoxCell::EV_BEFORESELECT));
return Utility::createServerCallback(signature, addParams, pCombo->id(), pCombo->beforeSelect.getOnSuccess(), pCombo->beforeSelect.getOnFailure());
}
Poco::WebWidgets::JSDelegate ComboBoxCellRenderer::createAfterLoadServerCallback(const ComboBox* pCombo)
{
poco_check_ptr (pCombo);
@@ -118,11 +131,16 @@ void ComboBoxCellRenderer::renderHead(const Renderable* pRenderable, const Rende
std::string tooltip (pCell->getToolTip());
if (pComboOwner && (pComboOwner->selected.hasJavaScriptCode() || !tooltip.empty()))
if (pComboOwner && (pComboOwner->selected.hasJavaScriptCode() || !tooltip.empty() || pComboOwner->beforeSelect.hasJavaScriptCode()))
{
ostr << ",listeners:{";
bool written = Utility::writeJSEvent(ostr, EV_SELECTED, pComboOwner->selected, &ComboBoxCellRenderer::createSelectedServerCallback, pComboOwner);
if (pComboOwner->beforeSelect.hasJavaScriptCode())
{
if (written)
ostr << ",";
written = Utility::writeJSEvent(ostr, EV_BEFORESELECT, pComboOwner->beforeSelect, &ComboBoxCellRenderer::createBeforeSelectServerCallback, pComboOwner);
}
if (!tooltip.empty())
{
if (written)