mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-17 11:05:03 +02:00
impl checked event
This commit is contained in:
@@ -41,12 +41,14 @@
|
||||
|
||||
|
||||
#include "Poco/WebWidgets/ExtJS/CellRenderer.h"
|
||||
#include "Poco/WebWidgets/JSDelegate.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace WebWidgets {
|
||||
|
||||
class ToggleButtonCell;
|
||||
class ToggleButton;
|
||||
|
||||
namespace ExtJS {
|
||||
|
||||
@@ -55,14 +57,19 @@ class ExtJS_API ToggleButtonCellRenderer: public Poco::WebWidgets::Renderer
|
||||
/// Abstract ToggleButtonCellRenderer renders a ToggleButton
|
||||
{
|
||||
public:
|
||||
static const std::string EV_CHECKED;
|
||||
|
||||
void writeConfigData(const Cell* pCell, const RenderContext& context, std::ostream& ostr);
|
||||
/// writes ConfigData, is a simple boolean containing isChecked
|
||||
|
||||
static void renderProperties(const ToggleButtonCell* pCell, std::ostream& ostr);
|
||||
/// Renders button properties
|
||||
|
||||
|
||||
void renderBody(const Renderable* pRenderable, const RenderContext& context, std::ostream& ostr);
|
||||
|
||||
static Poco::WebWidgets::JSDelegate createCheckedServerCallback(const ToggleButton* pButton);
|
||||
/// Adds a server callback for the change event. The method signature is
|
||||
/// check : ( Ext.form.Checkbox this, Boolean checked )
|
||||
|
||||
protected:
|
||||
ToggleButtonCellRenderer();
|
||||
|
@@ -39,6 +39,8 @@
|
||||
#include "Poco/WebWidgets/ExtJS/Utility.h"
|
||||
#include "Poco/WebWidgets/WebApplication.h"
|
||||
#include "Poco/WebWidgets/ToggleButtonCell.h"
|
||||
#include "Poco/WebWidgets/ToggleButton.h"
|
||||
#include "Poco/WebWidgets/RequestHandler.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
@@ -46,6 +48,8 @@ namespace WebWidgets {
|
||||
namespace ExtJS {
|
||||
|
||||
|
||||
const std::string ToggleButtonCellRenderer::EV_CHECKED("check");
|
||||
|
||||
ToggleButtonCellRenderer::ToggleButtonCellRenderer()
|
||||
{
|
||||
}
|
||||
@@ -70,8 +74,29 @@ void ToggleButtonCellRenderer::renderProperties(const ToggleButtonCell* pToggleB
|
||||
Utility::writeCellProperties(pToggleButtonCell, ostr);
|
||||
//tooltip is not supported by togglebutton
|
||||
std::string tooltip (pToggleButtonCell->getToolTip());
|
||||
if (!tooltip.empty())
|
||||
ostr << ",listeners:{render:function(c){c.getEl().dom.qtip='" << Utility::safe(tooltip) << "'; c.getEl().dom.qclass = 'x-form-tip';}}";
|
||||
View* pOwner = pToggleButtonCell->getOwner();
|
||||
ToggleButton* pButton = dynamic_cast<ToggleButton*>(pOwner);
|
||||
|
||||
if (!tooltip.empty() || (pButton && pButton->checked.hasJavaScriptCode()))
|
||||
{
|
||||
ostr << ",listeners:{";
|
||||
bool comma = false;
|
||||
if (!tooltip.empty())
|
||||
{
|
||||
comma = true;
|
||||
ostr << "render:function(c){c.getEl().dom.qtip='" << Utility::safe(tooltip) << "'; c.getEl().dom.qclass = 'x-form-tip';}";
|
||||
}
|
||||
if (pButton && pButton->checked.hasJavaScriptCode())
|
||||
{
|
||||
if (comma)
|
||||
ostr << ",";
|
||||
Utility::writeJSEvent(ostr, EV_CHECKED, pButton->checked, &ToggleButtonCellRenderer::createCheckedServerCallback, pButton);
|
||||
}
|
||||
|
||||
|
||||
ostr << "}"; // close listeners
|
||||
}
|
||||
|
||||
if (pToggleButtonCell->getOwner() && !pToggleButtonCell->getOwner()->getName().empty())
|
||||
{
|
||||
WebApplication::instance().registerFormProcessor(pToggleButtonCell->getOwner()->getName(), const_cast<ToggleButtonCell*>(pToggleButtonCell));
|
||||
@@ -79,4 +104,15 @@ void ToggleButtonCellRenderer::renderProperties(const ToggleButtonCell* pToggleB
|
||||
}
|
||||
|
||||
|
||||
Poco::WebWidgets::JSDelegate ToggleButtonCellRenderer::createCheckedServerCallback(const ToggleButton* pButton)
|
||||
{
|
||||
// check : ( Ext.form.Checkbox this, Boolean checked )
|
||||
static const std::string signature("function(box, bChecked)");
|
||||
std::map<std::string, std::string> addParams;
|
||||
addParams.insert(std::make_pair(ToggleButtonCell::FIELD_VAL, "+(bChecked?'true':'false')"));
|
||||
addParams.insert(std::make_pair(RequestHandler::KEY_EVID, ToggleButtonCell::EV_CHECKED));
|
||||
return Utility::createServerCallback(signature, addParams, pButton->id(), pButton->checked.getOnSuccess(), pButton->checked.getOnFailure());
|
||||
}
|
||||
|
||||
|
||||
} } } // namespace Poco::WebWidgets::ExtJS
|
||||
|
Reference in New Issue
Block a user