public inbox for [email protected]  
help / color / mirror / Atom feed
From: Khushboo Vashi <[email protected]>
To: pgadmin-hackers <[email protected]>
Subject: [pgAdmin4][Patch]: Backgrid StringDepsCell
Date: Wed, 30 Mar 2016 18:39:35 +0530
Message-ID: <CAFOhELcoJTEm=V=buZKdt_Eoc1ur4jGySg6J3BdKpNn5aVVhuw@mail.gmail.com> (raw)
List-Unsubscribe:  <mailto:[email protected]?body=unsub%20pgadmin-hackers>

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


-- 
Sent via pgadmin-hackers mailing list ([email protected])
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgadmin-hackers


Attachments:

  [text/x-patch] pgAdmin4_Backgrid_StringDepsCell.patch (2.0K, 3-pgAdmin4_Backgrid_StringDepsCell.patch)
  download | inline diff:
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;
 
 }));


view thread (7+ messages)  latest in thread

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected]
  Subject: Re: [pgAdmin4][Patch]: Backgrid StringDepsCell
  In-Reply-To: <CAFOhELcoJTEm=V=buZKdt_Eoc1ur4jGySg6J3BdKpNn5aVVhuw@mail.gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox