Rev 1686 | Rev 1724 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1576 | jmachado | 1 | /** |
2 | * Created by jorgemachado on 28/12/16. |
||
3 | */ |
||
4 | /** |
||
5 | * |
||
6 | * @param serviceName |
||
7 | * @param form |
||
8 | * @param handlerOk(responseObjJson) |
||
9 | * @param handlerFail(responseObjJson) |
||
10 | */ |
||
11 | function widgetCall(serviceName,form,handlerOk,handlerFail) |
||
12 | { |
||
1579 | jmachado | 13 | var data = $(form).serialize().replace(/%0D%0A/g, '%0A').replace(/\r?\n/g, "\r\n"); |
14 | |||
1686 | jmachado | 15 | widgetCallWithActionParameters($(form).attr("action"),serviceName,data,form,handlerOk,handlerFail); |
1579 | jmachado | 16 | } |
17 | |||
18 | /** |
||
19 | * Use parameters instead of serialize form |
||
20 | * @param serviceName |
||
21 | * @param parameters |
||
22 | * @param form |
||
23 | * @param handlerOk |
||
24 | * @param handlerFail |
||
25 | */ |
||
26 | function widgetCallWithParameters(serviceName,parameters,form,handlerOk,handlerFail) |
||
27 | { |
||
1686 | jmachado | 28 | widgetCallWithActionParameters($(form).attr("action"),serviceName,parameters,form,handlerOk,handlerFail); |
1579 | jmachado | 29 | } |
1675 | jmachado | 30 | |
1579 | jmachado | 31 | /** |
32 | * Created by jorgemachado on 28/12/16. |
||
33 | */ |
||
34 | /** |
||
35 | *Use parameters instead of serialize form and the action provided |
||
36 | * @param serviceName |
||
1586 | jmachado | 37 | * @param webMessagesContainer |
1579 | jmachado | 38 | * @param handlerOk(responseObjJson) |
39 | * @param handlerFail(responseObjJson) |
||
40 | */ |
||
1586 | jmachado | 41 | function widgetCallWithActionParameters(action,serviceName,parameters,webMessagesContainer,handlerOk,handlerFail) |
1579 | jmachado | 42 | { |
1586 | jmachado | 43 | $(webMessagesContainer).find(".web-messages").html('<div class="alert alert-info">Enviando ...</div>'); |
1576 | jmachado | 44 | |
1579 | jmachado | 45 | var data = parameters; |
1576 | jmachado | 46 | $.ajax({ |
1579 | jmachado | 47 | url: action + "?dispatch=executeService&serviceJson=" + serviceName, |
1576 | jmachado | 48 | type: "POST", |
49 | data: data, |
||
50 | dataType: "json", |
||
1686 | jmachado | 51 | statusCode: { |
52 | 401:function() { |
||
53 | $("#modalAuthentication").modal({ show : 'true'}); |
||
54 | } |
||
55 | }, |
||
1576 | jmachado | 56 | success: function(resposta) |
57 | { |
||
1579 | jmachado | 58 | |
1586 | jmachado | 59 | $(webMessagesContainer).find(".web-messages").html(""); |
1576 | jmachado | 60 | if(resposta.service == "error") |
61 | { |
||
1586 | jmachado | 62 | $(webMessagesContainer).find(".web-messages").html('<div class="alert alert-danger">' + resposta.exception + '</div>'); |
1711 | jmachado | 63 | if(handlerFail != undefined) |
64 | handlerFail(resposta.exception); |
||
65 | |||
1576 | jmachado | 66 | } |
67 | else if(resposta.service == "fail") |
||
68 | { |
||
69 | |||
70 | for(var msg in resposta.messages) |
||
71 | { |
||
1586 | jmachado | 72 | $(webMessagesContainer).find(".web-messages").append('<div class="alert alert-success">' + resposta.messages[msg] + '</div>'); |
1576 | jmachado | 73 | } |
74 | for(var error in resposta.errors) |
||
75 | { |
||
1586 | jmachado | 76 | $(webMessagesContainer).find(".web-messages").append('<div class="alert alert-warning">' + resposta.errors[error] + '</div>'); |
1576 | jmachado | 77 | } |
78 | if(handlerFail != undefined) |
||
79 | handlerFail(resposta.response); |
||
80 | |||
81 | } |
||
82 | else if(resposta.service == "ok") |
||
83 | { |
||
84 | for(var msg in resposta.messages) |
||
85 | { |
||
1586 | jmachado | 86 | $(webMessagesContainer).find(".web-messages").append('<div class="alert alert-success">' + resposta.messages[msg] + '</div>'); |
1576 | jmachado | 87 | } |
88 | if(handlerOk != undefined) |
||
89 | handlerOk(resposta.response); |
||
90 | } |
||
91 | }, |
||
92 | error: function() { |
||
1586 | jmachado | 93 | $(webMessagesContainer).find(".web-messages").html('<div class="alert alert-danger">Erro de comunicação, por favor tente novamente</div>'); |
1711 | jmachado | 94 | if(handlerFail != undefined) |
95 | handlerFail(resposta.exception); |
||
96 | |||
1576 | jmachado | 97 | } |
98 | }); |
||
99 | } |
||
100 | |||
1579 | jmachado | 101 | |
1586 | jmachado | 102 | function widgetSimpleCall(serviceName,form,handlerOk,handlerFail){ |
103 | var data = $(form).serialize().replace(/%0D%0A/g, '%0A').replace(/\r?\n/g, "\r\n"); |
||
1686 | jmachado | 104 | widgetSimpleCallWithActionParameters($(form).attr("action"),serviceName,data,form,handlerOk,handlerFail); |
1586 | jmachado | 105 | } |
1576 | jmachado | 106 | /** |
107 | * |
||
108 | * @param serviceName |
||
109 | * @param form |
||
110 | * @param handlerOk() |
||
111 | * @param handlerFail() |
||
112 | */ |
||
1586 | jmachado | 113 | function widgetSimpleCallWithActionParameters(action,serviceName,data,webMessagesContainer,handlerOk,handlerFail) |
1576 | jmachado | 114 | { |
1586 | jmachado | 115 | $(webMessagesContainer).find(".web-messages").html('<div class="alert alert-info">Enviando ...</div>'); |
1576 | jmachado | 116 | |
117 | $.ajax({ |
||
1586 | jmachado | 118 | url: action + "?dispatch=executeSimpleServiceOkFail&serviceJson=" + serviceName, |
1576 | jmachado | 119 | type: "POST", |
120 | data: data, |
||
121 | dataType: "json", |
||
1686 | jmachado | 122 | statusCode: { |
123 | 401:function() { |
||
124 | $('.modal').modal("hide"); |
||
125 | $("#modalAuthentication").modal({ show : 'true'}); |
||
126 | } |
||
127 | }, |
||
1576 | jmachado | 128 | success: function(resposta) |
129 | { |
||
1586 | jmachado | 130 | $(webMessagesContainer).find(".web-messages").html(""); |
1576 | jmachado | 131 | if(resposta.service == "error") |
132 | { |
||
1586 | jmachado | 133 | $(webMessagesContainer).find(".web-messages").html('<div class="alert alert-danger">' + resposta.exception + '</div>'); |
1711 | jmachado | 134 | if(handlerFail != undefined) |
135 | handlerFail(); |
||
1576 | jmachado | 136 | } |
137 | else if(resposta.service == "fail") |
||
138 | { |
||
139 | |||
140 | for(var msg in resposta.messages) |
||
141 | { |
||
1586 | jmachado | 142 | $(webMessagesContainer).find(".web-messages").append('<div class="alert alert-success">' + resposta.messages[msg] + '</div>'); |
1576 | jmachado | 143 | } |
144 | for(var error in resposta.errors) |
||
145 | { |
||
1586 | jmachado | 146 | $(webMessagesContainer).find(".web-messages").append('<div class="alert alert-warning">' + resposta.errors[error] + '</div>'); |
1576 | jmachado | 147 | } |
148 | if(handlerFail != undefined) |
||
149 | handlerFail(); |
||
150 | } |
||
151 | else if(resposta.service == "ok") |
||
152 | { |
||
153 | for(var msg in resposta.messages) |
||
154 | { |
||
1586 | jmachado | 155 | $(webMessagesContainer).find(".web-messages").append('<div class="alert alert-success">' + resposta.messages[msg] + '</div>'); |
1576 | jmachado | 156 | } |
1686 | jmachado | 157 | for(var error in resposta.errors) |
158 | { |
||
159 | $(webMessagesContainer).find(".web-messages").append('<div class="alert alert-warning">' + resposta.errors[error] + '</div>'); |
||
160 | } |
||
1576 | jmachado | 161 | if(handlerOk != undefined) |
162 | handlerOk(); |
||
163 | } |
||
164 | }, |
||
1686 | jmachado | 165 | error: function(resposta) |
166 | { |
||
1586 | jmachado | 167 | $(webMessagesContainer).find(".web-messages").html('<div class="alert alert-danger">Erro de comunicação, por favor tente novamente</div>'); |
1711 | jmachado | 168 | if(handlerFail != undefined) |
169 | handlerFail(); |
||
170 | |||
1576 | jmachado | 171 | } |
172 | }); |
||
173 | } |