source: trunk/library/ckeditor/plugins/expresso/plugin.js @ 6074

Revision 6074, 7.6 KB checked in by gustavo, 12 years ago (diff)

Ticket #2676 - Falha ao anexar imagens no expresso mail

  • Property svn:executable set to *
Line 
1
2
3CKEDITOR.plugins.add('expresso',
4{
5   
6    init: function (editor) {
7        var pluginName = 'expresso';
8        editor.ui.addButton('expAddImage',
9            {
10                label: 'Adicionar Imagem',
11                command: 'imgDialog',
12                icon: CKEDITOR.plugins.getPath('expresso') + 'img/Image.gif'
13            });
14                       
15        editor.ui.addRichCombo('expSignature',
16        {
17                    label: 'Assinaturas',
18                    voiceLabel : "Assinaturas",
19                    title: 'Assinaturas',
20                    className : 'cke_format',
21                    panel :
22                    {
23                           css : [ CKEDITOR.config.contentsCss, CKEDITOR.getUrl( editor.skinPath + 'editor.css' ) ],
24                           voiceLabel : 'xala'
25                    },
26
27                    init : function()
28                    {
29                         var options = RichTextEditor.getSignaturesOptions();
30                         for( var key in options )
31                             this.add(  options[key],key,key);   
32                                             
33                    },
34                   
35                    onClick : function( value )
36                    {         
37                       editor.focus();
38                       editor.fire( 'saveSnapshot' );
39                       editor.insertHtml(unescape(value));
40                       editor.fire( 'saveSnapshot' );
41                    }
42
43        });
44       
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       
96         
97
98    }
99});
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 maxAttachmentSize = (preferences.max_attachment_size !== "" && preferences.max_attachment_size != 0) ? (parseInt(preferences.max_attachment_size.replace('M', '')) * 1048576 ) : false;
106        fileUploadIMG.fileupload({
107                type: 'post',
108                dataType : 'json',
109                url: "../prototype/post.php",
110                forceIframeTransport: true,
111                formData: function(form) {
112                        return [
113                                {
114                                        name : "mailAttachment[0][source]",
115                                        value : "files0"
116                                },
117                                {
118                                        name : "mailAttachment[0][disposition]",
119                                        value : $('#attDisposition'+ID).val()
120                                },
121                                {
122                                        name: "MAX_FILE_SIZE",
123                                        value : maxAttachmentSize
124                                }
125                        ];
126                },
127                add: function (e, data) {
128     
129                        if(!maxAttachmentSize || data.files[0].size < maxAttachmentSize || is_ie) {
130                                setTimeout(function() {
131                                        $('#attDisposition'+ID).val('embedded');
132                                        data.submit();
133                                }, 5000);
134                        }
135                       
136                },
137                change: function (e, data) {
138                        $.each(data.files, function (index, file) {     
139                                var attach = {};
140                                attach.fullFileName = file.name;
141                                attach.fileName = file.name;
142                                if(file.name.length > 10)
143                                        attach.fileName = file.name.substr(0, 18) + "..." + file.name.substr(file.name.length-9, file.name.length);
144                                attach.fileSize = formatBytes(file.size);
145                                if(maxAttachmentSize && file.size > maxAttachmentSize)
146                                        attach.error = 'Tamanho de arquivo nao permitido!!'
147                                                               
148                                fileUploadMSG.find('.attachments-list').append(DataLayer.render("../prototype/modules/mail/templates/attachment_add_itemlist.ejs", {file : attach}));
149
150                                if(!maxAttachmentSize || file.size < maxAttachmentSize){
151                                        fileUploadMSG.find(' .fileinput-button.new').append(data.fileInput[0]).removeClass('new');
152                                        fileUploadMSG.find(' .attachments-list').find('[type=file]').addClass('hidden');
153                                       
154                                }else
155                                        fileUploadMSG.find(' .fileinput-button.new').removeClass('new');
156                               
157                               
158                                fileUploadMSG.find(' .attachments-list').find('.button.close').button({
159                                        icons: {
160                                                primary: "ui-icon-close"
161                                        },
162                                        text: false
163                                }).click(function(){
164                                        var idAttach = $(this).parent().find('input[name="fileId[]"]').val();
165                       
166                                        var content_body = RichTextEditor.getData('body_'+ID);
167                                        var imagens = content_body.match(/<img[^>]*>/g);
168       
169                                        if(imagens != null)
170                                            for (var x = 0; x < imagens.length; x++)
171                                                if(imagens[x].indexOf('src="../prototype/getArchive.php?mailAttachment='+idAttach+'"') !== -1)
172                                                        content_body = content_body.replace(imagens[x],'');
173         
174                                        RichTextEditor.setData('body_'+ID,content_body);   
175                                       
176                                        $('.attachments-list').find('input[value="'+idAttach+'"]').remove();
177                                        delAttachment(ID, idAttach);
178                                        $(this).parent().remove();
179                                });
180                               
181                                CKEDITOR.instances['body_'+ID].insertHtml('<img id="'+newImageId+'" src=""/>');
182
183                });
184               
185                    CKEDITOR.dialog.getCurrent().hide();
186                },
187                done: function(e, data){
188                        if(!!data.result && data.result != "[]"){
189                                var newAttach = data.result;
190                                if(!newAttach.mailAttachment.error){
191                                        if(newAttach.rollback !== false)
192                                        {
193                                                fileUploadMSG.find('.in-progress:first').parents('p').append('<input type="hidden" name="fileId[]" value="'+newAttach['mailAttachment'][0][0].id+'"/>').find('.status-upload').addClass('ui-icon ui-icon-check');
194                                                addAttachment(ID,newAttach['mailAttachment'][0][0].id);
195                                                var content_body  = RichTextEditor.getData('body_'+ID);
196                                                var rex = new RegExp('<img id="'+newImageId+'" src="" [^\/>]*\/>', 'i');
197                                                var newImg = '<img src="../prototype/getArchive.php?mailAttachment='+newAttach['mailAttachment'][0][0].id+'" />';
198                                                content_body = content_body.replace(rex,newImg);
199                                                RichTextEditor.setData('body_'+ID,content_body);
200                                        }
201                                        else
202                                                fileUploadMSG.find('.in-progress:first').parents('p').find('.status-upload').append('Erro ao fazer upload!').addClass('message-attach-error');   
203                                }else{
204                                        fileUploadMSG.find('.in-progress:first').parents('p').find('.status-upload').append(newAttach.mailAttachment.error).addClass('message-attach-error');   
205                                }
206                        }else {
207                                    fileUploadMSG.find('.in-progress:first').parents('p').find('.status-upload').append('Erro ao fazer upload!').addClass('message-attach-error');   
208                        }
209                        fileUploadMSG.find('.in-progress:first').remove();
210                   
211                }
212        });
213}
Note: See TracBrowser for help on using the repository browser.