fixed IE7 rendering error

This commit is contained in:
Peter Schojer 2008-06-24 09:55:10 +00:00
parent cfbe8fd28a
commit b486be2622
7 changed files with 163 additions and 29 deletions

View File

@ -59,6 +59,7 @@ class ExtJS_API PageRenderer: public Poco::WebWidgets::Renderer
public:
static const std::string EV_BEFORERENDER;
static const std::string EV_AFTERRENDER;
static const std::string VAR_LOCALTMP; /// local tmp variable
PageRenderer();
/// Creates the PageRenderer.

View File

@ -66,6 +66,7 @@ public:
static const std::string EV_ROWCLICKED;
static const std::string EV_AFTEREDIT;
static const std::string EV_AFTERLOAD;
static const std::string EV_RENDER;
static const std::string HIDDEN_INDEX_ROW;
TableRenderer();
@ -79,22 +80,7 @@ public:
void renderBody(const Renderable* pRenderable, const RenderContext& context, std::ostream& ostr);
/// Emits code for the page body to the given output stream.
protected:
static void renderProperties(const Table* pTable, const RenderContext& context, std::ostream& ostr);
/// Renders Table properties
static void renderColumns(const Table* pTable, const RenderContext& context, std::ostream& ostr);
/// Renders the columns of the table
static void renderColumn(const Table* pTable, const TableColumn& tc, int idx, const RenderContext& context, std::ostream& ostr);
/// Renders a single colum
static void renderStore(const Table* pTable, std::ostream& ostr);
/// Renders the data store of the table
static void onBeforeLoad(void* pSender, Table::LoadData& ld);
static Poco::WebWidgets::JSDelegate createCellValueChangedServerCallback(const Table* pTable);
/// Adds a javascript callback to inform the WebServer that the client has changed a value in the Table
/// The Extjs handler offers a method signature of "function(obj)" where obj is a complex element containing members (column, row, value)
@ -112,6 +98,25 @@ protected:
static Poco::WebWidgets::JSDelegate createAfterLoadServerCallback(const Table* pTable);
/// 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 )
static Poco::WebWidgets::JSDelegate createRenderServerCallback(const Table* pTable);
/// Adds a javascript callback to inform the WebServer that the client has finished rendering
/// Method signature is ( Grid this, config)
protected:
static void renderProperties(const Table* pTable, const RenderContext& context, std::ostream& ostr);
/// Renders Table properties
static void renderColumns(const Table* pTable, const RenderContext& context, std::ostream& ostr);
/// Renders the columns of the table
static void renderColumn(const Table* pTable, const TableColumn& tc, int idx, const RenderContext& context, std::ostream& ostr);
/// Renders a single colum
static void renderStore(const Table* pTable, std::ostream& ostr);
/// Renders the data store of the table
static void onBeforeLoad(void* pSender, Table::LoadData& ld);
};

View File

@ -51,6 +51,7 @@ namespace ExtJS {
const std::string PageRenderer::EV_BEFORERENDER("beforerender");
const std::string PageRenderer::EV_AFTERRENDER("show"); //don't use afterrender which fires before all the children are rendered!
const std::string PageRenderer::VAR_LOCALTMP("tmpLocal");
PageRenderer::PageRenderer()
@ -117,7 +118,9 @@ void PageRenderer::renderHead(const Renderable* pRenderable, const RenderContext
{
//start inline javascript block
ostr << "<script type=\"text/javascript\">";
ostr << "Ext.onReady(function() {";
ostr << "var " << VAR_LOCALTMP << ";"; // tmp variable needed for table renderer
ostr << "Ext.QuickTips.init();";
ostr << "Ext.Ajax.on({'requestexception':function(conn, resp, obj){";
ostr << "Ext.Msg.show({";

View File

@ -58,6 +58,7 @@ 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_AFTERLOAD("load");
const std::string TableRenderer::EV_RENDER("render");
const std::string TableRenderer::HIDDEN_INDEX_ROW("hidIdx");
@ -131,6 +132,17 @@ Poco::WebWidgets::JSDelegate TableRenderer::createAfterLoadServerCallback(const
}
Poco::WebWidgets::JSDelegate TableRenderer::createRenderServerCallback(const Table* pTable)
{
poco_check_ptr (pTable);
static const std::string signature("function(grid, cfg)");
std::map<std::string, std::string> addParams;
addParams.insert(std::make_pair(RequestHandler::KEY_EVID, Table::EV_RENDER));
return Utility::createServerCallback(signature, addParams, pTable->id(), pTable->afterRender.getOnSuccess(), pTable->afterRender.getOnFailure());
}
Poco::WebWidgets::JSDelegate TableRenderer::createCellClickedServerCallback(const Table* pTable)
{
poco_check_ptr (pTable);
@ -191,17 +203,30 @@ void TableRenderer::renderProperties(const Table* pTable, const RenderContext& c
else
written = Utility::writeJSEvent(ostr, EV_AFTEREDIT, modList);
}
if (written)
ostr << ",";
if (pTable->cellClicked.willDoServerCallback())
written = Utility::writeJSEvent(ostr, EV_CELLCLICKED, pTable->cellClicked.jsDelegates(),
if (pTable->cellClicked.hasJavaScriptCode())
{
if (written)
ostr << ",";
if (pTable->cellClicked.willDoServerCallback())
written = Utility::writeJSEvent(ostr, EV_CELLCLICKED, pTable->cellClicked.jsDelegates(),
TableRenderer::createCellClickedServerCallback(pTable),
pTable->cellClicked.getServerCallbackPos());
else
written = Utility::writeJSEvent(ostr, EV_CELLCLICKED, pTable->cellClicked.jsDelegates());
else
written = Utility::writeJSEvent(ostr, EV_CELLCLICKED, pTable->cellClicked.jsDelegates());
}
if (pTable->afterRender.hasJavaScriptCode())
{
if (written)
ostr << ",";
if (pTable->afterRender.willDoServerCallback())
written = Utility::writeJSEvent(ostr, EV_RENDER, pTable->afterRender.jsDelegates(),
TableRenderer::createRenderServerCallback(pTable),
pTable->afterRender.getServerCallbackPos());
else
written = Utility::writeJSEvent(ostr, EV_RENDER, pTable->afterRender.jsDelegates());
}
ostr << "},"; //close listeners
@ -209,6 +234,9 @@ 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
// sorting is allowed though, i.e row matching is active
ostr << ",clicksToEdit:1,stripeRows:true,enableColumnHide:false,enableColumnMove:false,loadMask:true";
if (pTable->getDragAndDrop())
ostr << ",enableDragDrop:true";
if (pTable->getSelectionModel() != Table::SM_CELL)
{
if (pTable->getSelectionModel() == Table::SM_SINGLEROW)
@ -232,8 +260,41 @@ void TableRenderer::renderProperties(const Table* pTable, const RenderContext& c
ostr << ",width:" << pTable->getWidth();
if (pTable->getHeight() > 0)
ostr << ",height:" << pTable->getHeight();
ostr << ",viewConfig: {";
ostr << "tpl: new Ext.XTemplate('<div class=\"cell\"></div>'),";
ostr << "getRowClass: function(rec, idx, p, store) {return 'cell';}";
ostr << "}";
ostr << ",store:";
ostr << "(tmpLocal=";
renderStore(pTable, ostr);
ostr << ")";
// bbar: new Ext.PagingToolbar({
// pageSize: 25,
// store: store,
// displayInfo: true,
// displayMsg: 'Displaying topics {0} - {1} of {2}',
// emptyMsg: "No topics to display",
// items:[
// '-', {
// pressed: true,
// enableToggle:true,
// text: 'Show Preview',
// cls: 'x-btn-text-icon details',
// toggleHandler: toggleDetails
// }]
// })
if (pTable->getPagingSize() > 0)
{
ostr << ",remoteSort:true";
ostr << ",bbar:new Ext.PagingToolbar({";
ostr << "pageSize:" << pTable->getPagingSize() << ",";
ostr << "displayInfo:true,";
ostr << "displayMsg: 'Displaying topics {0} - {1} of {2}',";
ostr << "emptyMsg:'No topics to display',";
ostr << "store:tmpLocal})";
}
Table* pT = const_cast<Table*>(pTable);
pT->beforeLoad += Poco::delegate(&TableRenderer::onBeforeLoad);
WebApplication::instance().registerAjaxProcessor(Poco::NumberFormatter::format(id), pT);

View File

@ -71,6 +71,7 @@ public:
static const std::string EV_CELLVALUECHANGED;
static const std::string EV_LOADDATA;
static const std::string EV_AFTERLOAD;
static const std::string EV_RENDER;
struct WebWidgets_API CellClick
{
@ -107,6 +108,8 @@ public:
JavaScriptEvent<Table*> afterLoad; // thrown after data was loaded
JavaScriptEvent<Table*> afterRender; // thrown after rendering
FIFOEvent<LoadData> beforeLoad; /// thrown whenever a load is requested, internal event to which the TableRenderer must register
enum SelectionModel
@ -116,8 +119,7 @@ public:
SM_SINGLEROW,
SM_MULTIROW
};
Table(const TableColumns& tc, TableModel::Ptr pModel);
/// Creates an anonymous Table.
@ -157,7 +159,19 @@ public:
void handleAjaxRequest(const Poco::Net::NameValueCollection& args, Poco::Net::HTTPServerResponse& response);
/// Handles a complete AJAX request submitted by the client.
void setDragAndDrop(bool val);
/// Sets drag adn drop support
bool getDragAndDrop() const;
/// Returns if drag and drop is enabled
void setPaging(int maxRowsPerPage);
/// Enables paging if maxRowsPerPage > 0
int getPagingSize() const;
/// Returns the paging size
protected:
Table(const std::string& name, const std::type_info& type, const TableColumns& tc, TableModel::Ptr pModel);
/// Creates a Table and assigns it the given name.
@ -175,6 +189,8 @@ private:
TableModel::Ptr _pModel;
TableColumns _columns;
SelectionModel _sm;
bool _dragAndDrop;
int _maxRowsPerPage;
};
@ -229,6 +245,29 @@ inline Table::SelectionModel Table::getSelectionModel() const
}
inline void Table::setDragAndDrop(bool val)
{
_dragAndDrop = val;
}
inline bool Table::getDragAndDrop() const
{
return _dragAndDrop;
}
inline void Table::setPaging(int maxRowsPerPage)
{
_maxRowsPerPage = maxRowsPerPage;
}
inline int Table::getPagingSize() const
{
return _maxRowsPerPage;
}
} } // namespace Poco::WebWidgets

View File

@ -75,6 +75,7 @@ void RequestHandler::handleRequest(Poco::Net::HTTPServerRequest& request, Poco::
_app.attachToThread();
Poco::Net::NameValueCollection args;
parseRequest(request, args);
if (args.empty())
{
Poco::Net::HTMLForm form(request, request.stream());
@ -86,6 +87,16 @@ void RequestHandler::handleRequest(Poco::Net::HTTPServerRequest& request, Poco::
}
else
{
Poco::Net::HTMLForm form(request, request.stream());
// we provide the form data transparently to the ajax request handler
// by simply adding it to the args already received via AJAX URI
Poco::Net::NameValueCollection::ConstIterator it = form.begin();
for (;it != form.end(); ++it)
{
const std::string& key = it->first;
const std::string& value = it->second;
args.add(key, value);
}
handleAjaxRequest(request, response, args);
}
}

View File

@ -53,13 +53,16 @@ const std::string Table::EV_ROWCLICKED("row");
const std::string Table::EV_CELLVALUECHANGED("edit");
const std::string Table::EV_LOADDATA("load");
const std::string Table::EV_AFTERLOAD("afterload");
const std::string Table::EV_RENDER("render");
Table::Table(const TableColumns& tc, TableModel::Ptr pModel):
View(typeid(Table)),
_pModel(pModel),
_columns(tc),
_sm(SM_CELL)
_sm(SM_CELL),
_dragAndDrop(false),
_maxRowsPerPage(0)
{
checkValidConfig();
}
@ -69,7 +72,9 @@ Table::Table(const std::string& name, const TableColumns& tc, TableModel::Ptr pM
View(name, typeid(Table)),
_pModel(pModel),
_columns(tc),
_sm(SM_CELL)
_sm(SM_CELL),
_dragAndDrop(false),
_maxRowsPerPage(0)
{
checkValidConfig();
}
@ -79,7 +84,9 @@ Table::Table(const std::string& name, const std::type_info& type, const TableCol
View(name, type),
_pModel(pModel),
_columns(tc),
_sm(SM_CELL)
_sm(SM_CELL),
_dragAndDrop(false),
_maxRowsPerPage(0)
{
checkValidConfig();
}
@ -89,7 +96,9 @@ Table::Table(const std::type_info& type, const TableColumns& tc, TableModel::Ptr
View(type),
_pModel(pModel),
_columns(tc),
_sm(SM_CELL)
_sm(SM_CELL),
_dragAndDrop(false),
_maxRowsPerPage(0)
{
checkValidConfig();
}
@ -190,6 +199,11 @@ void Table::handleAjaxRequest(const Poco::Net::NameValueCollection& args, Poco::
Table* pTable = this;
afterLoad(this, pTable);
}
else if (ev == EV_RENDER)
{
Table* pTable = this;
afterRender(this, pTable);
}
}