added new events to combobox, rendering fixes IE

This commit is contained in:
Peter Schojer 2008-09-03 12:49:54 +00:00
parent b74e41b626
commit 52ab7d01ca
8 changed files with 52 additions and 17 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_AFTERLOAD;
ComboBoxCellRenderer();
/// Creates the ComboBoxCellRenderer.
@ -72,7 +73,7 @@ public:
void renderBody(const Renderable* pRenderable, const RenderContext& context, std::ostream& ostr);
/// Emits code for the page body to the given output stream.
private:
static void onLoad(void* pSender, Poco::Net::HTTPServerResponse* &pResponse);
@ -81,6 +82,9 @@ private:
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 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_AFTERLOAD("load");
ComboBoxCellRenderer::ComboBoxCellRenderer()
@ -76,6 +77,16 @@ JSDelegate ComboBoxCellRenderer::createSelectedServerCallback(const ComboBox* pC
}
Poco::WebWidgets::JSDelegate ComboBoxCellRenderer::createAfterLoadServerCallback(const ComboBox* pCombo)
{
poco_check_ptr (pCombo);
static const std::string signature("function(aStore, recs, op)");
std::map<std::string, std::string> addParams;
addParams.insert(std::make_pair(RequestHandler::KEY_EVID, ComboBoxCell::EV_AFTERLOAD));
return Utility::createServerCallback(signature, addParams, pCombo->id(), pCombo->afterLoad.getOnSuccess(), pCombo->afterLoad.getOnFailure());
}
void ComboBoxCellRenderer::renderHead(const Renderable* pRenderable, const RenderContext& context, std::ostream& ostr)
{
poco_assert_dbg (pRenderable != 0);
@ -95,25 +106,31 @@ void ComboBoxCellRenderer::renderHead(const Renderable* pRenderable, const Rende
std::string url(Utility::createURI(addParams, pOwner->id()));
ostr << url << "}),";
ostr << "reader:new Ext.data.ArrayReader()})";
ostr << "reader:new Ext.data.ArrayReader()";
if (pComboOwner && pComboOwner->afterLoad.hasJavaScriptCode())
{
ostr << ",listeners:{";
Utility::writeJSEvent(ostr, EV_AFTERLOAD, pComboOwner->afterLoad, &ComboBoxCellRenderer::createAfterLoadServerCallback, pComboOwner);
ostr << "}";
}
ostr << "})"; // end SimpleStore
ostr << ",displayField:'d',typeAhead:true,triggerAction:'all'";
std::string tooltip (pCell->getToolTip());
if (pComboOwner && pComboOwner->selected.hasJavaScriptCode())
if (pComboOwner && (pComboOwner->selected.hasJavaScriptCode() || !tooltip.empty()))
{
ostr << ",listeners:{";
Utility::writeJSEvent(ostr, EV_SELECTED, pComboOwner->selected, &ComboBoxCellRenderer::createSelectedServerCallback, pComboOwner);
bool written = Utility::writeJSEvent(ostr, EV_SELECTED, pComboOwner->selected, &ComboBoxCellRenderer::createSelectedServerCallback, pComboOwner);
if (!tooltip.empty())
ostr << ",render:function(c){Ext.QuickTips.register({target:c.getEl(),text:'" << Utility::safe(tooltip) << "'});}";
{
if (written)
ostr << ",";
ostr << "render:function(c){Ext.QuickTips.register({target:c.getEl(),text:'" << Utility::safe(tooltip) << "'});}";
}
ostr << "}";
}
else if (!tooltip.empty())
{
ostr << ",listeners:{";
ostr << "render:function(c){Ext.QuickTips.register({target:c.getEl(),text:'" << Utility::safe(tooltip) << "'});}}";
}
ostr << "})";
pCell->beforeLoad += Poco::delegate(&ComboBoxCellRenderer::onLoad);

View File

@ -69,6 +69,7 @@ void LayoutRenderer::renderLayoutHead(const Layout* pLayout, const RenderContext
// the parent is not a panel
// assume that the direct parent is a panel
ostr << "new Ext.Panel({border:false,bodyBorder:false,";
ostr << "id:'" << pLayout->id() << "',";
renderParameters(pLayout, context, ostr, layoutId, layoutConfig, cols, horPad, vertPad);
ostr << "})";
}
@ -172,9 +173,9 @@ void LayoutRenderer::visitChildren(const Layout* pLayout, int cols, int horPad,
if (*it)
{
//horizontallayout works only when children are panels
ostr << "new Ext.Panel({border:false,bodyBorder:false,items:";
ostr << "new Ext.Panel({border:false,bodyBorder:false,items:[";
(*it)->renderHead(context, ostr);
ostr << "})";
ostr << "]})";
}
else
ostr << "{}";

View File

@ -64,6 +64,8 @@ public:
JavaScriptEvent<ComboBoxEvent> selected; /// thrown whenever a new element is selected
JavaScriptEvent<ComboBoxEvent> afterLoad; // thrown after data was loaded
ComboBox();
/// Creates the ComboBox.

View File

@ -59,9 +59,12 @@ public:
static const std::string EV_SELECTED;
static const std::string EV_LOAD;
static const std::string EV_AFTERLOAD;
static const std::string FIELD_VAL;
Delegate selected;
Delegate afterLoad;
FIFOEvent<Poco::Net::HTTPServerResponse*> beforeLoad; /// thrown whenever a load is requested
ComboBoxCell(View* pOwner);

View File

@ -41,6 +41,7 @@
#include "Poco/WebWidgets/TextField.h"
#include "Poco/WebWidgets/IntFormatter.h"
namespace Poco {
@ -56,7 +57,7 @@ public:
NumberField();
/// Creates an anonymous NumberField.
NumberField(const std::string& name);
NumberField(const std::string& name, Formatter::Ptr pF = new IntFormatter());
/// Creates a named NumberField.
protected:

View File

@ -43,7 +43,8 @@ namespace WebWidgets {
const std::string ComboBoxCell::FIELD_VAL("val");
const std::string ComboBoxCell::EV_LOAD("load");
const std::string ComboBoxCell::EV_LOAD("beforeLoad");
const std::string ComboBoxCell::EV_AFTERLOAD("afterLoad");
const std::string ComboBoxCell::EV_SELECTED("sel");
@ -92,6 +93,7 @@ void ComboBoxCell::handleAjaxRequest(const Poco::Net::NameValueCollection& args,
{
Poco::Net::HTTPServerResponse* pResponse = &response;
beforeLoad.notify(this, pResponse);
// response is handled in beofreLoad callback
}
else if (ev == EV_SELECTED)
{
@ -103,6 +105,11 @@ void ComboBoxCell::handleAjaxRequest(const Poco::Net::NameValueCollection& args,
response.send();
}
else if (ev == EV_AFTERLOAD)
{
afterLoad(this);
response.send();
}
}

View File

@ -54,8 +54,8 @@ NumberField::NumberField(const std::type_info& type):
}
NumberField::NumberField(const std::string& name):
TextField(name, typeid(NumberField), new NumberFieldCell(this))
NumberField::NumberField(const std::string& name, Formatter::Ptr pF):
TextField(name, typeid(NumberField), new NumberFieldCell(this, pF))
{
}