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
{
public:
static const std::string EV_ROWSELECT;
static const std::string EV_ROWDESELECT;
static const std::string EV_SELECTIONCHANGED;
ListBoxCellRenderer();
/// Creates the ListBoxCellRenderer.
@@ -79,7 +78,8 @@ public:
static void renderProperties(const ListBoxCell* pCell, std::ostream& ostr);
/// 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);

View File

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

View File

@@ -37,8 +37,7 @@ Ext.ux.Multiselect = Ext.extend(Ext.form.Field, {
'click' : true,
'change' : true,
'drop' : true,
'rowselect' : true,
'rowdeselect' : true
'selectionchange' : true
});
},
onRender: function(ct, position){
@@ -83,6 +82,7 @@ Ext.ux.Multiselect = Ext.extend(Ext.form.Field, {
sortField:this.sortField, sortDir:this.sortDir
});
this.view.on('selectionchange', this.onSelectionChange, this);
this.view.on('click', this.onViewClick, this);
this.view.on('beforeClick', this.onViewBeforeClick, 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) {
var arrayIndex = this.preClickSelections.indexOf(index);
if (arrayIndex != -1)
@@ -118,11 +122,7 @@ Ext.ux.Multiselect = Ext.extend(Ext.form.Field, {
this.preClickSelections.splice(arrayIndex, 1);
this.view.clearSelections(true);
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.hiddenField.dom.value = this.getValue();

View File

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