mirror of
https://github.com/pocoproject/poco.git
synced 2025-12-24 06:14:31 +01:00
refactored form handling
This commit is contained in:
@@ -43,10 +43,11 @@
|
||||
#include "Poco/WebWidgets/ExtJS/ExtJS.h"
|
||||
#include "Poco/WebWidgets/Renderer.h"
|
||||
#include "Poco/WebWidgets/Form.h"
|
||||
|
||||
#include "Poco/WebWidgets/JSDelegate.h"
|
||||
|
||||
namespace Poco {
|
||||
namespace WebWidgets {
|
||||
class Form;
|
||||
namespace ExtJS {
|
||||
|
||||
|
||||
@@ -68,6 +69,10 @@ public:
|
||||
|
||||
static std::string formVariableName(const Form* pForm);
|
||||
/// Creates the variable name for the form
|
||||
|
||||
static Poco::WebWidgets::JSDelegate createReloadFunction(const std::string& fctName, const Form* pForm);
|
||||
/// Creates a function with the given fctName (can be empty) that reloads the form
|
||||
/// E.g.: add the returned JSDelegate to pReload->buttonClicked
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -38,7 +38,9 @@
|
||||
#include "Poco/WebWidgets/Form.h"
|
||||
#include "Poco/WebWidgets/Button.h"
|
||||
#include "Poco/WebWidgets/WebApplication.h"
|
||||
#include "Poco/WebWidgets/RequestHandler.h"
|
||||
#include "Poco/NumberFormatter.h"
|
||||
#include <sstream>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
@@ -83,6 +85,7 @@ void FormRenderer::renderHead(const Renderable* pRenderable, const RenderContext
|
||||
}
|
||||
ostr << "]})";
|
||||
theApp.endForm(*pForm);
|
||||
WebApplication::instance().registerAjaxProcessor(Poco::NumberFormatter::format(pForm->id()), const_cast<Form*>(pForm));
|
||||
}
|
||||
|
||||
|
||||
@@ -98,4 +101,18 @@ std::string FormRenderer::formVariableName(const Form* pForm)
|
||||
}
|
||||
|
||||
|
||||
Poco::WebWidgets::JSDelegate FormRenderer::createReloadFunction(const std::string& fctName, const Form* pForm)
|
||||
{
|
||||
std::ostringstream out;
|
||||
out << "function ";
|
||||
out << fctName << "(){" << std::endl;
|
||||
out << "var theForm = Ext.getCmp('" << pForm->id() << "');" << std::endl;
|
||||
out << "var uri = '" << pForm->getURI().toString() << "/;" << RequestHandler::KEY_EVID << "=" << Form::EV_RELOAD << "&";
|
||||
out << RequestHandler::KEY_ID << "=" << pForm->id() << "';" << std::endl;
|
||||
out << "theForm.load({url:uri,method:'GET'});" << std::endl; // success, failure handlers
|
||||
out << "}" << std::endl;
|
||||
return jsDelegate(out.str());
|
||||
}
|
||||
|
||||
|
||||
} } } // namespace Poco::WebWidgets::ExtJS
|
||||
|
||||
Reference in New Issue
Block a user