Allow the privileges control to work properly. Resolved few typos and

trivial bugs within the privilige control.

i.e.
- Do not show 'ALL' for only one privilege type.
- Show correct privilege label in PrivilegeEditor.
- Typo in TEMPORARY privilege.
- Added missing toJSON function call, while calling the parent's toJSON
  function.
This commit is contained in:
Harshal Dhumal
2016-01-20 20:22:42 +05:30
committed by Ashesh Vashi
parent 3b1bbe55fa
commit 422bad4394

View File

@@ -41,6 +41,9 @@
privilege_type: undefined, privilege_type: undefined,
privilege: false, privilege: false,
with_grant: false with_grant: false
},
validate: function() {
return null;
} }
}); });
@@ -154,7 +157,7 @@
toJSON: function(session) { toJSON: function(session) {
if (session) { if (session) {
return pgNode.Model.prototype.apply(this, [true, false]); return pgNode.Model.prototype.toJSON.apply(this, arguments);
} }
var privileges = []; var privileges = [];
@@ -171,6 +174,10 @@
'grantor': this.get('grantor'), 'grantor': this.get('grantor'),
'privileges': privileges 'privileges': privileges
}; };
},
validate: function() {
return null;
} }
}); });
@@ -185,7 +192,7 @@
// generating the label for the specific Control // generating the label for the specific Control
Labels: { Labels: {
"C": "CREATE", "C": "CREATE",
"T": "TEMP", "T": "TEMPORARY",
"c": "CONNECT", "c": "CONNECT",
"a": "INSERT", "a": "INSERT",
"r": "SELECT", "r": "SELECT",
@@ -203,7 +210,7 @@
' <td class="renderable">', ' <td class="renderable">',
' <label>', ' <label>',
' <input type="checkbox" name="privilege" privilege="<%- privilege_type %>" target="<%- target %>" <%= privilege ? \'checked\' : "" %>></input>', ' <input type="checkbox" name="privilege" privilege="<%- privilege_type %>" target="<%- target %>" <%= privilege ? \'checked\' : "" %>></input>',
' <%- privilege_type %>', ' <%- privilege_label %>',
' </label>', ' </label>',
' </td>', ' </td>',
' <td class="renderable">', ' <td class="renderable">',
@@ -234,27 +241,32 @@
collection.each(function(m) { collection.each(function(m) {
var d = m.toJSON(); var d = m.toJSON();
privilege = (privilege && d.privilege);
with_grant = (with_grant && privilege && d.with_grant);
_.extend( _.extend(
d, { d, {
'target': self.cid, 'target': self.cid,
'header': false 'header': false,
'privilege_label': self.Labels[d.privilege_type]
}); });
privilege = (privilege && d.privilege); privilege = (privilege && d.privilege);
with_grant = (with_grant && privilege && d.with_grant); with_grant = (with_grant && privilege && d.with_grant);
tbl.append(self.template(d)); tbl.append(self.template(d));
}); });
// Preprend the ALL controls on that table if (collection.length > 1) {
tbl.prepend( // Preprend the ALL controls on that table
self.template({ tbl.prepend(
'target': self.cid, self.template({
'name': 'ALL', 'target': self.cid,
'privilege_type': 'ALL', 'privilege_label': 'ALL',
'privilege': privilege, 'privilege_type': 'ALL',
'with_grant': with_grant, 'privilege': privilege,
'header': true 'with_grant': with_grant,
})); 'header': true
}));
}
self.$el.find('input[type=checkbox]').first().focus(); self.$el.find('input[type=checkbox]').first().focus();
// Since blur event does not bubble we need to explicitly call parent's blur event. // Since blur event does not bubble we need to explicitly call parent's blur event.
$(self.$el.find('input[type=checkbox]')).on('blur',function() { $(self.$el.find('input[type=checkbox]')).on('blur',function() {
@@ -279,7 +291,7 @@
checked = $el.prop('checked'), checked = $el.prop('checked'),
$tr = $el.closest('tr'), $tr = $el.closest('tr'),
$tbl = $tr.closest('table'), $tbl = $tr.closest('table'),
collection = this.model.get('privileges');; collection = this.model.get('privileges');
/* /*
* If the checkbox selected/deselected is for 'ALL', we will select all * If the checkbox selected/deselected is for 'ALL', we will select all
@@ -383,7 +395,8 @@
'input[name=privilege][privilege!=\'ALL\']:checked' 'input[name=privilege][privilege!=\'ALL\']:checked'
); );
if ($allPrivileges.length == collection.models.length) { if ($allPrivileges.length > 1 &&
$allPrivileges.length == collection.models.length) {
$allPrivilege.prop('checked', true); $allPrivilege.prop('checked', true);
@@ -469,7 +482,7 @@
if (rawData instanceof Backbone.Collection) { if (rawData instanceof Backbone.Collection) {
rawData.each(function(m) { rawData.each(function(m) {
if (m.get('privilege')) { if (m.get('privilege')) {
res += self.notation[m.get('privilege_type')]; res += m.get('privilege_type');
if (m.get('with_grant')) { if (m.get('with_grant')) {
res += '*'; res += '*';
} }