app service CrudHelper function this addObject function model objectsL

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
app.service('CrudHelper', function() {
this.addObject = function(model, objectsList, modalHelper, resource) {
var modalInstance = modalHelper.getModal(model, resource.save);
return modalInstance.result.then(function(object) {
objectsList.push(object);
});
};
this.editObject = function(object, objectsList, modalHelper, resoruce) {
var objectIndex = objectsList.indexOf(object);
var objectCopy = angular.copy(object);
var modalInstance = modalHelper.getModal(objectCopy, resoruce.update);
return modalInstance.result.then(function(updatedObject) {
if (objectIndex > -1) {
objectsList.splice(objectIndex, 1, updatedObject);
}
})
};
this.removeObject = function(object, objectsList, resource) {
var index = objectsList.indexOf(object);
return resource.delete({id: object.id}).$promise.then(function() {
if (index > -1) {
objectsList.splice(index, 1);
}
});
}
});