mirror of
https://github.com/pocoproject/poco.git
synced 2025-11-24 06:04:15 +01:00
added support for custom JS cell renderers
This commit is contained in:
@@ -41,6 +41,7 @@
|
||||
#include "Poco/WebWidgets/LookAndFeel.h"
|
||||
#include "Poco/WebWidgets/WebApplication.h"
|
||||
#include "Poco/WebWidgets/RequestHandler.h"
|
||||
#include "Poco/NumberFormatter.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
@@ -71,8 +72,11 @@ void PageRenderer::renderHead(const Renderable* pRenderable, const RenderContext
|
||||
static const std::string STRC_TITLE ("</title>");
|
||||
poco_assert_dbg (pRenderable != 0);
|
||||
poco_assert_dbg (pRenderable->type() == typeid(Poco::WebWidgets::Page));
|
||||
const Page* pPage = static_cast<const Poco::WebWidgets::Page*>(pRenderable);
|
||||
poco_assert_dbg (WebApplication::instance().getCurrentPage().get() == pPage);
|
||||
Page* pPage = const_cast<Page*>(static_cast<const Poco::WebWidgets::Page*>(pRenderable));
|
||||
pPage->pageRequested.notify(this, pPage);
|
||||
|
||||
poco_assert_dbg (context.application().getCurrentPage().get() == pPage);
|
||||
|
||||
const LookAndFeel& laf = context.lookAndFeel();
|
||||
ResourceManager::Ptr pRM = context.application().getResourceManager();
|
||||
|
||||
@@ -173,7 +177,7 @@ void PageRenderer::renderHead(const Renderable* pRenderable, const RenderContext
|
||||
}
|
||||
|
||||
ostr << STRC_HEAD;
|
||||
|
||||
WebApplication::instance().registerAjaxProcessor(Poco::NumberFormatter::format(pPage->id()), pPage);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -295,8 +295,11 @@ void TableRenderer::renderColumn(const Table* pTable, const TableColumn& tc, int
|
||||
ostr << ",editor:";
|
||||
tc.getCell()->renderHead(context, ostr);
|
||||
}
|
||||
|
||||
if (pHandler->useRenderer())
|
||||
if (!tc.getCustomRenderer().empty())
|
||||
{
|
||||
ostr << ",renderer:" << tc.getCustomRenderer();
|
||||
}
|
||||
else if (pHandler->useRenderer())
|
||||
{
|
||||
ostr << ",renderer:";
|
||||
pHandler->writeDynamicData(ostr);
|
||||
|
||||
@@ -46,6 +46,8 @@
|
||||
#include "Poco/WebWidgets/RequestProcessor.h"
|
||||
#include "Poco/Net/NameValueCollection.h"
|
||||
#include "Poco/Net/HTTPServerResponse.h"
|
||||
#include "Poco/BasicEvent.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace WebWidgets {
|
||||
@@ -66,6 +68,9 @@ public:
|
||||
JavaScriptEvent<Page*> afterRender;
|
||||
/// event thrown after GUI rendering.
|
||||
|
||||
Poco::BasicEvent<Page*> pageRequested;
|
||||
/// Thrown whenever the page is requested, before code is generated
|
||||
|
||||
Page();
|
||||
/// Creates an anonymous Page.
|
||||
|
||||
|
||||
@@ -88,7 +88,14 @@ public:
|
||||
|
||||
bool isEditable() const;
|
||||
/// Returns true iff the Cell is editable.
|
||||
|
||||
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!
|
||||
|
||||
const std::string& getCustomRenderer() const;
|
||||
/// Returns the custom JavaScript code used to render the values of this column.
|
||||
/// Empty string if none set
|
||||
|
||||
protected:
|
||||
virtual ~TableColumn();
|
||||
@@ -98,6 +105,7 @@ private:
|
||||
Cell::Ptr _pCell;
|
||||
bool _sortable;
|
||||
std::string _header;
|
||||
std::string _customRenderer;
|
||||
};
|
||||
|
||||
|
||||
@@ -159,6 +167,18 @@ inline bool TableColumn::isEditable() const
|
||||
}
|
||||
|
||||
|
||||
inline void TableColumn::setCustomRenderer(const std::string& jsCode)
|
||||
{
|
||||
_customRenderer = jsCode;
|
||||
}
|
||||
|
||||
|
||||
inline const std::string& TableColumn::getCustomRenderer() const
|
||||
{
|
||||
return _customRenderer;
|
||||
}
|
||||
|
||||
|
||||
} } // namespace Poco::WebWidgets
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user