2
* Ext JS Library 3.0 RC2
3
* Copyright(c) 2006-2009, Ext JS, LLC.
6
* http://extjs.com/license
10
Ext.grid.EditorGridPanel = Ext.extend(Ext.grid.GridPanel, {
15
forceValidation: false,
27
trackMouseOver: false, // causes very odd FF errors
30
initComponent : function(){
31
Ext.grid.EditorGridPanel.superclass.initComponent.call(this);
35
this.selModel = new Ext.grid.CellSelectionModel();
38
this.activeEditor = null;
51
initEvents : function(){
52
Ext.grid.EditorGridPanel.superclass.initEvents.call(this);
54
this.on("bodyscroll", this.stopEditing, this, [true]);
55
this.on("columnresize", this.stopEditing, this, [true]);
57
if(this.clicksToEdit == 1){
58
this.on("cellclick", this.onCellDblClick, this);
60
if(this.clicksToEdit == 'auto' && this.view.mainBody){
61
this.view.mainBody.on("mousedown", this.onAutoEditClick, this);
63
this.on("celldblclick", this.onCellDblClick, this);
68
onCellDblClick : function(g, row, col){
69
this.startEditing(row, col);
73
onAutoEditClick : function(e, t){
77
var row = this.view.findRowIndex(t);
78
var col = this.view.findCellIndex(t);
79
if(row !== false && col !== false){
81
if(this.selModel.getSelectedCell){ // cell sm
82
var sc = this.selModel.getSelectedCell();
83
if(sc && sc.cell[0] === row && sc.cell[1] === col){
84
this.startEditing(row, col);
87
if(this.selModel.isSelected(row)){
88
this.startEditing(row, col);
95
onEditComplete : function(ed, value, startValue){
97
this.activeEditor = null;
98
ed.un("specialkey", this.selModel.onEditorKey, this.selModel);
100
var field = this.colModel.getDataIndex(ed.col);
101
value = this.postEditValue(value, startValue, r, field);
102
if(this.forceValidation === true || String(value) !== String(startValue)){
107
originalValue: startValue,
113
if(this.fireEvent("validateedit", e) !== false && !e.cancel && String(value) !== String(startValue)){
114
r.set(field, e.value);
116
this.fireEvent("afteredit", e);
119
this.view.focusCell(ed.row, ed.col);
123
startEditing : function(row, col){
125
if(this.colModel.isCellEditable(col, row)){
126
this.view.ensureVisible(row, col, true);
127
var r = this.store.getAt(row);
128
var field = this.colModel.getDataIndex(col);
133
value: r.data[field],
138
if(this.fireEvent("beforeedit", e) !== false && !e.cancel){
140
var ed = this.colModel.getCellEditor(col, row);
145
ed.render(this.view.getEditorParent(ed));
147
(function(){ // complex but required for focus issues in safari, ie and opera
151
ed.on("complete", this.onEditComplete, this, {single: true});
152
ed.on("specialkey", this.selModel.onEditorKey, this.selModel);
154
this.activeEditor = ed;
155
var v = this.preEditValue(r, field);
156
ed.startEdit(this.view.getCell(row, col).firstChild, v === undefined ? '' : v);
163
preEditValue : function(r, field){
164
var value = r.data[field];
165
return this.autoEncode && typeof value == 'string' ? Ext.util.Format.htmlDecode(value) : value;
169
postEditValue : function(value, originalValue, r, field){
170
return this.autoEncode && typeof value == 'string' ? Ext.util.Format.htmlEncode(value) : value;
174
stopEditing : function(cancel){
175
if(this.activeEditor){
176
this.activeEditor[cancel === true ? 'cancelEdit' : 'completeEdit']();
178
this.activeEditor = null;
181
Ext.reg('editorgrid', Ext.grid.EditorGridPanel);
183
// This is a support class used internally by the Grid components
184
Ext.grid.GridEditor = function(field, config){
185
Ext.grid.GridEditor.superclass.constructor.call(this, field, config);
186
field.monitorTab = false;
189
Ext.extend(Ext.grid.GridEditor, Ext.Editor, {
193
cls: "x-small-editor x-grid-editor",
198
Ext.grid.PropertyRecord = Ext.data.Record.create([
199
{name:'name',type:'string'}, 'value'
203
Ext.grid.PropertyStore = function(grid, source){
205
this.store = new Ext.data.Store({
206
recordType : Ext.grid.PropertyRecord
208
this.store.on('update', this.onUpdate, this);
210
this.setSource(source);
212
Ext.grid.PropertyStore.superclass.constructor.call(this);
214
Ext.extend(Ext.grid.PropertyStore, Ext.util.Observable, {
215
// protected - should only be called by the grid. Use grid.setSource instead.
216
setSource : function(o){
218
this.store.removeAll();
221
if(this.isEditableValue(o[k])){
222
data.push(new Ext.grid.PropertyRecord({name: k, value: o[k]}, k));
225
this.store.loadRecords({records: data}, {}, true);
229
onUpdate : function(ds, record, type){
230
if(type == Ext.data.Record.EDIT){
231
var v = record.data['value'];
232
var oldValue = record.modified['value'];
233
if(this.grid.fireEvent('beforepropertychange', this.source, record.id, v, oldValue) !== false){
234
this.source[record.id] = v;
236
this.grid.fireEvent('propertychange', this.source, record.id, v, oldValue);
244
getProperty : function(row){
245
return this.store.getAt(row);
249
isEditableValue: function(val){
252
}else if(typeof val == 'object' || typeof val == 'function'){
259
setValue : function(prop, value){
260
this.source[prop] = value;
261
this.store.getById(prop).set('value', value);
264
// protected - should only be called by the grid. Use grid.getSource instead.
265
getSource : function(){
271
Ext.grid.PropertyColumnModel = function(grid, store){
274
g.PropertyColumnModel.superclass.constructor.call(this, [
275
{header: this.nameText, width:50, sortable: true, dataIndex:'name', id: 'name', menuDisabled:true},
276
{header: this.valueText, width:50, resizable:false, dataIndex: 'value', id: 'value', menuDisabled:true}
279
this.bselect = Ext.DomHelper.append(document.body, {
280
tag: 'select', cls: 'x-grid-editor x-hide-display', children: [
281
{tag: 'option', value: 'true', html: 'true'},
282
{tag: 'option', value: 'false', html: 'false'}
287
var bfield = new f.Field({
289
bselect : this.bselect,
291
getValue : function(){
292
return this.bselect.value == 'true';
296
'date' : new g.GridEditor(new f.DateField({selectOnFocus:true})),
297
'string' : new g.GridEditor(new f.TextField({selectOnFocus:true})),
298
'number' : new g.GridEditor(new f.NumberField({selectOnFocus:true, style:'text-align:left;'})),
299
'boolean' : new g.GridEditor(bfield)
301
this.renderCellDelegate = this.renderCell.createDelegate(this);
302
this.renderPropDelegate = this.renderProp.createDelegate(this);
305
Ext.extend(Ext.grid.PropertyColumnModel, Ext.grid.ColumnModel, {
306
// private - strings used for locale support
309
dateFormat : 'm/j/Y',
312
renderDate : function(dateVal){
313
return dateVal.dateFormat(this.dateFormat);
317
renderBool : function(bVal){
318
return bVal ? 'true' : 'false';
322
isCellEditable : function(colIndex, rowIndex){
323
return colIndex == 1;
327
getRenderer : function(col){
329
this.renderCellDelegate : this.renderPropDelegate;
333
renderProp : function(v){
334
return this.getPropertyName(v);
338
renderCell : function(val){
341
rv = this.renderDate(val);
342
}else if(typeof val == 'boolean'){
343
rv = this.renderBool(val);
345
return Ext.util.Format.htmlEncode(rv);
349
getPropertyName : function(name){
350
var pn = this.grid.propertyNames;
351
return pn && pn[name] ? pn[name] : name;
355
getCellEditor : function(colIndex, rowIndex){
356
var p = this.store.getProperty(rowIndex);
357
var n = p.data['name'], val = p.data['value'];
358
if(this.grid.customEditors[n]){
359
return this.grid.customEditors[n];
362
return this.editors['date'];
363
}else if(typeof val == 'number'){
364
return this.editors['number'];
365
}else if(typeof val == 'boolean'){
366
return this.editors['boolean'];
368
return this.editors['string'];
373
destroy : function(){
374
Ext.grid.PropertyColumnModel.superclass.destroy.call(this);
375
for(var ed in this.editors){
382
Ext.grid.PropertyGrid = Ext.extend(Ext.grid.EditorGridPanel, {
387
// private config overrides
388
enableColumnMove:false,
390
trackMouseOver: false,
392
enableHdMenu : false,
398
initComponent : function(){
399
this.customEditors = this.customEditors || {};
400
this.lastEditRow = null;
401
var store = new Ext.grid.PropertyStore(this);
402
this.propStore = store;
403
var cm = new Ext.grid.PropertyColumnModel(this, store);
404
store.store.sort('name', 'ASC');
407
'beforepropertychange',
412
this.ds = store.store;
413
Ext.grid.PropertyGrid.superclass.initComponent.call(this);
415
this.mon(this.selModel, 'beforecellselect', function(sm, rowIndex, colIndex){
417
this.startEditing.defer(200, this, [rowIndex, 1]);
424
onRender : function(){
425
Ext.grid.PropertyGrid.superclass.onRender.apply(this, arguments);
427
this.getGridEl().addClass('x-props-grid');
431
afterRender: function(){
432
Ext.grid.PropertyGrid.superclass.afterRender.apply(this, arguments);
434
this.setSource(this.source);
439
setSource : function(source){
440
this.propStore.setSource(source);
444
getSource : function(){
445
return this.propStore.getSource();
448
Ext.reg("propertygrid", Ext.grid.PropertyGrid);