public inbox for [email protected]  
help / color / mirror / Atom feed
From: Harshal Dhumal <[email protected]>
To: Ashesh Vashi <[email protected]>
Cc: [email protected]
Subject: select2 cell and select2 backform control optionvalue issue fix
Date: Thu, 7 Jan 2016 12:56:28 +0530
Message-ID: <CAFiP3vxgLwys3e9cGvX=0R1URJo9KcW2d2z9S3YA_KSZ0HbcwQ@mail.gmail.com> (raw)
List-Unsubscribe:  <mailto:[email protected]?body=unsub%20pgadmin-hackers>

Hi,

Please find attached two patches for select2 cell and select2 control

Issue:
Resolving issue setting proper value for options in Select2Cell and Select2
control
-- 
*Harshal Dhumal*
*Software Engineer *



EenterpriseDB <http://www.enterprisedb.com;


-- 
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] select2_backgrid_cell_7_Jan_updated.patch (1.4K, 3-select2_backgrid_cell_7_Jan_updated.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 41143a3..000f4c4 100644
--- a/web/pgadmin/static/js/backgrid/backgrid.pgadmin.js
+++ b/web/pgadmin/static/js/backgrid/backgrid.pgadmin.js
@@ -310,17 +310,12 @@
       var col = _.defaults(this.column.toJSON(), this.defaults),
           model = this.model, column = this.column,
           editable = Backgrid.callByNeed(col.editable, column, model),
-          optionValues = this.column.get('optionValues');
+          optionValues = this.optionValues || this.column.get('options');
 
       this.$el.empty();
 
       if (!_.isArray(optionValues)) throw new TypeError("optionValues must be an array");
 
-      /* Add empty option as Select2 requires any empty '<option><option>' for
-       * some of its functionality to work.
-       */
-      optionValues.unshift([null, null]);
-
       var optionText = null,
           optionValue = null,
           model = this.model,
@@ -328,7 +323,11 @@
 
       delete this.$select;
 
-      this.$select = $("<select>", {tabIndex: -1}),
+      this.$select = $("<select>", {tabIndex: -1});
+      /* Add empty option as Select2 requires any empty '<option><option>' for
+       * some of its functionality to work.
+       */
+      this.$select.append($('<option></option>'));
       this.$el.append(this.$select);
 
       for (var i = 0; i < optionValues.length; i++) {


  [text/x-patch] select2_backform_controls_7_Jan_updated_2.patch (2.7K, 4-select2_backform_controls_7_Jan_updated_2.patch)
  download | inline diff:
diff --git a/web/pgadmin/browser/static/js/node.ui.js b/web/pgadmin/browser/static/js/node.ui.js
index 1412cc8..d385b6f 100644
--- a/web/pgadmin/browser/static/js/node.ui.js
+++ b/web/pgadmin/browser/static/js/node.ui.js
@@ -176,5 +176,50 @@ function($, _, pgAdmin, Backbone, Backform, Alertify, Node) {
     })
   });

+  /*
+   *  Backform Select2AjaxOptions control.
+   */
+  var Select2AjaxOptionsControl = Backform.Select2AjaxOptionsControl = Backform.NodeAjaxOptionsControl.extend({
+    render: function() {
+
+      var options = this.field.get('options') || [];
+
+      Backform.NodeAjaxOptionsControl.prototype.render.apply(this, arguments);
+
+      var col = _.defaults(this.field.toJSON(), this.defaults)
+      /* Add empty option as Select2 requires any empty '<option><option>' for
+       * some of its functionality to work and initialize select2 control.
+       */
+      this.$el.find("select").append($('<option></option>').select2(col.select2);
+      return this;
+    }
+  });
   return Backform.NodeListControl;
 });

diff --git a/web/pgadmin/static/css/overrides.css b/web/pgadmin/static/css/overrides.css
index 6d0f662..3ec4d6f 100755
--- a/web/pgadmin/static/css/overrides.css
+++ b/web/pgadmin/static/css/overrides.css
@@ -611,3 +611,20 @@ table.backgrid tr.new {
     right: 0px;
     bottom :0;
 }
+.select2 {
+  width: 100% !important;
+}
+.select2-search__field, select{
+  background:inherit !important;
+}
\ No newline at end of file
diff --git a/web/pgadmin/static/js/backform.pgadmin.js b/web/pgadmin/static/js/backform.pgadmin.js
index 7423909..86b9416 100644
--- a/web/pgadmin/static/js/backform.pgadmin.js
+++ b/web/pgadmin/static/js/backform.pgadmin.js
@@ -74,7 +74,8 @@
     'multiline': ['textarea', 'textarea', 'string'],
     'collection': ['sub-node-collection', 'sub-node-collection', 'string'],
     'uniqueColCollection': ['unique-col-collection', 'unique-col-collection', 'string'],
-    'switch' : 'switch'
+    'switch' : 'switch',
+    'select2': 'select2',
   };
@@ -1174,5 +1210,25 @@
     return groups;
   }
+  /*
+   *  Backform Select2 control.
+   */
+  var Select2Control = Backform.Select2Control = Backform.SelectControl.extend({
+    render: function() {
+      var options = this.field.get('options') || [];
+
+      Backform.SelectControl.prototype.render.apply(this, arguments);
+
+      var col = _.defaults(this.field.toJSON(), this.defaults)
+      /* Add empty option as Select2 requires any empty '<option><option>' for
+       * some of its functionality to work and initialize select2 control.
+       */
+      this.$el.find("select").append($('<option></option>').select2(col.select2);
+      return this;
+    }
+  });
   return Backform;
 }));


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], [email protected]
  Subject: Re: select2 cell and select2 backform control optionvalue issue fix
  In-Reply-To: <CAFiP3vxgLwys3e9cGvX=0R1URJo9KcW2d2z9S3YA_KSZ0HbcwQ@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