mirror of
https://github.com/pocoproject/poco.git
synced 2025-11-24 22:29:47 +01:00
added support for dynamic code loading
This commit is contained in:
@@ -137,14 +137,14 @@ void ComboBoxCell::setSelected(const Any& elem)
|
||||
|
||||
bool ComboBoxCell::serializeJSON(std::ostream& out, const std::string& name)
|
||||
{
|
||||
out << name;
|
||||
out << name << ":";
|
||||
if (hasSelected())
|
||||
{
|
||||
const Poco::Any& sel = getSelected();
|
||||
if (sel.type() == typeid(std::string) || sel.type() == typeid(Poco::DateTime))
|
||||
out << ":'" << getFormatter()->format(sel) << "'";
|
||||
out << "'" << getFormatter()->format(sel) << "'";
|
||||
else
|
||||
out << ":" << getFormatter()->format(sel);
|
||||
out << getFormatter()->format(sel);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -65,10 +65,10 @@ void DateFieldCell::setFormat(const std::string& dateFormat)
|
||||
|
||||
bool DateFieldCell::serializeJSON(std::ostream& out, const std::string& name)
|
||||
{
|
||||
out << name;
|
||||
out << name << ":";
|
||||
if (this->hasValue())
|
||||
{
|
||||
out << ":'" << getFormatter()->format(getValue()) << "'";
|
||||
out << "'" << getFormatter()->format(getValue()) << "'";
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
96
WebWidgets/src/DynamicCodeLoader.cpp
Normal file
96
WebWidgets/src/DynamicCodeLoader.cpp
Normal file
@@ -0,0 +1,96 @@
|
||||
//
|
||||
// DynamicCodeLoader.cpp
|
||||
//
|
||||
// $Id: //poco/Main/WebWidgets/src/DynamicCodeLoader.cpp#2 $
|
||||
//
|
||||
// Library: WebWidgets
|
||||
// Package: Core
|
||||
// Module: DynamicCodeLoader
|
||||
//
|
||||
// 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/DynamicCodeLoader.h"
|
||||
#include "Poco/WebWidgets/RequestHandler.h"
|
||||
#include "Poco/Net/NameValueCollection.h"
|
||||
#include "Poco/Net/HTTPServerResponse.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace WebWidgets {
|
||||
|
||||
|
||||
const std::string DynamicCodeLoader::EV_LOAD("dynload");
|
||||
|
||||
|
||||
DynamicCodeLoader::DynamicCodeLoader(View* pParent, const Poco::URI& uri, const std::string& fctName, View::Ptr pView):
|
||||
Renderable(typeid(DynamicCodeLoader)),
|
||||
_pParent(pParent),
|
||||
_uri(uri),
|
||||
_fctName(fctName),
|
||||
_loaderFct("load"),
|
||||
_pView(pView)
|
||||
{
|
||||
poco_check_ptr (_pView);
|
||||
poco_assert (!_fctName.empty());
|
||||
_loaderFct.append(_fctName);
|
||||
}
|
||||
|
||||
|
||||
DynamicCodeLoader::~DynamicCodeLoader()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void DynamicCodeLoader::handleForm(const std::string& field, const std::string& value)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void DynamicCodeLoader::handleAjaxRequest(const Poco::Net::NameValueCollection& args, Poco::Net::HTTPServerResponse& response)
|
||||
{
|
||||
const std::string& ev = args[RequestHandler::KEY_EVID];
|
||||
if (ev == EV_LOAD)
|
||||
{
|
||||
/// send the JS presentation of the page
|
||||
response.setContentType("text/javascript");
|
||||
response.setChunkedTransferEncoding(true);
|
||||
serializeJSON(response.send(),"");
|
||||
}
|
||||
else
|
||||
response.send();
|
||||
}
|
||||
|
||||
|
||||
bool DynamicCodeLoader::serializeJSON(std::ostream& out, const std::string& name)
|
||||
{
|
||||
out << _code;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
} } // namespace Poco::WebWidgets
|
||||
@@ -56,10 +56,10 @@ NumberFieldCell::~NumberFieldCell()
|
||||
|
||||
bool NumberFieldCell::serializeJSON(std::ostream& out, const std::string& name)
|
||||
{
|
||||
out << name;
|
||||
out << name << ":";
|
||||
if (this->hasValue())
|
||||
{
|
||||
out << ":" << getFormatter()->format(getValue());
|
||||
out << getFormatter()->format(getValue());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -54,10 +54,10 @@ PasswordFieldCell::~PasswordFieldCell()
|
||||
|
||||
bool PasswordFieldCell::serializeJSON(std::ostream& out, const std::string& name)
|
||||
{
|
||||
out << name;
|
||||
out << name << ":";
|
||||
if (this->hasValue())
|
||||
{
|
||||
out << ":'" << getFormatter()->format(getValue()) << "'";
|
||||
out << "'" << getFormatter()->format(getValue()) << "'";
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -75,10 +75,10 @@ void TextEditCell::handleForm(const std::string& field, const std::string& value
|
||||
|
||||
bool TextEditCell::serializeJSON(std::ostream& out, const std::string& name)
|
||||
{
|
||||
out << name;
|
||||
out << name << ":";
|
||||
if (this->hasValue())
|
||||
{
|
||||
out << ":'" << getFormatter()->format(getValue()) << "'";
|
||||
out << "'" << getFormatter()->format(getValue()) << "'";
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -87,10 +87,10 @@ void TextFieldCell::handleForm(const std::string& field, const std::string& valu
|
||||
|
||||
bool TextFieldCell::serializeJSON(std::ostream& out, const std::string& name)
|
||||
{
|
||||
out << name;
|
||||
out << name << ":";
|
||||
if (this->hasValue())
|
||||
{
|
||||
out << ":'" << getFormatter()->format(getValue()) << "'";
|
||||
out << "'" << getFormatter()->format(getValue()) << "'";
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -80,10 +80,10 @@ void TimeFieldCell::setFormat(TimeField::Format fmt)
|
||||
|
||||
bool TimeFieldCell::serializeJSON(std::ostream& out, const std::string& name)
|
||||
{
|
||||
out << name;
|
||||
out << name << ":";
|
||||
if (this->hasValue())
|
||||
{
|
||||
out << ":'" << getFormatter()->format(getValue()) << "'";
|
||||
out << "'" << getFormatter()->format(getValue()) << "'";
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user