mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-17 03:03:23 +02:00
simplified table serializing
This commit is contained in:
@@ -41,31 +41,30 @@
|
||||
|
||||
|
||||
#include "Poco/WebWidgets/ExtJS/ExtJS.h"
|
||||
#include "Poco/WebWidgets/TableModelSerializer.h"
|
||||
#include "Poco/Any.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace WebWidgets {
|
||||
|
||||
class Table;
|
||||
|
||||
namespace ExtJS {
|
||||
|
||||
|
||||
class ExtJS_API ArrayTableSerializer: public Poco::WebWidgets::TableModelSerializer
|
||||
class ExtJS_API ArrayTableSerializer
|
||||
/// ArrayTableSerializer serializes a Table in JSON format
|
||||
{
|
||||
public:
|
||||
typedef Poco::AutoPtr<ArrayTableSerializer> Ptr;
|
||||
|
||||
static void serialize(std::ostream& ostr, const Poco::WebWidgets::Table* pTable, std::size_t rowBegin = 0, std::size_t rowCnt = 0);
|
||||
/// Serializes the table starting with row 0. A rowCnt of 0 means serialize all rows
|
||||
|
||||
static const std::string& contentType();
|
||||
private:
|
||||
ArrayTableSerializer();
|
||||
/// Creates the ArrayTableSerializer with the given number of columns.
|
||||
|
||||
virtual ~ArrayTableSerializer();
|
||||
~ArrayTableSerializer();
|
||||
/// Destroys the ArrayTableSerializer.
|
||||
|
||||
void serialize(std::ostream& ostr, const Poco::WebWidgets::Table* pTable, std::size_t rowBegin = 0, std::size_t rowCnt = 0);
|
||||
/// Serializes the table starting with row 0. A rowCnt of 0 means serialize all rows
|
||||
|
||||
const std::string& contentType() const;
|
||||
};
|
||||
|
||||
|
||||
|
@@ -44,6 +44,7 @@
|
||||
#include "Poco/WebWidgets/Type.h"
|
||||
#include "Poco/WebWidgets/Renderer.h"
|
||||
#include "Poco/WebWidgets/Cell.h"
|
||||
#include "Poco/WebWidgets/Table.h"
|
||||
#include <map>
|
||||
|
||||
|
||||
@@ -51,7 +52,6 @@
|
||||
namespace Poco {
|
||||
namespace WebWidgets {
|
||||
|
||||
class Table;
|
||||
class TableColumn;
|
||||
class TableModel;
|
||||
|
||||
@@ -98,6 +98,8 @@ protected:
|
||||
|
||||
static void renderStore(const Table* pTable, std::ostream& ostr);
|
||||
/// Renders the data store of the table
|
||||
|
||||
static void onBeforeLoad(void* pSender, Table::LoadData& ld);
|
||||
};
|
||||
|
||||
|
||||
|
@@ -44,16 +44,6 @@ namespace WebWidgets {
|
||||
namespace ExtJS {
|
||||
|
||||
|
||||
ArrayTableSerializer::ArrayTableSerializer()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
ArrayTableSerializer::~ArrayTableSerializer()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void ArrayTableSerializer::serialize(std::ostream& ostr, const Table* pTable, std::size_t rowBegin, std::size_t rowCntUser)
|
||||
{
|
||||
//[
|
||||
@@ -119,7 +109,7 @@ void ArrayTableSerializer::serialize(std::ostream& ostr, const Table* pTable, st
|
||||
}
|
||||
|
||||
|
||||
const std::string& ArrayTableSerializer::contentType() const
|
||||
const std::string& ArrayTableSerializer::contentType()
|
||||
{
|
||||
static const std::string ct("text/javascript");
|
||||
return ct;
|
||||
|
@@ -38,10 +38,12 @@
|
||||
#include "Poco/WebWidgets/ExtJS/FormRenderer.h"
|
||||
#include "Poco/WebWidgets/ExtJS/Utility.h"
|
||||
#include "Poco/WebWidgets/ExtJS/TableCellHandlerFactory.h"
|
||||
#include "Poco/WebWidgets/ExtJS/ArrayTableSerializer.h"
|
||||
#include "Poco/WebWidgets/Table.h"
|
||||
#include "Poco/WebWidgets/WebApplication.h"
|
||||
#include "Poco/WebWidgets/RequestHandler.h"
|
||||
#include "Poco/WebWidgets/DateFormatter.h"
|
||||
#include "Poco/Delegate.h"
|
||||
#include <sstream>
|
||||
|
||||
|
||||
@@ -146,7 +148,9 @@ void TableRenderer::renderProperties(const Table* pTable, const RenderContext& c
|
||||
ostr << ",height:" << pTable->getHeight();
|
||||
ostr << ",store:";
|
||||
renderStore(pTable, ostr);
|
||||
WebApplication::instance().registerAjaxProcessor(Poco::NumberFormatter::format(id), const_cast<Table*>(pTable));
|
||||
Table* pT = const_cast<Table*>(pTable);
|
||||
pT->beforeLoad += Poco::delegate(&TableRenderer::onBeforeLoad);
|
||||
WebApplication::instance().registerAjaxProcessor(Poco::NumberFormatter::format(id), pT);
|
||||
}
|
||||
|
||||
|
||||
@@ -258,5 +262,13 @@ void TableRenderer::renderStore(const Table* pTable, std::ostream& ostr)
|
||||
}
|
||||
|
||||
|
||||
void TableRenderer::onBeforeLoad(void* pSender, Table::LoadData& ld)
|
||||
{
|
||||
ld.pResponse->setChunkedTransferEncoding(true);
|
||||
ld.pResponse->setContentType(ArrayTableSerializer::contentType());
|
||||
std::ostream& out = ld.pResponse->send();
|
||||
ArrayTableSerializer::serialize(out, ld.pTable, ld.firstRow, ld.rowCnt);
|
||||
}
|
||||
|
||||
|
||||
} } } // namespace Poco::WebWidgets::ExtJS
|
||||
|
@@ -35,7 +35,6 @@
|
||||
#include "CppUnit/TestSuite.h"
|
||||
#include "Poco/WebWidgets/ExtJS/Utility.h"
|
||||
#include "Poco/WebWidgets/ExtJS/TableCellHandler.h"
|
||||
#include "Poco/WebWidgets/ExtJS/ArrayTableSerializer.h"
|
||||
#include "Poco/WebWidgets/Page.h"
|
||||
#include "Poco/WebWidgets/Renderer.h"
|
||||
#include "Poco/WebWidgets/RenderContext.h"
|
||||
@@ -1171,7 +1170,7 @@ void ExtJSTest::testTable()
|
||||
Table::TableColumns tc;
|
||||
tc.push_back(new TableColumn(0, "StaticText"));
|
||||
tc.push_back(new TableColumn(new CheckButtonCell(0, "Const", true), "CheckButton"));
|
||||
Table::Ptr pTable = new Table(tc, new SimpleTableModel(2), new ArrayTableSerializer());
|
||||
Table::Ptr pTable = new Table(tc, new SimpleTableModel(2));
|
||||
pTable->setValue(std::string("one"), 0,0);
|
||||
pTable->setValue(std::string("two"), 1,0);
|
||||
pTable->setValue(std::string("three"), 2,0);
|
||||
@@ -1202,7 +1201,7 @@ void ExtJSTest::testTableEdit()
|
||||
Table::TableColumns tc;
|
||||
tc.push_back(new TableColumn(new TextFieldCell(0), "DynText"));
|
||||
tc.push_back(new TableColumn(new CheckButtonCell(0, "Const", true), "CheckButton"));
|
||||
Table::Ptr pTable = new Table(tc, new SimpleTableModel(2), new ArrayTableSerializer());
|
||||
Table::Ptr pTable = new Table(tc, new SimpleTableModel(2));
|
||||
pTable->setValue(std::string("one"), 0,0);
|
||||
pTable->setValue(std::string("two"), 1,0);
|
||||
pTable->setValue(std::string("three"), 2,0);
|
||||
@@ -1237,7 +1236,7 @@ void ExtJSTest::testTableComboBox()
|
||||
pCom->insert(std::string("3"));
|
||||
tc.push_back(new TableColumn(pCom, "DynText"));
|
||||
tc.push_back(new TableColumn(new CheckButtonCell(0, "Const", true), "CheckButton"));
|
||||
Table::Ptr pTable = new Table(tc, new SimpleTableModel(2), new ArrayTableSerializer());
|
||||
Table::Ptr pTable = new Table(tc, new SimpleTableModel(2));
|
||||
pTable->setValue(std::string("1"), 0,0);
|
||||
pTable->setValue(std::string("2"), 1,0);
|
||||
pTable->setValue(std::string("3"), 2,0);
|
||||
@@ -1268,7 +1267,7 @@ void ExtJSTest::testTableButton()
|
||||
Table::TableColumns tc;
|
||||
tc.push_back(new TableColumn(new ButtonCell(0), "ButtonText"));
|
||||
tc.push_back(new TableColumn(new CheckButtonCell(0, "Const", true), "CheckButton"));
|
||||
Table::Ptr pTable = new Table(tc, new SimpleTableModel(2), new ArrayTableSerializer());
|
||||
Table::Ptr pTable = new Table(tc, new SimpleTableModel(2));
|
||||
pTable->setValue(std::string("one"), 0,0);
|
||||
pTable->setValue(std::string("two"), 1,0);
|
||||
pTable->setValue(std::string("three"), 2,0);
|
||||
@@ -1299,7 +1298,7 @@ void ExtJSTest::testTableImageButton()
|
||||
Table::TableColumns tc;
|
||||
tc.push_back(new TableColumn(new ImageButtonCell(0,new Image(Poco::URI("dummy.jpg")))));
|
||||
tc.push_back(new TableColumn(new CheckButtonCell(0, "Const", true), "CheckButton"));
|
||||
Table::Ptr pTable = new Table(tc, new SimpleTableModel(2), new ArrayTableSerializer());
|
||||
Table::Ptr pTable = new Table(tc, new SimpleTableModel(2));
|
||||
pTable->setValue(std::string("Sunset.jpg"), 0,0);
|
||||
pTable->setValue(std::string("Sunset.jpg"), 1,0);
|
||||
pTable->setValue(std::string("Sunset.jpg"), 2,0);
|
||||
|
Reference in New Issue
Block a user