Hi,
Please find the attached patch for the Backgrid *StringDepsCell.*
The *StringDepsCell* displays HTML escaped strings and accepts
anything typed in.
Also, Listen to the dependent fields.
Usage of the Backgrid Cell:
If the Precision cell is dependent on the Datatype then:
{
id: 'precision', label:'{{ _('Precision') }}', type: 'test'
cell: *Backgrid.Extension.StringDepsCell*, deps: ['datatype']
}
Thanks,
Khushboo
diff --git a/web/pgadmin/static/js/backgrid/backgrid.pgadmin.js b/web/pgadmin/static/js/backgrid/backgrid.pgadmin.js
index 4b233d2..ed6bb51 100644
--- a/web/pgadmin/static/js/backgrid/backgrid.pgadmin.js
+++ b/web/pgadmin/static/js/backgrid/backgrid.pgadmin.js
@@ -447,6 +447,59 @@
editor: TextareaCellEditor
});
+ /**
+ StringDepsCell displays HTML escaped strings and accepts anything typed in.
+ Also, Listen to the dependent fields.
+
+ @class Backgrid.Extension.StringDepsCell
+ @extends Backgrid.StringCell
+ */
+ var StringDepsCell = Backgrid.Extension.StringDepsCell = Backgrid.StringCell.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);
+ },
+ render_deps: function () {
+ this.$el.empty();
+ var model = this.model;
+ var column = this.column;
+ editable = this.column.get("editable");
+
+ is_editable = _.isFunction(editable) ? !!editable.apply(column, [model]) : !!editable;
+ if (is_editable){ this.$el.addClass("editable"); }
+ else { this.$el.removeClass("editable"); }
+
+ this.delegateEvents();
+ return this;
+ }
+ });
+
return Backgrid;
}));
--
Sent via pgadmin-hackers mailing list ([email protected])
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgadmin-hackers