tvheadend/vendor/ext-3.4.1/docs/source/EditorGrid.html
Adam Sutton bafcfff42d webui: restructure webui/extjs source files
I want to keep the 3rd-party packages away from the main source
where possible.
2013-06-03 17:11:01 +01:00

363 lines
16 KiB
HTML

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>The source code</title>
<link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="../resources/prettify/prettify.js"></script>
<style type="text/css">
.highlight { display: block; background-color: #ddd; }
</style>
<script type="text/javascript">
function highlight() {
document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
}
</script>
</head>
<body onload="prettyPrint(); highlight();">
<pre class="prettyprint lang-js"><span id='Ext-grid-EditorGridPanel-method-constructor'><span id='Ext-grid-EditorGridPanel'>/**
</span></span> * @class Ext.grid.EditorGridPanel
* @extends Ext.grid.GridPanel
* &lt;p&gt;This class extends the {@link Ext.grid.GridPanel GridPanel Class} to provide cell editing
* on selected {@link Ext.grid.Column columns}. The editable columns are specified by providing
* an {@link Ext.grid.ColumnModel#editor editor} in the {@link Ext.grid.Column column configuration}.&lt;/p&gt;
* &lt;p&gt;Editability of columns may be controlled programatically by inserting an implementation
* of {@link Ext.grid.ColumnModel#isCellEditable isCellEditable} into the
* {@link Ext.grid.ColumnModel ColumnModel}.&lt;/p&gt;
* &lt;p&gt;Editing is performed on the value of the &lt;i&gt;field&lt;/i&gt; specified by the column's
* &lt;tt&gt;{@link Ext.grid.ColumnModel#dataIndex dataIndex}&lt;/tt&gt; in the backing {@link Ext.data.Store Store}
* (so if you are using a {@link Ext.grid.ColumnModel#setRenderer renderer} in order to display
* transformed data, this must be accounted for).&lt;/p&gt;
* &lt;p&gt;If a value-to-description mapping is used to render a column, then a {@link Ext.form.Field#ComboBox ComboBox}
* which uses the same {@link Ext.form.Field#valueField value}-to-{@link Ext.form.Field#displayFieldField description}
* mapping would be an appropriate editor.&lt;/p&gt;
* If there is a more complex mismatch between the visible data in the grid, and the editable data in
* the {@link Edt.data.Store Store}, then code to transform the data both before and after editing can be
* injected using the {@link #beforeedit} and {@link #afteredit} events.
* @constructor
* @param {Object} config The config object
* @xtype editorgrid
*/
Ext.grid.EditorGridPanel = Ext.extend(Ext.grid.GridPanel, {
<span id='Ext-grid-EditorGridPanel-cfg-clicksToEdit'> /**
</span> * @cfg {Number} clicksToEdit
* &lt;p&gt;The number of clicks on a cell required to display the cell's editor (defaults to 2).&lt;/p&gt;
* &lt;p&gt;Setting this option to 'auto' means that mousedown &lt;i&gt;on the selected cell&lt;/i&gt; starts
* editing that cell.&lt;/p&gt;
*/
clicksToEdit: 2,
<span id='Ext-grid-EditorGridPanel-cfg-forceValidation'> /**
</span> * @cfg {Boolean} forceValidation
* True to force validation even if the value is unmodified (defaults to false)
*/
forceValidation: false,
<span id='Ext-grid-EditorGridPanel-property-isEditor'> // private
</span> isEditor : true,
<span id='Ext-grid-EditorGridPanel-property-detectEdit'> // private
</span> detectEdit: false,
<span id='Ext-grid-EditorGridPanel-cfg-autoEncode'> /**
</span> * @cfg {Boolean} autoEncode
* True to automatically HTML encode and decode values pre and post edit (defaults to false)
*/
autoEncode : false,
<span id='Ext-grid-EditorGridPanel-cfg-trackMouseOver'> /**
</span> * @cfg {Boolean} trackMouseOver @hide
*/
<span id='Ext-grid-EditorGridPanel-cfg-trackMouseOver'> // private
</span> trackMouseOver: false, // causes very odd FF errors
<span id='Ext-grid-EditorGridPanel-method-initComponent'> // private
</span> initComponent : function(){
Ext.grid.EditorGridPanel.superclass.initComponent.call(this);
if(!this.selModel){
<span id='Ext-grid-EditorGridPanel-cfg-selModel'> /**
</span> * @cfg {Object} selModel Any subclass of AbstractSelectionModel that will provide the selection model for
* the grid (defaults to {@link Ext.grid.CellSelectionModel} if not specified).
*/
this.selModel = new Ext.grid.CellSelectionModel();
}
this.activeEditor = null;
this.addEvents(
<span id='Ext-grid-EditorGridPanel-event-beforeedit'> /**
</span> * @event beforeedit
* Fires before cell editing is triggered. The edit event object has the following properties &lt;br /&gt;
* &lt;ul style=&quot;padding:5px;padding-left:16px;&quot;&gt;
* &lt;li&gt;grid - This grid&lt;/li&gt;
* &lt;li&gt;record - The record being edited&lt;/li&gt;
* &lt;li&gt;field - The field name being edited&lt;/li&gt;
* &lt;li&gt;value - The value for the field being edited.&lt;/li&gt;
* &lt;li&gt;row - The grid row index&lt;/li&gt;
* &lt;li&gt;column - The grid column index&lt;/li&gt;
* &lt;li&gt;cancel - Set this to true to cancel the edit or return false from your handler.&lt;/li&gt;
* &lt;/ul&gt;
* @param {Object} e An edit event (see above for description)
*/
&quot;beforeedit&quot;,
<span id='Ext-grid-EditorGridPanel-event-afteredit'> /**
</span> * @event afteredit
* Fires after a cell is edited. The edit event object has the following properties &lt;br /&gt;
* &lt;ul style=&quot;padding:5px;padding-left:16px;&quot;&gt;
* &lt;li&gt;grid - This grid&lt;/li&gt;
* &lt;li&gt;record - The record being edited&lt;/li&gt;
* &lt;li&gt;field - The field name being edited&lt;/li&gt;
* &lt;li&gt;value - The value being set&lt;/li&gt;
* &lt;li&gt;originalValue - The original value for the field, before the edit.&lt;/li&gt;
* &lt;li&gt;row - The grid row index&lt;/li&gt;
* &lt;li&gt;column - The grid column index&lt;/li&gt;
* &lt;/ul&gt;
*
* &lt;pre&gt;&lt;code&gt;
grid.on('afteredit', afterEdit, this );
function afterEdit(e) {
// execute an XHR to send/commit data to the server, in callback do (if successful):
e.record.commit();
};
* &lt;/code&gt;&lt;/pre&gt;
* @param {Object} e An edit event (see above for description)
*/
&quot;afteredit&quot;,
<span id='Ext-grid-EditorGridPanel-event-validateedit'> /**
</span> * @event validateedit
* Fires after a cell is edited, but before the value is set in the record. Return false
* to cancel the change. The edit event object has the following properties &lt;br /&gt;
* &lt;ul style=&quot;padding:5px;padding-left:16px;&quot;&gt;
* &lt;li&gt;grid - This grid&lt;/li&gt;
* &lt;li&gt;record - The record being edited&lt;/li&gt;
* &lt;li&gt;field - The field name being edited&lt;/li&gt;
* &lt;li&gt;value - The value being set&lt;/li&gt;
* &lt;li&gt;originalValue - The original value for the field, before the edit.&lt;/li&gt;
* &lt;li&gt;row - The grid row index&lt;/li&gt;
* &lt;li&gt;column - The grid column index&lt;/li&gt;
* &lt;li&gt;cancel - Set this to true to cancel the edit or return false from your handler.&lt;/li&gt;
* &lt;/ul&gt;
* Usage example showing how to remove the red triangle (dirty record indicator) from some
* records (not all). By observing the grid's validateedit event, it can be cancelled if
* the edit occurs on a targeted row (for example) and then setting the field's new value
* in the Record directly:
* &lt;pre&gt;&lt;code&gt;
grid.on('validateedit', function(e) {
var myTargetRow = 6;
if (e.row == myTargetRow) {
e.cancel = true;
e.record.data[e.field] = e.value;
}
});
* &lt;/code&gt;&lt;/pre&gt;
* @param {Object} e An edit event (see above for description)
*/
&quot;validateedit&quot;
);
},
<span id='Ext-grid-EditorGridPanel-method-initEvents'> // private
</span> initEvents : function(){
Ext.grid.EditorGridPanel.superclass.initEvents.call(this);
this.getGridEl().on('mousewheel', this.stopEditing.createDelegate(this, [true]), this);
this.on('columnresize', this.stopEditing, this, [true]);
if(this.clicksToEdit == 1){
this.on(&quot;cellclick&quot;, this.onCellDblClick, this);
}else {
var view = this.getView();
if(this.clicksToEdit == 'auto' &amp;&amp; view.mainBody){
view.mainBody.on('mousedown', this.onAutoEditClick, this);
}
this.on('celldblclick', this.onCellDblClick, this);
}
},
<span id='Ext-grid-EditorGridPanel-method-onResize'> onResize : function(){
</span> Ext.grid.EditorGridPanel.superclass.onResize.apply(this, arguments);
var ae = this.activeEditor;
if(this.editing &amp;&amp; ae){
ae.realign(true);
}
},
<span id='Ext-grid-EditorGridPanel-method-onCellDblClick'> // private
</span> onCellDblClick : function(g, row, col){
this.startEditing(row, col);
},
<span id='Ext-grid-EditorGridPanel-method-onAutoEditClick'> // private
</span> onAutoEditClick : function(e, t){
if(e.button !== 0){
return;
}
var row = this.view.findRowIndex(t),
col = this.view.findCellIndex(t);
if(row !== false &amp;&amp; col !== false){
this.stopEditing();
if(this.selModel.getSelectedCell){ // cell sm
var sc = this.selModel.getSelectedCell();
if(sc &amp;&amp; sc[0] === row &amp;&amp; sc[1] === col){
this.startEditing(row, col);
}
}else{
if(this.selModel.isSelected(row)){
this.startEditing(row, col);
}
}
}
},
<span id='Ext-grid-EditorGridPanel-method-onEditComplete'> // private
</span> onEditComplete : function(ed, value, startValue){
this.editing = false;
this.lastActiveEditor = this.activeEditor;
this.activeEditor = null;
var r = ed.record,
field = this.colModel.getDataIndex(ed.col);
value = this.postEditValue(value, startValue, r, field);
if(this.forceValidation === true || String(value) !== String(startValue)){
var e = {
grid: this,
record: r,
field: field,
originalValue: startValue,
value: value,
row: ed.row,
column: ed.col,
cancel:false
};
if(this.fireEvent(&quot;validateedit&quot;, e) !== false &amp;&amp; !e.cancel &amp;&amp; String(value) !== String(startValue)){
r.set(field, e.value);
delete e.cancel;
this.fireEvent(&quot;afteredit&quot;, e);
}
}
this.view.focusCell(ed.row, ed.col);
},
<span id='Ext-grid-EditorGridPanel-method-startEditing'> /**
</span> * Starts editing the specified for the specified row/column
* @param {Number} rowIndex
* @param {Number} colIndex
*/
startEditing : function(row, col){
this.stopEditing();
if(this.colModel.isCellEditable(col, row)){
this.view.ensureVisible(row, col, true);
var r = this.store.getAt(row),
field = this.colModel.getDataIndex(col),
e = {
grid: this,
record: r,
field: field,
value: r.data[field],
row: row,
column: col,
cancel:false
};
if(this.fireEvent(&quot;beforeedit&quot;, e) !== false &amp;&amp; !e.cancel){
this.editing = true;
var ed = this.colModel.getCellEditor(col, row);
if(!ed){
return;
}
if(!ed.rendered){
ed.parentEl = this.view.getEditorParent(ed);
ed.on({
scope: this,
render: {
fn: function(c){
c.field.focus(false, true);
},
single: true,
scope: this
},
specialkey: function(field, e){
this.getSelectionModel().onEditorKey(field, e);
},
complete: this.onEditComplete,
canceledit: this.stopEditing.createDelegate(this, [true])
});
}
Ext.apply(ed, {
row : row,
col : col,
record : r
});
this.lastEdit = {
row: row,
col: col
};
this.activeEditor = ed;
if (ed.field.isXType('checkbox')) {
ed.allowBlur = false;
this.setupCheckbox(ed.field);
}
// Set the selectSameEditor flag if we are reusing the same editor again and
// need to prevent the editor from firing onBlur on itself.
ed.selectSameEditor = (this.activeEditor == this.lastActiveEditor);
var v = this.preEditValue(r, field);
ed.startEdit(this.view.getCell(row, col).firstChild, Ext.isDefined(v) ? v : '');
// Clear the selectSameEditor flag
(function(){
delete ed.selectSameEditor;
}).defer(50);
}
}
},
<span id='Ext-grid-EditorGridPanel-method-setupCheckbox'> setupCheckbox: function(field){
</span> var me = this,
fn = function() {
field.el.on('click', me.onCheckClick, me, {single: true});
};
if (field.rendered) {
fn();
} else {
field.on('render', fn, null, {single: true});
}
},
<span id='Ext-grid-EditorGridPanel-method-onCheckClick'> onCheckClick: function(){
</span> var ed = this.activeEditor;
ed.allowBlur = true;
ed.field.focus(false, 10);
},
<span id='Ext-grid-EditorGridPanel-method-preEditValue'> // private
</span> preEditValue : function(r, field){
var value = r.data[field];
return this.autoEncode &amp;&amp; Ext.isString(value) ? Ext.util.Format.htmlDecode(value) : value;
},
<span id='Ext-grid-EditorGridPanel-method-postEditValue'> // private
</span> postEditValue : function(value, originalValue, r, field){
return this.autoEncode &amp;&amp; Ext.isString(value) ? Ext.util.Format.htmlEncode(value) : value;
},
<span id='Ext-grid-EditorGridPanel-method-stopEditing'> /**
</span> * Stops any active editing
* @param {Boolean} cancel (optional) True to cancel any changes
*/
stopEditing : function(cancel){
if(this.editing){
// Store the lastActiveEditor to check if it is changing
var ae = this.lastActiveEditor = this.activeEditor;
if(ae){
ae[cancel === true ? 'cancelEdit' : 'completeEdit']();
this.view.focusCell(ae.row, ae.col);
}
this.activeEditor = null;
}
this.editing = false;
}
});
Ext.reg('editorgrid', Ext.grid.EditorGridPanel);</pre>
</body>
</html>