diff --git a/web/pgadmin/static/js/backgrid/backgrid.pgadmin.js b/web/pgadmin/static/js/backgrid/backgrid.pgadmin.js index 4b233d2..6ccea9a 100644 --- a/web/pgadmin/static/js/backgrid/backgrid.pgadmin.js +++ b/web/pgadmin/static/js/backgrid/backgrid.pgadmin.js @@ -447,6 +447,48 @@ editor: TextareaCellEditor }); + /** + DependentCell can be used as a base class for any backgrid cell which is + dependent on another cell. It will listen to the dependent fields/cells. + + Need to Extend this cell whenever required and has to implement render_deps + function to listen to the dependent fields change event. + + @class Backgrid.Extension.DependentCell + @extends Backgrid.DependentCell + */ + var DependentCell = Backgrid.Extension.DependentCell = Backgrid.Cell.extend({ + initialize: function(){ + Backgrid.StringCell.prototype.initialize.apply(this, arguments); + + // Listen to the dependent fields in the model for any change + var deps = this.column.get('deps'); + var self = this; + + if (deps && _.isArray(deps)) { + _.each(deps, function(d) { + attrArr = d.split('.'); + name = attrArr.shift(); + self.listenTo(self.model, "change:" + name, self.render_deps); + }); + } + }, + remove: function() { + // Remove the events for the dependent fields in the model + var self = this, + deps = self.column.get('deps'); + + if (deps && _.isArray(deps)) { + _.each(deps, function(d) { + attrArr = d.split('.'); + name = attrArr.shift(); + self.stopListening(self.model, "change:" + name, self.render_deps); + }); + } + Backbone.View.prototype.remove.apply(self, arguments); + } + }); + return Backgrid; }));