From ed0c400440eb9abcd1ca24f85177459eba0189d5 Mon Sep 17 00:00:00 2001 From: ampli Date: Wed, 29 Jun 2011 02:56:41 +0300 Subject: [PATCH 1/3] Columns in DataTable may be "randomly" deleted. This happens in updateSchema(), because both the column update loop and the row update loop use the same variable "i". Since variable scope in JS is by function and not block, the column loop variable gets overwritten. Repeat-by: 1. New Content->Basic->DataTable 2. data 3. Edit Schema 4. col1, add Column 5. col2, add Column 6. col3, Save 7. Edit Schema Note that col2 is missing. Fix: Change the name of the variable in the row loop. --- www/extras/yui-webgui/build/form/datatable.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/www/extras/yui-webgui/build/form/datatable.js b/www/extras/yui-webgui/build/form/datatable.js index d9f89b854..651c5f1ce 100644 --- a/www/extras/yui-webgui/build/form/datatable.js +++ b/www/extras/yui-webgui/build/form/datatable.js @@ -618,9 +618,9 @@ WebGUI.Form.DataTable // If the key has changed, update the row data if ( col && col.key != newKey ) { var rows = this.dataTable.getRecordSet().getRecords(); - for ( var i = 0; i < rows.length; i++ ) { - rows[ i ].setData( newKey, rows[ i ].getData( oldKey ) ); - rows[ i ].setData( oldKey, undefined ); + for ( var r = 0; r < rows.length; r++ ) { + rows[ r ].setData( newKey, rows[ r ].getData( oldKey ) ); + rows[ r ].setData( oldKey, undefined ); } } From 8e7beabaf06f78d2fa26243990be299385ec0e14 Mon Sep 17 00:00:00 2001 From: ampli Date: Wed, 29 Jun 2011 03:24:33 +0300 Subject: [PATCH 2/3] Fix #12179. In WebKit browsers, when a schema is saved, existing column field types are reset to "Text". This is not a bug in WebKit, and will happen in any browser that implements Option() as documented. Option() is not supposed to have an immediate action if only the default selection is updated on a newly added select object. See: http://download.oracle.com/docs/cd/E19957-01/816-6408-10/option.htm . Repeat-By: 1. New Content->basic->Datatable 2. data 3. Edit Schema 4. col1, Number, Add Column 5. col2, E-mail, Add Column 6. col3, URL, Add Column 7. Edit Schema (note that the field types got reset to "Text") 8 Save (now the field types incorrectly got overwritten in the DataTable) Fixed by adding 4th arguments to actually make the new selection to be equal to the default one. --- www/extras/yui-webgui/build/form/datatable.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/www/extras/yui-webgui/build/form/datatable.js b/www/extras/yui-webgui/build/form/datatable.js index 651c5f1ce..a2573b682 100644 --- a/www/extras/yui-webgui/build/form/datatable.js +++ b/www/extras/yui-webgui/build/form/datatable.js @@ -459,10 +459,12 @@ WebGUI.Form.DataTable format.name = "format_" + i; for ( var x = 0; x < availableFormats.length; x++ ) { + var selected = cols[i].formatter == availableFormats[x].value; var opt = new Option( availableFormats[x].label, availableFormats[x].value, - cols[i].formatter == availableFormats[x].value + selected, + selected ); format.appendChild( opt ); } From 5ea09092ad5df69ca103443415cfa3fd3a47a7b0 Mon Sep 17 00:00:00 2001 From: ampli Date: Wed, 29 Jun 2011 04:35:15 +0300 Subject: [PATCH 3/3] Fixed the following jslint warnings: Lint at line 5 character 16: 'WebGUI' was used before it was defined. var WebGUI = {}; Lint at line 53 character 86: Missing '()' invoking a constructor. data[ columns[ i ].key ] = columns[i].formatter == "date" ? new Date : ""; Lint at line 89 character 21: 'i' is already defined. for ( var i = 0; i < cols.length; i++ ) { Lint at line 612 character 25: 'col' is already defined. var col = this.dataTable.getColumn( oldKey ); Lint at line 661 character 63: Missing '()' invoking a constructor. allRecords[j].setData(newKey, new Date); --- www/extras/yui-webgui/build/form/datatable.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/www/extras/yui-webgui/build/form/datatable.js b/www/extras/yui-webgui/build/form/datatable.js index a2573b682..6d753f9ef 100644 --- a/www/extras/yui-webgui/build/form/datatable.js +++ b/www/extras/yui-webgui/build/form/datatable.js @@ -1,4 +1,5 @@ +/*global WebGUI*/ // Initialize namespace if (typeof WebGUI == "undefined") { var WebGUI = {}; @@ -49,7 +50,7 @@ WebGUI.Form.DataTable data = {}; var columns = this.dataTable.getColumnSet().getDefinitions(); for ( var i = 0; i < columns.length; i++ ) { - data[ columns[ i ].key ] = columns[i].formatter == "date" ? new Date : ""; + data[ columns[ i ].key ] = columns[i].formatter == "date" ? new Date() : ""; } } this.dataTable.addRow( data ); @@ -85,7 +86,7 @@ WebGUI.Form.DataTable // Get the columns var cols = this.dataTable.getColumnSet().getDefinitions(); - for ( var i = 0; i < cols.length; i++ ) { + for ( i = 0; i < cols.length; i++ ) { data.columns[ i ] = cols[i]; delete data.columns[ i ].editor; delete data.columns[ i ].editorOptions; @@ -608,7 +609,7 @@ WebGUI.Form.DataTable var oldKey = data[ "oldKey_" + i ]; var newKey = data[ "newKey_" + i ]; var format = data[ "format_" + i ][0]; - var col = this.dataTable.getColumn( oldKey ); + col = this.dataTable.getColumn( oldKey ); // Don't allow adding multiple columns with same key if ( oldKey != newKey && this.dataTable.getColumn( newKey ) ) { @@ -657,7 +658,7 @@ WebGUI.Form.DataTable var numRecords = allRecords.length; for (j=0; j < numRecords; j++) { if (format == "date") { - allRecords[j].setData(newKey, new Date); + allRecords[j].setData(newKey, new Date()); } else { allRecords[j].setData(newKey, ''); }