Rev 1675 | Rev 1711 | 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>'); |
1576 | jmachado | 63 | } |
64 | else if(resposta.service == "fail") |
||
65 | { |
||
66 | |||
67 | for(var msg in resposta.messages) |
||
68 | { |
||
1586 | jmachado | 69 | $(webMessagesContainer).find(".web-messages").append('<div class="alert alert-success">' + resposta.messages[msg] + '</div>'); |
1576 | jmachado | 70 | } |
71 | for(var error in resposta.errors) |
||
72 | { |
||
1586 | jmachado | 73 | $(webMessagesContainer).find(".web-messages").append('<div class="alert alert-warning">' + resposta.errors[error] + '</div>'); |
1576 | jmachado | 74 | } |
75 | if(handlerFail != undefined) |
||
76 | handlerFail(resposta.response); |
||
77 | |||
78 | } |
||
79 | else if(resposta.service == "ok") |
||
80 | { |
||
81 | for(var msg in resposta.messages) |
||
82 | { |
||
1586 | jmachado | 83 | $(webMessagesContainer).find(".web-messages").append('<div class="alert alert-success">' + resposta.messages[msg] + '</div>'); |
1576 | jmachado | 84 | } |
85 | if(handlerOk != undefined) |
||
86 | handlerOk(resposta.response); |
||
87 | } |
||
88 | }, |
||
89 | error: function() { |
||
1586 | jmachado | 90 | $(webMessagesContainer).find(".web-messages").html('<div class="alert alert-danger">Erro de comunicação, por favor tente novamente</div>'); |
1576 | jmachado | 91 | } |
92 | }); |
||
93 | } |
||
94 | |||
1579 | jmachado | 95 | |
1586 | jmachado | 96 | function widgetSimpleCall(serviceName,form,handlerOk,handlerFail){ |
97 | var data = $(form).serialize().replace(/%0D%0A/g, '%0A').replace(/\r?\n/g, "\r\n"); |
||
1686 | jmachado | 98 | widgetSimpleCallWithActionParameters($(form).attr("action"),serviceName,data,form,handlerOk,handlerFail); |
1586 | jmachado | 99 | } |
1576 | jmachado | 100 | /** |
101 | * |
||
102 | * @param serviceName |
||
103 | * @param form |
||
104 | * @param handlerOk() |
||
105 | * @param handlerFail() |
||
106 | */ |
||
1586 | jmachado | 107 | function widgetSimpleCallWithActionParameters(action,serviceName,data,webMessagesContainer,handlerOk,handlerFail) |
1576 | jmachado | 108 | { |
1586 | jmachado | 109 | $(webMessagesContainer).find(".web-messages").html('<div class="alert alert-info">Enviando ...</div>'); |
1576 | jmachado | 110 | |
111 | $.ajax({ |
||
1586 | jmachado | 112 | url: action + "?dispatch=executeSimpleServiceOkFail&serviceJson=" + serviceName, |
1576 | jmachado | 113 | type: "POST", |
114 | data: data, |
||
115 | dataType: "json", |
||
1686 | jmachado | 116 | statusCode: { |
117 | 401:function() { |
||
118 | $('.modal').modal("hide"); |
||
119 | $("#modalAuthentication").modal({ show : 'true'}); |
||
120 | } |
||
121 | }, |
||
1576 | jmachado | 122 | success: function(resposta) |
123 | { |
||
1586 | jmachado | 124 | $(webMessagesContainer).find(".web-messages").html(""); |
1576 | jmachado | 125 | if(resposta.service == "error") |
126 | { |
||
1586 | jmachado | 127 | $(webMessagesContainer).find(".web-messages").html('<div class="alert alert-danger">' + resposta.exception + '</div>'); |
1576 | jmachado | 128 | } |
129 | else if(resposta.service == "fail") |
||
130 | { |
||
131 | |||
132 | for(var msg in resposta.messages) |
||
133 | { |
||
1586 | jmachado | 134 | $(webMessagesContainer).find(".web-messages").append('<div class="alert alert-success">' + resposta.messages[msg] + '</div>'); |
1576 | jmachado | 135 | } |
136 | for(var error in resposta.errors) |
||
137 | { |
||
1586 | jmachado | 138 | $(webMessagesContainer).find(".web-messages").append('<div class="alert alert-warning">' + resposta.errors[error] + '</div>'); |
1576 | jmachado | 139 | } |
140 | if(handlerFail != undefined) |
||
141 | handlerFail(); |
||
142 | |||
143 | } |
||
144 | else if(resposta.service == "ok") |
||
145 | { |
||
146 | for(var msg in resposta.messages) |
||
147 | { |
||
1586 | jmachado | 148 | $(webMessagesContainer).find(".web-messages").append('<div class="alert alert-success">' + resposta.messages[msg] + '</div>'); |
1576 | jmachado | 149 | } |
1686 | jmachado | 150 | for(var error in resposta.errors) |
151 | { |
||
152 | $(webMessagesContainer).find(".web-messages").append('<div class="alert alert-warning">' + resposta.errors[error] + '</div>'); |
||
153 | } |
||
1576 | jmachado | 154 | if(handlerOk != undefined) |
155 | handlerOk(); |
||
156 | } |
||
157 | }, |
||
1686 | jmachado | 158 | error: function(resposta) |
159 | { |
||
1586 | jmachado | 160 | $(webMessagesContainer).find(".web-messages").html('<div class="alert alert-danger">Erro de comunicação, por favor tente novamente</div>'); |
1576 | jmachado | 161 | } |
162 | }); |
||
163 | } |