mirror of
https://github.com/pocoproject/poco.git
synced 2025-01-19 00:46:03 +01:00
added support for dynamic code loading
This commit is contained in:
parent
69608ecbe3
commit
a981fb3130
@ -245,6 +245,10 @@
|
||||
RelativePath=".\include\Poco\WebWidgets\ExtJS\DateFieldCellRenderer.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\Poco\WebWidgets\ExtJS\DynamicCodeLoaderRenderer.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\Poco\WebWidgets\ExtJS\ExtJS.h"
|
||||
>
|
||||
@ -397,6 +401,10 @@
|
||||
RelativePath=".\src\DateFieldCellRenderer.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\DynamicCodeLoaderRenderer.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\FormRenderer.cpp"
|
||||
>
|
||||
|
@ -0,0 +1,73 @@
|
||||
//
|
||||
// DynamicCodeLoaderRenderer.h
|
||||
//
|
||||
// $Id: //poco/Main/WebWidgets/ExtJS/include/Poco/WebWidgets/ExtJS/DynamicCodeLoaderRenderer.h#2 $
|
||||
//
|
||||
// Library: ExtJS
|
||||
// Package: Core
|
||||
// Module: DynamicCodeLoaderRenderer
|
||||
//
|
||||
// Definition of the DynamicCodeLoaderRenderer 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_DynamicCodeLoaderRenderer_INCLUDED
|
||||
#define ExtJS_DynamicCodeLoaderRenderer_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/WebWidgets/ExtJS/ExtJS.h"
|
||||
#include "Poco/WebWidgets/Renderer.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace WebWidgets {
|
||||
namespace ExtJS {
|
||||
|
||||
|
||||
class ExtJS_API DynamicCodeLoaderRenderer: public Poco::WebWidgets::Renderer
|
||||
/// DynamicCodeLoaderRenderer renders a vertical Layout
|
||||
{
|
||||
public:
|
||||
DynamicCodeLoaderRenderer();
|
||||
/// Creates the DynamicCodeLoaderRenderer.
|
||||
|
||||
virtual ~DynamicCodeLoaderRenderer();
|
||||
/// Destroys the DynamicCodeLoaderRenderer.
|
||||
|
||||
void renderHead(const Renderable* pRenderable, const RenderContext& context, std::ostream& ostr);
|
||||
/// Emits code for the page header to the given output stream.
|
||||
|
||||
void renderBody(const Renderable* pRenderable, const RenderContext& context, std::ostream& ostr);
|
||||
/// Emits code for the page body to the given output stream.
|
||||
};
|
||||
|
||||
|
||||
} } } // namespace Poco::WebWidgets::ExtJS
|
||||
|
||||
|
||||
#endif // ExtJS_DynamicCodeLoaderRenderer_INCLUDED
|
115
WebWidgets/ExtJS/src/DynamicCodeLoaderRenderer.cpp
Normal file
115
WebWidgets/ExtJS/src/DynamicCodeLoaderRenderer.cpp
Normal file
@ -0,0 +1,115 @@
|
||||
//
|
||||
// DynamicCodeLoaderRenderer.cpp
|
||||
//
|
||||
// $Id: //poco/Main/WebWidgets/ExtJS/src/DynamicCodeLoaderRenderer.cpp#2 $
|
||||
//
|
||||
// Library: ExtJS
|
||||
// Package: Core
|
||||
// Module: DynamicCodeLoaderRenderer
|
||||
//
|
||||
// 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/DynamicCodeLoaderRenderer.h"
|
||||
#include "Poco/WebWidgets/ExtJS/Utility.h"
|
||||
#include "Poco/WebWidgets/VerticalLayout.h"
|
||||
#include "Poco/WebWidgets/DynamicCodeLoader.h"
|
||||
#include "Poco/WebWidgets/RequestHandler.h"
|
||||
#include "Poco/NumberFormatter.h"
|
||||
#include <sstream>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace WebWidgets {
|
||||
namespace ExtJS {
|
||||
|
||||
|
||||
DynamicCodeLoaderRenderer::DynamicCodeLoaderRenderer()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
DynamicCodeLoaderRenderer::~DynamicCodeLoaderRenderer()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void DynamicCodeLoaderRenderer::renderHead(const Renderable* pRenderable, const RenderContext& context, std::ostream& str)
|
||||
{
|
||||
// we need to render two things:
|
||||
// - first a load method in the header which loads a js file
|
||||
// - second, the js file which must be set as code at the DynamicCodeLoader
|
||||
const DynamicCodeLoader* pLoader = static_cast<const DynamicCodeLoader*>(pRenderable);
|
||||
poco_assert_dbg (pLoader != 0);
|
||||
str << "var " << pLoader->loaderFunctionName() << "Loaded = false;" << std::endl;
|
||||
str << "function " << pLoader->loaderFunctionName() << "(){" << std::endl;
|
||||
str << "if ("<< pLoader->loaderFunctionName() << "Loaded) return;" << std::endl;
|
||||
str << pLoader->loaderFunctionName() << "Loaded = true;" << std::endl;
|
||||
str << "Ext.Ajax.request({" << std::endl;
|
||||
str << "url: '" << pLoader->uri().toString() << "/;" << RequestHandler::KEY_EVID << "=" << DynamicCodeLoader::EV_LOAD << "&";
|
||||
str << RequestHandler::KEY_ID << "=" << pLoader->id() << "'," << std::endl;
|
||||
str << "success: function(response){" << std::endl;
|
||||
str << "loadScriptDynamically('script" << pLoader->id() << "', response);" << std::endl;
|
||||
str << "var parent = Ext.getCmp('" << pLoader->parent()->id() << "');" << std::endl;
|
||||
str << "var child = " << pLoader->functionName() << "();" << std::endl;
|
||||
str << "parent.add(child);" << std::endl;
|
||||
if (!pLoader->getSuccessCall().empty())
|
||||
str << pLoader->getSuccessCall() << ";" << std::endl;
|
||||
str << "}";
|
||||
if (!pLoader->getErrorCall().empty())
|
||||
str << ",failure:" << pLoader->getErrorCall() << std::endl;
|
||||
str << "});" << std::endl;
|
||||
str << "}" << std::endl;
|
||||
|
||||
DynamicCodeLoader* pL = const_cast<DynamicCodeLoader*>(pLoader);
|
||||
|
||||
WebApplication::instance().registerAjaxProcessor(Poco::NumberFormatter::format(pLoader->id()), pL);
|
||||
|
||||
// the js file: only do when not already set
|
||||
if (!pLoader->getViewCode().empty())
|
||||
return;
|
||||
|
||||
std::ostringstream out;
|
||||
View::Ptr pView = pLoader->view();
|
||||
out << "function " << pLoader->functionName() << "(){";
|
||||
out << "return ";
|
||||
pView->renderHead(context, out);
|
||||
out << ";"; // close return
|
||||
out << "}";
|
||||
|
||||
pL->setViewCode(out.str());
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
void DynamicCodeLoaderRenderer::renderBody(const Renderable* pRenderable, const RenderContext& context, std::ostream& ostr)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
} } } // namespace Poco::WebWidgets::ExtJS
|
@ -127,6 +127,29 @@ void PageRenderer::renderHead(const Renderable* pRenderable, const RenderContext
|
||||
ostr << *itF << std::endl;
|
||||
}
|
||||
|
||||
const std::set<DynamicCodeLoader::Ptr>& dcls = pPage->dynamicCodeLoaders();
|
||||
if (!dcls.empty())
|
||||
{
|
||||
ostr << "function loadScriptDynamically(sId, source){" << std::endl;
|
||||
ostr << "if (!source) return;" << std::endl;
|
||||
ostr << "var oHead = document.getElementsByTagName('HEAD').item(0);" << std::endl;
|
||||
ostr << "var oScript = document.createElement('script');" << std::endl;
|
||||
ostr << "oScript.language = 'javascript';" << std::endl;
|
||||
ostr << "oScript.type = 'text/javascript';" << std::endl;
|
||||
ostr << "oScript.id = sId;" << std::endl;
|
||||
ostr << "oScript.defer = true;" << std::endl;
|
||||
ostr << "oScript.text = source.responseText;" << std::endl;
|
||||
ostr << "oHead.appendChild(oScript);" << std::endl;
|
||||
ostr << "}" << std::endl;
|
||||
}
|
||||
std::set<DynamicCodeLoader::Ptr>::const_iterator itDC = dcls.begin();
|
||||
for (; itDC != dcls.end(); ++itDC)
|
||||
{
|
||||
(*itDC)->renderHead(context, ostr);
|
||||
}
|
||||
|
||||
|
||||
|
||||
ostr << "Ext.onReady(function() {";
|
||||
ostr << "var " << VAR_LOCALTMP << ";"; // tmp variable needed for table renderer
|
||||
ostr << "Ext.QuickTips.init();";
|
||||
|
@ -62,6 +62,7 @@
|
||||
#include "Poco/WebWidgets/ExtJS/TableRenderer.h"
|
||||
#include "Poco/WebWidgets/ExtJS/ProgressIndicatorRenderer.h"
|
||||
#include "Poco/WebWidgets/ExtJS/HTMLRenderer.h"
|
||||
#include "Poco/WebWidgets/ExtJS/DynamicCodeLoaderRenderer.h"
|
||||
|
||||
#include "Poco/WebWidgets/Label.h"
|
||||
#include "Poco/WebWidgets/Page.h"
|
||||
@ -77,6 +78,7 @@
|
||||
#include "Poco/WebWidgets/TextFieldCell.h"
|
||||
#include "Poco/WebWidgets/TimeFieldCell.h"
|
||||
#include "Poco/WebWidgets/DateFieldCell.h"
|
||||
#include "Poco/WebWidgets/DynamicCodeLoader.h"
|
||||
#include "Poco/WebWidgets/PasswordFieldCell.h"
|
||||
#include "Poco/WebWidgets/NumberFieldCell.h"
|
||||
#include "Poco/WebWidgets/ComboBoxCell.h"
|
||||
@ -137,6 +139,7 @@ void Utility::initialize(LookAndFeel::Ptr ptr)
|
||||
ptr->registerRenderer(typeid(Table), new TableRenderer());
|
||||
ptr->registerRenderer(typeid(ProgressIndicator), new ProgressIndicatorRenderer());
|
||||
ptr->registerRenderer(typeid(HTML),new HTMLRenderer());
|
||||
ptr->registerRenderer(typeid(DynamicCodeLoader),new DynamicCodeLoaderRenderer());
|
||||
}
|
||||
|
||||
|
||||
|
@ -233,6 +233,10 @@
|
||||
RelativePath=".\include\Poco\WebWidgets\Delegate.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\Poco\WebWidgets\DynamicCodeLoader.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\Poco\WebWidgets\Event.h"
|
||||
>
|
||||
@ -317,6 +321,10 @@
|
||||
RelativePath=".\src\Delegate.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\DynamicCodeLoader.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\JSDelegate.cpp"
|
||||
>
|
||||
|
@ -232,6 +232,10 @@
|
||||
RelativePath=".\include\Poco\WebWidgets\Delegate.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\Poco\WebWidgets\DynamicCodeLoader.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\Poco\WebWidgets\Event.h"
|
||||
>
|
||||
@ -316,6 +320,10 @@
|
||||
RelativePath=".\src\Delegate.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\DynamicCodeLoader.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\JSDelegate.cpp"
|
||||
>
|
||||
|
204
WebWidgets/include/Poco/WebWidgets/DynamicCodeLoader.h
Normal file
204
WebWidgets/include/Poco/WebWidgets/DynamicCodeLoader.h
Normal file
@ -0,0 +1,204 @@
|
||||
//
|
||||
// DynamicCodeLoader.h
|
||||
//
|
||||
// $Id: //poco/Main/WebWidgets/include/Poco/WebWidgets/DynamicCodeLoader.h#2 $
|
||||
//
|
||||
// Library: WebWidgets
|
||||
// Package: Core
|
||||
// Module: DynamicCodeLoader
|
||||
//
|
||||
// Definition of the DynamicCodeLoader 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_DynamicCodeLoader_INCLUDED
|
||||
#define WebWidgets_DynamicCodeLoader_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/WebWidgets/Renderable.h"
|
||||
#include "Poco/WebWidgets/RequestProcessor.h"
|
||||
#include "Poco/WebWidgets/View.h"
|
||||
#include "Poco/URI.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace WebWidgets {
|
||||
|
||||
|
||||
class WebWidgets_API DynamicCodeLoader: public Renderable, public RequestProcessor
|
||||
/// A DynamicCodeLoader loads Javascript GUI code from an URL
|
||||
/// and adds a creator function to the Page
|
||||
{
|
||||
public:
|
||||
typedef Poco::AutoPtr<DynamicCodeLoader> Ptr;
|
||||
|
||||
static const std::string EV_LOAD;
|
||||
|
||||
DynamicCodeLoader(View* pParent, const Poco::URI& uri, const std::string& fctName, View::Ptr pView);
|
||||
/// Makes the code available at URI, containing JS code
|
||||
/// Adds a factory function named fctName() to the js file
|
||||
/// which will return the JS GUI component.
|
||||
/// fctName and pView must not be empty
|
||||
/// pParent must not be empty, defines the View to which the dynamic code is added
|
||||
|
||||
bool operator < (const DynamicCodeLoader& other) const;
|
||||
/// Compares loaders by fctname
|
||||
|
||||
const std::string& functionName() const;
|
||||
/// Returns the function name
|
||||
|
||||
const std::string& loaderFunctionName() const;
|
||||
/// Returns the function name used to load the js
|
||||
|
||||
View::Ptr view() const;
|
||||
/// Returns the view
|
||||
|
||||
void setViewCode(const std::string& jsCode);
|
||||
/// Sets the JS code for the view
|
||||
|
||||
const std::string& getViewCode() const;
|
||||
/// Returns the JS code for the view
|
||||
|
||||
const Poco::URI& uri() const;
|
||||
|
||||
View* parent() const;
|
||||
|
||||
// RequestProcessor
|
||||
void handleForm(const std::string& field, const std::string& value);
|
||||
/// Handles a form field submitted by the client.
|
||||
///
|
||||
/// The default implementation does nothing.
|
||||
|
||||
void handleAjaxRequest(const Poco::Net::NameValueCollection& args, Poco::Net::HTTPServerResponse& response);
|
||||
/// Handles onload
|
||||
|
||||
bool serializeJSON(std::ostream& out, const std::string& name);
|
||||
/// Sends the view as js to out, param name is ignored
|
||||
|
||||
void setSuccessCall(const std::string& jsFct);
|
||||
/// The JS fucntion which should be called on success
|
||||
|
||||
const std::string& getSuccessCall() const;
|
||||
|
||||
void setErrorCall(const std::string& jsFct);
|
||||
/// The JS fucntion which should be called on success
|
||||
|
||||
const std::string& getErrorCall() const;
|
||||
|
||||
protected:
|
||||
~DynamicCodeLoader();
|
||||
/// Destroys the DynamicCodeLoader.
|
||||
|
||||
private:
|
||||
View* _pParent;
|
||||
Poco::URI _uri;
|
||||
std::string _fctName;
|
||||
std::string _loaderFct;
|
||||
View::Ptr _pView;
|
||||
std::string _code;
|
||||
std::string _success;
|
||||
std::string _error;
|
||||
};
|
||||
|
||||
|
||||
inline View* DynamicCodeLoader::parent() const
|
||||
{
|
||||
return _pParent;
|
||||
}
|
||||
|
||||
|
||||
inline const std::string& DynamicCodeLoader::functionName() const
|
||||
{
|
||||
return _fctName;
|
||||
}
|
||||
|
||||
|
||||
inline View::Ptr DynamicCodeLoader::view() const
|
||||
{
|
||||
return _pView;
|
||||
}
|
||||
|
||||
|
||||
inline void DynamicCodeLoader::setViewCode(const std::string& jsCode)
|
||||
{
|
||||
_code = jsCode;
|
||||
}
|
||||
|
||||
|
||||
inline const std::string& DynamicCodeLoader::getViewCode() const
|
||||
{
|
||||
return _code;
|
||||
}
|
||||
|
||||
|
||||
inline const std::string& DynamicCodeLoader::loaderFunctionName() const
|
||||
{
|
||||
return _loaderFct;
|
||||
}
|
||||
|
||||
|
||||
inline bool DynamicCodeLoader::operator < (const DynamicCodeLoader& other) const
|
||||
{
|
||||
return _fctName < other._fctName;
|
||||
}
|
||||
|
||||
|
||||
inline const Poco::URI& DynamicCodeLoader::uri() const
|
||||
{
|
||||
return _uri;
|
||||
}
|
||||
|
||||
|
||||
inline void DynamicCodeLoader::setSuccessCall(const std::string& jsFct)
|
||||
{
|
||||
_success = jsFct;
|
||||
}
|
||||
|
||||
|
||||
inline const std::string& DynamicCodeLoader::getSuccessCall() const
|
||||
{
|
||||
return _success;
|
||||
}
|
||||
|
||||
|
||||
inline void DynamicCodeLoader::setErrorCall(const std::string& jsFct)
|
||||
{
|
||||
_error = jsFct;
|
||||
}
|
||||
|
||||
|
||||
inline const std::string& DynamicCodeLoader::getErrorCall() const
|
||||
{
|
||||
return _error;
|
||||
}
|
||||
|
||||
|
||||
} } // namespace Poco::WebWidgets
|
||||
|
||||
|
||||
#endif // WebWidgets_DynamicCodeLoader_INCLUDED
|
@ -44,9 +44,12 @@
|
||||
#include "Poco/WebWidgets/JavaScriptEvent.h"
|
||||
#include "Poco/WebWidgets/ResourceManager.h"
|
||||
#include "Poco/WebWidgets/RequestProcessor.h"
|
||||
#include "Poco/WebWidgets/DynamicCodeLoader.h"
|
||||
#include "Poco/Net/NameValueCollection.h"
|
||||
#include "Poco/Net/HTTPServerResponse.h"
|
||||
#include "Poco/BasicEvent.h"
|
||||
#include <set>
|
||||
#include <vector>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
@ -122,6 +125,10 @@ public:
|
||||
|
||||
void appendPostRenderCode(const std::string& js);
|
||||
/// Appends Javascript code that should be executed after the page code was written.
|
||||
|
||||
void addDynamicCodeLoader(DynamicCodeLoader::Ptr pLoader);
|
||||
|
||||
const std::set<DynamicCodeLoader::Ptr>& dynamicCodeLoaders() const;
|
||||
|
||||
protected:
|
||||
Page(const std::string& name, const std::type_info& type);
|
||||
@ -137,6 +144,7 @@ private:
|
||||
std::string _text;
|
||||
ResourceManager _rm;
|
||||
std::vector<std::string> _jsCode;
|
||||
std::set<DynamicCodeLoader::Ptr> _codeLoaders;
|
||||
std::string _postRenderCode;
|
||||
};
|
||||
|
||||
@ -198,6 +206,18 @@ inline bool Page::serializeJSON(std::ostream&, const std::string&)
|
||||
}
|
||||
|
||||
|
||||
inline void Page::addDynamicCodeLoader(DynamicCodeLoader::Ptr pLoader)
|
||||
{
|
||||
if (pLoader) _codeLoaders.insert(pLoader);
|
||||
}
|
||||
|
||||
|
||||
inline const std::set<DynamicCodeLoader::Ptr>& Page::dynamicCodeLoaders() const
|
||||
{
|
||||
return _codeLoaders;
|
||||
}
|
||||
|
||||
|
||||
} } // namespace Poco::WebWidgets
|
||||
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user