Commit | Line | Data |
---|---|---|
19b53e5b C |
1 | (function(angular, $, _) { |
2 | ||
3 | angular.module('api4').factory('crmApi4', function($q) { | |
4 | var crmApi4 = function(entity, action, params, index) { | |
5 | // JSON serialization in CRM.api4 is not aware of Angular metadata like $$hash, so use angular.toJson() | |
6 | var deferred = $q.defer(); | |
7 | var p; | |
8 | var backend = crmApi4.backend || CRM.api4; | |
9 | if (_.isObject(entity)) { | |
10 | // eval content is locally generated. | |
11 | /*jshint -W061 */ | |
12 | p = backend(eval('('+angular.toJson(entity)+')'), action); | |
13 | } else { | |
14 | // eval content is locally generated. | |
15 | /*jshint -W061 */ | |
16 | p = backend(entity, action, eval('('+angular.toJson(params)+')'), index); | |
17 | } | |
18 | p.then( | |
19 | function(result) { | |
20 | deferred.resolve(result); | |
21 | }, | |
22 | function(error) { | |
23 | deferred.reject(error); | |
24 | } | |
25 | ); | |
26 | return deferred.promise; | |
27 | }; | |
28 | crmApi4.backend = null; | |
29 | crmApi4.val = function(value) { | |
30 | var d = $.Deferred(); | |
31 | d.resolve(value); | |
32 | return d.promise(); | |
33 | }; | |
34 | return crmApi4; | |
35 | }); | |
36 | ||
37 | })(angular, CRM.$, CRM._); |