public inbox for [email protected]  
help / color / mirror / Atom feed
[pgAdmin4][Patch][RM_2448]: Multiple button presses to switch boolean fields
2+ messages / 2 participants
[nested] [flat]

* [pgAdmin4][Patch][RM_2448]: Multiple button presses to switch boolean fields
@ 2017-06-02 10:20 Surinder Kumar <[email protected]>
  2017-06-06 10:31 ` Re: [pgAdmin4][Patch][RM_2448]: Multiple button presses to switch boolean fields Dave Page <[email protected]>
  0 siblings, 1 reply; 2+ messages in thread

From: Surinder Kumar @ 2017-06-02 10:20 UTC (permalink / raw)
  To: pgadmin-hackers

Hi

The behaviour for checkbox click will go "false -> true -> null ->"

Please find attached patch and review.

Thanks,
Surinder Kumar


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


Attachments:

  [application/octet-stream] RM_2448.patch (5.4K, 3-RM_2448.patch)
  download | inline diff:
diff --git a/web/pgadmin/static/js/slickgrid/slick.pgadmin.editors.js b/web/pgadmin/static/js/slickgrid/slick.pgadmin.editors.js
index a3f4469..6803d2c 100644
--- a/web/pgadmin/static/js/slickgrid/slick.pgadmin.editors.js
+++ b/web/pgadmin/static/js/slickgrid/slick.pgadmin.editors.js
@@ -481,7 +481,7 @@
   /* Override CheckboxEditor to implement checkbox with three states.
    * 1) checked=true
    * 2) unchecked=false
-   * 3) indeterminate=null/''
+   * 3) indeterminate=null
    */
   function CheckboxEditor(args) {
     var $select, el;
@@ -489,32 +489,37 @@
     var scope = this;
 
     this.init = function () {
-      $select = $("<INPUT type=checkbox value='true' class='editor-checkbox' hideFocus>");
+      $select = $("<INPUT type=checkbox class='editor-checkbox' hideFocus>");
       $select.appendTo(args.container);
       $select.focus();
 
       // The following code is taken from https://css-tricks.com/indeterminate-checkboxes/
-      $select.data('checked', 0).bind("click", function (e) {
+      $select.bind("click", function (e) {
         el = $(this);
-        switch(el.data('checked')) {
+        el.prop('indeterminate', false);
+
+        var checkbox_status = el.data('checked');
+        // add new row > checkbox clicked
+        if (el.data('checked') == undefined) {
+          checkbox_status = 1;
+        }
+        switch(checkbox_status) {
           // unchecked, going indeterminate
           case 0:
-            el.data('checked', 1);
             el.prop('indeterminate', true);
+            el.data('checked', 2); // determines next checkbox status
             break;
 
           // indeterminate, going checked
           case 1:
-            el.data('checked', 2);
-            el.prop('indeterminate', false);
             el.prop('checked', true);
+            el.data('checked', 0);
             break;
 
           // checked, going unchecked
           default:
-            el.data('checked', 0);
-            el.prop('indeterminate', false);
             el.prop('checked', false);
+            el.data('checked', 1);
         }
       });
     };
@@ -529,15 +534,18 @@
 
     this.loadValue = function (item) {
       defaultValue = item[args.column.pos];
-      if (_.isNull(defaultValue)||_.isUndefined(defaultValue)) {
+      if (_.isNull(defaultValue)|| _.isUndefined(defaultValue)) {
         $select.prop('indeterminate', true);
+        $select.data('checked', 2);
       }
       else {
         defaultValue = !!item[args.column.pos];
         if (defaultValue) {
           $select.prop('checked', true);
+          $select.data('checked', 0);
         } else {
           $select.prop('checked', false);
+          $select.data('checked', 1);
         }
       }
     };
@@ -554,7 +562,10 @@
     };
 
     this.isValueChanged = function () {
-      return (this.serializeValue() !== defaultValue);
+      // var select_value = this.serializeValue();
+      var select_value = $select.data('checked');
+      return (!(select_value === 2 && (defaultValue == null || defaultValue == undefined))) &&
+            (select_value !== defaultValue);
     };
 
     this.validate = function () {
@@ -783,31 +794,6 @@
       $select = $("<INPUT type=checkbox value='true' class='editor-checkbox' hideFocus disabled>");
       $select.appendTo(args.container);
       $select.focus();
-
-      // The following code is taken from https://css-tricks.com/indeterminate-checkboxes/
-      $select.data('checked', 0).bind("click", function (e) {
-        el = $(this);
-        switch(el.data('checked')) {
-          // unchecked, going indeterminate
-          case 0:
-            el.data('checked', 1);
-            el.prop('indeterminate', true);
-            break;
-
-          // indeterminate, going checked
-          case 1:
-            el.data('checked', 2);
-            el.prop('indeterminate', false);
-            el.prop('checked', true);
-            break;
-
-          // checked, going unchecked
-          default:
-            el.data('checked', 0);
-            el.prop('indeterminate', false);
-            el.prop('checked', false);
-        }
-      });
     };
 
     this.destroy = function () {
@@ -819,16 +805,19 @@
     };
 
     this.loadValue = function (item) {
-      defaultValue = item[args.column.field];
-      if (_.isNull(defaultValue)||_.isUndefined(defaultValue)) {
+      defaultValue = item[args.column.pos];
+      if (_.isNull(defaultValue)|| _.isUndefined(defaultValue)) {
         $select.prop('indeterminate', true);
+        $select.data('checked', 2);
       }
       else {
-        defaultValue = !!item[args.column.field];
+        defaultValue = !!item[args.column.pos];
         if (defaultValue) {
           $select.prop('checked', true);
+          $select.data('checked', 0);
         } else {
           $select.prop('checked', false);
+          $select.data('checked', 1);
         }
       }
     };
@@ -841,11 +830,14 @@
     };
 
     this.applyValue = function (item, state) {
-      item[args.column.field] = state;
+      item[args.column.pos] = state;
     };
 
     this.isValueChanged = function () {
-      return (this.serializeValue() !== defaultValue);
+      // var select_value = this.serializeValue();
+      var select_value = $select.data('checked');
+      return (!(select_value === 2 && (defaultValue == null || defaultValue == undefined))) &&
+            (select_value !== defaultValue);
     };
 
     this.validate = function () {


^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: [pgAdmin4][Patch][RM_2448]: Multiple button presses to switch boolean fields
  2017-06-02 10:20 [pgAdmin4][Patch][RM_2448]: Multiple button presses to switch boolean fields Surinder Kumar <[email protected]>
@ 2017-06-06 10:31 ` Dave Page <[email protected]>
  0 siblings, 0 replies; 2+ messages in thread

From: Dave Page @ 2017-06-06 10:31 UTC (permalink / raw)
  To: Surinder Kumar <[email protected]>; +Cc: pgadmin-hackers

Thanks, applied.

On Fri, Jun 2, 2017 at 11:20 AM, Surinder Kumar
<[email protected]> wrote:
> Hi
>
> The behaviour for checkbox click will go "false -> true -> null ->"
>
> Please find attached patch and review.
>
> Thanks,
> Surinder Kumar
>
>
> --
> Sent via pgadmin-hackers mailing list ([email protected])
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgadmin-hackers
>



-- 
Dave Page
Blog: http://pgsnake.blogspot.com
Twitter: @pgsnake

EnterpriseDB UK: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


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




^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2017-06-06 10:31 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2017-06-02 10:20 [pgAdmin4][Patch][RM_2448]: Multiple button presses to switch boolean fields Surinder Kumar <[email protected]>
2017-06-06 10:31 ` Dave Page <[email protected]>

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