added support for delayed init

This commit is contained in:
Peter Schojer
2008-10-01 13:56:11 +00:00
parent 8ccc58be02
commit a01e9c78b8
4 changed files with 31 additions and 9 deletions

View File

@@ -46,6 +46,7 @@
namespace Poco { namespace Poco {
namespace WebWidgets { namespace WebWidgets {
class DynamicCodeLoader;
namespace ExtJS { namespace ExtJS {
@@ -64,6 +65,9 @@ public:
void renderBody(const Renderable* pRenderable, const RenderContext& context, std::ostream& ostr); void renderBody(const Renderable* pRenderable, const RenderContext& context, std::ostream& ostr);
/// Emits code for the page body to the given output stream. /// Emits code for the page body to the given output stream.
private:
static void onCodeGen(DynamicCodeLoader* &pLoader);
}; };

View File

@@ -41,7 +41,10 @@
#include "Poco/WebWidgets/DynamicCodeLoader.h" #include "Poco/WebWidgets/DynamicCodeLoader.h"
#include "Poco/WebWidgets/RequestHandler.h" #include "Poco/WebWidgets/RequestHandler.h"
#include "Poco/WebWidgets/Panel.h" #include "Poco/WebWidgets/Panel.h"
#include "Poco/WebWidgets/WebApplication.h"
#include "Poco/WebWidgets/RenderContext.h"
#include "Poco/NumberFormatter.h" #include "Poco/NumberFormatter.h"
#include "Poco/Delegate.h"
#include <sstream> #include <sstream>
@@ -93,15 +96,27 @@ void DynamicCodeLoaderRenderer::renderHead(const Renderable* pRenderable, const
str << "}" << std::endl; str << "}" << std::endl;
DynamicCodeLoader* pL = const_cast<DynamicCodeLoader*>(pLoader); DynamicCodeLoader* pL = const_cast<DynamicCodeLoader*>(pLoader);
pL->generateCode += Poco::delegate(&DynamicCodeLoaderRenderer::onCodeGen);
WebApplication::instance().registerAjaxProcessor(Poco::NumberFormatter::format(pLoader->id()), pL); 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; std::ostringstream out;
out << "function " << pLoader->functionName() << "(){"; out << "function " << pL->functionName() << "(){";
out << "return "; out << "return ";
// only render the child when we have a panel // only render the child when we have a panel
if (pPanel) 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 } } } // namespace Poco::WebWidgets::ExtJS

View File

@@ -44,6 +44,7 @@
#include "Poco/WebWidgets/RequestProcessor.h" #include "Poco/WebWidgets/RequestProcessor.h"
#include "Poco/WebWidgets/View.h" #include "Poco/WebWidgets/View.h"
#include "Poco/URI.h" #include "Poco/URI.h"
#include "Poco/FIFOEvent.h"
namespace Poco { namespace Poco {
@@ -58,6 +59,9 @@ public:
typedef Poco::AutoPtr<DynamicCodeLoader> Ptr; typedef Poco::AutoPtr<DynamicCodeLoader> Ptr;
static const std::string EV_LOAD; 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); DynamicCodeLoader(View* pParent, const Poco::URI& uri, const std::string& fctName, View::Ptr pView);
/// Makes the code available at URI, containing JS code /// Makes the code available at URI, containing JS code
@@ -123,6 +127,7 @@ private:
std::string _code; std::string _code;
std::string _success; std::string _success;
std::string _error; std::string _error;
}; };

View File

@@ -76,6 +76,9 @@ void DynamicCodeLoader::handleAjaxRequest(const Poco::Net::NameValueCollection&
const std::string& ev = args[RequestHandler::KEY_EVID]; const std::string& ev = args[RequestHandler::KEY_EVID];
if (ev == EV_LOAD) if (ev == EV_LOAD)
{ {
beforeLoad(this, _pView);
DynamicCodeLoader* pThis = this;
generateCode(this, pThis);
/// send the JS presentation of the page /// send the JS presentation of the page
response.setContentType("text/javascript"); response.setContentType("text/javascript");
response.setChunkedTransferEncoding(true); response.setChunkedTransferEncoding(true);