Hi,

Please find attached patch to fix below given issues from pgAgent Jobs
Steps module.
1) 'Connection Type' cell was not honouring to 'Kind' option in Subnode
control.
2) Kind option was not saved properly
3) User was not be able to update Kind option in edit mode.
RM#2633

--
Regards,
Murtuza Zabuawala
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

[image: https://community.postgresrocks.net/]
<https://community.postgresrocks.net/>
diff --git 
a/web/pgadmin/browser/server_groups/servers/pgagent/steps/static/js/pga_jobstep.js
 
b/web/pgadmin/browser/server_groups/servers/pgagent/steps/static/js/pga_jobstep.js
index 1a9653d..0c5a523 100644
--- 
a/web/pgadmin/browser/server_groups/servers/pgagent/steps/static/js/pga_jobstep.js
+++ 
b/web/pgadmin/browser/server_groups/servers/pgagent/steps/static/js/pga_jobstep.js
@@ -1,8 +1,8 @@
 define('pgadmin.node.pga_jobstep', [
   'sources/gettext', 'sources/url_for', 'jquery', 'underscore',
   'underscore.string', 'sources/pgadmin', 'pgadmin.browser', 'alertify', 
'backform',
-  'pgadmin.backform'
-], function(gettext, url_for, $, _, S, pgAdmin, pgBrowser, Alertify, Backform) 
{
+  'backgrid', 'pgadmin.backform', 'pgadmin.backgrid'
+], function(gettext, url_for, $, _, S, pgAdmin, pgBrowser, Alertify, Backform, 
Backgrid) {
 
   if (!pgBrowser.Nodes['coll-pga_jobstep']) {
     pgBrowser.Nodes['coll-pga_jobstep'] =
@@ -18,6 +18,40 @@ define('pgadmin.node.pga_jobstep', [
       });
   }
 
+  // Switch Cell with Deps, Needed for SubNode control
+  var SwitchDepsCell = Backgrid.Extension.SwitchCell.extend({
+    initialize: function initialize() {
+      Backgrid.Extension.SwitchCell.prototype.initialize.apply(this, 
arguments);
+      Backgrid.Extension.DependentCell.prototype.initialize.apply(this, 
arguments);
+    },
+    dependentChanged: function dependentChanged() {
+      var model = this.model,
+          column = this.column,
+          editable = this.column.get("editable"),
+          input = this.$el.find('input[type=checkbox]').first(),
+          self_name = column.get('name'),
+          is_editable;
+
+      is_editable = _.isFunction(editable) ? !!editable.apply(column, [model]) 
: !!editable;
+      if (is_editable) {
+        this.$el.addClass("editable");
+        input.bootstrapSwitch('disabled', false);
+      } else {
+        this.$el.removeClass("editable");
+        input.bootstrapSwitch('disabled', true);
+        // Set self value into model
+        setTimeout(function () {
+          model.set(self_name, true);
+        }, 10);
+
+      }
+
+      this.delegateEvents();
+      return this;
+    },
+    remove: Backgrid.Extension.DependentCell.prototype.remove
+  });
+
   if (!pgBrowser.Nodes['pga_jobstep']) {
     pgBrowser.Nodes['pga_jobstep'] = pgBrowser.Node.extend({
       parent_type: 'pga_job',
@@ -118,6 +152,11 @@ define('pgadmin.node.pga_jobstep', [
           id: 'jstconntype', label: gettext('Connection type'),
           type: 'switch', deps: ['jstkind'], mode: ['create', 'edit'],
           disabled: function(m) { return !m.get('jstkind'); },
+          cell: SwitchDepsCell,
+          editable: function(m) {
+            // If jstkind is Batch then disable it
+            return m.get('jstkind');
+          },
           options: {
             'onText': gettext('Local'), 'offText': gettext('Remote'),
             'onColor': 'primary', 'offColor': 'primary'
diff --git 
a/web/pgadmin/browser/server_groups/servers/pgagent/templates/macros/pga_jobstep.macros
 
b/web/pgadmin/browser/server_groups/servers/pgagent/templates/macros/pga_jobstep.macros
index 520d89f..45753af 100644
--- 
a/web/pgadmin/browser/server_groups/servers/pgagent/templates/macros/pga_jobstep.macros
+++ 
b/web/pgadmin/browser/server_groups/servers/pgagent/templates/macros/pga_jobstep.macros
@@ -14,10 +14,15 @@ INSERT INTO pgagent.pga_jobstep (
 ) {% if jid %}RETURNING jstid{% endif %};
 {%- endmacro %}
 {% macro UPDATE(has_connstr, jid, jstid, data) -%}
+{% if 'jstname' in data or 'jstenabled' in data or 'jstdesc' in data or 
'jstonerror' in data or 'jstcode' in data %}
+{% set is_colon_required = True %}
+{% else %}
+{% set is_colon_required = False %}
+{% endif %}
 -- Updating the existing step (id: {{ jstid|qtLiteral }} jobid: {{ 
jid|qtLiteral }})
 UPDATE pgagent.pga_jobstep
 SET
-    {% if has_connstr %}{% if 'jstconntype' in data %}{% if data.jstconntype 
%}jstdbname={{ data.jstdbname|qtLiteral }}, jstconnstr=''{% else 
%}jstdbname='', jstconnstr={{ data.jstconnstr|qtLiteral }}{% endif %}{% if 
'jstname' in data or 'jstenabled' in data or 'jstdesc' in data or 'jstonerror' 
in data or 'jstcode' in data %},{% endif %}{% endif %}{% else %}{% if 
'jstdbname' in data %}jstdbname={{ data.jstdbname|qtLiteral }}::name{% endif 
%}{% if 'jstname' in data or 'jstenabled' in data or 'jstdesc' in data or 
'jstonerror' in data or 'jstcode' in data %},{% endif %}{% endif %}{% if 
'jstname' in data  %}
+    {% if has_connstr %}{% if 'jstkind' in data %}{% if data.jstkind 
%}jstkind='s'::character(1), jstdbname={{ data.jstdbname|qtLiteral }}{% else 
%}jstkind='b'::character(1), jstdbname='', jstconnstr=''{% endif %}{% if 
is_colon_required %}, {% endif %}{% elif 'jstconntype' in data %}{% if 
data.jstconntype %}jstdbname={{ data.jstdbname|qtLiteral }}, jstconnstr=''{% 
else %}jstdbname='', jstconnstr={{ data.jstconnstr|qtLiteral }}{% endif %}{% if 
is_colon_required %},{% endif %}{% endif %}{% else %}{% if 'jstdbname' in data 
%}jstdbname={{ data.jstdbname|qtLiteral }}::name{% endif %}{% if 
is_colon_required %},{% endif %}{% endif %}{% if 'jstname' in data  %}
 
     jstname={{ data.jstname|qtLiteral }}::text{% if 'jstenabled' in data or 
'jstdesc' in data or 'jstonerror' in data or 'jstcode' in data %},{% endif %}{% 
endif %}{% if 'jstenabled' in data %}
 
@@ -38,7 +43,7 @@ DELETE FROM pgagent.pga_jobstep WHERE jstid={{ 
jstid|qtLiteral }}::integer AND j
 {% macro PROPERTIES(has_connstr, jid, jstid) -%}
 SELECT
     jstid,  jstjobid, jstname, jstdesc, jstenabled, jstkind = 's'::bpchar as 
jstkind,
-    jstcode, CASE WHEN jstdbname != '' THEN true ELSE false END AS jstconntype,
+    jstcode, CASE WHEN (jstdbname != '' OR jstkind = 'b'::bpchar) THEN true 
ELSE false END AS jstconntype,
     {% if has_connstr %}jstconnstr, {% endif %} jstdbname, jstonerror, 
jscnextrun
 FROM
     pgagent.pga_jobstep

Reply via email to