Skip to content

Commit

Permalink
Fixes #1076 - bug that made peer objects required
Browse files Browse the repository at this point in the history
  • Loading branch information
brianhyder committed Jul 19, 2016
1 parent 0849c2b commit d5f24b3
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
Expand Up @@ -194,7 +194,7 @@ module.exports = function(pb) {
}

//TODO: This is REALLY bad for large systems. This needs to move
//to an API call (searchable and pagable)
//to an API call (searchable and pageable)
var query = {
where: pb.DAO.ANYWHERE,
select: {
Expand Down
Expand Up @@ -40,7 +40,9 @@
</div>
<div class="form-group" ng-if="field.field_type == 'peer_object'">
<label ng-bind="field.name"></label>
<select class="form-control" ng-model="customObject[field.name]" ng-options="availableObject._id as availableObject.name for availableObject in field.available_objects"></select>
<select class="form-control" ng-model="customObject[field.name]" ng-options="availableObject._id as availableObject.name for availableObject in field.available_objects">
<option value=""></option>
</select>
</div>
<div id="{{field.name}}" class="form-group" ng-if="field.field_type == 'child_objects'">
<label ng-bind="field.name"></label>
Expand Down
Expand Up @@ -55,8 +55,8 @@
return true;
}
}
for(var i = 0; i < inactive.length; i++) {
if(itemToTest._id === inactive[i]._id) {
for(var j = 0; j < inactive.length; j++) {
if(itemToTest._id === inactive[j]._id) {
return true;
}
}
Expand Down Expand Up @@ -90,10 +90,12 @@

var saveObject = {type: $scope.objectType._id.toString()};
for(var i = 0; i < $scope.objectType.fields.length; i++) {
if($scope.objectType.fields[i].field_type === 'date') {
var fieldType = $scope.objectType.fields[i].field_type;

if(fieldType === 'date') {
saveObject[$scope.objectType.fields[i].name] = (new Date($filter('parsableDate')($scope.customObject[$scope.objectType.fields[i].name]))).getTime();
}
else if($scope.objectType.fields[i].field_type === 'child_objects') {
else if(fieldType === 'child_objects') {
var children = [];
for(var j = 0; j < $scope.customObject[$scope.objectType.fields[i].name].length; j++) {
children.push($scope.customObject[$scope.objectType.fields[i].name][j]._id.toString());
Expand All @@ -102,10 +104,15 @@
}
else {
saveObject[$scope.objectType.fields[i].name] = $scope.customObject[$scope.objectType.fields[i].name];

//this ensures that our validation will pass server-side. See #1076
if (!saveObject[$scope.objectType.fields[i].name] && fieldType == 'peer_object') {
saveObject[$scope.objectType.fields[i].name] = null;
}
}
}

var postURL = '/actions/admin/content/objects/' + $scope.objectType._id
var postURL = '/actions/admin/content/objects/' + $scope.objectType._id;
if($scope.customObject._id) {
postURL += '/' + $scope.customObject._id;
}
Expand Down

0 comments on commit d5f24b3

Please sign in to comment.