source: sandbox/2.4.2-expresso2/library/ckeditor/plugins/expresso/plugin.js @ 6776

Revision 6776, 10.0 KB checked in by gustavo, 12 years ago (diff)

Ticket #2953 - Melhorar a disposição da listagem de anexos no expressoMail

  • 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[]"  onclick="bindFileUpload(this);" 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 fileUploadIMG = $(e).parents('form');
103        var fileUploadMSG = $('#fileupload_msg'+ID);
104        var maxAttachmentSize = (preferences.max_attachment_size !== "" && preferences.max_attachment_size != 0) ? (parseInt(preferences.max_attachment_size.replace('M', '')) * 1048576 ) : false;
105        fileUploadIMG.fileupload({
106                type: 'post',
107                dataType : 'json',
108                url: "../prototype/post.php",
109                forceIframeTransport: true,
110                formData: function(form) {
111                        return [
112                                {
113                                        name : "mailAttachment[0][source]",
114                                        value : "files0"
115                                },
116                                {
117                                        name : "mailAttachment[0][disposition]",
118                                        value : $('#attDisposition'+ID).val()
119                                },
120                                {
121                                        name: "MAX_FILE_SIZE",
122                                        value : maxAttachmentSize
123                                }
124                        ];
125                },
126                add: function (e, data) {
127     
128                        if(!maxAttachmentSize || data.files[0].size < maxAttachmentSize || is_ie) {
129                                setTimeout(function() {
130                                        $('#attDisposition'+ID).val('embedded');
131                                        data.submit();
132                                }, 5000);
133                        }
134            fileUploadMSG.find(' .attachments-list').show();
135                        $.each(data.files, function (index, file) {     
136                                var attach = {};
137                                attach.fullFileName = file.name;
138                                attach.fileName = file.name;
139                                if(file.name.length > 20)
140                                        attach.fileName = file.name.substr(0, 17) + "..." + file.name.substr(file.name.length-9, file.name.length);
141                                attach.fileSize = formatBytes(file.size);
142                                if(maxAttachmentSize && file.size > maxAttachmentSize)
143                                        attach.error = 'Tamanho de arquivo nao permitido!!'
144                                else
145                    attach.error = true;
146                                var upload = $(DataLayer.render("../prototype/modules/mail/templates/attachment_add_itemlist.ejs", {file : attach}));   
147
148                                upload.find('.att-box-delete').click(function(){
149                                        var idAttach = $(this).parent().find('input[name="fileId[]"]').val();
150                       
151                    var content_body = RichTextEditor.getData('body_'+ID);
152                    var imagens = content_body.match(/<img[^>]*>/g);
153       
154                    if(imagens != null)
155                        for (var x = 0; x < imagens.length; x++)
156                            if(imagens[x].indexOf('src="../prototype/getArchive.php?mailAttachment='+idAttach+'"') !== -1)
157                                content_body = content_body.replace(imagens[x],'');
158         
159                    RichTextEditor.setData('body_'+ID,content_body);   
160                                       
161                    $('.attachments-list').find('input[value="'+idAttach+'"]').remove();
162                    delAttachment(ID, idAttach);
163                                        $(this).parent().qtip("destroy");
164                    $(this).parent().remove();
165                    if(!fileUploadMSG.find(' .attachments-list').find(".att-box").length){
166                        fileUploadMSG.find(' .attachments-list').hide();
167                    }
168                                });
169                               
170            fileUploadMSG.find('.attachments-list').append(upload);
171            fileUploadMSG.find('.attachments-list .att-box:last').qtip({
172                content: DataLayer.render("../prototype/modules/mail/templates/attachment_add_itemlist_tooltip.ejs", {attach : attach}),
173                position: {
174                    corner: {
175                        tooltip: 'bottomMiddle',
176                        target: 'topMiddle'
177                    },
178                    adjust: {
179                       resize: true,
180                       scroll: true
181                    }
182                },
183                show: {
184                    when: 'mouseover', // Don't specify a show event
185                    ready: false // Show the tooltip when ready
186                },
187                hide: 'mouseout', // Don't specify a hide event
188                style: {
189                    border: {
190                        width: 1,
191                        radius: 5
192                    },
193                    padding: 3,
194                    textAlign: 'left',
195                    tip: true, // Give it a speech bubble tip with automatic corner detection
196                    name: (typeof(attach.error) == 'boolean' ? 'light' : 'red') // Style it according to the preset 'cream' style
197                }
198            });
199                        if(!maxAttachmentSize || file.size < maxAttachmentSize){
200                                if(data.fileInput){
201                                        fileUploadMSG.find('.fileinput-button.new').append(data.fileInput[0]).removeClass('new');
202                                        fileUploadMSG.find('.attachments-list').find('[type=file]').addClass('hidden');
203                                }
204                        }else
205                                fileUploadMSG.find(' .fileinput-button.new').removeClass('new');
206                                                               
207                CKEDITOR.instances['body_'+ID].insertHtml('<img src=""/>');
208
209                        });
210               
211            CKEDITOR.dialog.getCurrent().hide();       
212                       
213                },
214                done: function(e, data){
215            var attach_box = fileUploadMSG.find('.att-box-loading:first').parents('.att-box');
216            var attach = {
217                fullFileName : attach_box.find(".att-box-fullfilename").text(),
218                fileSize : attach_box.find(".att-box-filesize").text(),
219                OK : true,
220                error : false
221            };
222            if(!!data.result && data.result != "[]" ){
223                var newAttach = data.result;                             
224                if(!newAttach.mailAttachment.error || newAttach.rollback !== false){
225                                        attach_box.append('<input type="hidden" name="fileId[]" value="'+newAttach['mailAttachment'][0][0].id+'"/>');
226                                        addAttachment(ID,newAttach['mailAttachment'][0][0].id);
227                                        var content_body  = RichTextEditor.getData('body_'+ID);
228                                        var rex = new RegExp('<img src="" [^\/>]*\/>', 'i');
229                                        var newImg = '<img src="../prototype/getArchive.php?mailAttachment='+newAttach['mailAttachment'][0][0].id+'" />';
230                                        content_body = content_body.replace(rex,newImg);
231                                        RichTextEditor.setData('body_'+ID,content_body);
232                                }else{
233                                        attach_box.addClass('invalid-email-box');
234                    attach.error = newAttach.mailAttachment.error ? newAttach.mailAttachment.error : 'Erro ao anexar...';
235                }
236                        }else {
237                attach_box.addClass('invalid-email-box');
238                attach.error = 'Erro ao anexar...';
239            }
240            attach_box.qtip("destroy").qtip({
241                content: DataLayer.render("../prototype/modules/mail/templates/attachment_add_itemlist_tooltip.ejs", {attach : attach}),
242                position: {
243                    corner: {
244                        tooltip: 'bottomMiddle',
245                        target: 'topMiddle'
246                    },
247                    adjust: {
248                       resize: true,
249                       scroll: true
250                    }
251                },
252                show: {
253                    when: 'mouseover', // Don't specify a show event
254                    ready: false // Show the tooltip when ready
255                },
256                hide: 'mouseout', // Don't specify a hide event
257                style: {
258                    border: {
259                        width: 1,
260                        radius: 5
261                    },
262                    padding: 3,
263                    textAlign: 'left',
264                    tip: true, // Give it a speech bubble tip with automatic corner detection
265                    name: (attach.error == false ? 'blue' : 'red')// Style it according to the preset 'cream' style
266                }
267            });
268            fileUploadMSG.find(' .att-box-loading:first').remove();
269                }
270        });
271}
Note: See TracBrowser for help on using the repository browser.