Defined SwitchDepsCell in the schema javascript module, because - it

will be loaded before every other javascript module requires this Cell.
This commit is contained in:
Ashesh Vashi 2016-05-25 01:00:57 +05:30
parent 05dde57651
commit d20db0f43e
4 changed files with 40 additions and 37 deletions

View File

@ -140,9 +140,10 @@ function($, _, S, pgAdmin, pgBrowser, Backform, alertify) {
cellHeaderClasses:'width_percent_30',
editable: 'editable_check_for_table'
},{
// Need to show this field only when creating new table [in SubNode control]
id: 'is_primary_key', label: '{{ _('Is primary key?') }}', cell: SwitchDepCell,
type: 'switch', deps:['name'],
// Need to show this field only when creating new table
// [in SubNode control]
id: 'is_primary_key', label: '{{ _('Is primary key?') }}',
cell: Backgrid.Extension.SwitchDepCell, type: 'switch', deps:['name'],
options: {
onText: 'Yes', offText: 'No', onColor: 'success',
offColor: 'primary', size: 'small'},

View File

@ -99,8 +99,9 @@ function($, _, S, pgAdmin, pgBrowser, Backform, alertify) {
return options;
}
},{
id: 'sort_order', label:'{{ _('Sort order') }}', cell: SwitchDepCell,
type: 'switch', disabled: 'checkAccessMethod',
id: 'sort_order', label:'{{ _('Sort order') }}',
cell: Backgrid.ExtensionSwitchDepCell, type: 'switch',
disabled: 'checkAccessMethod',
editable: function(m) {
// Header cell then skip
if (m instanceof Backbone.Collection) {
@ -115,8 +116,9 @@ function($, _, S, pgAdmin, pgBrowser, Backform, alertify) {
'size': 'small'
}
},{
id: 'nulls', label:'{{ _('NULLs') }}', cell: SwitchDepCell,
type: 'switch', disabled: 'checkAccessMethod',
id: 'nulls', label:'{{ _('NULLs') }}',
cell: Backgrid.Extension.SwitchDepCell, type: 'switch',
disabled: 'checkAccessMethod',
editable: function(m) {
// Header cell then skip
if (m instanceof Backbone.Collection) {

View File

@ -16,33 +16,6 @@ function($, _, S, pgAdmin, pgBrowser, alertify) {
});
};
// Switch Cell with Deps
var SwitchDepCell = Backgrid.Extension.SwitchCell.extend({
initialize: function() {
Backgrid.Extension.SwitchCell.prototype.initialize.apply(this, arguments);
Backgrid.Extension.DependentCell.prototype.initialize.apply(this, arguments);
},
dependentChanged: function () {
var model = this.model,
column = this.column,
editable = this.column.get("editable"),
input = this.$el.find('input[type=checkbox]').first();
is_editable = _.isFunction(editable) ? !!editable.apply(column, [model]) : !!editable;
if (is_editable) {
this.$el.addClass("editable");
input.prop('disabled', false);
} else {
this.$el.removeClass("editable");
input.prop('disabled', true);
}
this.delegateEvents();
return this;
},
remove: Backgrid.Extension.DependentCell.prototype.remove
});
if (!pgBrowser.Nodes['table']) {
pgAdmin.Browser.Nodes['table'] = pgBrowser.Node.extend({
type: 'table',

View File

@ -128,7 +128,7 @@ function($, _, S, pgAdmin, pgBrowser, Backform, alertify) {
});
// Extend the browser's collection class for VacuumSettingsModel
var VacuumSettingsSchema = Backform.VacuumSettingsSchema =
var VacuumSettingsSchema = Backform.VacuumSettingsSchema =
[{
id: 'autovacuum_custom', label: '{{ _("Custom auto-vacuum?") }}',
group: '{{ _("Table") }}', mode: ['edit', 'create'],
@ -476,9 +476,36 @@ function($, _, S, pgAdmin, pgBrowser, Backform, alertify) {
// by default we do not want to allow create menu
return true;
}
});
});
}
// Switch Cell with Deps
var SwitchDepCell = Backgrid.Extension.SwitchCell.extend({
initialize: function() {
Backgrid.Extension.SwitchCell.prototype.initialize.apply(this, arguments);
Backgrid.Extension.DependentCell.prototype.initialize.apply(this, arguments);
},
dependentChanged: function () {
var model = this.model,
column = this.column,
editable = this.column.get("editable"),
input = this.$el.find('input[type=checkbox]').first();
is_editable = _.isFunction(editable) ? !!editable.apply(column, [model]) : !!editable;
if (is_editable) {
this.$el.addClass("editable");
input.prop('disabled', false);
} else {
this.$el.removeClass("editable");
input.prop('disabled', true);
}
this.delegateEvents();
return this;
},
remove: Backgrid.Extension.DependentCell.prototype.remove
});
return pgBrowser.Nodes['schema'];
});