Passing the version_compability information in the controls, and use

them in the custom controls.

This commit also includes the patch from Harshal regarding the broken
updateInvalidate(..) function.
This commit is contained in:
Ashesh Vashi
2016-01-12 12:01:45 +05:30
parent f8fd93c207
commit 5b9b55ee8e
3 changed files with 61 additions and 32 deletions

View File

@@ -91,7 +91,7 @@
self.availVariables = opts.column.get('availVariables');
var variable = (self.availVariables[name]),
cell = self.variableCellMapper[variable.vartype] || Backgrid.Cell;
cell = self.variableCellMapper[variable && variable.vartype] || Backgrid.Cell;
/*
* Set properties for dynamic cell.
@@ -102,7 +102,7 @@
DynamicVariableCell.__super__.initialize.apply(self, arguments);
switch(variable.vartype) {
switch(variable && variable.vartype) {
case "bool":
// There are no specific properties for BooleanCell.
break;
@@ -221,6 +221,7 @@
},
availVariables: self.availVariables,
node: node, first_empty: false,
version_compitible: self.field.get('version_compitible'),
transform: function(vars) {
var self = this,
opts = self.field.get('availVariables');
@@ -251,6 +252,7 @@
headerSchema.push({
id: 'database', label:'', type: 'text', cache_level: 'server',
control: Backform.NodeListByNameControl, node: 'database',
version_compitible: self.field.get('version_compitible')
});
headerDefaults['database'] = null;
gridCols.push('database');
@@ -259,7 +261,8 @@
if (self.hasRole) {
headerSchema.push({
id: 'role', label:'', type: 'text', cache_level: 'server',
control: Backform.NodeListByNameControl, node: 'role'
control: Backform.NodeListByNameControl, node: 'role',
version_compitible: self.field.get('version_compitible')
});
headerDefaults['role'] = null;
gridCols.push('role');
@@ -296,14 +299,14 @@
},
/*
* Get the variable options for this control.
* Get the variable data for this node.
*/
getVariables: function() {
var self = this,
url = this.field.get('url'),
m = self.model;
if (url && !m.isNew()) {
if (this.field.get('version_compitible') && url && !m.isNew()) {
var node = self.field.get('node'),
node_data = self.field.get('node_data'),
node_info = self.field.get('node_info'),
@@ -333,6 +336,7 @@
*/
self.collection.startNewSession();
}
} else {
}
},
@@ -342,11 +346,11 @@
" <div class='container-fluid'>",
" <div class='row'>",
" <div class='col-md-4'>",
" <label class='control-label'>Variable name</label>",
" <label class='control-label'><%-variable_label%></label>",
" </div>",
" <div class='col-md-4' header='name'></div>",
" <div class='col-md-4'>",
" <button class='btn-sm btn-default add'>Add</buttton>",
" <button class='btn-sm btn-default add' <%=canAdd ? \"\" : \"disabled\"%>><%-add_label%></buttton>",
" </div>",
" </div>"];
@@ -354,7 +358,7 @@
header.push([
" <div class='row'>",
" <div class='col-md-4'>",
" <label class='control-label'>Database</label>",
" <label class='control-label'><%-database_label%></label>",
" </div>",
" <div class='col-md-4' header='database'></div>",
" </div>"].join("\n")
@@ -365,7 +369,7 @@
header.push([
" <div class='row'>",
" <div class='col-md-4'>",
" <label class='control-label'>Role</label>",
" <label class='control-label'>>%-role_label%></label>",
" </div>",
" <div class='col-md-4' header='role'></div>",
" </div>"].join("\n")
@@ -376,8 +380,17 @@
" </div>",
"</div>"].join("\n"));
// TODO:: Do the i18n
_.extend(data, {
variable_label: "Variable Name",
add_label: "ADD",
database_label: "Database",
role_label: "Role"
});
var self = this,
$header = $(header.join("\n")),
headerTmpl = _.template(header.join("\n")),
$header = $(headerTmpl(data)),
controls = this.controls;
this.headerFields.each(function(field) {
@@ -393,8 +406,8 @@
controls.push(control);
});
// Set visibility of Add button
if (data.disabled || data.canAdd == false) {
// We should not show add but in properties mode
if (data.mode == 'properties') {
$header.find("button.add").remove();
}

View File

@@ -93,7 +93,8 @@ function($, _, pgAdmin, Backbone, Backform, Alertify, Node) {
*/
var data = cache_node.cache(url, node_info, cache_level);
if (_.isUndefined(data) || _.isNull(data)) {
if (this.field.get('ver_in_limit') &&
(_.isUndefined(data) || _.isNull(data))) {
m.trigger('pgadmin:view:fetching', m, self.field);
$.ajax({
async: false,

View File

@@ -645,14 +645,18 @@
self.model.set(self.field.get('name'), collection, {silent: true});
}
self.listenTo(collection, "add", self.collectionChanged);
self.listenTo(collection, "change", self.collectionChanged);
if (this.field.get('version_compitible')) {
self.listenTo(collection, "add", self.collectionChanged);
self.listenTo(collection, "change", self.collectionChanged);
}
},
remove: function() {
var self = this;
self.stopListening(collection, "add", self.collectionChanged);
self.stopListening(collection, "change", self.collectionChanged);
if (this.field.get('version_compitible')) {
self.stopListening(collection, "add", self.collectionChanged);
self.stopListening(collection, "change", self.collectionChanged);
}
Backform.Control.prototype.remove.apply(this, arguments);
},
@@ -746,12 +750,18 @@
// Evaluate the disabled, visible, required, canAdd, & canDelete option
_.extend(data, {
disabled: evalF(data.disabled, this.model),
visible: evalF(data.visible, this.model),
required: evalF(data.required, this.model),
canAdd: evalF(data.canAdd, this.model),
canDelete: evalF(data.canDelete, this.model)
disabled: (field.version_compitible &&
evalF.apply(this.field, [data.disabled, this.model])
),
visible: evalF.apply(this.field, [data.visible, this.model]),
required: evalF.apply(this.field, [data.required, this.model]),
canAdd: (field.version_compitible &&
evalF.apply(this.field, [data.canAdd, this.model])
),
canDelete: evalF.apply(this.field, [data.canDelete, this.model])
});
_.extend(data, {add_label: "ADD"});
// Show Backgrid Control
grid = this.showGridControl(data);
@@ -761,11 +771,14 @@
return this;
},
showGridControl: function(data) {
var gridHeader = ["<div class='subnode-header'>",
" <label class='control-label col-sm-4'>" + data.label + "</label>" ,
" <button class='btn-sm btn-default add'>Add</buttton>",
"</div>"].join("\n"),
gridBody = $("<div class='pgadmin-control-group backgrid form-group col-xs-12 object subnode-body'></div>").append(gridHeader);
var gridHeader = _.template([
'<div class="subnode-header">',
' <label class="control-label col-sm-4"><%-label%></label>',
' <button class="btn-sm btn-default add" <%= canAdd ? "" : "disabled"%>><%-add_label%></buttton>',
'</div>'].join("\n")),
gridBody = $('<div class="pgadmin-control-group backgrid form-group col-xs-12 object subnode-body"></div>').append(
gridHeader(data)
);
if (!(data.subnode)) {
return '';
@@ -778,12 +791,12 @@
self = this;
// Set visibility of Add button
if (data.disabled || data.canAdd == false) {
if (data.mode == 'properties') {
$(gridBody).find("button.add").remove();
}
// Insert Delete Cell into Grid
if (data.disabled == false && data.canDelete) {
if (!data.disabled && data.canDelete) {
gridSchema.columns.unshift({
name: "pg-backform-delete", label: "",
cell: Backgrid.Extension.DeleteCell,
@@ -792,6 +805,7 @@
}
var collection = this.model.get(data.name);
// Initialize a new Grid instance
var grid = self.grid = new Backgrid.Grid({
columns: gridSchema.columns,
@@ -858,7 +872,7 @@
this.clearInvalid();
this.$el.find('.subnode-body').each(function(ix, el) {
var error = self.keyPathAccessor(errorModel.toJSON(), this.field.get('name'));
var error = self.keyPathAccessor(errorModel.toJSON(), self.field.get('name'));
if (_.isEmpty(error)) return;
@@ -1207,7 +1221,7 @@
};
groups = {},
server_info = node_info && ('server' in node_info) &&
pgBrowser.serverInfo && pgBrowser.serverInfo[node_info.server.id];
pgBrowser.serverInfo && pgBrowser.serverInfo[node_info.server._id];
_.each(schema, function(s) {
// Do we understand - what control, we're creating
@@ -1259,7 +1273,8 @@
(ver_in_limit ?
(s.version || true) : false) : s.version || true),
node: node,
node_data: treeData
node_data: treeData,
version_compitible: ver_in_limit
});
delete o.id;