Ignore:
Timestamp:
03/02/12 03:48:47 (12 years ago)
Author:
cristiano
Message:

Ticket #2497 - Nova estrategia para o salvamento automatico de rascunhos

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/library/ckeditor/plugins/expresso/plugin.js

    r5081 r5604  
    99            { 
    1010                label: 'Adicionar Imagem', 
    11                 command: 'expAddImageCMD', 
     11                command: 'imgDialog', 
    1212                icon: CKEDITOR.plugins.getPath('expresso') + 'img/Image.gif' 
    1313            }); 
     
    4343        }); 
    4444         
     45         
     46        editor.addCommand( 'imgDialog',new CKEDITOR.dialogCommand( 'imgDialog' ) ); 
     47 
     48                if ( editor.contextMenu ) 
     49                { 
     50                        editor.addMenuGroup( 'mygroup', 10 ); 
     51                        editor.addMenuItem( 'My Dialog', 
     52                        { 
     53                                label : 'Open dialog', 
     54                                command : 'imgDialog', 
     55                                group : 'mygroup' 
     56                        }); 
     57                        editor.contextMenu.addListener( function( element ) 
     58                        { 
     59                                return {'My Dialog' : CKEDITOR.TRISTATE_OFF}; 
     60                        }); 
     61                } 
     62                 
     63                CKEDITOR.dialog.add( 'imgDialog', function( api ) 
     64                { 
     65                        var ID = currentTab; 
     66                        // CKEDITOR.dialog.definition 
     67                        var dialogDefinition = 
     68                        { 
     69                                 
     70                                title : 'Inserir Imagem', 
     71                                minWidth : 400, 
     72                                minHeight : 70, 
     73                                contents : [ 
     74                                        { 
     75                                                id : 'tab1', 
     76                                                label : 'Label', 
     77                                                title : 'Title', 
     78                                                expand : true, 
     79                                                padding : 0, 
     80                                                elements : 
     81                                                [ 
     82                                                        { 
     83                                                                type : 'html', 
     84                                                                html :  '<form id="fileupload_img'+ID+'" class="fileupload" action="mailAttachment:img" method="POST">    <input type="file" name="files[]" multiple="" onclick="bindFileUpload();" style="margin-left:10px"></form>'  
     85                                                        } 
     86                                                ] 
     87                                        } 
     88                                ], 
     89                                buttons : [ CKEDITOR.dialog.cancelButton] 
     90                                 
     91                        }; 
     92                                 
     93                        return dialogDefinition; 
     94                } ); 
     95         
    4596          
    46         var cmd = editor.addCommand('expAddImageCMD',  { exec: showexpIncImageDialog }); 
     97 
    4798    } 
    4899}); 
    49 function showexpIncImageDialog(e) { 
    50    RichTextEditor.createImage(); 
     100function bindFileUpload(e) { 
     101        var ID = currentTab; 
     102        var newImageId = new Date().getTime(); 
     103        var fileUploadIMG = $('#fileupload_img'+ID); 
     104        var fileUploadMSG = $('#fileupload_msg'+ID); 
     105        var maxAttachmentSise = (preferences.max_attachment_size !== "" && preferences.max_attachment_size != 0) ? (parseInt(preferences.max_attachment_size.replace('M', '')) * 1048576 ) : false; 
     106        fileUploadIMG.fileupload({ 
     107                sequentialUploads: true, 
     108                add: function (e, data) { 
     109      
     110                        if(!maxAttachmentSise || data.files[0].size < maxAttachmentSise) { 
     111                                setTimeout(function() { 
     112                                        $('#attDisposition'+ID).val('embedded'); 
     113                                        data.submit(); 
     114                                }, 5000); 
     115                        } 
     116                         
     117                }, 
     118                change: function (e, data) { 
     119                        $.each(data.files, function (index, file) {      
     120                                var attach = {}; 
     121                                attach.fullFileName = file.name; 
     122                                attach.fileName = file.name; 
     123                                if(file.name.length > 10) 
     124                                        attach.fileName = file.name.substr(0, 18) + "..." + file.name.substr(file.name.length-9, file.name.length); 
     125                                attach.fileSize = formatBytes(file.size); 
     126                                if(maxAttachmentSise && file.size > maxAttachmentSise) 
     127                                        attach.error = 'Tamanho de arquivo nao permitido!!' 
     128                                                                 
     129                                fileUploadMSG.find('.attachments-list').append(DataLayer.render("../prototype/modules/mail/templates/attachment_add_itemlist.ejs", {file : attach})); 
     130 
     131                                if(!maxAttachmentSise || file.size < maxAttachmentSise){ 
     132                                        fileUploadMSG.find(' .fileinput-button.new').append(data.fileInput[0]).removeClass('new'); 
     133                                        fileUploadMSG.find(' .attachments-list').find('[type=file]').addClass('hidden'); 
     134                                         
     135                                }else 
     136                                        fileUploadMSG.find(' .fileinput-button.new').removeClass('new'); 
     137                                 
     138                                 
     139                                fileUploadMSG.find(' .attachments-list').find('.button.close').button({ 
     140                                        icons: { 
     141                                                primary: "ui-icon-close" 
     142                                        }, 
     143                                        text: false 
     144                                }).click(function(){ 
     145                                        var idAttach = $(this).parent().find('input[name="fileId[]"]').val(); 
     146                         
     147                                        var content_body = RichTextEditor.getData('body_'+ID); 
     148                                        var imagens = content_body.match(/<img[^>]*>/g); 
     149        
     150                                        if(imagens != null) 
     151                                            for (var x = 0; x < imagens.length; x++) 
     152                                                if(imagens[x].indexOf('src="../prototype/getArchive.php?mailAttachment='+idAttach+'"') !== -1) 
     153                                                        content_body = content_body.replace(imagens[x],''); 
     154          
     155                                        RichTextEditor.setData('body_'+ID,content_body);    
     156                                         
     157                                        $('.attachments-list').find('input[value="'+idAttach+'"]').remove(); 
     158                                        delAttachment(ID, idAttach); 
     159                                        $(this).parent().remove(); 
     160                                }); 
     161                                 
     162                                CKEDITOR.instances['body_'+ID].insertHtml('<img id="'+newImageId+'" src=""/>'); 
     163 
     164                }); 
     165                 
     166                    CKEDITOR.dialog.getCurrent().hide(); 
     167                }, 
     168                done: function(e, data){ 
     169                        if(!!data.result && data.result != "[]"){ 
     170                                var newAttach = jQuery.parseJSON(data.result); 
     171                                fileUploadMSG.find('.in-progress:first').parents('p').append('<input type="hidden" name="fileId[]" value="'+newAttach['mailAttachment'][0][0].id+'"/>'); 
     172                                addAttachment(ID,newAttach['mailAttachment'][0][0].id); 
     173                                var content_body  = RichTextEditor.getData('body_'+ID); 
     174                                var rex = new RegExp('<img id="'+newImageId+'" src="" [^\/>]*\/>', 'i');  
     175                                var newImg = '<img src="../prototype/getArchive.php?mailAttachment='+newAttach['mailAttachment'][0][0].id+'" />';  
     176                                content_body = content_body.replace(rex,newImg);  
     177                                RichTextEditor.setData('body_'+ID,content_body);  
     178       
     179                        }else { 
     180                                fileUploadMSG.find(' .progress.on-complete:first').removeClass('on-complete').parents('p').find('.status-upload').addClass('ui-icon ui-icon-cancel'); 
     181                        } 
     182                        fileUploadMSG.find('.in-progress:first').remove(); 
     183                     
     184                } 
     185        }); 
    51186} 
Note: See TracChangeset for help on using the changeset viewer.