mirror of
https://github.com/pocoproject/poco.git
synced 2025-01-31 14:39:53 +01:00
added beforeselect event
This commit is contained in:
parent
3e3ff2766c
commit
9778ea9f5e
@ -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
|
||||
};
|
||||
|
@ -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)
|
||||
|
@ -63,7 +63,9 @@ public:
|
||||
typedef Event<ComboBox> ComboBoxEvent;
|
||||
typedef ComboBoxCell::OldNewValue SelectEvent; /// a pair of old, then new value
|
||||
|
||||
JavaScriptEvent<const SelectEvent> selected; /// thrown whenever a new element is selected
|
||||
JavaScriptEvent<const Poco::Any> beforeSelect; /// thrown before a new element is selected
|
||||
|
||||
JavaScriptEvent<const SelectEvent> selected; /// thrown after a new element is selected
|
||||
|
||||
JavaScriptEvent<ComboBoxEvent> afterLoad; // thrown after data was loaded
|
||||
|
||||
@ -130,6 +132,9 @@ protected:
|
||||
void fireSelected(const void* pSender, const SelectEvent& oldNewPair);
|
||||
/// Fires the selected event.
|
||||
|
||||
void fireBeforeSelect(const void* pSender, const Poco::Any& newValue);
|
||||
/// Fires the beforeSelect event.
|
||||
|
||||
void fireAfterLoad(void* pSender);
|
||||
/// Fires the afterLoad event.
|
||||
|
||||
|
@ -60,12 +60,15 @@ public:
|
||||
|
||||
|
||||
static const std::string EV_SELECTED;
|
||||
static const std::string EV_BEFORESELECT;
|
||||
static const std::string EV_LOAD;
|
||||
static const std::string EV_AFTERLOAD;
|
||||
static const std::string FIELD_VAL;
|
||||
|
||||
FIFOEvent<const OldNewValue> selected; /// thrown whenever a new element is selected
|
||||
Delegate afterLoad;
|
||||
FIFOEvent<const Poco::Any> beforeSelect; /// thrown before a new element is selected
|
||||
FIFOEvent<const OldNewValue> selected; /// thrown after a new element is selected
|
||||
|
||||
Delegate afterLoad;
|
||||
|
||||
FIFOEvent<Poco::Net::HTTPServerResponse*> beforeLoad; /// thrown whenever a load is requested
|
||||
|
||||
|
@ -48,6 +48,7 @@ ComboBox::ComboBox(const std::string& name, const std::type_info& type):
|
||||
{
|
||||
ComboBoxCell::Ptr pCell = cell<ComboBoxCell>();
|
||||
pCell->selected += Poco::delegate(this, &ComboBox::fireSelected);
|
||||
pCell->beforeSelect += Poco::delegate(this, &ComboBox::fireBeforeSelect);
|
||||
pCell->afterLoad = delegate(*this, &ComboBox::fireAfterLoad);
|
||||
}
|
||||
|
||||
@ -57,6 +58,7 @@ ComboBox::ComboBox(const std::type_info& type):
|
||||
{
|
||||
ComboBoxCell::Ptr pCell = cell<ComboBoxCell>();
|
||||
pCell->selected += Poco::delegate(this, &ComboBox::fireSelected);
|
||||
pCell->beforeSelect += Poco::delegate(this, &ComboBox::fireBeforeSelect);
|
||||
pCell->afterLoad = delegate(*this, &ComboBox::fireAfterLoad);
|
||||
}
|
||||
|
||||
@ -66,6 +68,7 @@ ComboBox::ComboBox(const std::string& name):
|
||||
{
|
||||
ComboBoxCell::Ptr pCell = cell<ComboBoxCell>();
|
||||
pCell->selected += Poco::delegate(this, &ComboBox::fireSelected);
|
||||
pCell->beforeSelect += Poco::delegate(this, &ComboBox::fireBeforeSelect);
|
||||
pCell->afterLoad = delegate(*this, &ComboBox::fireAfterLoad);
|
||||
}
|
||||
|
||||
@ -75,6 +78,7 @@ ComboBox::ComboBox():
|
||||
{
|
||||
ComboBoxCell::Ptr pCell = cell<ComboBoxCell>();
|
||||
pCell->selected += Poco::delegate(this, &ComboBox::fireSelected);
|
||||
pCell->beforeSelect += Poco::delegate(this, &ComboBox::fireBeforeSelect);
|
||||
pCell->afterLoad = delegate(*this, &ComboBox::fireAfterLoad);
|
||||
}
|
||||
|
||||
@ -90,6 +94,12 @@ void ComboBox::fireSelected(const void* pSender, const ComboBoxCell::OldNewValue
|
||||
}
|
||||
|
||||
|
||||
void ComboBox::fireBeforeSelect(const void* pSender, const Poco::Any& newValue)
|
||||
{
|
||||
beforeSelect(this, newValue);
|
||||
}
|
||||
|
||||
|
||||
void ComboBox::fireAfterLoad(void* pSender)
|
||||
{
|
||||
ComboBoxEvent sel(this);
|
||||
|
@ -46,6 +46,7 @@ const std::string ComboBoxCell::FIELD_VAL("val");
|
||||
const std::string ComboBoxCell::EV_LOAD("doLoad");
|
||||
const std::string ComboBoxCell::EV_AFTERLOAD("afterLoad");
|
||||
const std::string ComboBoxCell::EV_SELECTED("sel");
|
||||
const std::string ComboBoxCell::EV_BEFORESELECT("befSel");
|
||||
|
||||
|
||||
ComboBoxCell::ComboBoxCell(View* pOwner):
|
||||
@ -105,6 +106,13 @@ void ComboBoxCell::handleAjaxRequest(const Poco::Net::NameValueCollection& args,
|
||||
|
||||
response.send();
|
||||
}
|
||||
else if (ev == EV_BEFORESELECT)
|
||||
{
|
||||
Formatter::Ptr pForm(getFormatter());
|
||||
Poco::Any newVal = pForm->parse(args[FIELD_VAL]);
|
||||
beforeSelect(this, newVal);
|
||||
response.send();
|
||||
}
|
||||
else if (ev == EV_AFTERLOAD)
|
||||
{
|
||||
afterLoad(this);
|
||||
@ -115,6 +123,8 @@ void ComboBoxCell::handleAjaxRequest(const Poco::Net::NameValueCollection& args,
|
||||
|
||||
void ComboBoxCell::setSelected(const Any& elem)
|
||||
{
|
||||
//don't throw beforeSelect here: it's a web only event
|
||||
//(otherwise we get two beforeSelect events)
|
||||
Poco::Any old;
|
||||
if (hasSelected())
|
||||
old = getSelected();
|
||||
|
Loading…
x
Reference in New Issue
Block a user