Changeset 6312 for sandbox/webservice


Ignore:
Timestamp:
05/25/12 14:51:26 (12 years ago)
Author:
niltonneto
Message:

Ticket #2507 - Implementado em RestClient? teste de download de anexo.

Location:
sandbox/webservice/restclient
Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • sandbox/webservice/restclient/index.html

    r6311 r6312  
    33<HEAD> 
    44        <script type="text/javascript" src="./libs/jquery.js"></script> 
     5        <script type="text/javascript" src="./libs/jquery.json-2.3.min.js"></script> 
    56        <script type="text/javascript" src="./libs/jsonreport.js"></script> 
    67        <script type="text/javascript" src="./libs/Base64.js"></script> 
     
    7071                                <TD colspan=2><select id="folder_id" onchange="javascript:jExecute('Mail/Messages')"><option value="INBOX">Selecionar pasta</option></select> 
    7172                                        <select id="message_id" onchange="javascript:jExecute('getMessage')"><option value="-1">Selecionar mensagem</option></select> 
     73                                        <select id="attachment_id" onchange="javascript:jExecute('getAttachment')"><option value="-1">Selecionar Anexo</option></select> 
    7274                                </TD> 
    7375                        </TR> 
     
    154156                                $('#folder_id').attr("disabled", true); 
    155157                                $('#message_id').attr("disabled", true); 
     158                                $('#attachment_id').attr("disabled", true); 
    156159                                $('#sel_contacts').attr("disabled", true); 
    157160                                $('#sel_catalog').attr("disabled", true); 
     
    189192                                $('#bt_rename_folder').attr("disabled", false); 
    190193                        } 
    191                         if(a_response.result.messages && a_response.result.messages.length > 1) { 
    192                                 $("#message_id").find('option').remove().end().append("<option value='-1'>Selecionar Mensagem</option>"); 
    193                                 for (var j in a_response.result.messages){ 
    194                                         var value = a_response.result.messages[j].msgSubject.length > 20 ? 
    195                                                 a_response.result.messages[j].msgSubject.substring(0, 20) : a_response.result.messages[j].msgSubject; 
    196  
    197                                         a_response.result.messages[j].msgBodyResume = (a_response.result.messages[j].msgBodyResume); 
    198                                         $("#message_id").append("<option value='"+a_response.result.messages[j].msgID+"'>"+ 
    199                                                         value+"</option>"); 
    200                                 } 
     194                        if(a_response.result.messages) { 
    201195                                $('#message_id').attr("disabled", false); 
     196                                if(a_response.result.messages.length == 1) { 
     197                                        $("#attachment_id").find('option').remove().end().append("<option value='-1'>Selecionar Anexo</option>"); 
     198                                        if(a_response.result.messages[0].msgHasAttachments > 0) { 
     199                                                $('#attachment_id').attr("disabled", false); 
     200                                                var attachments = a_response.result.messages[0].msgAttachments; 
     201                                                for (var j in attachments){ 
     202                                                        $("#attachment_id").append("<option value='"+attachments[j].pid+"'>"+attachments[j].name+"</option>"); 
     203                                                } 
     204                                        } 
     205                                        else{ 
     206                                                $('#attachment_id').attr("disabled", true); 
     207                                        } 
     208                                } 
     209                                else{ 
     210                                        $("#message_id").find('option').remove().end().append("<option value='-1'>Selecionar Mensagem</option>"); 
     211                                        for (var j in a_response.result.messages){ 
     212                                                var value = a_response.result.messages[j].msgSubject.length > 20 ? 
     213                                                        a_response.result.messages[j].msgSubject.substring(0, 20) : a_response.result.messages[j].msgSubject; 
     214 
     215                                                a_response.result.messages[j].msgBodyResume = (a_response.result.messages[j].msgBodyResume); 
     216                                                $("#message_id").append("<option value='"+a_response.result.messages[j].msgID+"'>"+ 
     217                                                                value+"</option>"); 
     218                                        } 
     219                                } 
    202220                        } 
    203221 
     
    259277                } 
    260278 
     279 
     280                if(_action == "getAttachment"){ 
     281                        downloadAttachment(); 
     282                        return; 
     283                } 
    261284 
    262285                switch(_action){ 
     
    355378        } 
    356379 
     380        function downloadAttachment(){ 
     381                var _server = getCookie('server') ? getCookie('server') : ($('#server').val() ? $('#server').val() : null);              
     382                var form = document.createElement("form");               
     383                $(form).attr({"action":_server+"Mail/Attachment","method":"POST"});              
     384 
     385                var _params = { 
     386                                auth:  getCookie('auth') != null ? getCookie('auth') : "", 
     387                                folderID:  $('#folder_id').val(), 
     388                                msgID:  $('#message_id').val(), 
     389                                attachmentID: $('#attachment_id').val() 
     390                        }; 
     391 
     392                $(form).append($(document.createElement('input')).attr( {"name":"params", "value": $.toJSON(_params)})); 
     393                var secretThing = $('<iframe id="IFrameToDownload"></iframe>', { css: { 'display': 'none' }});           
     394                $('body').append(secretThing); 
     395                $("#IFrameToDownload").contents().find('body').append(form);             
     396                $(form).submit();        
     397        } 
     398 
    357399        function getCookie(c_name) 
    358400        { 
     
    393435        $('#bt_logout').attr("disabled", isLoggedIn ? false : true); 
    394436        $('#bt_listFolders').attr("disabled", isLoggedIn ? false : true); 
    395         $('#folder_id').attr("disabled", isLoggedIn ? false : true); 
    396         $('#message_id').attr("disabled", isLoggedIn ? false : true); 
    397         $('#contact_id').attr("disabled", isLoggedIn ? false : true); 
    398         $('#sel_contacts').attr("disabled", isLoggedIn ? false : true); 
    399         $('#sel_catalog').attr("disabled", isLoggedIn ? false : true); 
     437        $('#folder_id').attr("disabled", true); 
     438        $('#message_id').attr("disabled", true); 
     439        $('#attachment_id').attr("disabled", true); 
     440        $('#contact_id').attr("disabled",true); 
     441        $('#sel_contacts').attr("disabled", true); 
     442        $('#sel_catalog').attr("disabled", true); 
    400443        $('#search_contacts').attr("disabled", isLoggedIn ? false : true); 
    401444        $('#search_catalog').attr("disabled", isLoggedIn ? false : true); 
Note: See TracChangeset for help on using the changeset viewer.