Files
pgadmin4/web/pgadmin/browser/server_groups/static/js/server_group.js
Ashesh Vashi 845025db8f Some cosmetic changes.
- Loading 'pgadmin' as 'sources/pgadmin', as found under the 'sources'
  reference directory to be consistent with other files.
- Removed the 'pgadmin' reference from the base.html template.
- Renamed 'pgadmin.slickgrid.editors.js', and
  'pgadmin.slickgrid.formatters.js' as 'editors.js', and 'formatters.js'
  respectively, as they're already in the 'pgadmin/static/js/slickgrid'
  directory.
- Removed the duplicate entry of 'translations' from the webpack.shim.js
2017-08-09 16:52:12 +05:30

83 lines
2.6 KiB
JavaScript

define('pgadmin.node.server_group', [
'sources/gettext', 'sources/url_for', 'jquery', 'underscore', 'sources/pgadmin',
'backbone', 'pgadmin.browser', 'pgadmin.browser.node'
], function(gettext, url_for, $, _, pgAdmin, Backbone) {
if (!pgAdmin.Browser.Nodes['server_group']) {
pgAdmin.Browser.Nodes['server_group'] = pgAdmin.Browser.Node.extend({
parent_type: null,
type: 'server_group',
dialogHelp: url_for('help.static', {'filename': 'server_group_dialog.html'}),
label: gettext('Server Group'),
width: '350px',
height: '250px',
is_collection: true,
Init: function() {
/* Avoid multiple registration of menus */
if (this.initialized)
return;
this.initialized = true;
pgAdmin.Browser.add_menus([{
name: 'create_server_group', node: 'server_group', module: this,
applies: ['object', 'context'], callback: 'show_obj_properties',
category: 'create', priority: 1, label: gettext('Server Group...'),
data: {'action': 'create'}, icon: 'wcTabIcon icon-server_group'
}]);
},
model: pgAdmin.Browser.Node.Model.extend({
defaults: {
id: undefined,
name: null
},
schema: [
{
id: 'id', label: gettext('ID'), type: 'int', group: null,
mode: ['properties']
},{
id: 'name', label: gettext('Name'), type: 'text', group: null,
mode: ['properties', 'edit', 'create']
}
],
validate: function(attrs, options) {
var err = {},
errmsg = null;
this.errorModel.clear();
if (!this.isNew() && 'id' in this.changed) {
errmsg = gettext('The ID cannot be changed.');
this.errorModel.set('id', errmsg);
return errmsg;
}
if (_.isUndefined(this.get('name')) ||
_.isNull(this.get('name')) ||
String(this.get('name')).replace(/^\s+|\s+$/g, '') == '') {
errmsg = gettext('Name cannot be empty.');
this.errorModel.set('name', errmsg);
return errmsg;
}
return null;
}
}),
canDrop: function(itemData, item, data) {
if(itemData.can_delete) {
return true;
}
return false;
},
canDelete: function(i) {
var s = pgAdmin.Browser.tree.siblings(i, true);
/* This is the only server group - we can't remove it*/
if (!s || s.length == 0) {
return false;
}
return true;
}
});
}
return pgAdmin.Browser.Nodes['server_group'];
});