diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/types/templates/type/js/type.js b/web/pgadmin/browser/server_groups/servers/databases/schemas/types/templates/type/js/type.js index 7a411798f..8da86484d 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/types/templates/type/js/type.js +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/types/templates/type/js/type.js @@ -270,7 +270,7 @@ function($, _, S, pgAdmin, pgBrowser, alertify, Backgrid) { schema: [{ id: 'name', label: '{{ _('Name') }}', cell: 'string', type: 'text', mode: ['properties', 'create', 'edit'], - disabled: 'inSchema' + disabled: 'schemaCheck' },{ id: 'oid', label:'{{ _('OID') }}', cell: 'string', type: 'text' , mode: ['properties'], disabled: true @@ -282,7 +282,7 @@ function($, _, S, pgAdmin, pgBrowser, alertify, Backgrid) { },{ id: 'schema', label:'{{ _('Schema') }}', cell: 'string', type: 'text', mode: ['create', 'edit'], node: 'schema', - disabled: 'inSchema', filter: function(d) { + disabled: 'schemaCheck', filter: function(d) { // If schema name start with pg_* then we need to exclude them if(d && d.label.match(/^pg_/)) { @@ -290,18 +290,7 @@ function($, _, S, pgAdmin, pgBrowser, alertify, Backgrid) { } return true; }, - control: Backform.NodeListByNameControl.extend({ - render: function(){ - // Initialize parent's render method - Backform.NodeListByNameControl.prototype.render.apply(this, arguments); - - // Set schema default value to its parent Schema - if(this.model.isNew()){ - this.model.set({'schema': this.model.node_info.schema.label}); - } - return this; - } - }) + control: 'node-list-by-name' },{ id: 'typtype', label:'{{ _('Type') }}', mode: ['create','edit'], disabled: 'inSchemaWithModelCheck', @@ -314,7 +303,7 @@ function($, _, S, pgAdmin, pgBrowser, alertify, Backgrid) { {label: "Enumeration", value: "e"}, {label: "External", value: "b"}, {label: "Range", value: "r"}, - {label: "Shell", value: "s"} + {label: "Shell", value: "p"} ] }, disabled: 'inSchemaWithModelCheck', @@ -724,7 +713,7 @@ function($, _, S, pgAdmin, pgBrowser, alertify, Backgrid) { uniqueCol : ['grantee'], deps: ['typtype'], canAdd: function(m) { // Do not allow to add when shell type is selected - return !(m.get('typtype') === 's'); + return !(m.get('typtype') === 'p'); } },{ id: 'seclabels', label: '{{ _('Security Labels') }}', @@ -734,7 +723,7 @@ function($, _, S, pgAdmin, pgBrowser, alertify, Backgrid) { control: 'unique-col-collection', deps: ['typtype'], canAdd: function(m) { // Do not allow to add when shell type is selected - return !(m.get('typtype') === 's'); + return !(m.get('typtype') === 'p'); } }], @@ -789,6 +778,17 @@ function($, _, S, pgAdmin, pgBrowser, alertify, Backgrid) { } return false; }, + schemaCheck: function(m) { + if(this.node_info && 'schema' in this.node_info) + { + if (m.isNew()) { + return false; + } else { + return m.get('typtype') === 'p'; + } + } + return true; + }, // We will check if we are under schema node & in 'create' mode inSchemaWithModelCheck: function(m) { if(this.node_info && 'schema' in this.node_info) diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/types/templates/type/sql/9.1_plus/create.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/types/templates/type/sql/9.1_plus/create.sql index 35403b6d4..ed4eb28f4 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/types/templates/type/sql/9.1_plus/create.sql +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/types/templates/type/sql/9.1_plus/create.sql @@ -1,7 +1,7 @@ {% import 'macros/schemas/security.macros' as SECLABLE %} {% import 'macros/schemas/privilege.macros' as PRIVILEGE %} {## If user selected shell type then just create type template ##} -{% if data and data.typtype == 's' %} +{% if data and data.typtype == 'p' %} CREATE TYPE {{ conn|qtIdent(data.schema, data.name) }}; {% endif %} {### Composite Type ###} @@ -80,4 +80,4 @@ COMMENT ON TYPE {% if data.schema %}{{ conn|qtIdent(data.schema, data.name) }}{% {{ SECLABLE.SET(conn, 'TYPE', data.name, r.provider, r.security_label, data.schema) }} {% endif %} {% endfor %} -{% endif %} \ No newline at end of file +{% endif %} diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/types/templates/type/sql/9.1_plus/update.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/types/templates/type/sql/9.1_plus/update.sql index 170b03a87..ab617b082 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/types/templates/type/sql/9.1_plus/update.sql +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/types/templates/type/sql/9.1_plus/update.sql @@ -131,9 +131,9 @@ ALTER TYPE {{ conn|qtIdent(o_data.schema, o_data.name) }} {# Below will change the schema for object #} {# with extra if condition we will also make sure that object has correct name #} {% if data.schema and data.schema != o_data.schema %} -ALTER TYPE {% if data.name != o_data.name %}{{ conn|qtIdent(o_data.schema, data.name) }} -{% else %}{{ conn|qtIdent(o_data.schema, o_data.name) }}{% endif %} +ALTER TYPE {% if data.name and data.name != o_data.name %}{{ conn|qtIdent(o_data.schema, data.name) }} +{% else %}{{ conn|qtIdent(o_data.schema, o_data.name) }} +{% endif %} SET SCHEMA {{ conn|qtIdent(data.schema) }}; - {% endif %} {% endif %} \ No newline at end of file