Subject: PATCH: Minor patch to fix issue in Integer Control [ pgAdmin4 ]

From: Murtuza Zabuawala <[email-masked]>
Date: Thu, 7 Jan 2016 10:38:07 +0530

Hi,

Please find minor patch to fix Backform Integer-Control.

_Issue:__
_    After validation of input value, value was not getting updated in 
model, hence it was taking default value from schema.

Regards,
Murtuza Zabuawala
diff --git a/web/pgadmin/static/js/backform.pgadmin.js b/web/pgadmin/static/js/backform.pgadmin.js
index 708b7fb..b5e5962 100644
--- a/web/pgadmin/static/js/backform.pgadmin.js
+++ b/web/pgadmin/static/js/backform.pgadmin.js
@@ -1070,6 +1070,12 @@
               ).value()
             );
       }
+
+      //After validation we need to set that value into model
+      this.stopListening(this.model, "change:" + name, this.render);
+      this.model.set(name, value);
+      this.listenTo(this.model, "change:" + name, this.render);
+
     }
   });

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

---

From: Murtuza Zabuawala <[email-masked]>
Date: Thu, 7 Jan 2016 11:02:22 +0530

+++ Updated patch file.

Hi,

I have added fix for server drop issue & added min & max value for 
'port' when we add db server in pgAdmin4.
I have also added flags to make sure we enter correct value in model 
when we use Integer Control.

Thanks,
Murtuza Zabuawala

> model, hence it was taking default value from schema.

diff --git a/web/pgadmin/browser/server_groups/servers/templates/servers/servers.js b/web/pgadmin/browser/server_groups/servers/templates/servers/servers.js
index 667e1ad..bd932d6 100644
--- a/web/pgadmin/browser/server_groups/servers/templates/servers/servers.js
+++ b/web/pgadmin/browser/server_groups/servers/templates/servers/servers.js
@@ -7,6 +7,7 @@ function($, _, S, pgAdmin, pgBrowser, alertify) {
       parent_type: 'server-group',
       type: 'server',
       label: '{{ _('Server') }}',
+      canDrop: true,
       Init: function() {
 
         /* Avoid multiple registration of same menus */
@@ -26,11 +27,6 @@ function($, _, S, pgAdmin, pgBrowser, alertify) {
           category: 'create', priority: 3, label: '{{ _('Server...') }}',
           data: {action: 'create'}, icon: 'wcTabIcon icon-server'
         },{
-          name: 'drop_server', node: 'server', module: this,
-          applies: ['object', 'context'], callback: 'delete_obj',
-          category: 'drop', priority: 3, label: '{{ _('Drop Server...') }}',
-          icon: 'fa fa-trash', enable: 'is_not_connected'
-        },{
           name: 'connect_server', node: 'server', module: this,
           applies: ['object', 'context'], callback: 'connect_server',
           category: 'connect', priority: 4, label: '{{ _('Connect Server...') }}',
@@ -166,7 +162,7 @@ function($, _, S, pgAdmin, pgBrowser, alertify) {
           mode: ['properties', 'edit', 'create'], disabled: 'isConnected'
         },{
           id: 'port', label:'{{ _('Port') }}', type: 'int', group: "Connection",
-          mode: ['properties', 'edit', 'create'], disabled: 'isConnected'
+          mode: ['properties', 'edit', 'create'], disabled: 'isConnected', min: 1024, max: 65534
         },{
           id: 'db', label:'{{ _('Maintenance Database') }}', type: 'text', group: "Connection",
           mode: ['properties', 'edit', 'create'], disabled: 'isConnected'
diff --git a/web/pgadmin/static/js/backform.pgadmin.js b/web/pgadmin/static/js/backform.pgadmin.js
index 708b7fb..3ce8061 100644
--- a/web/pgadmin/static/js/backform.pgadmin.js
+++ b/web/pgadmin/static/js/backform.pgadmin.js
@@ -1034,6 +1034,9 @@
           value = this.getValueFromDOM(),
           min_value = field.min,
           max_value = field.max,
+          valid_int = false,
+          valid_min = false,
+          valid_max = false,
           intPattern = new RegExp("^-?[0-9]*$"),
           isMatched = intPattern.test(value);
 
@@ -1046,6 +1049,9 @@
               field.label
               ).value()
             );
+      } else {
+        //We have valid int hence set the falg to true
+        valid_int = true;
       }
 
       // Below will check if entered value is in-between min & max range
@@ -1058,6 +1064,9 @@
               min_value
               ).value()
             );
+      } else {
+        //We have valid value when compare to min hence set the falg to true
+        valid_min = true;
       }
 
       if (!_.isUndefined(max_value) && value > max_value) {
@@ -1069,6 +1078,16 @@
               max_value
               ).value()
             );
+      } else {
+        //We have valid value when compare to max hence set the falg to true
+        valid_max = true;
+      }
+
+      //After validation we need to set that value into model (only if all falgs are true)
+      if (valid_int && valid_min && valid_max) {
+      this.stopListening(this.model, "change:" + name, this.render);
+      this.model.set(name, value);
+      this.listenTo(this.model, "change:" + name, this.render);
       }
     }
   });