mirror of
https://github.com/pocoproject/poco.git
synced 2025-03-04 19:13:30 +01:00
added support for delayed init
This commit is contained in:
parent
8ccc58be02
commit
a01e9c78b8
@ -46,6 +46,7 @@
|
||||
|
||||
namespace Poco {
|
||||
namespace WebWidgets {
|
||||
class DynamicCodeLoader;
|
||||
namespace ExtJS {
|
||||
|
||||
|
||||
@ -64,6 +65,9 @@ public:
|
||||
|
||||
void renderBody(const Renderable* pRenderable, const RenderContext& context, std::ostream& ostr);
|
||||
/// Emits code for the page body to the given output stream.
|
||||
|
||||
private:
|
||||
static void onCodeGen(DynamicCodeLoader* &pLoader);
|
||||
};
|
||||
|
||||
|
||||
|
@ -41,7 +41,10 @@
|
||||
#include "Poco/WebWidgets/DynamicCodeLoader.h"
|
||||
#include "Poco/WebWidgets/RequestHandler.h"
|
||||
#include "Poco/WebWidgets/Panel.h"
|
||||
#include "Poco/WebWidgets/WebApplication.h"
|
||||
#include "Poco/WebWidgets/RenderContext.h"
|
||||
#include "Poco/NumberFormatter.h"
|
||||
#include "Poco/Delegate.h"
|
||||
#include <sstream>
|
||||
|
||||
|
||||
@ -93,15 +96,27 @@ void DynamicCodeLoaderRenderer::renderHead(const Renderable* pRenderable, const
|
||||
str << "}" << std::endl;
|
||||
|
||||
DynamicCodeLoader* pL = const_cast<DynamicCodeLoader*>(pLoader);
|
||||
pL->generateCode += Poco::delegate(&DynamicCodeLoaderRenderer::onCodeGen);
|
||||
|
||||
WebApplication::instance().registerAjaxProcessor(Poco::NumberFormatter::format(pLoader->id()), pL);
|
||||
|
||||
// the js file: only do when not already set
|
||||
// bug: this optimization breaks logout/login stuff!
|
||||
}
|
||||
|
||||
|
||||
void DynamicCodeLoaderRenderer::renderBody(const Renderable* pRenderable, const RenderContext& context, std::ostream& ostr)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void DynamicCodeLoaderRenderer::onCodeGen(DynamicCodeLoader* &pL)
|
||||
{
|
||||
View::Ptr pView = pL->view();
|
||||
Panel::Ptr pPanel = pView.cast<Panel>();
|
||||
WebApplication& webApp = WebApplication::instance();
|
||||
RenderContext context(*webApp.getLookAndFeel(), webApp);
|
||||
|
||||
std::ostringstream out;
|
||||
|
||||
out << "function " << pLoader->functionName() << "(){";
|
||||
out << "function " << pL->functionName() << "(){";
|
||||
out << "return ";
|
||||
// only render the child when we have a panel
|
||||
if (pPanel)
|
||||
@ -118,9 +133,4 @@ void DynamicCodeLoaderRenderer::renderHead(const Renderable* pRenderable, const
|
||||
}
|
||||
|
||||
|
||||
void DynamicCodeLoaderRenderer::renderBody(const Renderable* pRenderable, const RenderContext& context, std::ostream& ostr)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
} } } // namespace Poco::WebWidgets::ExtJS
|
||||
|
@ -44,6 +44,7 @@
|
||||
#include "Poco/WebWidgets/RequestProcessor.h"
|
||||
#include "Poco/WebWidgets/View.h"
|
||||
#include "Poco/URI.h"
|
||||
#include "Poco/FIFOEvent.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
@ -58,6 +59,9 @@ public:
|
||||
typedef Poco::AutoPtr<DynamicCodeLoader> Ptr;
|
||||
|
||||
static const std::string EV_LOAD;
|
||||
|
||||
Poco::FIFOEvent<View::Ptr> beforeLoad; /// Thrown before a load
|
||||
Poco::FIFOEvent<DynamicCodeLoader*> generateCode;
|
||||
|
||||
DynamicCodeLoader(View* pParent, const Poco::URI& uri, const std::string& fctName, View::Ptr pView);
|
||||
/// Makes the code available at URI, containing JS code
|
||||
@ -123,6 +127,7 @@ private:
|
||||
std::string _code;
|
||||
std::string _success;
|
||||
std::string _error;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
@ -76,6 +76,9 @@ void DynamicCodeLoader::handleAjaxRequest(const Poco::Net::NameValueCollection&
|
||||
const std::string& ev = args[RequestHandler::KEY_EVID];
|
||||
if (ev == EV_LOAD)
|
||||
{
|
||||
beforeLoad(this, _pView);
|
||||
DynamicCodeLoader* pThis = this;
|
||||
generateCode(this, pThis);
|
||||
/// send the JS presentation of the page
|
||||
response.setContentType("text/javascript");
|
||||
response.setChunkedTransferEncoding(true);
|
||||
|
Loading…
x
Reference in New Issue
Block a user