1
1
2
2
var RestangularBase = {
3
3
getRestangularUrl : function ( ) {
4
- return this . $urlHandler . fetchUrl ( this ) ;
4
+ return this . $service . urlHandler . fetchUrl ( this ) ;
5
5
} ,
6
6
getRequestedUrl : function ( ) {
7
- return this . $urlHandler . fetchRequestedUrl ( this ) ;
7
+ return this . $service . urlHandler . fetchRequestedUrl ( this ) ;
8
8
} ,
9
9
clone : function ( ) {
10
10
var copiedElement = _ . cloneDeep ( this ) ;
11
11
// TODO remove restangularizeElem() call
12
- return this . $restangularizeElem ( copiedElement [ this . $config . restangularFields . parentResource ] ,
12
+ return this . $service . restangularizeElem ( copiedElement [ this . $config . restangularFields . parentResource ] ,
13
13
copiedElement , copiedElement [ this . $config . restangularFields . route ] , true ) ;
14
- }
14
+ } ,
15
+
16
+ addRestangularMethod : function ( name , operation , path , defaultParams , defaultHeaders , defaultElem ) {
17
+ var bindedFunction ;
18
+ if ( operation === 'getList' ) {
19
+ bindedFunction = _ . bind ( fetchFunction , this , path ) ;
20
+ } else {
21
+ bindedFunction = _ . bind ( customFunction , this , operation , path ) ;
22
+ }
23
+
24
+ var createdFunction = function ( params , headers , elem ) {
25
+ var callParams = _ . defaults ( {
26
+ params : params ,
27
+ headers : headers ,
28
+ elem : elem
29
+ } , {
30
+ params : defaultParams ,
31
+ headers : defaultHeaders ,
32
+ elem : defaultElem
33
+ } ) ;
34
+ return bindedFunction ( callParams . params , callParams . headers , callParams . elem ) ;
35
+ } ;
36
+
37
+ if ( this . $config . isSafe ( operation ) ) {
38
+ this [ name ] = createdFunction ;
39
+ } else {
40
+ this [ name ] = function ( elem , params , headers ) {
41
+ return createdFunction ( params , headers , elem ) ;
42
+ } ;
43
+ }
44
+ } ,
45
+
46
+ plain : function ( ) {
47
+ this . $service . stripRestangular ( this ) ;
48
+ } ,
49
+
50
+ one : function ( /*parent, route, id, singleOne*/ ) {
51
+ return this . $service . one . apply ( this . $service , [ this ] . concat ( arguments ) ) ;
52
+ } ,
53
+
54
+ all :function ( /*parent, route*/ ) {
55
+ return this . $service . all . apply ( this . $service , [ this ] . concat ( arguments ) ) ;
56
+ } ,
57
+
58
+ several : function ( /*parent, route , ..ids */ ) {
59
+ return this . $service . serveral . apply ( this . $service , [ this ] . concat ( arguments ) ) ;
60
+ } ,
61
+
62
+ oneUrl : function ( /*parent, route, url*/ ) {
63
+ return this . $service . oneUrl . apply ( this . $service , [ this ] . concat ( arguments ) ) ;
64
+ } ,
65
+
66
+ allUrl : function ( /*parent, route, url*/ ) {
67
+ return this . $service . allUrl . apply ( this . $service , [ this ] . concat ( arguments ) ) ;
68
+ } ,
69
+
70
+ remove :function ( params , headers ) {
71
+ return _ . bind ( elemFunction , this ) ( 'remove' , undefined , params , undefined , headers ) ;
72
+ } ,
73
+
74
+ head : function ( params , headers ) {
75
+ return _ . bind ( elemFunction , this ) ( 'head' , undefined , params , undefined , headers ) ;
76
+ } ,
77
+
78
+ trace : function ( params , headers ) {
79
+ return _ . bind ( elemFunction , this ) ( 'trace' , undefined , params , undefined , headers ) ;
80
+ } ,
81
+
82
+ options : function ( params , headers ) {
83
+ return _ . bind ( elemFunction , this ) ( 'options' , undefined , params , undefined , headers ) ;
84
+ } ,
85
+
86
+ patch : function ( elem , params , headers ) {
87
+ return _ . bind ( elemFunction , this ) ( 'patch' , undefined , params , elem , headers ) ;
88
+ } ,
89
+
90
+ restangularized : true
15
91
16
92
} ;
93
+
94
+ function addCustomOperation ( elem ) {
95
+ elem [ config . restangularFields . customOperation ] = _ . bind ( customFunction , elem ) ;
96
+ _ . each ( [ 'put' , 'post' , 'get' , 'delete' ] , function ( oper ) {
97
+ _ . each ( [ 'do' , 'custom' ] , function ( alias ) {
98
+ var callOperation = oper === 'delete' ? 'remove' : oper ;
99
+ var name = alias + oper . toUpperCase ( ) ;
100
+ var callFunction ;
101
+
102
+ if ( callOperation !== 'put' && callOperation !== 'post' ) {
103
+ callFunction = customFunction ;
104
+ } else {
105
+ callFunction = function ( operation , elem , path , params , headers ) {
106
+ return _ . bind ( customFunction , this ) ( operation , path , params , headers , elem ) ;
107
+ } ;
108
+ }
109
+ elem [ name ] = _ . bind ( callFunction , elem , callOperation ) ;
110
+ } ) ;
111
+ } ) ;
112
+ elem [ config . restangularFields . customGETLIST ] = _ . bind ( fetchFunction , elem ) ;
113
+ elem [ config . restangularFields . doGETLIST ] = elem [ config . restangularFields . customGETLIST ] ;
114
+ }
115
+
116
+
117
+ function customFunction ( operation , path , params , headers , elem ) {
118
+ return _ . bind ( elemFunction , this ) ( operation , path , params , elem , headers ) ;
119
+ }
0 commit comments