summaryrefslogtreecommitdiff
path: root/includes/js/dojox/grid/_grid/edit.js
diff options
context:
space:
mode:
authormensonge <mensonge@b3834d28-1941-0410-a4f8-b48e95affb8f>2008-11-13 09:49:11 +0000
committermensonge <mensonge@b3834d28-1941-0410-a4f8-b48e95affb8f>2008-11-13 09:49:11 +0000
commite44a7e37b6c7b5961adaffc62b9042b8d442938e (patch)
tree95b67c356e93163467db2451f2b8cce84ed5d582 /includes/js/dojox/grid/_grid/edit.js
parenta62b9742ee5e28bcec6872d88f50f25b820914f6 (diff)
downloadsemanticscuttle-e44a7e37b6c7b5961adaffc62b9042b8d442938e.tar.gz
semanticscuttle-e44a7e37b6c7b5961adaffc62b9042b8d442938e.tar.bz2
New feature: basic Ajax suggestion for tags and implementation of Dojo toolkit
git-svn-id: https://semanticscuttle.svn.sourceforge.net/svnroot/semanticscuttle/trunk@151 b3834d28-1941-0410-a4f8-b48e95affb8f
Diffstat (limited to 'includes/js/dojox/grid/_grid/edit.js')
-rw-r--r--includes/js/dojox/grid/_grid/edit.js238
1 files changed, 238 insertions, 0 deletions
diff --git a/includes/js/dojox/grid/_grid/edit.js b/includes/js/dojox/grid/_grid/edit.js
new file mode 100644
index 0000000..d918423
--- /dev/null
+++ b/includes/js/dojox/grid/_grid/edit.js
@@ -0,0 +1,238 @@
+if(!dojo._hasResource["dojox.grid._grid.edit"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
+dojo._hasResource["dojox.grid._grid.edit"] = true;
+dojo.provide("dojox.grid._grid.edit");
+
+dojo.declare("dojox.grid.edit", null, {
+ // summary:
+ // Controls grid cell editing process. Owned by grid and used internally for editing.
+ constructor: function(inGrid){
+ // inGrid: dojox.Grid
+ // The dojox.Grid this editor should be attached to
+ this.grid = inGrid;
+ this.connections = [];
+ if(dojo.isIE){
+ this.connections.push(dojo.connect(document.body, "onfocus", dojo.hitch(this, "_boomerangFocus")));
+ }
+ },
+
+ info: {},
+
+ destroy: function(){
+ dojo.forEach(this.connections,dojo.disconnect);
+ },
+
+ cellFocus: function(inCell, inRowIndex){
+ // summary:
+ // Invoke editing when cell is focused
+ // inCell: cell object
+ // Grid cell object
+ // inRowIndex: Integer
+ // Grid row index
+ if(this.grid.singleClickEdit || this.isEditRow(inRowIndex)){
+ // if same row or quick editing, edit
+ this.setEditCell(inCell, inRowIndex);
+ }else{
+ // otherwise, apply any pending row edits
+ this.apply();
+ }
+ // if dynamic or static editing...
+ if(this.isEditing() || (inCell && (inCell.editor||0).alwaysOn)){
+ // let the editor focus itself as needed
+ this._focusEditor(inCell, inRowIndex);
+ }
+ },
+
+ rowClick: function(e){
+ if(this.isEditing() && !this.isEditRow(e.rowIndex)){
+ this.apply();
+ }
+ },
+
+ styleRow: function(inRow){
+ if(inRow.index == this.info.rowIndex){
+ inRow.customClasses += ' dojoxGrid-row-editing';
+ }
+ },
+
+ dispatchEvent: function(e){
+ var c = e.cell, ed = c && c.editor;
+ return ed && ed.dispatchEvent(e.dispatch, e);
+ },
+
+ // Editing
+ isEditing: function(){
+ // summary:
+ // Indicates editing state of the grid.
+ // returns: Boolean
+ // True if grid is actively editing
+ return this.info.rowIndex !== undefined;
+ },
+
+ isEditCell: function(inRowIndex, inCellIndex){
+ // summary:
+ // Indicates if the given cell is being edited.
+ // inRowIndex: Integer
+ // Grid row index
+ // inCellIndex: Integer
+ // Grid cell index
+ // returns: Boolean
+ // True if given cell is being edited
+ return (this.info.rowIndex === inRowIndex) && (this.info.cell.index == inCellIndex);
+ },
+
+ isEditRow: function(inRowIndex){
+ // summary:
+ // Indicates if the given row is being edited.
+ // inRowIndex: Integer
+ // Grid row index
+ // returns: Boolean
+ // True if given row is being edited
+ return this.info.rowIndex === inRowIndex;
+ },
+
+ setEditCell: function(inCell, inRowIndex){
+ // summary:
+ // Set the given cell to be edited
+ // inRowIndex: Integer
+ // Grid row index
+ // inCell: Object
+ // Grid cell object
+ if(!this.isEditCell(inRowIndex, inCell.index) && this.grid.canEdit(inCell, inRowIndex)){
+ this.start(inCell, inRowIndex, this.isEditRow(inRowIndex) || inCell.editor);
+ }
+ },
+
+ _focusEditor: function(inCell, inRowIndex){
+ dojox.grid.fire(inCell.editor, "focus", [inRowIndex]);
+ },
+
+ focusEditor: function(){
+ if(this.isEditing()){
+ this._focusEditor(this.info.cell, this.info.rowIndex);
+ }
+ },
+
+ // implement fix for focus boomerang effect on IE
+ _boomerangWindow: 500,
+ _shouldCatchBoomerang: function(){
+ return this._catchBoomerang > new Date().getTime();
+ },
+ _boomerangFocus: function(){
+ //console.log("_boomerangFocus");
+ if(this._shouldCatchBoomerang()){
+ // make sure we don't utterly lose focus
+ this.grid.focus.focusGrid();
+ // let the editor focus itself as needed
+ this.focusEditor();
+ // only catch once
+ this._catchBoomerang = 0;
+ }
+ },
+ _doCatchBoomerang: function(){
+ // give ourselves a few ms to boomerang IE focus effects
+ if(dojo.isIE){this._catchBoomerang = new Date().getTime() + this._boomerangWindow;}
+ },
+ // end boomerang fix API
+
+ start: function(inCell, inRowIndex, inEditing){
+ this.grid.beginUpdate();
+ this.editorApply();
+ if(this.isEditing() && !this.isEditRow(inRowIndex)){
+ this.applyRowEdit();
+ this.grid.updateRow(inRowIndex);
+ }
+ if(inEditing){
+ this.info = { cell: inCell, rowIndex: inRowIndex };
+ this.grid.doStartEdit(inCell, inRowIndex);
+ this.grid.updateRow(inRowIndex);
+ }else{
+ this.info = {};
+ }
+ this.grid.endUpdate();
+ // make sure we don't utterly lose focus
+ this.grid.focus.focusGrid();
+ // let the editor focus itself as needed
+ this._focusEditor(inCell, inRowIndex);
+ // give ourselves a few ms to boomerang IE focus effects
+ this._doCatchBoomerang();
+ },
+
+ _editorDo: function(inMethod){
+ var c = this.info.cell
+ //c && c.editor && c.editor[inMethod](c, this.info.rowIndex);
+ c && c.editor && c.editor[inMethod](this.info.rowIndex);
+ },
+
+ editorApply: function(){
+ this._editorDo("apply");
+ },
+
+ editorCancel: function(){
+ this._editorDo("cancel");
+ },
+
+ applyCellEdit: function(inValue, inCell, inRowIndex){
+ if(this.grid.canEdit(inCell, inRowIndex)){
+ this.grid.doApplyCellEdit(inValue, inRowIndex, inCell.fieldIndex);
+ }
+ },
+
+ applyRowEdit: function(){
+ this.grid.doApplyEdit(this.info.rowIndex);
+ },
+
+ apply: function(){
+ // summary:
+ // Apply a grid edit
+ if(this.isEditing()){
+ this.grid.beginUpdate();
+ this.editorApply();
+ this.applyRowEdit();
+ this.info = {};
+ this.grid.endUpdate();
+ this.grid.focus.focusGrid();
+ this._doCatchBoomerang();
+ }
+ },
+
+ cancel: function(){
+ // summary:
+ // Cancel a grid edit
+ if(this.isEditing()){
+ this.grid.beginUpdate();
+ this.editorCancel();
+ this.info = {};
+ this.grid.endUpdate();
+ this.grid.focus.focusGrid();
+ this._doCatchBoomerang();
+ }
+ },
+
+ save: function(inRowIndex, inView){
+ // summary:
+ // Save the grid editing state
+ // inRowIndex: Integer
+ // Grid row index
+ // inView: Object
+ // Grid view
+ var c = this.info.cell;
+ if(this.isEditRow(inRowIndex) && (!inView || c.view==inView) && c.editor){
+ c.editor.save(c, this.info.rowIndex);
+ }
+ },
+
+ restore: function(inView, inRowIndex){
+ // summary:
+ // Restores the grid editing state
+ // inRowIndex: Integer
+ // Grid row index
+ // inView: Object
+ // Grid view
+ var c = this.info.cell;
+ if(this.isEditRow(inRowIndex) && c.view == inView && c.editor){
+ c.editor.restore(c, this.info.rowIndex);
+ }
+ }
+});
+
+}