mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-21 23:56:54 +02:00
added autoedit table
This commit is contained in:
@@ -94,8 +94,14 @@ void TableRenderer::renderHead(const Renderable* pRenderable, const RenderContex
|
|||||||
if ((*it) && (*it)->getCell())
|
if ((*it) && (*it)->getCell())
|
||||||
editable |= (*it)->isEditable();
|
editable |= (*it)->isEditable();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (editable)
|
if (editable)
|
||||||
|
{
|
||||||
|
if (pTable->autoEdit())
|
||||||
|
ostr << "new Ext.grid.AppinfTable({autoEdit:true,";
|
||||||
|
else
|
||||||
ostr << "new Ext.grid.EditorGridPanel({";
|
ostr << "new Ext.grid.EditorGridPanel({";
|
||||||
|
}
|
||||||
else
|
else
|
||||||
ostr << "new Ext.grid.GridPanel({";
|
ostr << "new Ext.grid.GridPanel({";
|
||||||
|
|
||||||
|
@@ -147,6 +147,7 @@ void Utility::initialize(ResourceManager::Ptr ptr, const Poco::Path& extJSDir)
|
|||||||
#else
|
#else
|
||||||
ptr->appendJSInclude(Poco::Path(aDir, "ext-all.js"));
|
ptr->appendJSInclude(Poco::Path(aDir, "ext-all.js"));
|
||||||
#endif
|
#endif
|
||||||
|
ptr->appendJSInclude(Poco::Path(aDir, "AppinfTable.js"));
|
||||||
ptr->appendJSInclude(Poco::Path(aDir, "DDView.js"));
|
ptr->appendJSInclude(Poco::Path(aDir, "DDView.js"));
|
||||||
ptr->appendJSInclude(Poco::Path(aDir, "Multiselect.js"));
|
ptr->appendJSInclude(Poco::Path(aDir, "Multiselect.js"));
|
||||||
|
|
||||||
|
125
WebWidgets/ExtJS/testsuite/bin/AppinfTable.js
Normal file
125
WebWidgets/ExtJS/testsuite/bin/AppinfTable.js
Normal file
@@ -0,0 +1,125 @@
|
|||||||
|
|
||||||
|
Ext.grid.AppinfTable = Ext.extend(Ext.grid.EditorGridPanel, {
|
||||||
|
/**
|
||||||
|
* @cfg {Boolean} autoEdit
|
||||||
|
* enables autoEdit Mode
|
||||||
|
*/
|
||||||
|
autoEdit: true,
|
||||||
|
|
||||||
|
charThatStartedEdit: null,
|
||||||
|
|
||||||
|
origEditValue: null,
|
||||||
|
|
||||||
|
// private
|
||||||
|
initComponent : function(){
|
||||||
|
//make sure we have cell selection!
|
||||||
|
this.selModel = new Ext.grid.CellSelectionModel();
|
||||||
|
Ext.grid.AppinfTable.superclass.initComponent.call(this);
|
||||||
|
},
|
||||||
|
|
||||||
|
// private
|
||||||
|
initEvents : function(){
|
||||||
|
Ext.grid.AppinfTable.superclass.initEvents.call(this);
|
||||||
|
this.on("keydown", this.onKeyDownEvent, this);
|
||||||
|
},
|
||||||
|
|
||||||
|
//private
|
||||||
|
onKeyDownEvent: function(e){
|
||||||
|
var code = e.getKey();
|
||||||
|
if (code != undefined && code != e.LEFT && code != e.RIGHT && code != e.UP && code != e.DOWN && code != e.ESC && code != e.ENTER
|
||||||
|
&& code != e.TAB && code != e.SHIFT && code != e.PAGEUP && code != e.PAGEDOWN && code != e.HOME && code != e.F5 &&
|
||||||
|
code != e.END && code != e.DELETE && code != e.CONTROL && code != e.BACKSPACE){
|
||||||
|
this.charThatStartedEdit = code;
|
||||||
|
var sc = this.selModel.getSelectedCell();
|
||||||
|
var col = sc[1];
|
||||||
|
var row = sc[0];
|
||||||
|
this.startEditing(row, col);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
this.charThatStartedEdit = null;
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
Ext.reg('appinfgrid', Ext.grid.AppinfTable);
|
||||||
|
|
||||||
|
Ext.override(Ext.grid.AppinfTable, {
|
||||||
|
startEditing : function(row, col){
|
||||||
|
this.stopEditing();
|
||||||
|
if(this.colModel.isCellEditable(col, row)){
|
||||||
|
this.view.ensureVisible(row, col, true);
|
||||||
|
var r = this.store.getAt(row);
|
||||||
|
var field = this.colModel.getDataIndex(col);
|
||||||
|
var e = {
|
||||||
|
grid: this,
|
||||||
|
record: r,
|
||||||
|
field: field,
|
||||||
|
value: r.data[field],
|
||||||
|
row: row,
|
||||||
|
column: col,
|
||||||
|
cancel:false
|
||||||
|
};
|
||||||
|
if(this.fireEvent("beforeedit", e) !== false && !e.cancel){
|
||||||
|
this.editing = true;
|
||||||
|
var ed = this.colModel.getCellEditor(col, row);
|
||||||
|
if(!ed.rendered){
|
||||||
|
var edView = this.view.getEditorParent(ed);
|
||||||
|
ed.render(edView);
|
||||||
|
}
|
||||||
|
var edfield = ed.field;
|
||||||
|
ed.row = row;
|
||||||
|
ed.col = col;
|
||||||
|
ed.record = r;
|
||||||
|
ed.field = edfield;
|
||||||
|
ed.on("complete", this.onEditComplete, this, {single: true});
|
||||||
|
ed.on("specialkey", this.selModel.onEditorKey, this.selModel);
|
||||||
|
this.activeEditor = ed;
|
||||||
|
var v = this.preEditValue(r, field);
|
||||||
|
this.origEditValue = v;
|
||||||
|
if (v == e.value)
|
||||||
|
{
|
||||||
|
if (this.autoEdit && this.charThatStartedEdit)
|
||||||
|
{
|
||||||
|
e.value = String.fromCharCode(this.charThatStartedEdit);
|
||||||
|
ed.field.selectOnFocus = false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
ed.field.selectOnFocus = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
ed.field.selectOnFocus = false;
|
||||||
|
this.charThatStartedEdit = null;
|
||||||
|
(function(){
|
||||||
|
ed.startEdit(this.view.getCell(row, col), e.value);
|
||||||
|
ed.field.preFocus();
|
||||||
|
}).defer(50, this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
onEditComplete : function(ed, value, startValue){
|
||||||
|
this.editing = false;
|
||||||
|
this.activeEditor = null;
|
||||||
|
ed.un("specialkey", this.selModel.onEditorKey, this.selModel);
|
||||||
|
var r = ed.record;
|
||||||
|
var field = this.colModel.getDataIndex(ed.col);
|
||||||
|
value = this.postEditValue(value, startValue, r, field);
|
||||||
|
if(String(value) !== String(this.origEditValue)){
|
||||||
|
var e = {
|
||||||
|
grid: this,
|
||||||
|
record: r,
|
||||||
|
field: field,
|
||||||
|
originalValue: this.origEditValue,
|
||||||
|
value: value,
|
||||||
|
row: ed.row,
|
||||||
|
column: ed.col,
|
||||||
|
cancel:false
|
||||||
|
};
|
||||||
|
if(this.fireEvent("validateedit", e) !== false && !e.cancel){
|
||||||
|
r.set(field, e.value);
|
||||||
|
delete e.cancel;
|
||||||
|
this.fireEvent("afteredit", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.view.focusCell(ed.row, ed.col);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
@@ -202,6 +202,12 @@ public:
|
|||||||
int getPagingSize() const;
|
int getPagingSize() const;
|
||||||
/// Returns the paging size
|
/// Returns the paging size
|
||||||
|
|
||||||
|
void autoEdit(bool val);
|
||||||
|
/// Enables/disables autoedit. autoedit works only with cell based selection!
|
||||||
|
|
||||||
|
bool autoEdit() const;
|
||||||
|
// Returns if autoEdit is on/off
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Table(const std::string& name, const std::type_info& type, const TableColumns& tc, TableModel::Ptr pModel);
|
Table(const std::string& name, const std::type_info& type, const TableColumns& tc, TableModel::Ptr pModel);
|
||||||
/// Creates a Table and assigns it the given name.
|
/// Creates a Table and assigns it the given name.
|
||||||
@@ -220,6 +226,7 @@ private:
|
|||||||
TableColumns _columns;
|
TableColumns _columns;
|
||||||
SelectionModel _sm;
|
SelectionModel _sm;
|
||||||
bool _dragAndDrop;
|
bool _dragAndDrop;
|
||||||
|
bool _autoEdit;
|
||||||
int _maxRowsPerPage;
|
int _maxRowsPerPage;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -299,6 +306,18 @@ inline int Table::getPagingSize() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
inline void Table::autoEdit(bool val)
|
||||||
|
{
|
||||||
|
_autoEdit = val;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
inline bool Table::autoEdit() const
|
||||||
|
{
|
||||||
|
return _autoEdit;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
} } // namespace Poco::WebWidgets
|
} } // namespace Poco::WebWidgets
|
||||||
|
|
||||||
|
|
||||||
|
@@ -72,6 +72,7 @@ Table::Table(const TableColumns& tc, TableModel::Ptr pModel):
|
|||||||
_columns(tc),
|
_columns(tc),
|
||||||
_sm(SM_CELL),
|
_sm(SM_CELL),
|
||||||
_dragAndDrop(false),
|
_dragAndDrop(false),
|
||||||
|
_autoEdit(false),
|
||||||
_maxRowsPerPage(0)
|
_maxRowsPerPage(0)
|
||||||
{
|
{
|
||||||
checkValidConfig();
|
checkValidConfig();
|
||||||
|
Reference in New Issue
Block a user