Fix a couple of issues with the unique-collection control:

- Pass the data to evaluation functions like canEdit, canAdd
- Properly honour the canAdd option.
This commit is contained in:
Khushboo Vashi
2016-03-11 09:36:26 +00:00
committed by Dave Page
parent d21e60cc60
commit 2f334673a3
2 changed files with 29 additions and 22 deletions

View File

@@ -528,21 +528,26 @@
checkVars.push('role');
}
self.collection.each(function(m) {
if (!inSelected) {
var has = true;
_.each(checkVars, function(v) {
val = m.get(v);
has = has && ((
(_.isUndefined(val) || _.isNull(val)) &&
(_.isUndefined(data[v]) || _.isNull(data[v]))
) ||
(val == data[v]));
});
if (self.control_data.canAdd) {
self.collection.each(function(m) {
if (!inSelected) {
var has = true;
_.each(checkVars, function(v) {
val = m.get(v);
has = has && ((
(_.isUndefined(val) || _.isNull(val)) &&
(_.isUndefined(data[v]) || _.isNull(data[v]))
) ||
(val == data[v]));
});
inSelected = has;
}
});
inSelected = has;
}
});
}
else {
inSelected = true;
}
self.$header.find('button.add').prop('disabled', inSelected);
},