updated MultiSelect

This commit is contained in:
Peter Schojer 2008-09-29 06:36:46 +00:00
parent 6ea765969d
commit 9bc329f95d
8 changed files with 45 additions and 44 deletions

View File

@ -61,8 +61,7 @@ class ExtJS_API ListBoxCellRenderer: public Poco::WebWidgets::Renderer
/// ListBoxCellRenderer renders a button /// ListBoxCellRenderer renders a button
{ {
public: public:
static const std::string EV_ROWSELECT; static const std::string EV_SELECTIONCHANGED;
static const std::string EV_ROWDESELECT;
ListBoxCellRenderer(); ListBoxCellRenderer();
/// Creates the ListBoxCellRenderer. /// Creates the ListBoxCellRenderer.
@ -79,7 +78,8 @@ public:
static void renderProperties(const ListBoxCell* pCell, std::ostream& ostr); static void renderProperties(const ListBoxCell* pCell, std::ostream& ostr);
/// Renders button properties /// Renders button properties
static Poco::WebWidgets::JSDelegate createRowSelectionServerCallback(const ListBox* pList); static Poco::WebWidgets::JSDelegate createSelectionChangedServerCallback(const ListBox* pList);
/// JS signature: function(dataView, selArray){
static void onBeforeLoad(void* pSender, std::pair<ListBoxCell*, Poco::Net::HTTPServerResponse*>& ld); static void onBeforeLoad(void* pSender, std::pair<ListBoxCell*, Poco::Net::HTTPServerResponse*>& ld);

View File

@ -53,8 +53,7 @@ namespace WebWidgets {
namespace ExtJS { namespace ExtJS {
const std::string ListBoxCellRenderer::EV_ROWSELECT("rowselect"); const std::string ListBoxCellRenderer::EV_SELECTIONCHANGED("selectionchange");
const std::string ListBoxCellRenderer::EV_ROWDESELECT("rowdeselect");
ListBoxCellRenderer::ListBoxCellRenderer() ListBoxCellRenderer::ListBoxCellRenderer()
@ -99,19 +98,12 @@ void ListBoxCellRenderer::renderProperties(const ListBoxCell* pListBoxCell, std:
if (pList) if (pList)
{ {
bool hasListeners = (pList->rowDeselected.hasJavaScriptCode() || bool hasListeners = pList->selectionChanged.hasJavaScriptCode();
pList->rowSelected.hasJavaScriptCode());
if (hasListeners) if (hasListeners)
{ {
ostr << ",listeners:{"; ostr << ",listeners:{";
bool comma = false; Utility::writeJSEvent(ostr, EV_SELECTIONCHANGED, pList->selectionChanged, &ListBoxCellRenderer::createSelectionChangedServerCallback, pList);
if (pList->rowDeselected.hasJavaScriptCode())
comma = Utility::writeJSEvent(ostr, EV_ROWDESELECT, pList->rowDeselected, &ListBoxCellRenderer::createRowSelectionServerCallback, pList);
if (pList->rowDeselected.hasJavaScriptCode())
{
if (comma) ostr << ",";
comma = Utility::writeJSEvent(ostr, EV_ROWSELECT, pList->rowSelected, &ListBoxCellRenderer::createRowSelectionServerCallback, pList);
}
ostr << "}"; ostr << "}";
} }
} }
@ -162,15 +154,14 @@ void ListBoxCellRenderer::renderProperties(const ListBoxCell* pListBoxCell, std:
} }
Poco::WebWidgets::JSDelegate ListBoxCellRenderer::createRowSelectionServerCallback(const ListBox* pList) Poco::WebWidgets::JSDelegate ListBoxCellRenderer::createSelectionChangedServerCallback(const ListBox* pList)
{ {
// rowselect : ( Ext.ux.Multiselect field, Int idx, bool selected ) // selectionchange : ( dataView, selArray )
static const std::string signature("function(field,idx,sel)"); static const std::string signature("function(view, sel)");
std::map<std::string, std::string> addParams; std::map<std::string, std::string> addParams;
addParams.insert(std::make_pair(ListBoxCell::ARG_ROW, "+idx")); addParams.insert(std::make_pair(ListBoxCell::ARG_ROW, "+sel.toString()"));
addParams.insert(std::make_pair(ListBoxCell::ARG_SELECTED, "+(sel?'1':'0')")); addParams.insert(std::make_pair(RequestHandler::KEY_EVID, ListBoxCell::EV_SELECTIONCHANGED));
addParams.insert(std::make_pair(RequestHandler::KEY_EVID, ListBoxCell::EV_ROWSELECTED)); return Utility::createServerCallback(signature, addParams, pList->id(), pList->selectionChanged.getOnSuccess(), pList->selectionChanged.getOnFailure());
return Utility::createServerCallback(signature, addParams, pList->id(), pList->rowSelected.getOnSuccess(), pList->rowSelected.getOnFailure());
} }

View File

@ -37,8 +37,7 @@ Ext.ux.Multiselect = Ext.extend(Ext.form.Field, {
'click' : true, 'click' : true,
'change' : true, 'change' : true,
'drop' : true, 'drop' : true,
'rowselect' : true, 'selectionchange' : true
'rowdeselect' : true
}); });
}, },
onRender: function(ct, position){ onRender: function(ct, position){
@ -83,6 +82,7 @@ Ext.ux.Multiselect = Ext.extend(Ext.form.Field, {
sortField:this.sortField, sortDir:this.sortDir sortField:this.sortField, sortDir:this.sortDir
}); });
this.view.on('selectionchange', this.onSelectionChange, this);
this.view.on('click', this.onViewClick, this); this.view.on('click', this.onViewClick, this);
this.view.on('beforeClick', this.onViewBeforeClick, this); this.view.on('beforeClick', this.onViewBeforeClick, this);
this.view.on('dblclick', this.onViewDblClick, this); this.view.on('dblclick', this.onViewDblClick, this);
@ -111,6 +111,10 @@ Ext.ux.Multiselect = Ext.extend(Ext.form.Field, {
} }
}, },
onSelectionChange: function(dataView, selArray){
this.fireEvent('selectionchange', this, dataView, selArray);
},
onViewClick: function(vw, index, node, e) { onViewClick: function(vw, index, node, e) {
var arrayIndex = this.preClickSelections.indexOf(index); var arrayIndex = this.preClickSelections.indexOf(index);
if (arrayIndex != -1) if (arrayIndex != -1)
@ -118,11 +122,7 @@ Ext.ux.Multiselect = Ext.extend(Ext.form.Field, {
this.preClickSelections.splice(arrayIndex, 1); this.preClickSelections.splice(arrayIndex, 1);
this.view.clearSelections(true); this.view.clearSelections(true);
this.view.select(this.preClickSelections); this.view.select(this.preClickSelections);
var sel = this.view.isSelected(arrayIndex);
if (sel)
this.fireEvent('rowselect', this, arrayIndex, sel);
else
this.fireEvent('rowdeselect', this, arrayIndex, sel);
} }
this.fireEvent('change', this, this.getValue(), this.hiddenField.dom.value); this.fireEvent('change', this, this.getValue(), this.hiddenField.dom.value);
this.hiddenField.dom.value = this.getValue(); this.hiddenField.dom.value = this.getValue();

View File

@ -1117,7 +1117,7 @@ void ExtJSTest::testListBox()
ptrList->insert(std::string("FirstSelected"), true); ptrList->insert(std::string("FirstSelected"), true);
ptrList->insert(std::string("Second"), false); ptrList->insert(std::string("Second"), false);
ptrList->insert(std::string("SecondSelected"), true); ptrList->insert(std::string("SecondSelected"), true);
ptrList->rowSelected.setServerCallback(Poco::WebWidgets::SC_YES); ptrList->selectionChanged.setServerCallback(Poco::WebWidgets::SC_YES);
std::ostringstream ostr; std::ostringstream ostr;
std::ofstream fstr("testListBox.html"); std::ofstream fstr("testListBox.html");

View File

@ -45,6 +45,7 @@
#include "Poco/WebWidgets/JavaScriptEvent.h" #include "Poco/WebWidgets/JavaScriptEvent.h"
#include "Poco/FIFOEvent.h" #include "Poco/FIFOEvent.h"
#include <vector> #include <vector>
#include <set>
namespace Poco { namespace Poco {
@ -63,9 +64,11 @@ public:
JavaScriptEvent<ListBox*> afterLoad; // thrown after data was loaded JavaScriptEvent<ListBox*> afterLoad; // thrown after data was loaded
JavaScriptEvent<int> rowSelected; /// fires the row selected event FIFOEvent<int> rowSelected; /// fires the row selected event
JavaScriptEvent<int> rowDeselected; /// fires the row deselected event FIFOEvent<int> rowDeselected; /// fires the row deselected event
JavaScriptEvent<const std::set<int> > selectionChanged; /// fires the row selection change event
ListBox(const std::string& name); ListBox(const std::string& name);
/// Creates a ListBox with the given name. /// Creates a ListBox with the given name.
@ -151,6 +154,8 @@ protected:
void fireRowDeselected(int& pos); void fireRowDeselected(int& pos);
void fireSelectionChange(const std::set<int>& sel);
private: private:
ListBoxCell* _pLBCell; ListBoxCell* _pLBCell;
}; };

View File

@ -44,6 +44,7 @@
#include "Poco/WebWidgets/Delegate.h" #include "Poco/WebWidgets/Delegate.h"
#include "Poco/FIFOEvent.h" #include "Poco/FIFOEvent.h"
#include <vector> #include <vector>
#include <set>
namespace Poco { namespace Poco {
@ -64,11 +65,8 @@ public:
static const std::string EV_LOADDATA; static const std::string EV_LOADDATA;
static const std::string EV_AFTERLOAD; static const std::string EV_AFTERLOAD;
static const std::string EV_ROWSELECTED; static const std::string EV_SELECTIONCHANGED;
static const std::string ARG_SELECTED;
static const std::string ARG_ROW; static const std::string ARG_ROW;
static const std::string VAL_SELECTED;
static const std::string VAL_DESELECTED;
FIFOEvent<std::pair<ListBoxCell*, Poco::Net::HTTPServerResponse*> > beforeLoad; /// thrown whenever a load is requested, internal event to which the ListBoxCellRenderer must register FIFOEvent<std::pair<ListBoxCell*, Poco::Net::HTTPServerResponse*> > beforeLoad; /// thrown whenever a load is requested, internal event to which the ListBoxCellRenderer must register
@ -78,6 +76,8 @@ public:
FIFOEvent<int> rowDeselected; /// fires the row selected event FIFOEvent<int> rowDeselected; /// fires the row selected event
FIFOEvent<const std::set<int> > selectionChanged; /// fires the row selection change event
struct WebWidgets_API RowValueChange struct WebWidgets_API RowValueChange
/// Data sent with a rowValueChanged event. /// Data sent with a rowValueChanged event.
{ {

View File

@ -97,6 +97,7 @@ void ListBox::init()
_pLBCell->beforeLoad += Poco::delegate(this, &ListBox::fireBeforeLoad); _pLBCell->beforeLoad += Poco::delegate(this, &ListBox::fireBeforeLoad);
_pLBCell->rowDeselected += Poco::delegate(this, &ListBox::fireRowDeselected); _pLBCell->rowDeselected += Poco::delegate(this, &ListBox::fireRowDeselected);
_pLBCell->rowSelected += Poco::delegate(this, &ListBox::fireRowSelected); _pLBCell->rowSelected += Poco::delegate(this, &ListBox::fireRowSelected);
_pLBCell->selectionChanged += Poco::delegate(this, &ListBox::fireSelectionChange);
setCell(_pLBCell); setCell(_pLBCell);
} }
@ -110,6 +111,7 @@ void ListBox::init(Cell::Ptr ptrCell)
_pLBCell->beforeLoad += Poco::delegate(this, &ListBox::fireBeforeLoad); _pLBCell->beforeLoad += Poco::delegate(this, &ListBox::fireBeforeLoad);
_pLBCell->rowDeselected += Poco::delegate(this, &ListBox::fireRowDeselected); _pLBCell->rowDeselected += Poco::delegate(this, &ListBox::fireRowDeselected);
_pLBCell->rowSelected += Poco::delegate(this, &ListBox::fireRowSelected); _pLBCell->rowSelected += Poco::delegate(this, &ListBox::fireRowSelected);
_pLBCell->selectionChanged += Poco::delegate(this, &ListBox::fireSelectionChange);
setCell(ptrCell); setCell(ptrCell);
} }
@ -139,4 +141,10 @@ void ListBox::fireRowDeselected(int& pos)
} }
void ListBox::fireSelectionChange(const std::set<int>& sel)
{
selectionChanged(this, sel);
}
} } // namespace Poco::WebWidgets } } // namespace Poco::WebWidgets

View File

@ -47,11 +47,8 @@ namespace WebWidgets {
const std::string ListBoxCell::EV_LOADDATA("load"); const std::string ListBoxCell::EV_LOADDATA("load");
const std::string ListBoxCell::EV_AFTERLOAD("afterLoad"); const std::string ListBoxCell::EV_AFTERLOAD("afterLoad");
const std::string ListBoxCell::EV_ROWSELECTED("rowSel"); const std::string ListBoxCell::EV_SELECTIONCHANGED("selChange");
const std::string ListBoxCell::ARG_SELECTED("sel");
const std::string ListBoxCell::ARG_ROW("row"); const std::string ListBoxCell::ARG_ROW("row");
const std::string ListBoxCell::VAL_SELECTED("1");
const std::string ListBoxCell::VAL_DESELECTED("0");
ListBoxCell::ListBoxCell(View* pOwner): ListBoxCell::ListBoxCell(View* pOwner):
@ -96,6 +93,8 @@ void ListBoxCell::handleForm(const std::string& field, const std::string& value)
else else
deselectByIndex(i); deselectByIndex(i);
} }
selectionChanged(this, selected);
} }
@ -269,11 +268,9 @@ void ListBoxCell::handleAjaxRequest(const Poco::Net::NameValueCollection& args,
afterLoad(this); afterLoad(this);
response.send(); response.send();
} }
else if (ev == EV_ROWSELECTED) else if (ev == EV_SELECTIONCHANGED)
{ {
int row = Poco::NumberParser::parse(args[ARG_ROW]); handleForm("", args[ARG_ROW]);
bool sel = (args.get(ARG_SELECTED) == VAL_SELECTED);
selectByIndex(row, sel);
response.send(); response.send();
} }
else else