Hi,

The current implementation of the unique-collection control does not pass
the control data to the evaluation function like canAdd, canEdit etc., so
that has been fixed.

Also, the current implementation of the variable control does not honour
the canAdd option settings, which has been fixed.

Please find attached patch for the same.

Thanks,
Khushboo
diff --git a/web/pgadmin/browser/server_groups/servers/static/js/variable.js b/web/pgadmin/browser/server_groups/servers/static/js/variable.js
index 4c13215..6d829d4 100644
--- a/web/pgadmin/browser/server_groups/servers/static/js/variable.js
+++ b/web/pgadmin/browser/server_groups/servers/static/js/variable.js
@@ -528,21 +528,26 @@
         checkVars.push('role');
       }
 
-      self.collection.each(function(m) {
-        if (!inSelected) {
-          var has = true;
-          _.each(checkVars, function(v) {
-            val = m.get(v);
-            has = has && ((
-              (_.isUndefined(val) || _.isNull(val)) &&
-              (_.isUndefined(data[v]) || _.isNull(data[v]))
-              ) ||
-              (val == data[v]));
-          });
-
-          inSelected = has;
-        }
-      });
+      if (self.control_data.canAdd) {
+        self.collection.each(function(m) {
+          if (!inSelected) {
+            var has = true;
+            _.each(checkVars, function(v) {
+              val = m.get(v);
+              has = has && ((
+                (_.isUndefined(val) || _.isNull(val)) &&
+                (_.isUndefined(data[v]) || _.isNull(data[v]))
+                ) ||
+                (val == data[v]));
+            });
+
+            inSelected = has;
+          }
+        });
+      }
+      else {
+        inSelected = true;
+      }
 
       self.$header.find('button.add').prop('disabled', inSelected);
     },
diff --git a/web/pgadmin/static/js/backform.pgadmin.js b/web/pgadmin/static/js/backform.pgadmin.js
index b7ffc26..0756bac 100644
--- a/web/pgadmin/static/js/backform.pgadmin.js
+++ b/web/pgadmin/static/js/backform.pgadmin.js
@@ -872,22 +872,22 @@
             attributes: attributes,
             formatter: this.formatter
            }),
-          evalF = function(f, m) {
-            return (_.isFunction(f) ? !!f(m) : !!f);
+          evalF = function(f, d, m) {
+            return (_.isFunction(f) ? !!f.apply(d, [m]) : !!f);
           };
 
       // Evaluate the disabled, visible, required, canAdd, & canDelete option
       _.extend(data, {
         disabled: (field.version_compatible &&
-                   evalF.apply(this.field, [data.disabled, this.model])
+                   evalF.apply(this.field, [data.disabled, data, this.model])
                    ),
-        visible:  evalF.apply(this.field, [data.visible, this.model]),
-        required: evalF.apply(this.field, [data.required, this.model]),
+        visible:  evalF.apply(this.field, [data.visible, data, this.model]),
+        required: evalF.apply(this.field, [data.required, data, this.model]),
         canAdd: (field.version_compatible &&
-          evalF.apply(this.field, [data.canAdd, this.model])
+          evalF.apply(this.field, [data.canAdd, data, this.model])
           ),
-        canDelete: evalF.apply(this.field, [data.canDelete, this.model]),
-        canEdit: evalF.apply(this.field, [data.canEdit, this.model])
+        canDelete: evalF.apply(this.field, [data.canDelete, data, this.model]),
+        canEdit: evalF.apply(this.field, [data.canEdit, data, this.model])
       });
       _.extend(data, {add_label: "ADD"});
 
@@ -896,6 +896,8 @@
         return this;
       }
 
+      this.control_data = _.clone(data);
+
       // Show Backgrid Control
       grid = this.showGridControl(data);
 
-- 
Sent via pgadmin-hackers mailing list (pgadmin-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgadmin-hackers

Reply via email to