Hi, Here is updated patch.
In initial patch I fixed this issue in only Subnode control while Type node uses unique collection control (which is special case of subnode control). Now I have fixed in both control. -- *Harshal Dhumal* *Software Engineer * EenterpriseDB <http://www.enterprisedb.com> On Thu, Mar 17, 2016 at 6:41 PM, Dave Page <dp...@pgadmin.org> wrote: > Hi > > On Thu, Mar 17, 2016 at 11:14 AM, Harshal Dhumal < > harshal.dhu...@enterprisedb.com> wrote: > >> Hi, >> >> PFA patch for Subnode grid row close issue. >> >> Issue fixed: >> >> 1] Close any existing row while adding new row. >> 2] Close any existing row if we edit new row. >> > > This doesn't appear to make any difference to me. I've confirmed the patch > is applied, restarted the app, emptied my cache and reloaded, and tested > with composite types on the Create Type dialogue. I still see multiple row > forms when I hit the ADD button if one is already open. > > > -- > Dave Page > Blog: http://pgsnake.blogspot.com > Twitter: @pgsnake > > EnterpriseDB UK: http://www.enterprisedb.com > The Enterprise PostgreSQL Company >
diff --git a/web/pgadmin/static/js/backform.pgadmin.js b/web/pgadmin/static/js/backform.pgadmin.js index 39e3233..4a0476d 100644 --- a/web/pgadmin/static/js/backform.pgadmin.js +++ b/web/pgadmin/static/js/backform.pgadmin.js @@ -975,6 +975,29 @@ var collection = this.model.get(data.name); + var cellEditing = function(args){ + var self = this, + cell = args[0]; + // Search for any other rows which are open. + this.each(function(m){ + // Check if row which we are about to close is not current row. + if (cell.model != m) { + var idx = self.indexOf(m); + if (idx > -1) { + var row = grid.body.rows[idx], + editCell = row.$el.find(".subnode-edit-in-process").parent(); + // Only close row if it's open. + if (editCell.length > 0){ + var event = new Event('click'); + editCell[0].dispatchEvent(event); + } + } + } + }); + } + // Listen for any row which is about to enter in edit mode. + collection.on( "enteringEditMode", cellEditing, collection); + // Initialize a new Grid instance var grid = self.grid = new Backgrid.Grid({ columns: gridSchema.columns, @@ -997,6 +1020,17 @@ if (!(data.disabled || data.canAdd == false)) { $dialog.find('button.add').first().click(function(e) { e.preventDefault(); + + // Close any existing expanded row before adding new one. + _.each(grid.body.rows, function(row){ + var editCell = row.$el.find(".subnode-edit-in-process").parent(); + // Only close row if it's open. + if (editCell.length > 0){ + var event = new Event('click'); + editCell[0].dispatchEvent(event); + } + }); + var allowMultipleEmptyRows = !!self.field.get('allowMultipleEmptyRows'); // If allowMultipleEmptyRows is not set or is false then don't allow second new empty row. @@ -1163,6 +1197,30 @@ }); self.model.set(data.name, collection, {silent: true}); } + + var cellEditing = function(args){ + var self = this, + cell = args[0]; + // Search for any other rows which are open. + this.each(function(m){ + // Check if row which we are about to close is not current row. + if (cell.model != m) { + var idx = self.indexOf(m); + if (idx > -1) { + var row = grid.body.rows[idx], + editCell = row.$el.find(".subnode-edit-in-process").parent(); + // Only close row if it's open. + if (editCell.length > 0){ + var event = new Event('click'); + editCell[0].dispatchEvent(event); + } + } + } + }); + } + // Listen for any row which is about to enter in edit mode. + collection.on( "enteringEditMode", cellEditing, collection); + // Initialize a new Grid instance var grid = self.grid = new Backgrid.Grid({ columns: gridSchema.columns, @@ -1184,7 +1242,18 @@ // Add button callback $dialog.find('button.add').click(function(e) { e.preventDefault(); + // Close any existing expanded row before adding new one. + _.each(grid.body.rows, function(row){ + var editCell = row.$el.find(".subnode-edit-in-process").parent(); + // Only close row if it's open. + if (editCell.length > 0){ + var event = new Event('click'); + editCell[0].dispatchEvent(event); + } + }); + grid.insertRow({}); + var newRow = $(grid.body.rows[collection.length - 1].$el); newRow.attr("class", "new").click(function(e) { $(this).attr("class", "editable"); diff --git a/web/pgadmin/static/js/backgrid/backgrid.pgadmin.js b/web/pgadmin/static/js/backgrid/backgrid.pgadmin.js index 7c7eb0b..4b233d2 100644 --- a/web/pgadmin/static/js/backgrid/backgrid.pgadmin.js +++ b/web/pgadmin/static/js/backgrid/backgrid.pgadmin.js @@ -190,6 +190,9 @@ }); }, enterEditMode: function () { + // Notify that we are about to enter in edit mode for current cell. + this.model.trigger("enteringEditMode", [this]); + Backgrid.Cell.prototype.enterEditMode.apply(this, arguments); /* Make sure - we listen to the click event */ this.delegateEvents();
-- Sent via pgadmin-hackers mailing list (pgadmin-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgadmin-hackers