fixes to table, events, datefields

This commit is contained in:
Peter Schojer
2008-05-30 12:48:59 +00:00
parent 72a0f3c3ff
commit fafec95355
16 changed files with 329 additions and 66 deletions

View File

@@ -81,7 +81,9 @@ void ComboBoxCellRenderer::renderHead(const Renderable* pRenderable, const Rende
poco_assert_dbg (pRenderable != 0);
poco_assert_dbg (pRenderable->type() == typeid(Poco::WebWidgets::ComboBoxCell));
ComboBoxCell* pCell = const_cast<ComboBoxCell*>(static_cast<const Poco::WebWidgets::ComboBoxCell*>(pRenderable));
ComboBox* pOwner = dynamic_cast<ComboBox*>(pCell->getOwner());
//two scenarios: owner is either a ComboBox or a TableColumn!
View* pOwner = pCell->getOwner();
ComboBox* pComboOwner = dynamic_cast<ComboBox*>(pOwner);
poco_check_ptr (pOwner);
ostr << "new Ext.form.ComboBox({";
@@ -98,10 +100,10 @@ void ComboBoxCellRenderer::renderHead(const Renderable* pRenderable, const Rende
std::string tooltip (pCell->getToolTip());
if (!pOwner->selected.jsDelegates().empty())
if (pComboOwner && !pComboOwner->selected.jsDelegates().empty())
{
ostr << ",listeners:{";
Utility::writeJSEvent(ostr, EV_SELECTED, pOwner->selected.jsDelegates());
Utility::writeJSEvent(ostr, EV_SELECTED, pComboOwner->selected.jsDelegates());
if (!tooltip.empty())
ostr << ",render:function(c){Ext.QuickTips.register({target:c.getEl(),text:'" << Utility::safe(tooltip) << "'});}";
ostr << "}";

View File

@@ -64,13 +64,15 @@ void PanelRenderer::renderHead(const Renderable* pRenderable, const RenderContex
Utility::writeRenderableProperties(pRenderable, ostr);
if (!pPanel->getName().empty())
ostr << ",title:'" << pPanel->getName() << "'";
ostr << ",title:'" << pPanel->getTitle() << "'";
if (pPanel->getWidth() > 0)
ostr << ",width:" << pPanel->getWidth();
if (pPanel->getHeight() > 0)
ostr << ",height:" << pPanel->getHeight();
if (pPanel->getModal())
ostr << ",modal:true";
if (!pPanel->hasCloseIcon())
ostr << ",closable:false";
// minimizable set to true only fires a minimize event, without an event handler attached
// it is pretty useless, instead use collapsible

View File

@@ -86,7 +86,7 @@ TableCellHandlerFactory::TableCellHandlerFactory()
registerFactory(typeid(ImageButtonCell), pHandle);
}
{
TableCellHandler<DateFieldCell>::Ptr pHandle(new TableCellHandler<DateFieldCell>(true, false));
TableCellHandler<DateFieldCell>::Ptr pHandle(new TableCellHandler<DateFieldCell>(true, true));
registerFactory(typeid(DateFieldCell), pHandle);
}
}

View File

@@ -97,7 +97,11 @@ void TableRenderer::addCellValueChangedServerCallback(Table* pTable, const std::
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, origRow));
addParams.insert(std::make_pair(Table::FIELD_VAL, "+obj.value"));
//problem: I need the displayed string from teh renderer, not the value!
// date fields cause problems here, and I only habe one cellclick event per table not per column!
// from the tabel get the TableCOlumn, from thsi get the renderer for the given col and render obj.value
// {(var r=obj.grid.getColumnModel().getRenderer(obj.col))?r(obj.value);:obj.value;} hm, no working
addParams.insert(std::make_pair(Table::FIELD_VAL, "+obj.value"));
addParams.insert(std::make_pair(RequestHandler::KEY_EVID, Table::EV_CELLVALUECHANGED));
Utility::addServerCallback(pTable->cellValueChanged, signature, addParams, pTable->id(), onSuccess, onFailure);
pTable->cellValueChanged.add(jsDelegate("function(obj){obj.grid.getStore().commitChanges();}"));
@@ -207,12 +211,12 @@ void TableRenderer::renderColumn(const Table* pTable, const TableColumn& tc, int
ostr << ",editor:";
tc.getCell()->renderHead(context, ostr);
}
if (pHandler->useRenderer())
{
ostr << ",renderer:";
pHandler->writeDynamicData(ostr);
}
}
ostr << "}";
@@ -244,7 +248,14 @@ void TableRenderer::renderStore(const Table* pTable, std::ostream& ostr)
{
if (i != 0)
ostr << ",";
ostr << "{name:'" << i << "'}";
if ((*it)->getCell()->type() == typeid(Poco::WebWidgets::DateFieldCell))
{
Poco::WebWidgets::DateFieldCell::Ptr pDf = (*it)->getCell().cast<Poco::WebWidgets::DateFieldCell>();
ostr << "{name:'" << i << "',type:'date',dateFormat:'" << Utility::convertPocoDateToPHPDate(pDf->getFormat()) << "'}";
}
else
ostr << "{name:'" << i << "'}";
}
ostr << ",{name:'" << i << "'}";
ostr << "],"; // close fields

View File

@@ -92,6 +92,7 @@
#include "Poco/WebWidgets/RequestHandler.h"
#include "Poco/String.h"
#include "Poco/StringTokenizer.h"
#include "Poco/NumberFormatter.h"
#include "Poco/DateTimeFormat.h"
#include <sstream>
@@ -412,16 +413,40 @@ bool Utility::writeJSEvent(std::ostream& out, const std::string& eventName, cons
invoke << "invoke:" << fct <<"{";
std::list<JSDelegate>::const_iterator it = delegates.begin();
int cnt(0);
for (; it != delegates.end(); ++it)
for (; it != delegates.end(); ++it, ++cnt)
{
std::string fctName("d");
fctName.append(Poco::NumberFormatter::format(cnt));
if (cnt > 0)
std::string myFctName("d");
myFctName.append(Poco::NumberFormatter::format(cnt));
out << myFctName << ":";
std::string fctName;
std::vector<std::string> params;
std::string code;
analyzeFunction(*it, fctName, params, code);
if (fctName == "function")
{
out << ",";
// an inline definition, we must have code
if (!code.empty())
{
writeFunction(out, fctName, params, code);
}
}
out << fctName << ":" << it->jsCode() << ","; //always write comma because invoke is written as the last method
invoke << "this." << createFunctionSignature(fctName, maxParams) << ";";
else
{
if (code.empty())
{
// a reference to another js function
//maybe the user defined params too -> ignore them
out << fctName;
}
else
{
// we have code, so rename the function to function :-)
writeFunction(out, "function", params, code);
}
}
out << ","; //always write comma because invoke is written as the last method
invoke << "this." << createFunctionSignature(myFctName, maxParams) << ";";
}
invoke << "}";
@@ -436,6 +461,27 @@ bool Utility::writeJSEvent(std::ostream& out, const std::string& eventName, cons
}
void Utility::writeFunction(std::ostream& out, const std::string& fctName, const std::vector<std::string> &params, const std::string& code)
{
out << fctName << "(";
std::vector<std::string>::const_iterator it = params.begin();
for (; it != params.end(); ++it)
{
if (it != params.begin())
out << ",";
out << *it;
}
out << ")";
bool openWritten = false;
if (code.find('{') != 0)
{
out << "{";
openWritten = true;
}
out << code;
if (openWritten)
out << "}";
}
std::string Utility::createURI(const std::map<std::string, std::string>& addParams, Renderable::ID id)
@@ -526,39 +572,55 @@ int Utility::detectMaxParamCount(const std::list<JSDelegate>& delegates)
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;
}
}
std::string tmp;
std::string tmp2;
std::vector<std::string> params;
analyzeFunction(*it, tmp, params, tmp2);
tmpCnt = (int)params.size();
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)
void Utility::analyzeFunction(const JSDelegate& delegate, std::string& fctName, std::vector<std::string>& paramNames, std::string& code)
{
while (pos < code.size() && std::isspace(code[pos]))
// 3 cases:
// function(...){...}
// myname(....) {}
// myname //external call
const std::string& jsCode = delegate.jsCode();
fctName.clear();
paramNames.clear();
code.clear();
std::string::size_type pos = jsCode.find(')');
std::string fctHeader = jsCode.substr(0, pos);
if (pos != std::string::npos)
{
++pos;
code = jsCode.substr(pos);
Poco::trimInPlace(code);
}
Poco::StringTokenizer tok(fctHeader, "(,", Poco::StringTokenizer::TOK_TRIM | Poco::StringTokenizer::TOK_IGNORE_EMPTY);
if (tok.count() > 0)
{
Poco::StringTokenizer::Iterator it = tok.begin();
fctName = *it;
++it;
for (; it != tok.end(); ++it)
paramNames.push_back(*it);
}
}
std::string Utility::createFunctionSignature(int paramCnt)
{
static const std::string fct("function");