mirror of
https://github.com/pocoproject/poco.git
synced 2024-12-13 18:45:10 +01:00
table performance updates+JSEvent handling changes
This commit is contained in:
parent
ab07e2cbba
commit
7a0aa6987c
@ -213,6 +213,10 @@
|
||||
RelativePath=".\include\Poco\WebWidgets\ExtJS\AbstractTableCellHandler.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\Poco\WebWidgets\ExtJS\ArrayTableSerializer.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\Poco\WebWidgets\ExtJS\ButtonCellRenderer.h"
|
||||
>
|
||||
@ -361,6 +365,10 @@
|
||||
RelativePath=".\src\AbstractTableCellHandler.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\ArrayTableSerializer.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\ButtonCellRenderer.cpp"
|
||||
>
|
||||
|
@ -0,0 +1,75 @@
|
||||
//
|
||||
// ArrayTableSerializer.h
|
||||
//
|
||||
// $Id: //poco/Main/WebWidgets/include/Poco/WebWidgets/ArrayTableSerializer.h#4 $
|
||||
//
|
||||
// Library: ExtJS
|
||||
// Package: Core
|
||||
// Module: ArrayTableSerializer
|
||||
//
|
||||
// Definition of the ArrayTableSerializer class.
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef ExtJS_ArrayTableSerializer_INCLUDED
|
||||
#define ExtJS_ArrayTableSerializer_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/WebWidgets/ExtJS/ExtJS.h"
|
||||
#include "Poco/WebWidgets/TableModelSerializer.h"
|
||||
#include "Poco/Any.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace WebWidgets {
|
||||
namespace ExtJS {
|
||||
|
||||
|
||||
class ExtJS_API ArrayTableSerializer: public Poco::WebWidgets::TableModelSerializer
|
||||
/// ArrayTableSerializer serializes a Table in JSON format
|
||||
{
|
||||
public:
|
||||
typedef Poco::AutoPtr<ArrayTableSerializer> Ptr;
|
||||
|
||||
ArrayTableSerializer();
|
||||
/// Creates the ArrayTableSerializer with the given number of columns.
|
||||
|
||||
virtual ~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;
|
||||
};
|
||||
|
||||
|
||||
} } } // namespace Poco::WebWidgets::ExtJS
|
||||
|
||||
|
||||
#endif // ExtJS_ArrayTableSerializer_INCLUDED
|
@ -62,6 +62,9 @@ class ExtJS_API TableRenderer: public Poco::WebWidgets::Renderer
|
||||
/// TableRenderer renders a button
|
||||
{
|
||||
public:
|
||||
static const std::string EV_CELLCLICKED;
|
||||
static const std::string EV_AFTEREDIT;
|
||||
|
||||
TableRenderer();
|
||||
/// Creates the TableRenderer.
|
||||
|
||||
@ -73,6 +76,14 @@ public:
|
||||
|
||||
void renderBody(const Renderable* pRenderable, const RenderContext& context, std::ostream& ostr);
|
||||
/// Emits code for the page body to the given output stream.
|
||||
|
||||
static void addCellValueChangedServerCallback(Table* pTable, const std::string& onSuccess=std::string(), const std::string& onFailure=std::string());
|
||||
/// 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)
|
||||
|
||||
static void addCellClickedServerCallback(Table* pTable, const std::string& onSuccess=std::string(), const std::string& onFailure=std::string());
|
||||
/// Adds a javascript callback to inform the WebServer that the client has changed a value in the Table
|
||||
/// Method signature is cellclick : ( Grid this, Number rowIndex, Number columnIndex, Ext.EventObject e )
|
||||
|
||||
protected:
|
||||
static void renderProperties(const Table* pTable, const RenderContext& context, std::ostream& ostr);
|
||||
|
@ -45,7 +45,7 @@
|
||||
#include "Poco/WebWidgets/LookAndFeel.h"
|
||||
#include "Poco/WebWidgets/JavaScriptEvent.h"
|
||||
#include <ostream>
|
||||
#include <set>
|
||||
#include <list>
|
||||
#include <map>
|
||||
|
||||
|
||||
@ -100,32 +100,55 @@ public:
|
||||
static std::string convertPocoDateToPHPDate(const std::string& dateTimeFmt);
|
||||
/// Converts a poco date time format string to its PHP/extjs equivalent
|
||||
|
||||
static bool writeJSEvent(std::ostream& out, const std::string& eventName, const std::set<JSDelegate>& delegates);
|
||||
static bool writeJSEvent(std::ostream& out, const std::string& eventName, const std::list<JSDelegate>& delegates);
|
||||
/// writes all JS Delegates for a single named JSEvent.
|
||||
/// Returns true if data was written, false if no delegates were present and no event handler was written.
|
||||
|
||||
static bool writeJSEventPlusServerCallback(std::ostream& out, const std::string& eventName, const std::set<JSDelegate>& delegates, const std::map<std::string, std::string>& addServerParams, bool reloadPage);
|
||||
/// writes all JS Delegates for a single named JSEvent. adds a callback to the server
|
||||
/// Returns true if data was written, false if no delegates were present and no event handler was written.
|
||||
/// an addParam that should be treated as a variable must start with the '+' character!
|
||||
|
||||
static std::string createURI(const std::map<std::string, std::string>& addParams);
|
||||
/// Creates the url from the function parameters, writes a js fucntion with method signature function(obj)
|
||||
|
||||
static std::string createURI(const std::map<std::string, std::string>& addParams, Renderable::ID id);
|
||||
/// Creates the url from the function parameters, adds the id parameter automatically
|
||||
/// a WebApplication must be set!
|
||||
|
||||
static std::string createCallbackFunctionCode(const std::string& signature, const std::map<std::string, std::string>& addParams, bool reloadPage);
|
||||
/// Creates the url from the function parameters, writes a js fucntion with the given method signature
|
||||
static std::string createCallbackFunctionCode(const std::string& signature,
|
||||
const std::map<std::string, std::string>& addParams,
|
||||
Renderable::ID id,
|
||||
bool reloadPage);
|
||||
/// Creates the url from the function parameters, writes a js function with the given method signature.
|
||||
/// Sets onSuccess and onFailure to reload the page if reloadPage is set
|
||||
|
||||
static bool writeServerCallback(std::ostream& out, const std::string& eventName, const std::string& signature, const std::map<std::string, std::string>& addServerParams, bool reloadPage);
|
||||
/// Writes a server callback for the given ExtJS eventName and server Params
|
||||
// signature contaisn the function declaration (i.e.: function(p1,p2))
|
||||
static std::string createCallbackFunctionCode(const std::string& signature,
|
||||
const std::map<std::string, std::string>& addParams,
|
||||
Renderable::ID id,
|
||||
const std::string& onSuccess,
|
||||
const std::string& onFailure);
|
||||
/// Creates the url from the function parameters, writes a js function with the given method signature
|
||||
|
||||
|
||||
template <typename T>
|
||||
static void addServerCallback(JavaScriptEvent<T>& ev,
|
||||
const std::string& signature,
|
||||
const std::map<std::string, std::string>& addServerParams,
|
||||
Renderable::ID id,
|
||||
const std::string& onSuccessJS,
|
||||
const std::string& onFailureJS)
|
||||
{
|
||||
std::string code(createCallbackFunctionCode(signature, addServerParams, id, onSuccessJS, onFailureJS));
|
||||
ev.add(jsDelegate(code));
|
||||
|
||||
}
|
||||
|
||||
private:
|
||||
static void writeCodeForDelegate(std::ostream& invoke, std::ostream& jsOut, const std::set<JSDelegate>& jsDels);
|
||||
static void writeCodeForDelegate(std::ostream& invoke, std::ostream& jsOut, const JSDelegate& jsDel, int cnt);
|
||||
static void convertPocoDateToPHPDate(char in, std::string& result);
|
||||
static void convertPHPDateToPocoDate(char in, std::string& result);
|
||||
static void escapeCharForPHP(char in, std::string& result);
|
||||
static LookAndFeel::Ptr createDefault();
|
||||
static int detectMaxParamCount(const std::list<JSDelegate>& delegates);
|
||||
|
||||
static void skipWhiteSpace(const std::string& code, std::string::size_type& pos);
|
||||
static std::string createFunctionSignature(int paramCnt);
|
||||
/// Creates an anonmyous JS function with the given param count
|
||||
|
||||
static std::string createFunctionSignature(const std::string& fctName, int paramCnt);
|
||||
|
||||
private:
|
||||
Utility();
|
||||
|
127
WebWidgets/ExtJS/src/ArrayTableSerializer.cpp
Normal file
127
WebWidgets/ExtJS/src/ArrayTableSerializer.cpp
Normal file
@ -0,0 +1,127 @@
|
||||
//
|
||||
// ArrayTableSerializer.cpp
|
||||
//
|
||||
// $Id: //poco/Main/WebWidgets/src/ArrayTableSerializer.cpp#3 $
|
||||
//
|
||||
// Library: ExtJS
|
||||
// Package: Core
|
||||
// Module: ArrayTableSerializer
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/WebWidgets/ExtJS/ArrayTableSerializer.h"
|
||||
#include "Poco/WebWidgets/Table.h"
|
||||
#include "Poco/DateTime.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
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)
|
||||
{
|
||||
//[
|
||||
// ['3m Co',71.72,0.02,0.03,'9/1 12:00am'],
|
||||
// ['Alcoa Inc',29.01,0.42,1.47,'9/1 12:00am']
|
||||
//]
|
||||
const TableModel& tm = pTable->getModel();
|
||||
const Table::TableColumns& tc = pTable->getColumns();
|
||||
|
||||
poco_assert_dbg (tc.size() == tm.getColumnCount());
|
||||
|
||||
std::size_t colCnt = tm.getColumnCount();
|
||||
std::size_t rowCnt = tm.getRowCount();
|
||||
if (rowBegin < 0)
|
||||
rowBegin = 0;
|
||||
if ((rowCntUser > 0) && (rowBegin + rowCntUser < rowCnt))
|
||||
rowCnt = rowBegin + rowCntUser;
|
||||
ostr << "[";
|
||||
for (std::size_t row = rowBegin; row < rowCnt; ++row)
|
||||
{
|
||||
if (row != 0)
|
||||
ostr << ",[";
|
||||
else
|
||||
ostr << "[";
|
||||
for (std::size_t col = 0; col < colCnt; ++col)
|
||||
{
|
||||
if (col != 0)
|
||||
ostr << ",";
|
||||
|
||||
// how do we distinguish if we want to write something as text or GUIElement?
|
||||
// Example: Checkbutton can be written as text "true"/"false" or as a CheckButton
|
||||
// we use the Cell: if we have a Cell set -> complex Type otherwise text
|
||||
// -> already handled by the renderer!
|
||||
const Poco::Any& aVal = tm.getValue(row, col);
|
||||
|
||||
if (aVal.empty())
|
||||
ostr << "''";
|
||||
else
|
||||
{
|
||||
//FIXME: we have no type nfo at all, assume string for everything
|
||||
bool isString = (typeid(std::string) == aVal.type());
|
||||
Cell::Ptr ptrCell = tc[col]->getCell();
|
||||
if (isString)
|
||||
ostr << "'" << RefAnyCast<std::string>(aVal) << "'";
|
||||
else if (ptrCell)
|
||||
{
|
||||
//date must be written as string
|
||||
if (typeid(Poco::DateTime) == aVal.type())
|
||||
ostr << "'" << tc[col]->getCell()->getFormatter()->format(aVal) << "'";
|
||||
else
|
||||
ostr << tc[col]->getCell()->getFormatter()->format(aVal);
|
||||
}
|
||||
else
|
||||
; //FIXME:
|
||||
}
|
||||
}
|
||||
ostr << "]";
|
||||
}
|
||||
ostr << "]";
|
||||
}
|
||||
|
||||
|
||||
const std::string& ArrayTableSerializer::contentType() const
|
||||
{
|
||||
static const std::string ct("text/javascript");
|
||||
return ct;
|
||||
}
|
||||
|
||||
|
||||
|
||||
} } } // namespace Poco::WebWidgets::ExtJS
|
@ -50,6 +50,10 @@ namespace WebWidgets {
|
||||
namespace ExtJS {
|
||||
|
||||
|
||||
const std::string TableRenderer::EV_CELLCLICKED("cellclick");
|
||||
const std::string TableRenderer::EV_AFTEREDIT("afteredit");
|
||||
|
||||
|
||||
TableRenderer::TableRenderer()
|
||||
{
|
||||
}
|
||||
@ -79,33 +83,47 @@ void TableRenderer::renderBody(const Renderable* pRenderable, const RenderContex
|
||||
}
|
||||
|
||||
|
||||
void TableRenderer::renderProperties(const Table* pTable, const RenderContext& context, std::ostream& ostr)
|
||||
void TableRenderer::addCellValueChangedServerCallback(Table* pTable, const std::string& onSuccess, const std::string& onFailure)
|
||||
{
|
||||
WebApplication& app = WebApplication::instance();
|
||||
Renderable::ID id = app.getCurrentPage()->id();
|
||||
Utility::writeRenderableProperties(pTable, ostr);
|
||||
static const std::string afterEdit("afteredit");
|
||||
static const std::string cellClicked("cellclick");
|
||||
poco_check_ptr (pTable);
|
||||
static const std::string signature("function(obj)");
|
||||
std::map<std::string, std::string> addParams;
|
||||
addParams.insert(std::make_pair(Table::FIELD_COL, "+obj.column"));
|
||||
addParams.insert(std::make_pair(Table::FIELD_ROW, "+obj.row"));
|
||||
addParams.insert(std::make_pair(Table::FIELD_VAL, "+obj.value"));
|
||||
addParams.insert(std::make_pair(RequestHandler::KEY_EVID, Table::EV_CELLVALUECHANGED));
|
||||
JavaScriptEvent<int> ev;
|
||||
ev.setJSDelegates(pTable->cellValueChanged.jsDelegates());
|
||||
ev.add(jsDelegate("function(obj){obj.grid.getStore().commitChanges();}"));
|
||||
ostr << ",listeners:{";
|
||||
Utility::writeJSEventPlusServerCallback(ostr, afterEdit, ev.jsDelegates(), addParams, pTable->cellValueChanged.hasLocalHandlers());
|
||||
|
||||
//cellclick : ( Grid this, Number rowIndex, Number columnIndex, Ext.EventObject e )
|
||||
//hm, more than one param in the eventhanlder of cellclick, writeJSEvent creates a fucntion(obj) wrapper
|
||||
//FIXME: no support for custom javascript yet
|
||||
addParams.clear();
|
||||
addParams.insert(std::make_pair(Table::FIELD_COL, "+columnIndex"));
|
||||
addParams.insert(std::make_pair(Table::FIELD_ROW, "+rowIndex"));
|
||||
Utility::addServerCallback(pTable->cellValueChanged, signature, addParams, pTable->id(), onSuccess, onFailure);
|
||||
pTable->cellValueChanged.add(jsDelegate("function(obj){obj.grid.getStore().commitChanges();}"));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void TableRenderer::addCellClickedServerCallback(Table* pTable, const std::string& onSuccess, const std::string& onFailure)
|
||||
{
|
||||
poco_check_ptr (pTable);
|
||||
static const std::string signature("function(theGrid,row,col,e)");
|
||||
std::map<std::string, std::string> addParams;
|
||||
addParams.insert(std::make_pair(Table::FIELD_COL, "+col"));
|
||||
addParams.insert(std::make_pair(Table::FIELD_ROW, "+row"));
|
||||
addParams.insert(std::make_pair(RequestHandler::KEY_EVID, Table::EV_CELLCLICKED));
|
||||
ostr << ",";
|
||||
Utility::writeServerCallback(ostr,cellClicked, "function(aGrid, rowIndex,columnIndex,e)",addParams, pTable->cellClicked.hasLocalHandlers());
|
||||
Utility::addServerCallback(pTable->cellClicked, signature, addParams, pTable->id(), onSuccess, onFailure);
|
||||
}
|
||||
|
||||
|
||||
void TableRenderer::renderProperties(const Table* pTable, const RenderContext& context, std::ostream& ostr)
|
||||
{
|
||||
WebApplication& app = WebApplication::instance();
|
||||
Renderable::ID id = pTable->id();
|
||||
Utility::writeRenderableProperties(pTable, ostr);
|
||||
|
||||
ostr << ",listeners:{";
|
||||
bool written = Utility::writeJSEvent(ostr, EV_AFTEREDIT, pTable->cellValueChanged.jsDelegates());
|
||||
if (written)
|
||||
ostr << ",";
|
||||
|
||||
|
||||
Utility::writeJSEvent(ostr, EV_CELLCLICKED, pTable->cellClicked.jsDelegates());
|
||||
|
||||
ostr << "},"; //close listeners
|
||||
|
||||
@ -240,6 +258,7 @@ void TableRenderer::renderDataModel(const Table* pTable, std::ostream& ostr)
|
||||
|
||||
void TableRenderer::renderStore(const Table* pTable, std::ostream& ostr)
|
||||
{
|
||||
|
||||
//new Ext.data.SimpleStore({
|
||||
// fields: [
|
||||
// {name: 'company'},
|
||||
@ -248,13 +267,14 @@ void TableRenderer::renderStore(const Table* pTable, std::ostream& ostr)
|
||||
// {name: 'pctChange', type: 'float'},
|
||||
// {name: 'lastChange', type: 'date', dateFormat: 'n/j h:ia'}
|
||||
// ],
|
||||
// data: [...]
|
||||
// proxy: new Ext.data.HttpProxy({url:'/myuri;...'}),
|
||||
// reader: new Ext.data.ArrayReader()
|
||||
//});
|
||||
|
||||
// we don't know the type, we just have a formatter, the name is always the idx!
|
||||
// we use the formatter later to set a renderer for a different type than string
|
||||
const Table::TableColumns& columns = pTable->getColumns();
|
||||
ostr << "new Ext.data.SimpleStore({fields:[";
|
||||
ostr << "new Ext.data.SimpleStore({autoLoad:true,fields:[";
|
||||
Table::TableColumns::const_iterator it = columns.begin();
|
||||
int i = 0;
|
||||
for (; it != columns.end(); ++it, ++i)
|
||||
@ -264,9 +284,16 @@ void TableRenderer::renderStore(const Table* pTable, std::ostream& ostr)
|
||||
ostr << "{name:'" << i << "'}";
|
||||
}
|
||||
ostr << "],"; // close fields
|
||||
ostr << "proxy: new Ext.data.HttpProxy({url:";
|
||||
std::map<std::string, std::string> addParams;
|
||||
addParams.insert(std::make_pair(RequestHandler::KEY_EVID,Table::EV_LOADDATA));
|
||||
|
||||
std::string url(Utility::createURI(addParams, pTable->id()));
|
||||
ostr << url << "}),";
|
||||
ostr << "reader: new Ext.data.ArrayReader()";
|
||||
//Write data
|
||||
ostr << "data:";
|
||||
renderDataModel(pTable, ostr);
|
||||
/*ostr << "data:";
|
||||
renderDataModel(pTable, ostr);*/
|
||||
ostr << "})";
|
||||
}
|
||||
|
||||
|
@ -92,8 +92,10 @@
|
||||
#include "Poco/WebWidgets/RequestHandler.h"
|
||||
|
||||
#include "Poco/String.h"
|
||||
#include "Poco/NumberFormatter.h"
|
||||
#include "Poco/DateTimeFormat.h"
|
||||
#include <sstream>
|
||||
#include <cctype>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
@ -381,7 +383,7 @@ Form::Ptr Utility::insideForm(const Cell* pChild)
|
||||
}
|
||||
|
||||
|
||||
bool Utility::writeJSEvent(std::ostream& out, const std::string& eventName, const std::set<JSDelegate>& delegates)
|
||||
bool Utility::writeJSEvent(std::ostream& out, const std::string& eventName, const std::list<JSDelegate>& delegates)
|
||||
{
|
||||
//'click' : {
|
||||
// fn: this.onClick,
|
||||
@ -398,15 +400,30 @@ bool Utility::writeJSEvent(std::ostream& out, const std::string& eventName, cons
|
||||
else
|
||||
{
|
||||
// rather simple way to support more than one delegate
|
||||
// TODO: there sure is a more efficient way to do this
|
||||
std::ostringstream invoke;
|
||||
invoke << "invoke:function(" << JS_EVENTARGNAME << "){";
|
||||
out << "{fn:function(" << JS_EVENTARGNAME << "){var all={";
|
||||
writeCodeForDelegate(invoke, out, delegates);
|
||||
int maxParams = detectMaxParamCount(delegates);
|
||||
std::string fct(createFunctionSignature(maxParams));
|
||||
out << "{fn:" << fct << "{var all={";
|
||||
// the invoke function calls all the other functions sequentially
|
||||
invoke << "invoke:" << fct <<"{";
|
||||
std::list<JSDelegate>::const_iterator it = delegates.begin();
|
||||
int cnt(0);
|
||||
for (; it != delegates.end(); ++it)
|
||||
{
|
||||
std::string fctName("d");
|
||||
fctName.append(Poco::NumberFormatter::format(cnt));
|
||||
if (cnt > 0)
|
||||
{
|
||||
out << ",";
|
||||
}
|
||||
out << fctName << ":" << it->jsCode() << ","; //always write comma because invoke is written as the last method
|
||||
invoke << "this." << createFunctionSignature(fctName, maxParams) << ";";
|
||||
}
|
||||
|
||||
invoke << "}";
|
||||
out << invoke.str() << "};"; //closes all
|
||||
|
||||
out << "all.invoke(" << JS_EVENTARGNAME << ");";
|
||||
out << "all." << createFunctionSignature("invoke", maxParams) << ";";
|
||||
out << "}"; //closes fn
|
||||
out << "}"; //closes function
|
||||
}
|
||||
@ -415,75 +432,11 @@ bool Utility::writeJSEvent(std::ostream& out, const std::string& eventName, cons
|
||||
}
|
||||
|
||||
|
||||
void Utility::writeCodeForDelegate(std::ostream& invoke, std::ostream& out, const std::set<JSDelegate>& jsDels)
|
||||
{
|
||||
int cnt(0);
|
||||
std::set<JSDelegate>::const_iterator it = jsDels.begin();
|
||||
for (; it != jsDels.end(); ++it)
|
||||
{
|
||||
writeCodeForDelegate(invoke, out, *it, cnt);
|
||||
++cnt;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Utility::writeCodeForDelegate(std::ostream& invoke, std::ostream& out, const JSDelegate& jsDel, int cnt)
|
||||
{
|
||||
std::string code(Poco::trim(jsDel.jsCode()));
|
||||
if (code.find("function") == 0)
|
||||
{
|
||||
// inline function definition
|
||||
out << "d" << cnt << ":" << code << ",";
|
||||
invoke << "this.d" << cnt << "(" << JS_EVENTARGNAME << ");";
|
||||
}
|
||||
else
|
||||
{
|
||||
out << "d" << cnt << ":function(" << JS_EVENTARGNAME << "){" << code;
|
||||
if (!code.empty() && code[code.size()-1] != ';')
|
||||
out << ";";
|
||||
out << "},";
|
||||
invoke << "this.d" << cnt << "(" << JS_EVENTARGNAME << ");";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool Utility::writeJSEventPlusServerCallback(std::ostream& out, const std::string& eventName, const std::set<JSDelegate>& delegates, const std::map<std::string, std::string>& addServerParams, bool reloadPage)
|
||||
{
|
||||
// rather simple way to support more than one delegate
|
||||
// TODO: there sure is a more efficient way to do this
|
||||
|
||||
out << eventName << ":";
|
||||
static const std::string defSignature("function("+JS_EVENTARGNAME+")");
|
||||
|
||||
std::ostringstream invoke;
|
||||
invoke << "invoke:function(" << JS_EVENTARGNAME << "){";
|
||||
out << "{fn:function(" << JS_EVENTARGNAME << "){var all={";
|
||||
writeCodeForDelegate(invoke, out, delegates);
|
||||
//write server callback
|
||||
writeCodeForDelegate(invoke, out, jsDelegate(createCallbackFunctionCode(defSignature, addServerParams, reloadPage)), static_cast<int>(delegates.size()));
|
||||
invoke << "}";
|
||||
out << invoke.str() << "};"; //closes all
|
||||
|
||||
out << "all.invoke(" << JS_EVENTARGNAME << ");";
|
||||
out << "}"; //closes fn
|
||||
out << "}"; //closes function
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Utility::writeServerCallback(std::ostream& out, const std::string& eventName, const std::string& signature, const std::map<std::string, std::string>& addServerParams, bool reloadPage)
|
||||
{
|
||||
std::string fctCode(createCallbackFunctionCode(signature, addServerParams, reloadPage));
|
||||
out << eventName << ":";
|
||||
out << fctCode;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
std::string Utility::createURI(const std::map<std::string, std::string>& addParams)
|
||||
std::string Utility::createURI(const std::map<std::string, std::string>& addParams, Renderable::ID id)
|
||||
{
|
||||
WebApplication& app = WebApplication::instance();
|
||||
Renderable::ID id = app.getCurrentPage()->id();
|
||||
std::ostringstream uri;
|
||||
std::string theUri(app.getURI().toString());
|
||||
if (theUri.empty())
|
||||
@ -529,26 +482,101 @@ std::string Utility::createURI(const std::map<std::string, std::string>& addPara
|
||||
}
|
||||
|
||||
|
||||
std::string Utility::createCallbackFunctionCode(const std::string& signature, const std::map<std::string, std::string>& addParams, bool reloadPage)
|
||||
std::string Utility::createCallbackFunctionCode(const std::string& signature, const std::map<std::string, std::string>& addParams, Renderable::ID id, bool reloadPage)
|
||||
{
|
||||
static const std::string onSuccessReload("function(){window.location.reload();}");
|
||||
static const std::string onFailureReload("function(){Ext.MessageBox.alert('Status','Failed to write changes back to server.');window.location.reload();}");
|
||||
static const std::string onSuccess;
|
||||
static const std::string onFailure("function(){Ext.MessageBox.alert('Status','Failed to write changes back to server.');}");
|
||||
if (reloadPage)
|
||||
return createCallbackFunctionCode(signature, addParams, id, onSuccessReload, onFailureReload);
|
||||
return createCallbackFunctionCode(signature, addParams, id, onSuccess, onFailure);
|
||||
}
|
||||
|
||||
|
||||
|
||||
std::string Utility::createCallbackFunctionCode(const std::string& signature, const std::map<std::string, std::string>& addParams, Renderable::ID id, const std::string& onSuccess, const std::string& onFailure)
|
||||
{
|
||||
poco_assert_dbg (!signature.empty());
|
||||
poco_assert_dbg(signature.find("function") != std::string::npos);
|
||||
poco_assert_dbg(signature.find("{") == std::string::npos);
|
||||
std::string uri(createURI(addParams));
|
||||
std::string uri(createURI(addParams, id));
|
||||
// now add the callback code
|
||||
std::ostringstream function;
|
||||
function << signature;
|
||||
function << "{var uri=" << uri << ";";
|
||||
function << "Ext.Ajax.request({url:uri,";
|
||||
if (reloadPage)
|
||||
{
|
||||
function << "success:function(){window.location.reload();},";
|
||||
function << "failure:function(){Ext.MessageBox.alert('Status','Failed to write changes back to server.');window.location.reload();}});}";
|
||||
}
|
||||
else
|
||||
function << "failure:function(){Ext.MessageBox.alert('Status','Failed to write changes back to server.');}});}";
|
||||
function << "Ext.Ajax.request({url:uri";
|
||||
if (!onSuccess.empty())
|
||||
function << ",success:" << onSuccess;
|
||||
if (!onFailure.empty())
|
||||
function << ",failure:" << onFailure;
|
||||
function << "});}";
|
||||
return function.str();
|
||||
}
|
||||
|
||||
|
||||
int Utility::detectMaxParamCount(const std::list<JSDelegate>& delegates)
|
||||
{
|
||||
int cnt = 0;
|
||||
std::list<JSDelegate>::const_iterator it = delegates.begin();
|
||||
for (; it != delegates.end(); ++it)
|
||||
{
|
||||
//count all , between ()
|
||||
int tmpCnt(0);
|
||||
const std::string& code = it->jsCode();
|
||||
std::string::size_type pos = code.find('(');
|
||||
if (pos != std::string::npos)
|
||||
{
|
||||
++pos; //skip (
|
||||
skipWhiteSpace(code, pos);
|
||||
bool stop = false;
|
||||
while(!stop && pos < code.size())
|
||||
{
|
||||
if (code[pos] == ')')
|
||||
stop = true;
|
||||
else if (code[pos] == ',')
|
||||
++tmpCnt;
|
||||
++pos;
|
||||
}
|
||||
}
|
||||
if (tmpCnt > cnt)
|
||||
cnt = tmpCnt;
|
||||
}
|
||||
if (cnt > 0) // we counted ','
|
||||
++cnt; // we want var count
|
||||
return cnt;
|
||||
}
|
||||
|
||||
|
||||
void Utility::skipWhiteSpace(const std::string& code, std::string::size_type& pos)
|
||||
{
|
||||
while (pos < code.size() && std::isspace(code[pos]))
|
||||
++pos;
|
||||
}
|
||||
|
||||
|
||||
std::string Utility::createFunctionSignature(int paramCnt)
|
||||
{
|
||||
static const std::string fct("function");
|
||||
return createFunctionSignature(fct, paramCnt);
|
||||
}
|
||||
|
||||
|
||||
std::string Utility::createFunctionSignature(const std::string& fctName, int paramCnt)
|
||||
{
|
||||
std::string result(fctName);
|
||||
result.append("(");
|
||||
while (paramCnt > 0)
|
||||
{
|
||||
result.append("p");
|
||||
result.append(Poco::NumberFormatter::format(paramCnt));
|
||||
--paramCnt;
|
||||
if (paramCnt > 0)
|
||||
result.append(",");
|
||||
}
|
||||
result.append(")");
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
} } } // namespace Poco::WebWidgets::ExtJS
|
||||
|
@ -35,6 +35,7 @@
|
||||
#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"
|
||||
@ -1170,7 +1171,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));
|
||||
Table::Ptr pTable = new Table(tc, new SimpleTableModel(2), new ArrayTableSerializer());
|
||||
pTable->setValue(std::string("one"), 0,0);
|
||||
pTable->setValue(std::string("two"), 1,0);
|
||||
pTable->setValue(std::string("three"), 2,0);
|
||||
@ -1201,7 +1202,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));
|
||||
Table::Ptr pTable = new Table(tc, new SimpleTableModel(2), new ArrayTableSerializer());
|
||||
pTable->setValue(std::string("one"), 0,0);
|
||||
pTable->setValue(std::string("two"), 1,0);
|
||||
pTable->setValue(std::string("three"), 2,0);
|
||||
@ -1236,7 +1237,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));
|
||||
Table::Ptr pTable = new Table(tc, new SimpleTableModel(2), new ArrayTableSerializer());
|
||||
pTable->setValue(std::string("1"), 0,0);
|
||||
pTable->setValue(std::string("2"), 1,0);
|
||||
pTable->setValue(std::string("3"), 2,0);
|
||||
@ -1267,7 +1268,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));
|
||||
Table::Ptr pTable = new Table(tc, new SimpleTableModel(2), new ArrayTableSerializer());
|
||||
pTable->setValue(std::string("one"), 0,0);
|
||||
pTable->setValue(std::string("two"), 1,0);
|
||||
pTable->setValue(std::string("three"), 2,0);
|
||||
@ -1298,7 +1299,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));
|
||||
Table::Ptr pTable = new Table(tc, new SimpleTableModel(2), new ArrayTableSerializer());
|
||||
pTable->setValue(std::string("Sunset.jpg"), 0,0);
|
||||
pTable->setValue(std::string("Sunset.jpg"), 1,0);
|
||||
pTable->setValue(std::string("Sunset.jpg"), 2,0);
|
||||
|
@ -649,6 +649,10 @@
|
||||
RelativePath=".\include\Poco\WebWidgets\TableModel.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\Poco\WebWidgets\TableModelSerializer.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\Poco\WebWidgets\TabView.h"
|
||||
>
|
||||
@ -713,6 +717,10 @@
|
||||
RelativePath=".\src\TableModel.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\TableModelSerializer.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\TabView.cpp"
|
||||
>
|
||||
|
@ -165,6 +165,12 @@ public:
|
||||
/// Handles a complete HTTP request submitted by the client.
|
||||
///
|
||||
/// The default implementation does nothing.
|
||||
|
||||
virtual void handleRequestAndResponse(const Poco::Net::HTTPServerRequest& request, Poco::Net::HTTPServerResponse& response);
|
||||
/// Handles a complete HTTP request submitted by the client. Also takes care of handing the response,
|
||||
/// e.g. if one wants to send back data.
|
||||
///
|
||||
/// The default implementation does nothing (except calling handleRequest and response.send()).
|
||||
|
||||
protected:
|
||||
Cell(View* pOwner, const std::type_info& type);
|
||||
|
@ -61,6 +61,8 @@ public:
|
||||
/// The javascript code that should be executed
|
||||
|
||||
bool operator<(const JSDelegate& del) const;
|
||||
|
||||
bool operator ==(const JSDelegate& del) const;
|
||||
|
||||
private:
|
||||
std::string _jsCode;
|
||||
@ -73,6 +75,12 @@ inline const std::string& JSDelegate::jsCode() const
|
||||
}
|
||||
|
||||
|
||||
inline bool JSDelegate::operator ==(const JSDelegate& del) const
|
||||
{
|
||||
return jsCode() == del.jsCode();
|
||||
}
|
||||
|
||||
|
||||
static JSDelegate jsDelegate(const std::string& jsCode);
|
||||
|
||||
|
||||
|
@ -46,14 +46,13 @@
|
||||
#include "Poco/DefaultStrategy.h"
|
||||
#include "Poco/AbstractDelegate.h"
|
||||
#include "Poco/CompareFunctions.h"
|
||||
#include <list>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace WebWidgets {
|
||||
|
||||
|
||||
static const std::string JS_EVENTARGNAME("obj"); /// each javascript method receives one single param which is named JS_EVENTARGNAME
|
||||
|
||||
|
||||
template <class TArgs>
|
||||
class JavaScriptEvent: public Poco::AbstractEvent <
|
||||
TArgs, Poco::DefaultStrategy<TArgs, Poco::AbstractDelegate<TArgs>, Poco::p_less<Poco::AbstractDelegate<TArgs> > >,
|
||||
@ -64,6 +63,8 @@ class JavaScriptEvent: public Poco::AbstractEvent <
|
||||
/// which will be embedded into the WebPage when the Parser generates the site.
|
||||
{
|
||||
public:
|
||||
typedef typename std::list<JSDelegate> JSDelegates;
|
||||
|
||||
JavaScriptEvent()
|
||||
/// Creates the JavaScriptEvent.
|
||||
{
|
||||
@ -90,32 +91,31 @@ public:
|
||||
/// Adds a javascript delegate to the event.
|
||||
{
|
||||
FastMutex::ScopedLock lock(this->_mutex);
|
||||
_jsHandlers.insert(aDelegate);
|
||||
_jsHandlers.push_back(aDelegate);
|
||||
}
|
||||
|
||||
void remove (const JSDelegate& aDelegate)
|
||||
/// Removes a javascript delegate from the event. If the delegate is equal to an
|
||||
/// already existing one is determined by the < operator.
|
||||
/// Removes a javascript delegate from the event.
|
||||
/// If the observer is not found, the unregister will be ignored
|
||||
{
|
||||
FastMutex::ScopedLock lock(this->_mutex);
|
||||
_jsHandlers.erase(aDelegate);
|
||||
_jsHandlers.remove(aDelegate);
|
||||
}
|
||||
|
||||
const std::set<JSDelegate>& jsDelegates() const
|
||||
const JSDelegates& jsDelegates() const
|
||||
/// Returns all delegates currently registered
|
||||
{
|
||||
return _jsHandlers;
|
||||
}
|
||||
|
||||
void setJSDelegates(const std::set<JSDelegate>& all)
|
||||
void setJSDelegates(const JSDelegates& all)
|
||||
/// Overwrites all JSDelegates
|
||||
{
|
||||
_jsHandlers = all;
|
||||
}
|
||||
|
||||
private:
|
||||
std::set<JSDelegate> _jsHandlers;
|
||||
JSDelegates _jsHandlers;
|
||||
};
|
||||
|
||||
|
||||
|
@ -46,6 +46,7 @@
|
||||
namespace Poco {
|
||||
namespace Net {
|
||||
class HTTPServerRequest;
|
||||
class HTTPServerResponse;
|
||||
} }
|
||||
|
||||
|
||||
@ -63,6 +64,10 @@ public:
|
||||
|
||||
virtual void handleRequest(const Poco::Net::HTTPServerRequest& request) = 0;
|
||||
/// Handles a complete HTTP request submitted by the client.
|
||||
|
||||
virtual void handleRequestAndResponse(const Poco::Net::HTTPServerRequest& request, Poco::Net::HTTPServerResponse& response) = 0;
|
||||
/// Handles a complete HTTP request submitted by the client. Also takes care of handing the response,
|
||||
/// e.g. if one wants to send back data.
|
||||
|
||||
protected:
|
||||
RequestProcessor();
|
||||
|
@ -70,6 +70,9 @@ public:
|
||||
|
||||
void deleteRow(std::size_t row);
|
||||
/// Removes the row from the TableModel
|
||||
|
||||
void clear();
|
||||
/// Deletes all rows from the TableModel
|
||||
|
||||
protected:
|
||||
virtual ~SimpleTableModel();
|
||||
@ -106,6 +109,12 @@ inline void SimpleTableModel::deleteRow(std::size_t row)
|
||||
}
|
||||
|
||||
|
||||
inline void SimpleTableModel::clear()
|
||||
{
|
||||
_data.clear();
|
||||
}
|
||||
|
||||
|
||||
} } // namespace Poco::WebWidgets
|
||||
|
||||
|
||||
|
@ -46,6 +46,7 @@
|
||||
#include "Poco/WebWidgets/TableColumn.h"
|
||||
#include "Poco/WebWidgets/RequestProcessor.h"
|
||||
#include "Poco/WebWidgets/JavaScriptEvent.h"
|
||||
#include "Poco/WebWidgets/TableModelSerializer.h"
|
||||
#include <vector>
|
||||
|
||||
|
||||
@ -63,8 +64,10 @@ public:
|
||||
static const std::string FIELD_COL;
|
||||
static const std::string FIELD_ROW;
|
||||
static const std::string FIELD_VAL;
|
||||
static const std::string FIELD_CNT;
|
||||
static const std::string EV_CELLCLICKED;
|
||||
static const std::string EV_CELLVALUECHANGED;
|
||||
static const std::string EV_LOADDATA;
|
||||
|
||||
struct CellClick
|
||||
{
|
||||
@ -88,10 +91,10 @@ public:
|
||||
JavaScriptEvent<Table::CellValueChange> cellValueChanged;
|
||||
|
||||
|
||||
Table(const TableColumns& tc, TableModel::Ptr pModel);
|
||||
Table(const TableColumns& tc, TableModel::Ptr pModel, TableModelSerializer::Ptr pSer);
|
||||
/// Creates an anonymous Table.
|
||||
|
||||
Table(const std::string& name, const TableColumns& tc, TableModel::Ptr pModel);
|
||||
Table(const std::string& name, const TableColumns& tc, TableModel::Ptr pModel, TableModelSerializer::Ptr pSer);
|
||||
/// Creates a Table with the given name.
|
||||
|
||||
std::size_t getColumnCount() const;
|
||||
@ -105,6 +108,9 @@ public:
|
||||
|
||||
void setValue(const Poco::Any& val, std::size_t row, std::size_t col);
|
||||
/// Sets the value at pos(row, col)
|
||||
|
||||
void clear();
|
||||
/// Clears the content of the table
|
||||
|
||||
const Table::TableColumns& getColumns() const;
|
||||
/// Returns the columns of the table
|
||||
@ -117,6 +123,10 @@ public:
|
||||
|
||||
void handleRequest(const Poco::Net::HTTPServerRequest& request);
|
||||
/// Handles a complete HTTP request submitted by the client.
|
||||
|
||||
void handleRequestAndResponse(const Poco::Net::HTTPServerRequest& request, Poco::Net::HTTPServerResponse& response);
|
||||
/// Handles a complete HTTP request submitted by the client. Also takes care of handing the response,
|
||||
/// e.g. if one wants to send back data.
|
||||
|
||||
private:
|
||||
void handleValueChanged();
|
||||
@ -128,11 +138,12 @@ private:
|
||||
void handleCol(const std::string& val);
|
||||
void handleRow(const std::string& val);
|
||||
void handleVal(const std::string& val);
|
||||
void handleCnt(const std::string& val);
|
||||
protected:
|
||||
Table(const std::string& name, const std::type_info& type, const TableColumns& tc, TableModel::Ptr pModel);
|
||||
Table(const std::string& name, const std::type_info& type, const TableColumns& tc, TableModel::Ptr pModel, TableModelSerializer::Ptr pSer);
|
||||
/// Creates a Table and assigns it the given name.
|
||||
|
||||
Table(const std::type_info& type, const TableColumns& tc, TableModel::Ptr pModel);
|
||||
Table(const std::type_info& type, const TableColumns& tc, TableModel::Ptr pModel, TableModelSerializer::Ptr pSer);
|
||||
/// Creates a Table.
|
||||
|
||||
~Table();
|
||||
@ -146,8 +157,10 @@ private:
|
||||
TableColumns _columns;
|
||||
int _col;
|
||||
int _row;
|
||||
int _cnt;
|
||||
std::string _val;
|
||||
std::string _ev;
|
||||
TableModelSerializer::Ptr _pSer;
|
||||
};
|
||||
|
||||
|
||||
@ -172,6 +185,12 @@ inline std::size_t Table::getRowCount() const
|
||||
}
|
||||
|
||||
|
||||
inline void Table::clear()
|
||||
{
|
||||
return _pModel->clear();
|
||||
}
|
||||
|
||||
|
||||
inline const Table::TableColumns& Table::getColumns() const
|
||||
{
|
||||
return _columns;
|
||||
|
@ -73,6 +73,9 @@ public:
|
||||
|
||||
virtual void deleteRow(std::size_t row) = 0;
|
||||
/// Removes the row from the TableModel
|
||||
|
||||
virtual void clear() = 0;
|
||||
/// Deletes all rows from the TableModel
|
||||
|
||||
protected:
|
||||
virtual ~TableModel();
|
||||
|
78
WebWidgets/include/Poco/WebWidgets/TableModelSerializer.h
Normal file
78
WebWidgets/include/Poco/WebWidgets/TableModelSerializer.h
Normal file
@ -0,0 +1,78 @@
|
||||
//
|
||||
// TableModelSerializer.h
|
||||
//
|
||||
// $Id: //poco/Main/WebWidgets/include/Poco/WebWidgets/TableModelSerializer.h#4 $
|
||||
//
|
||||
// Library: WebWidgets
|
||||
// Package: Views
|
||||
// Module: TableModelSerializer
|
||||
//
|
||||
// Definition of the TableModelSerializer class.
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef WebWidgets_TableModelSerializer_INCLUDED
|
||||
#define WebWidgets_TableModelSerializer_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/WebWidgets/WebWidgets.h"
|
||||
#include "Poco/RefCountedObject.h"
|
||||
#include "Poco/AutoPtr.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace WebWidgets {
|
||||
|
||||
|
||||
class Table;
|
||||
|
||||
|
||||
class WebWidgets_API TableModelSerializer: public Poco::RefCountedObject
|
||||
/// TableModelSerializer defines the interface for Table serialization
|
||||
{
|
||||
public:
|
||||
typedef Poco::AutoPtr<TableModelSerializer> Ptr;
|
||||
|
||||
TableModelSerializer();
|
||||
/// Creates the TableModelSerializer with the given number of columns.
|
||||
|
||||
virtual ~TableModelSerializer();
|
||||
/// Destroys the TableModelSerializer.
|
||||
|
||||
virtual void serialize(std::ostream& ostr, const Table* pTable, std::size_t rowBegin = 0, std::size_t rowCnt = 0) = 0;
|
||||
/// Serializes the table starting with row 0. A rowCnt <= 0 means serialize all rows
|
||||
|
||||
virtual const std::string& contentType() const = 0;
|
||||
/// Returns the content type that the answer will be encoded in
|
||||
};
|
||||
|
||||
|
||||
} } // namespace Poco::WebWidgets
|
||||
|
||||
|
||||
#endif // WebWidgets_TableModelSerializer_INCLUDED
|
@ -36,6 +36,7 @@
|
||||
|
||||
#include "Poco/WebWidgets/Cell.h"
|
||||
#include "Poco/WebWidgets/StringFormatter.h"
|
||||
#include "Poco/Net//HTTPServerResponse.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
@ -179,4 +180,11 @@ void Cell::handleRequest(const Poco::Net::HTTPServerRequest& request)
|
||||
}
|
||||
|
||||
|
||||
void Cell::handleRequestAndResponse(const Poco::Net::HTTPServerRequest& request, Poco::Net::HTTPServerResponse& response)
|
||||
{
|
||||
handleRequest(request);
|
||||
response.send();
|
||||
}
|
||||
|
||||
|
||||
} } // namespace Poco::WebWidgets
|
||||
|
@ -134,8 +134,7 @@ void RequestHandler::handleAjaxRequest(Poco::Net::HTTPServerRequest& request, Po
|
||||
}
|
||||
try
|
||||
{
|
||||
pProc->handleRequest(request);
|
||||
response.send();
|
||||
pProc->handleRequestAndResponse(request, response);
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
|
@ -37,6 +37,7 @@
|
||||
#include "Poco/WebWidgets/Table.h"
|
||||
#include "Poco/WebWidgets/RequestHandler.h"
|
||||
#include "Poco/NumberParser.h"
|
||||
#include "Poco/Net/HTTPServerResponse.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
@ -46,53 +47,67 @@ namespace WebWidgets {
|
||||
const std::string Table::FIELD_COL("col");
|
||||
const std::string Table::FIELD_ROW("row");
|
||||
const std::string Table::FIELD_VAL("val");
|
||||
const std::string Table::FIELD_CNT("cnt");
|
||||
const std::string Table::EV_CELLCLICKED("click");
|
||||
const std::string Table::EV_CELLVALUECHANGED("edit");
|
||||
const std::string Table::EV_LOADDATA("load");
|
||||
|
||||
|
||||
Table::Table(const TableColumns& tc, TableModel::Ptr pModel):
|
||||
Table::Table(const TableColumns& tc, TableModel::Ptr pModel, TableModelSerializer::Ptr pSer):
|
||||
View(typeid(Table)),
|
||||
_pModel(pModel),
|
||||
_columns(tc),
|
||||
_col(-1),
|
||||
_row(-1),
|
||||
_val()
|
||||
_cnt(-1),
|
||||
_val(),
|
||||
_ev(),
|
||||
_pSer(pSer)
|
||||
{
|
||||
checkValidConfig();
|
||||
}
|
||||
|
||||
|
||||
Table::Table(const std::string& name, const TableColumns& tc, TableModel::Ptr pModel):
|
||||
Table::Table(const std::string& name, const TableColumns& tc, TableModel::Ptr pModel, TableModelSerializer::Ptr pSer):
|
||||
View(name, typeid(Table)),
|
||||
_pModel(pModel),
|
||||
_columns(tc),
|
||||
_col(-1),
|
||||
_row(-1),
|
||||
_val()
|
||||
_cnt(-1),
|
||||
_val(),
|
||||
_ev(),
|
||||
_pSer(pSer)
|
||||
{
|
||||
checkValidConfig();
|
||||
}
|
||||
|
||||
|
||||
Table::Table(const std::string& name, const std::type_info& type, const TableColumns& tc, TableModel::Ptr pModel):
|
||||
Table::Table(const std::string& name, const std::type_info& type, const TableColumns& tc, TableModel::Ptr pModel, TableModelSerializer::Ptr pSer):
|
||||
View(name, type),
|
||||
_pModel(pModel),
|
||||
_columns(tc),
|
||||
_col(-1),
|
||||
_row(-1),
|
||||
_val()
|
||||
_cnt(-1),
|
||||
_val(),
|
||||
_ev(),
|
||||
_pSer(pSer)
|
||||
{
|
||||
checkValidConfig();
|
||||
}
|
||||
|
||||
|
||||
Table::Table(const std::type_info& type, const TableColumns& tc, TableModel::Ptr pModel):
|
||||
Table::Table(const std::type_info& type, const TableColumns& tc, TableModel::Ptr pModel, TableModelSerializer::Ptr pSer):
|
||||
View(type),
|
||||
_pModel(pModel),
|
||||
_columns(tc),
|
||||
_col(-1),
|
||||
_row(-1),
|
||||
_val()
|
||||
_cnt(-1),
|
||||
_val(),
|
||||
_ev(),
|
||||
_pSer(pSer)
|
||||
{
|
||||
checkValidConfig();
|
||||
}
|
||||
@ -118,6 +133,7 @@ void Table::checkValidConfig()
|
||||
if ((*it))
|
||||
adoptChild((*it));;
|
||||
}
|
||||
poco_check_ptr (_pSer);
|
||||
}
|
||||
|
||||
|
||||
@ -129,6 +145,8 @@ void Table::handleForm(const std::string& field, const std::string& value)
|
||||
handleRow(value);
|
||||
else if (field == FIELD_VAL)
|
||||
handleVal(value);
|
||||
else if (field == FIELD_CNT)
|
||||
handleCnt(value);
|
||||
else if (field == RequestHandler::KEY_EVID)
|
||||
_ev = value;
|
||||
}
|
||||
@ -142,11 +160,37 @@ void Table::handleRequest(const Poco::Net::HTTPServerRequest& req)
|
||||
handleCellClicked();
|
||||
_col = -1;
|
||||
_row = -1;
|
||||
_cnt = -1;
|
||||
_val.clear();
|
||||
_ev.clear();
|
||||
}
|
||||
|
||||
|
||||
void Table::handleRequestAndResponse(const Poco::Net::HTTPServerRequest& request, Poco::Net::HTTPServerResponse& response)
|
||||
{
|
||||
// RequestHandler has already called all the handeForm stuff
|
||||
if (_ev == EV_LOADDATA)
|
||||
{
|
||||
/// serialize the Table back
|
||||
/// check for cnt and start if only a segment was requested
|
||||
response.setChunkedTransferEncoding(true);
|
||||
response.setContentType(_pSer->contentType());
|
||||
std::ostream& out = response.send();
|
||||
if (_row < 0)
|
||||
_row = 0;
|
||||
if (_cnt < 0)
|
||||
_cnt = 0;
|
||||
_pSer->serialize(out, this, _row, _cnt);
|
||||
}
|
||||
else
|
||||
{
|
||||
handleRequest(request);
|
||||
response.send();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Table::handleValueChanged()
|
||||
{
|
||||
if (_col < 0 || _row < 0 || _col >= getColumnCount())
|
||||
@ -196,6 +240,12 @@ void Table::handleVal(const std::string& val)
|
||||
}
|
||||
|
||||
|
||||
void Table::handleCnt(const std::string& val)
|
||||
{
|
||||
_cnt = Poco::NumberParser::parse(val);
|
||||
}
|
||||
|
||||
|
||||
void Table::setValue(const Poco::Any& val, std::size_t row, std::size_t col)
|
||||
{
|
||||
Poco::Any oldValue;
|
||||
|
54
WebWidgets/src/TableModelSerializer.cpp
Normal file
54
WebWidgets/src/TableModelSerializer.cpp
Normal file
@ -0,0 +1,54 @@
|
||||
//
|
||||
// TableModelSerializer.cpp
|
||||
//
|
||||
// $Id: //poco/Main/WebWidgets/src/TableModelSerializer.cpp#3 $
|
||||
//
|
||||
// Library: WebWidgets
|
||||
// Package: Views
|
||||
// Module: TableModelSerializer
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/WebWidgets/TableModelSerializer.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace WebWidgets {
|
||||
|
||||
|
||||
TableModelSerializer::TableModelSerializer()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
TableModelSerializer::~TableModelSerializer()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
} } // namespace Poco::WebWidgets
|
Loading…
Reference in New Issue
Block a user