@@ -26,12 +26,28 @@ private static String getJsCode() {
2626 }
2727 return "" ;
2828 }
29+
30+ /**
31+ * Submits an existing form
32+ * @param formRef the Vuejs form ref
33+ * @param action the action (url for submit)
34+ * @param successCallback the javascript code to execute if success (parameter response)
35+ * @param errorCallback the javascript code to execute on error (parameter response)
36+ * @return
37+ */
2938 public static String submitForm (String formRef ,String action ,String successCallback ,String errorCallback ) {
3039 String result = getJsCode ()+"let form=this.$refs['" +formRef +"'];" +
3140 "let formData=form.model;" +request ("form.$vnode.data.attrs.method.toLowerCase()" , action , "formData" , successCallback ,errorCallback );
3241 return result ;
3342 }
3443
44+ /**
45+ * Submits an existing form
46+ * @param formRef the Vuejs form ref
47+ * @param action the action (url for submit)
48+ * @param successCallback the javascript code to execute if success (parameter response)
49+ * @return
50+ */
3551 public static String submitForm (String formRef ,String action ,String successCallback ) {
3652 return submitForm (formRef , action , successCallback , null );
3753 }
@@ -46,6 +62,15 @@ public static String submitForm(String formRef,String successCallback) {
4662 return Http .submitForm (formRef , "form.$vnode.data.attrs.action" , successCallback ,null );
4763 }
4864
65+ /**
66+ * Sends a request
67+ * @param method the http method (get,post,delete,patch,put,options,head)
68+ * @param url the url to request
69+ * @param data the data to send to the request
70+ * @param successCallback the javascript code to execute if success (parameter response)
71+ * @param errorCallback the javascript code to execute on error (parameter response)
72+ * @return
73+ */
4974 public static String request (String method ,String url ,Object data ,String successCallback ,String errorCallback ){
5075 if (!url .contains ("$" )&& !url .startsWith ("this" )) {
5176 url ="'" +url +"'" ;
@@ -66,86 +91,233 @@ public static String request(String method,String url,Object data,String success
6691 return result ;
6792 }
6893
94+ /**
95+ * Sends a request
96+ * @param method the http method (get,post,delete,patch,put,options,head)
97+ * @param url the url to request
98+ * @param data the data to send to the request
99+ * @param successCallback the javascript code to execute if success (parameter response)
100+ * @return
101+ */
69102 public static String request (String method ,String url ,Object data ,String successCallback ) {
70103 return request (method , url , data , successCallback , null );
71104 }
72105
106+ /**
107+ * Sends a get request
108+ * @param url the url to request
109+ * @param data the data to send to the request
110+ * @param successCallback the javascript code to execute if success (parameter response)
111+ * @param errorCallback the javascript code to execute on error (parameter response)
112+ * @return
113+ */
73114 public static String get (String url ,Object data ,String successCallback ,String errorCallback ) {
74115 return request ("'get'" , url , data , successCallback , errorCallback );
75116 }
76117
118+ /**
119+ * Sends a get request
120+ * @param url the url to request
121+ * @param data the data to send to the request
122+ * @param successCallback the javascript code to execute if success (parameter response)
123+ * @return
124+ */
77125 public static String get (String url ,Object data ,String successCallback ) {
78126 return request ("'get'" , url , data , successCallback , null );
79127 }
80128
129+ /**
130+ * Sends a get request
131+ * @param url the url to request
132+ * @param successCallback the javascript code to execute if success (parameter response)
133+ * @return
134+ */
81135 public static String get (String url ,String successCallback ) {
82136 return request ("'get'" , url , "{}" , successCallback , null );
83137 }
84138
139+ /**
140+ * Sends a get request
141+ * @param url the url to request
142+ * @param successCallback the javascript code to execute if success (parameter response)
143+ * @param errorCallback the javascript code to execute on error (parameter response)
144+ * @return
145+ */
85146 public static String get (String url ,String successCallback ,String errorCallback ) {
86147 return request ("'get'" , url , "{}" , successCallback , errorCallback );
87148 }
88149
150+ /**
151+ * Sends a delete request
152+ * @param url the url to request
153+ * @param data the data to send to the request
154+ * @param successCallback the javascript code to execute if success (parameter response)
155+ * @param errorCallback the javascript code to execute on error (parameter response)
156+ * @return
157+ */
89158 public static String delete (String url ,Object data ,String successCallback ,String errorCallback ) {
90159 return request ("'delete'" , url , data , successCallback , errorCallback );
91160 }
92161
162+ /**
163+ * Sends a delete request
164+ * @param url the url to request
165+ * @param data the data to send to the request
166+ * @param successCallback the javascript code to execute if success (parameter response)
167+ * @return
168+ */
93169 public static String delete (String url ,Object data ,String successCallback ) {
94170 return request ("'delete'" , url , data , successCallback , null );
95171 }
96172
173+ /**
174+ * Sends a delete request
175+ * @param url the url to request
176+ * @param successCallback the javascript code to execute if success (parameter response)
177+ * @return
178+ */
97179 public static String delete (String url ,String successCallback ) {
98180 return request ("'delete'" , url , "{}" , successCallback , null );
99181 }
100182
183+ /**
184+ * Sends a delete request
185+ * @param url the url to request
186+ * @param successCallback the javascript code to execute if success (parameter response)
187+ * @param errorCallback the javascript code to execute on error (parameter response)
188+ * @return
189+ */
101190 public static String delete (String url ,String successCallback ,String errorCallback ) {
102191 return request ("'delete'" , url , "{}" , successCallback , errorCallback );
103192 }
104193
194+ /**
195+ * Sends a put request
196+ * @param url the url to request
197+ * @param data the data to send to the request
198+ * @param successCallback the javascript code to execute if success (parameter response)
199+ * @param errorCallback the javascript code to execute on error (parameter response)
200+ * @return
201+ */
105202 public static String put (String url ,Object data ,String successCallback ,String errorCallback ) {
106203 return request ("'put'" , url , data , successCallback , errorCallback );
107204 }
108205
206+ /**
207+ * Sends a put request
208+ * @param url the url to request
209+ * @param data the data to send to the request
210+ * @param successCallback the javascript code to execute if success (parameter response)
211+ * @return
212+ */
109213 public static String put (String url ,Object data ,String successCallback ) {
110214 return request ("'put'" , url , data , successCallback , null );
111215 }
112216
217+ /**
218+ * Sends a put request
219+ * @param url the url to request
220+ * @param successCallback the javascript code to execute if success (parameter response)
221+ * @return
222+ */
113223 public static String put (String url ,String successCallback ) {
114224 return request ("'put'" , url , "{}" , successCallback , null );
115225 }
116226
227+ /**
228+ * Sends a put request
229+ * @param url the url to request
230+ * @param successCallback the javascript code to execute if success (parameter response)
231+ * @param errorCallback the javascript code to execute on error (parameter response)
232+ * @return
233+ */
117234 public static String put (String url ,String successCallback ,String errorCallback ) {
118235 return request ("'put'" , url , "{}" , successCallback , errorCallback );
119236 }
120237
238+ /**
239+ * Sends a patch request
240+ * @param url the url to request
241+ * @param data the data to send to the request
242+ * @param successCallback the javascript code to execute if success (parameter response)
243+ * @param errorCallback the javascript code to execute on error (parameter response)
244+ * @return
245+ */
121246 public static String patch (String url ,Object data ,String successCallback ,String errorCallback ) {
122247 return request ("'patch'" , url , data , successCallback , errorCallback );
123248 }
124249
250+ /**
251+ * Sends a patch request
252+ * @param url the url to request
253+ * @param data the data to send to the request
254+ * @param successCallback the javascript code to execute if success (parameter response)
255+ * @return
256+ */
125257 public static String patch (String url ,Object data ,String successCallback ) {
126258 return request ("'patch'" , url , data , successCallback , null );
127259 }
128260
261+ /**
262+ * Sends a patch request
263+ * @param url the url to request
264+ * @param successCallback the javascript code to execute if success (parameter response)
265+ * @return
266+ */
129267 public static String patch (String url ,String successCallback ) {
130268 return request ("'patch'" , url , "{}" , successCallback , null );
131269 }
132270
271+ /**
272+ * Sends a patch request
273+ * @param url the url to request
274+ * @param successCallback the javascript code to execute if success (parameter response)
275+ * @param errorCallback the javascript code to execute on error (parameter response)
276+ * @return
277+ */
133278 public static String patch (String url ,String successCallback ,String errorCallback ) {
134279 return request ("'patch'" , url , "{}" , successCallback , errorCallback );
135280 }
136281
282+ /**
283+ * Sends a post request
284+ * @param url the url to request
285+ * @param data the data to send to the request
286+ * @param successCallback the javascript code to execute if success (parameter response)
287+ * @param errorCallback the javascript code to execute on error (parameter response)
288+ * @return
289+ */
137290 public static String post (String url ,Object data ,String successCallback ,String errorCallback ) {
138291 return request ("'post'" , url , data , successCallback , errorCallback );
139292 }
140293
294+ /**
295+ * Sends a post request
296+ * @param url the url to request
297+ * @param data the data to send to the request
298+ * @param successCallback the javascript code to execute if success (parameter response)
299+ * @return
300+ */
141301 public static String post (String url ,Object data ,String successCallback ) {
142302 return request ("'post'" , url , data , successCallback , null );
143303 }
144304
305+ /**
306+ * Sends a post request
307+ * @param url the url to request
308+ * @param successCallback the javascript code to execute if success (parameter response)
309+ * @return
310+ */
145311 public static String post (String url ,String successCallback ) {
146312 return request ("'post'" , url , "{}" , successCallback , null );
147313 }
148314
315+ /**
316+ * Defines a request header
317+ * @param key the header key
318+ * @param value the header value
319+ * @return
320+ */
149321 public static String setRequestHeader (String key , String value ) {
150322 return "this.$http.headers.set('" +key +"', '" +value +"');" ;
151323 }
0 commit comments