codekingpro/portable-devtools
114k
1/////////////////////////////////////////////////////////////2//3// pgAdmin 4 - PostgreSQL Tools4//5// Copyright (C) 2013 - 2024, The pgAdmin Development Team6// This software is released under the PostgreSQL Licence7//8//////////////////////////////////////////////////////////////9import { getNodeAjaxOptions } from '../../../../../../static/js/node_ajax';10import CastSchema from './cast.ui';11import getApiInstance from '../../../../../../../static/js/api_instance';12 13define('pgadmin.node.cast', [14 'sources/gettext', 'sources/url_for',15 'sources/pgadmin', 'pgadmin.browser',16 'pgadmin.browser.collection',17], function(gettext, url_for, pgAdmin, pgBrowser) {18 // Extend the collection class for cast19 if (!pgBrowser.Nodes['coll-cast']) {20 pgAdmin.Browser.Nodes['coll-cast'] =21 pgAdmin.Browser.Collection.extend({22 node: 'cast',23 label: gettext('Casts'),24 type: 'coll-cast',25 columns: ['name', 'description'],26 });27 }28 29 // Extend the node class for cast30 if (!pgBrowser.Nodes['cast']) {31 pgAdmin.Browser.Nodes['cast'] = pgAdmin.Browser.Node.extend({32 parent_type: 'database',33 type: 'cast',34 sqlAlterHelp: 'sql-altercast.html',35 sqlCreateHelp: 'sql-createcast.html',36 dialogHelp: url_for('help.static', {'filename': 'cast_dialog.html'}),37 canDrop: true,38 canDropCascade: true,39 label: gettext('Cast'),40 hasSQL: true,41 hasDepends: true,42 Init: function() {43 44 // Avoid multiple registration of menus45 if (this.initialized)46 return;47 48 this.initialized = true;49 50 // Add context menus for cast51 pgBrowser.add_menus([{52 name: 'create_cast_on_database', node: 'database', module: this,53 applies: ['object', 'context'], callback: 'show_obj_properties',54 category: 'create', priority: 4, label: gettext('Cast...'),55 data: {action: 'create'},56 enable: pgBrowser.Nodes['database'].is_conn_allow,57 },{58 name: 'create_cast_on_coll', node: 'coll-cast', module: this,59 applies: ['object', 'context'], callback: 'show_obj_properties',60 category: 'create', priority: 4, label: gettext('Cast...'),61 data: {action: 'create'},62 },{63 name: 'create_cast', node: 'cast', module: this,64 applies: ['object', 'context'], callback: 'show_obj_properties',65 category: 'create', priority: 4, label: gettext('Cast...'),66 data: {action: 'create'},67 }]);68 69 },70 71 getSchema: function(treeNodeInfo, itemNodeData){72 return new CastSchema({73 getTypeOptions: ()=>getNodeAjaxOptions('get_type', this, treeNodeInfo, itemNodeData),74 getFuncOptions: (srcTyp, trgtyp) =>75 {76 return new Promise((resolve, reject)=>{77 const api = getApiInstance();78 79 let _url = pgBrowser.Nodes['cast'].generate_url(80 null, 'get_functions', itemNodeData, false,81 treeNodeInfo,82 );83 let data = {'srctyp' : srcTyp, 'trgtyp' : trgtyp};84 85 if(srcTyp != undefined && srcTyp != '' &&86 trgtyp != undefined && trgtyp != ''){87 88 api.post(_url, data)89 .then(res=>{90 data = res.data.data;91 resolve(data);92 })93 .catch((err)=>{94 reject(err);95 });96 } else {97 data = [];98 resolve(data);99 }100 });101 },102 },103 );104 },105 });106 107 }108 return pgBrowser.Nodes['coll-cast'];109});110 