Skip to content

Commit

Permalink
#1307 Add custom field uniqueness validation
Browse files Browse the repository at this point in the history
  • Loading branch information
nadouani committed May 6, 2020
1 parent 4babc62 commit ec4a3d7
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
self.customField.options = (customField.options || []).join('\n');

var onSuccess = function(data) {
NotificationSrv.log('The Custom field has been successfully saved.', 'success');
$uibModalInstance.close(data);
};

Expand Down Expand Up @@ -57,28 +58,20 @@
.catch(onFailure);
} else {

CustomFieldsSrv.create(postData)
.then(onSuccess)
.catch(onFailure);

// ListSrv.exists({
// 'listId': 'custom_fields'
// }, {
// key: 'reference',
// value: postData.reference
// }, function(response) {
//
// if (response.toJSON().found === true) {
// form.name.$setValidity('unique', false);
// form.name.$setDirty();
// } else {
// ListSrv.save({
// 'listId': 'custom_fields'
// }, {
// 'value': postData
// }, onSuccess, onFailure);
// }
// }, onFailure);
CustomFieldsSrv.get(postData.reference)
.then(function() {
form.reference.$setValidity('unique', false);
form.reference.$setDirty();
}, function(err) {
if(err.status === 404) {
CustomFieldsSrv.create(postData)
.then(onSuccess)
.catch(onFailure);
}
})
.catch(function(err) {
NotificationSrv.error('AdminCustomFieldDialogCtrl', err.data, err.status);
});
}
};

Expand Down
10 changes: 0 additions & 10 deletions frontend/app/scripts/controllers/admin/AdminCustomFieldsCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,6 @@
size: 'lg',
resolve: {
customField: function() {
// return customField.id ? {
// id: customField.id,
// name: customField.reference,
// displayName: customField.name,
// description: customField.description,
// type: customField.type,
// options: customField.options,
// mandatory: customField.mandatory
// } : {};

return customField.id ? angular.copy(customField, {}) : {};
}
}
Expand Down
4 changes: 4 additions & 0 deletions frontend/app/scripts/services/api/CustomFieldsSrv.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
return $http.get('./api/customField');
};

this.get = function(idOrReference) {
return $http.get('./api/customField/' + idOrReference);
};

this.create = function(field) {
//return $http.post('./api/customField', self._convert(field));
return $http.post('./api/customField', field);
Expand Down

0 comments on commit ec4a3d7

Please sign in to comment.