[6092] | 1 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> |
---|
| 2 | <HTML> |
---|
| 3 | <HEAD> |
---|
| 4 | <script type="text/javascript" src="./libs/jquery.js"></script> |
---|
| 5 | <script type="text/javascript" src="./libs/jsonreport.js"></script> |
---|
| 6 | <script type="text/javascript" src="./libs/Base64.js"></script> |
---|
| 7 | <TITLE>..:: Página de Teste - REST API ::..</TITLE> |
---|
| 8 | <META http-equiv="Content-Type" content="text/html; charset=utf-8"> |
---|
| 9 | <style type="text/css"> |
---|
| 10 | * { |
---|
| 11 | font-family: sans-serif, verdana, arial; |
---|
| 12 | font-size: 12px; |
---|
| 13 | } |
---|
| 14 | table { |
---|
| 15 | background:#ECECEC; |
---|
| 16 | padding:5px; |
---|
| 17 | border:1px solid black |
---|
| 18 | } |
---|
| 19 | |
---|
| 20 | .loader |
---|
| 21 | { |
---|
| 22 | position:absolute; |
---|
| 23 | padding: 5px; |
---|
| 24 | right:10px; |
---|
| 25 | top:10px; |
---|
| 26 | color: black; |
---|
| 27 | text-align:center; |
---|
| 28 | border: solid 1px black; |
---|
| 29 | z-index: 200; |
---|
| 30 | } |
---|
| 31 | </style> |
---|
| 32 | </HEAD> |
---|
| 33 | <BODY> |
---|
| 34 | <DIV style="display:none" class="loader" id="loader"> |
---|
| 35 | <label id="loader_msg"></label><br> |
---|
| 36 | <img src="./images/loader.gif"/> |
---|
| 37 | </DIV> |
---|
| 38 | <TABLE> |
---|
| 39 | <TR><TD><b>Servidor</b></TD> |
---|
| 40 | <TD><select id="server"><option value="">Selecionar ....</option></select> |
---|
| 41 | <input id="bt_servers" type="button" value="Listar Servidores" onclick="javascript:jExecute('AvailableServers')"/> |
---|
| 42 | <input id="bt_version" type="button" value="Versão API" onclick="javascript:jExecute('ExpressoVersion')"/> |
---|
| 43 | <input id="bt_version" type="button" value="Teste Erro" onclick="javascript:jExecute('Teste')"/> |
---|
| 44 | </TD> |
---|
| 45 | </TR> |
---|
| 46 | <TR><TD><b>Login</b></TD><TD><input type="text" id="user"/></TD></TR> |
---|
| 47 | <TR><TD><b>Senha</b></TD><TD><input type="password" id="password"/> |
---|
| 48 | <input id="bt_login" type="button" value="Conectar" onclick="javascript:jExecute('Login')"/> |
---|
| 49 | <input id="bt_logout" type="button" value="Desconectar" onclick="javascript:jExecute('Logout')"/> |
---|
| 50 | </TD></TR> |
---|
| 51 | </TABLE> |
---|
| 52 | <BR><BR> |
---|
| 53 | <TABLE> |
---|
| 54 | <TR><TD><b>Esvaziar Lixeira</b></TD> |
---|
| 55 | <TD><input id="bt_esvaziar_lixeira" type="button" value="Esvaziar Lixeira" onclick="javascript:jExecute('CleanTrash')"/></TD> |
---|
| 56 | </TR> |
---|
| 57 | <TR><TD><b>Suporte/Sugestão</b></TD> |
---|
| 58 | <TD><textarea id="text_message">Texto do e-mail de suporte/sugestao!!</textarea></TD> |
---|
| 59 | <TD><input id="bt_sugestao" type="button" value="Enviar Sugestão" onclick="javascript:jExecute('SendSupportFeedback')"/></TD> |
---|
| 60 | </TR> |
---|
| 61 | </TABLE><br><br> |
---|
| 62 | <TABLE> |
---|
| 63 | <TR><TD><b>Pastas IMAP</b></TD> |
---|
[6156] | 64 | <TD><input type="text" id="search_folders"/><input id="bt_listFolders" type="button" value="Pesquisar" onclick="javascript:jExecute('Mail/Folders')"/></TD> |
---|
| 65 | <TD colspan=2><select id="folder_id" onchange="javascript:jExecute('Mail/Messages')"><option value="INBOX">Selecionar pasta</option></select> |
---|
[6092] | 66 | <select id="message_id" onchange="javascript:jExecute('getMessage')"><option value="-1">Selecionar mensagem</option></select> |
---|
| 67 | </TD> |
---|
| 68 | </TR> |
---|
[6156] | 69 | <TR><TD></TD><TD></TD> |
---|
| 70 | <TD colspan=2><input id="bt_del_folder" type="button" value="Apagar Pasta" onclick="javascript:jExecute('DelFolder')"/></TD> |
---|
| 71 | </TR> |
---|
| 72 | <TR><TD></TD><TD></TD> |
---|
| 73 | <TD><input type="text" id="new_folder_name"/></TD> |
---|
| 74 | <TD> |
---|
| 75 | <input id="bt_add_folder" type="button" value="Adicionar Pasta" onclick="javascript:jExecute('AddFolder')"/><br> |
---|
| 76 | <input id="bt_rename_folder" type="button" value="Renomear Pasta" onclick="javascript:jExecute('RenameFolder')"/> |
---|
| 77 | </TD> |
---|
| 78 | </TR> |
---|
[6092] | 79 | <TR><TD><b>Contatos</b></TD> |
---|
[6156] | 80 | <TD colspan=3><input type="text" id="search_contacts"/><input id="bt_contacts" type="button" value="Pesquisar" onclick="javascript:jExecute('getContacts')"/> |
---|
[6092] | 81 | <select id="sel_contacts" onchange="javascript:jExecute('getContactPicture')"><option value="-1">Selecionar contato</option></select> |
---|
| 82 | |
---|
| 83 | </TD> |
---|
| 84 | </TR> |
---|
| 85 | <TR><TD><b>Catalogo</b></TD> |
---|
[6156] | 86 | <TD colspan=3> |
---|
[6092] | 87 | <input type="text" id="search_catalog"/><input id="bt_catalog" type="button" value="Pesquisar" onclick="javascript:jExecute('getCatalog')"/> |
---|
| 88 | <select id="sel_catalog" onchange="javascript:jExecute('getCatalogPicture')"><option value="-1">Selecionar contato</option></select> |
---|
| 89 | </TD> |
---|
| 90 | </TR> |
---|
| 91 | </TABLE> |
---|
| 92 | <BR><BR> |
---|
| 93 | <TABLE> |
---|
| 94 | <TR><TD><b>Resposta JSON-RPC</b> |
---|
| 95 | <input id="bt_clear" type="button" value="Limpar Saída" onclick="javascript:clearOut()"/> |
---|
| 96 | </TD></TR> |
---|
| 97 | <TR><TD style="background:#FFF !important;padding:0px;"> |
---|
| 98 | <img id="img_photo" style="display:none;"/> |
---|
| 99 | <div id="message" class="jsonreport"></div> |
---|
| 100 | </TD></TR> |
---|
| 101 | </TABLE> |
---|
| 102 | </BODY> |
---|
| 103 | <script language="Javascript"> |
---|
| 104 | |
---|
| 105 | function clearOut(){ |
---|
| 106 | $('#message').html(""); |
---|
| 107 | $('#img_photo').hide(); |
---|
| 108 | } |
---|
| 109 | |
---|
| 110 | function dispatch(_action, response, _search){ |
---|
| 111 | var a_response = jQuery.parseJSON(response); |
---|
| 112 | if(a_response){ |
---|
| 113 | |
---|
| 114 | if(a_response.result && a_response.result.auth) { |
---|
| 115 | setCookie ("auth", a_response.result.auth); |
---|
| 116 | setCookie ("server", $('#server').val()); |
---|
| 117 | $('#user').attr("disabled", true); |
---|
| 118 | $('#password').attr("disabled", true); |
---|
| 119 | $('#server').attr("disabled", true); |
---|
| 120 | |
---|
| 121 | $('#bt_servers').attr("disabled", true); |
---|
| 122 | $('#bt_login').attr("disabled", true); |
---|
| 123 | $('#bt_logout').attr("disabled", false); |
---|
| 124 | $('#bt_listFolders').attr("disabled", false); |
---|
| 125 | $('#bt_contacts').attr("disabled", false); |
---|
| 126 | $('#bt_catalog').attr("disabled", false); |
---|
| 127 | $('#sel_contacts').attr("disabled", false); |
---|
| 128 | $('#sel_catalog').attr("disabled", false); |
---|
| 129 | $('#search_contacts').attr("disabled", false); |
---|
| 130 | $('#search_catalog').attr("disabled", false); |
---|
| 131 | $('#search_folders').attr("disabled", false); |
---|
| 132 | |
---|
| 133 | } |
---|
| 134 | else if(_action == 'Logout' || (a_response.error && a_response.error.code == 7 )) { |
---|
| 135 | $('#user').attr("disabled", false); |
---|
| 136 | $('#password').attr("disabled", false); |
---|
| 137 | $('#server').attr("disabled", false); |
---|
| 138 | |
---|
| 139 | $('#bt_servers').attr("disabled", false); |
---|
| 140 | $('#bt_login').attr("disabled", false); |
---|
| 141 | $('#bt_logout').attr("disabled", true); |
---|
| 142 | $('#bt_contacts').attr("disabled", true); |
---|
| 143 | $('#bt_catalog').attr("disabled", true); |
---|
| 144 | $('#bt_listFolders').attr("disabled", true); |
---|
[6156] | 145 | $('#bt_del_folder').attr("disabled", true); |
---|
| 146 | $('#bt_add_folder').attr("disabled", true); |
---|
| 147 | $('#bt_rename_folder').attr("disabled", true); |
---|
[6092] | 148 | |
---|
| 149 | $('#folder_id').attr("disabled", true); |
---|
| 150 | $('#message_id').attr("disabled", true); |
---|
| 151 | $('#sel_contacts').attr("disabled", true); |
---|
| 152 | $('#sel_catalog').attr("disabled", true); |
---|
| 153 | $('#search_contacts').attr("disabled", true); |
---|
| 154 | $('#search_catalog').attr("disabled", true); |
---|
| 155 | $('#search_folders').attr("disabled", true); |
---|
[6156] | 156 | $('#new_folder_name').attr("disabled", true); |
---|
[6092] | 157 | |
---|
| 158 | clearOut(); |
---|
| 159 | setCookie ("auth", ''); |
---|
| 160 | setCookie ("server", ''); |
---|
| 161 | } |
---|
| 162 | } |
---|
| 163 | $('#message').append("<BR>"); |
---|
| 164 | if(a_response.error){ |
---|
| 165 | clearOut(); |
---|
| 166 | $('#message').append("<font color='red'>[erro "+a_response.error.code+"] "+a_response.error.message+"</font>"); |
---|
| 167 | return; |
---|
| 168 | } |
---|
| 169 | if(a_response.result){ |
---|
| 170 | if(typeof(a_response.result) != 'object') { |
---|
| 171 | $('#message').append("<font color='green'>"+a_response.result+"</font>"); |
---|
| 172 | return; |
---|
| 173 | } |
---|
| 174 | if(a_response.result.folders) { |
---|
| 175 | $("#folder_id").find('option').remove().end().append("<option value='-1'>Selecionar Pasta</option>"); |
---|
| 176 | for (var j in a_response.result.folders){ |
---|
| 177 | $("#folder_id").append("<option value='"+a_response.result.folders[j].folderID+"'>"+ |
---|
| 178 | a_response.result.folders[j].folderName+"</option>"); |
---|
| 179 | } |
---|
| 180 | $('#folder_id').attr("disabled", false); |
---|
[6156] | 181 | $('#new_folder_name').attr("disabled", false); |
---|
| 182 | $('#bt_del_folder').attr("disabled", false); |
---|
| 183 | $('#bt_add_folder').attr("disabled", false); |
---|
| 184 | $('#bt_rename_folder').attr("disabled", false); |
---|
[6092] | 185 | } |
---|
| 186 | if(a_response.result.messages && a_response.result.messages.length > 1) { |
---|
| 187 | $("#message_id").find('option').remove().end().append("<option value='-1'>Selecionar Mensagem</option>"); |
---|
| 188 | for (var j in a_response.result.messages){ |
---|
| 189 | var value = a_response.result.messages[j].msgSubject.length > 20 ? |
---|
| 190 | a_response.result.messages[j].msgSubject.substring(0, 20) : a_response.result.messages[j].msgSubject; |
---|
| 191 | |
---|
| 192 | a_response.result.messages[j].msgBodyResume = (a_response.result.messages[j].msgBodyResume); |
---|
| 193 | $("#message_id").append("<option value='"+a_response.result.messages[j].msgID+"'>"+ |
---|
| 194 | value+"</option>"); |
---|
| 195 | } |
---|
| 196 | $('#message_id').attr("disabled", false); |
---|
| 197 | } |
---|
| 198 | |
---|
| 199 | var select_id = (_search == '#search_contacts' ? '#sel_contacts' : (_search == '#search_catalog' ? '#sel_catalog' : '')); |
---|
| 200 | if(select_id) |
---|
| 201 | $(select_id).find('option').remove().end().append("<option value='-1'>Selecionar Contato</option>"); |
---|
| 202 | |
---|
| 203 | if(a_response.result.contacts && a_response.result.contacts.length > 0) { |
---|
| 204 | for (var j in a_response.result.contacts){ |
---|
| 205 | var value = (a_response.result.contacts[j].contactFullName != null ? a_response.result.contacts[j].contactFullName : "Vazio (ID "+a_response.result.contacts[j].contactID+")"); |
---|
| 206 | if(select_id){ |
---|
| 207 | $(select_id).append("<option value='"+a_response.result.contacts[j].contactID+"'>"+ |
---|
| 208 | value+"</option>"); |
---|
| 209 | } |
---|
| 210 | } |
---|
| 211 | if(a_response.result.contacts && a_response.result.contacts.length == 1) { |
---|
| 212 | if(a_response.result.contacts[0].contactImagePicture){ |
---|
| 213 | base64Data = a_response.result.contacts[0].contactImagePicture; |
---|
| 214 | $('#img_photo').attr("src", "data:image/jpg;base64,"+ base64Data); |
---|
| 215 | $('#img_photo').show(); |
---|
| 216 | return; |
---|
| 217 | } |
---|
| 218 | else{ |
---|
| 219 | $('#img_photo').hide(); |
---|
| 220 | } |
---|
| 221 | } |
---|
| 222 | if(select_id){ |
---|
| 223 | $(select_id).attr("disabled", false); |
---|
| 224 | } |
---|
| 225 | } |
---|
| 226 | |
---|
| 227 | if(a_response.result.servers) { |
---|
| 228 | $("#server").find('option').remove().end().append("<option value=''>Selecionar Servidor</option>"); |
---|
| 229 | for (var j in a_response.result.servers){ |
---|
| 230 | $("#server").append("<option value='"+(a_response.result.servers[j].serverUrl+a_response.result.servers[j].serverContext)+"'>"+ |
---|
| 231 | a_response.result.servers[j].serverName+"</option>"); |
---|
| 232 | } |
---|
| 233 | $('#bt_version').attr("disabled", false); |
---|
| 234 | $('#bt_clear').attr("disabled", false); |
---|
| 235 | } |
---|
| 236 | |
---|
| 237 | var html = _.jsonreport(a_response.result); |
---|
| 238 | |
---|
| 239 | $('#message').html(html); |
---|
| 240 | } |
---|
| 241 | } |
---|
| 242 | |
---|
| 243 | function jExecute(_action){ |
---|
| 244 | var _server = getCookie('server') ? getCookie('server') : ($('#server').val() ? $('#server').val() : null); |
---|
| 245 | var _contactType; |
---|
| 246 | var _contactID; |
---|
| 247 | var _search; |
---|
| 248 | var _message; |
---|
| 249 | var _method = "POST"; |
---|
| 250 | |
---|
| 251 | if(_server == null && _action != 'AvailableServers'){ |
---|
| 252 | alert("Nenhum servidor foi definido."); |
---|
| 253 | return; |
---|
| 254 | } |
---|
| 255 | |
---|
| 256 | |
---|
| 257 | switch(_action){ |
---|
| 258 | case 'Mail/Folders': |
---|
| 259 | _search = '#search_folders'; |
---|
| 260 | break; |
---|
[6156] | 261 | case 'AddFolder': |
---|
| 262 | _action = 'Mail/AddFolder'; |
---|
| 263 | break; |
---|
| 264 | case 'DelFolder': |
---|
| 265 | _action = 'Mail/DelFolder'; |
---|
| 266 | break; |
---|
| 267 | case 'RenameFolder': |
---|
| 268 | _action = 'Mail/RenameFolder'; |
---|
| 269 | break; |
---|
[6092] | 270 | case 'getMessages': |
---|
| 271 | _action = 'Mail/Messages'; |
---|
| 272 | $("#message_id").find('option').remove().end().append("<option value='-1'>Selecionar Mensagem</option>"); |
---|
| 273 | break; |
---|
| 274 | case 'getMessage': |
---|
| 275 | _action = 'Mail/Messages'; |
---|
| 276 | break; |
---|
| 277 | case 'CleanTrash': |
---|
| 278 | _action = 'Mail/CleanTrash'; |
---|
| 279 | break; |
---|
| 280 | case 'SendSupportFeedback': |
---|
| 281 | _action = 'Mail/SendSupportFeedback'; |
---|
| 282 | _message = $('#text_message').val(); |
---|
| 283 | break; |
---|
| 284 | case 'getContacts': |
---|
| 285 | _action = 'Catalog/Contacts'; |
---|
| 286 | _search = '#search_contacts'; |
---|
| 287 | _contactType = '1'; |
---|
| 288 | $("#sel_contacts").find('option').remove().end().append("<option value='-1'>Selecionar Contato</option>"); |
---|
| 289 | break; |
---|
| 290 | case 'getCatalog': |
---|
| 291 | _action = 'Catalog/Contacts'; |
---|
| 292 | _search = '#search_catalog'; |
---|
| 293 | _contactType = '2'; |
---|
| 294 | $("#sel_catalog").find('option').remove().end().append("<option value='-1'>Selecionar Contato</option>"); |
---|
| 295 | break; |
---|
| 296 | case 'getContactPicture': |
---|
| 297 | _action = 'Catalog/ContactPicture'; |
---|
| 298 | _contactID = '#sel_contacts'; |
---|
| 299 | _contactType = '1'; |
---|
| 300 | break; |
---|
| 301 | case 'getCatalogPicture': |
---|
| 302 | _action = 'Catalog/ContactPicture'; |
---|
| 303 | _contactID = '#sel_catalog'; |
---|
| 304 | _contactType = '2'; |
---|
| 305 | break; |
---|
| 306 | |
---|
| 307 | } |
---|
| 308 | |
---|
| 309 | $.ajax({ |
---|
| 310 | type: "POST", |
---|
| 311 | url: "restclient.php", |
---|
| 312 | data: {params: { |
---|
| 313 | user: $('#user').val(), |
---|
| 314 | password: $('#password').val(), |
---|
| 315 | server: _server, |
---|
| 316 | auth: getCookie('auth') != null ? getCookie('auth') : "", |
---|
| 317 | folderID: $('#folder_id').val(), |
---|
| 318 | msgID: $('#message_id').val(), |
---|
| 319 | contactID: $(_contactID).val(), |
---|
| 320 | message: _message, |
---|
| 321 | contactType: _contactType, |
---|
[6156] | 322 | search: $(_search).val(), |
---|
| 323 | newFolderName: $('#new_folder_name').val(), |
---|
[6092] | 324 | method: _method |
---|
| 325 | }, |
---|
| 326 | action: _action |
---|
| 327 | }, |
---|
| 328 | beforeSend: function() { |
---|
| 329 | clearOut(); |
---|
| 330 | $('#loader_msg').html("Aguarde, solicitando informações ..."); |
---|
| 331 | $('#loader').show(); |
---|
| 332 | } |
---|
| 333 | , |
---|
| 334 | success: function(response) { |
---|
| 335 | dispatch(_action, response, _search); |
---|
| 336 | $('#loader').hide(); |
---|
| 337 | } |
---|
| 338 | , |
---|
| 339 | error: function(response) { |
---|
| 340 | alert("Serviço indisponÃvel"); |
---|
| 341 | $('#loader').hide(); |
---|
| 342 | } |
---|
| 343 | |
---|
| 344 | }); |
---|
| 345 | |
---|
| 346 | } |
---|
| 347 | |
---|
| 348 | function getCookie(c_name) |
---|
| 349 | { |
---|
| 350 | var i,x,y,ARRcookies=document.cookie.split(";"); |
---|
| 351 | for (i=0;i<ARRcookies.length;i++) |
---|
| 352 | { |
---|
| 353 | x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("=")); |
---|
| 354 | y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1); |
---|
| 355 | x=x.replace(/^\s+|\s+$/g,""); |
---|
| 356 | if (x==c_name) |
---|
| 357 | { |
---|
| 358 | if(y == "") |
---|
| 359 | return null; |
---|
| 360 | else |
---|
| 361 | return unescape(y); |
---|
| 362 | } |
---|
| 363 | } |
---|
| 364 | } |
---|
| 365 | |
---|
| 366 | function setCookie(c_name,value,exdays) |
---|
| 367 | { |
---|
| 368 | var exdate=new Date(); |
---|
| 369 | exdate.setDate(exdate.getDate() + exdays); |
---|
| 370 | var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString()); |
---|
| 371 | document.cookie=c_name + "=" + c_value; |
---|
| 372 | } |
---|
| 373 | // Reset values |
---|
| 374 | var isLoggedIn = false; |
---|
| 375 | if(getCookie('auth') != null && getCookie('server') != null){ |
---|
| 376 | isLoggedIn = true; |
---|
| 377 | } |
---|
| 378 | |
---|
| 379 | $('#user').attr("disabled", isLoggedIn ? true : false); |
---|
| 380 | $('#password').attr("disabled", isLoggedIn ? true : false); |
---|
| 381 | $('#server').attr("disabled", isLoggedIn ? true : false); |
---|
| 382 | $('#bt_servers').attr("disabled", isLoggedIn ? true : false); |
---|
| 383 | $('#bt_login').attr("disabled", isLoggedIn ? true : false); |
---|
| 384 | $('#bt_logout').attr("disabled", isLoggedIn ? false : true); |
---|
| 385 | $('#bt_listFolders').attr("disabled", isLoggedIn ? false : true); |
---|
| 386 | $('#folder_id').attr("disabled", isLoggedIn ? false : true); |
---|
| 387 | $('#message_id').attr("disabled", isLoggedIn ? false : true); |
---|
| 388 | $('#contact_id').attr("disabled", isLoggedIn ? false : true); |
---|
| 389 | $('#sel_contacts').attr("disabled", isLoggedIn ? false : true); |
---|
| 390 | $('#sel_catalog').attr("disabled", isLoggedIn ? false : true); |
---|
| 391 | $('#search_contacts').attr("disabled", isLoggedIn ? false : true); |
---|
| 392 | $('#search_catalog').attr("disabled", isLoggedIn ? false : true); |
---|
| 393 | $('#search_folders').attr("disabled", isLoggedIn ? false : true); |
---|
[6156] | 394 | $('#new_folder_name').attr("disabled", isLoggedIn ? false : true); |
---|
[6092] | 395 | $('#bt_contacts').attr("disabled", isLoggedIn ? false : true); |
---|
| 396 | $('#bt_catalog').attr("disabled", isLoggedIn ? false : true); |
---|
[6156] | 397 | $('#bt_del_folder').attr("disabled", isLoggedIn ? false : true); |
---|
| 398 | $('#bt_add_folder').attr("disabled", isLoggedIn ? false : true); |
---|
| 399 | $('#bt_rename_folder').attr("disabled", isLoggedIn ? false : true); |
---|
[6092] | 400 | $('#bt_version').attr("disabled", false); |
---|
| 401 | $('#bt_clear').attr("disabled", false); |
---|
| 402 | </script> |
---|
| 403 | </html> |
---|