[5081] | 1 | |
---|
| 2 | |
---|
| 3 | CKEDITOR.plugins.add('expresso', |
---|
| 4 | { |
---|
| 5 | |
---|
| 6 | init: function (editor) { |
---|
| 7 | var pluginName = 'expresso'; |
---|
| 8 | editor.ui.addButton('expAddImage', |
---|
| 9 | { |
---|
| 10 | label: 'Adicionar Imagem', |
---|
[5604] | 11 | command: 'imgDialog', |
---|
[5081] | 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 | |
---|
[5604] | 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 | { |
---|
[7144] | 53 | label : 'Adicionar imagem', |
---|
[5604] | 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 | { |
---|
[6410] | 65 | var ID = currentTab; |
---|
[5604] | 66 | // CKEDITOR.dialog.definition |
---|
| 67 | var dialogDefinition = |
---|
| 68 | { |
---|
| 69 | |
---|
[6410] | 70 | title : 'Inserir Imagem', |
---|
[5604] | 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', |
---|
[6410] | 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>' |
---|
[5604] | 85 | } |
---|
| 86 | ] |
---|
| 87 | } |
---|
| 88 | ], |
---|
| 89 | buttons : [ CKEDITOR.dialog.cancelButton] |
---|
| 90 | |
---|
| 91 | }; |
---|
| 92 | |
---|
| 93 | return dialogDefinition; |
---|
| 94 | } ); |
---|
| 95 | |
---|
[5081] | 96 | |
---|
[5604] | 97 | |
---|
[5081] | 98 | } |
---|
| 99 | }); |
---|
[5604] | 100 | function bindFileUpload(e) { |
---|
[6073] | 101 | var ID = currentTab; |
---|
[6410] | 102 | var fileUploadIMG = $(e).parents('form'); |
---|
[6073] | 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; |
---|
[5604] | 105 | fileUploadIMG.fileupload({ |
---|
[6073] | 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 | }, |
---|
[5604] | 126 | add: function (e, data) { |
---|
[6930] | 127 | var iterator = idattachbycontent; |
---|
[6074] | 128 | if(!maxAttachmentSize || data.files[0].size < maxAttachmentSize || is_ie) { |
---|
[5604] | 129 | setTimeout(function() { |
---|
| 130 | $('#attDisposition'+ID).val('embedded'); |
---|
[6930] | 131 | jqXHR[iterator] = data.submit(); |
---|
| 132 | }, 100); |
---|
[5604] | 133 | } |
---|
[6930] | 134 | fileUploadMSG.find(' .attachments-list').show(); |
---|
[5604] | 135 | $.each(data.files, function (index, file) { |
---|
| 136 | var attach = {}; |
---|
| 137 | attach.fullFileName = file.name; |
---|
| 138 | attach.fileName = file.name; |
---|
[6930] | 139 | if(file.name.length > 20) |
---|
| 140 | attach.fileName = file.name.substr(0, 17) + "..." + file.name.substr(file.name.length-9, file.name.length); |
---|
[5604] | 141 | attach.fileSize = formatBytes(file.size); |
---|
[6073] | 142 | if(maxAttachmentSize && file.size > maxAttachmentSize) |
---|
[5604] | 143 | attach.error = 'Tamanho de arquivo nao permitido!!' |
---|
[6930] | 144 | else |
---|
| 145 | attach.error = true; |
---|
[6410] | 146 | var upload = $(DataLayer.render("../prototype/modules/mail/templates/attachment_add_itemlist.ejs", {file : attach})); |
---|
[5604] | 147 | |
---|
[6930] | 148 | upload.find('.att-box-delete').click(function(){ |
---|
[5604] | 149 | var idAttach = $(this).parent().find('input[name="fileId[]"]').val(); |
---|
| 150 | |
---|
[6410] | 151 | var content_body = RichTextEditor.getData('body_'+ID); |
---|
| 152 | var imagens = content_body.match(/<img[^>]*>/g); |
---|
[5604] | 153 | |
---|
[6410] | 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],''); |
---|
[5604] | 158 | |
---|
[6410] | 159 | RichTextEditor.setData('body_'+ID,content_body); |
---|
[5604] | 160 | |
---|
[6410] | 161 | $('.attachments-list').find('input[value="'+idAttach+'"]').remove(); |
---|
| 162 | delAttachment(ID, idAttach); |
---|
[6930] | 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 | if(jqXHR){ |
---|
| 169 | jqXHR[iterator].abort(); |
---|
| 170 | } |
---|
[5604] | 171 | }); |
---|
| 172 | |
---|
[6930] | 173 | fileUploadMSG.find('.attachments-list').append(upload); |
---|
| 174 | fileUploadMSG.find('.attachments-list .att-box:last').qtip({ |
---|
| 175 | content: DataLayer.render("../prototype/modules/mail/templates/attachment_add_itemlist_tooltip.ejs", {attach : attach}), |
---|
| 176 | position: { |
---|
| 177 | corner: { |
---|
| 178 | tooltip: 'bottomMiddle', |
---|
| 179 | target: 'topMiddle' |
---|
| 180 | }, |
---|
| 181 | adjust: { |
---|
| 182 | resize: true, |
---|
| 183 | scroll: true, |
---|
[7001] | 184 | screen: true |
---|
[6930] | 185 | } |
---|
| 186 | }, |
---|
| 187 | show: { |
---|
| 188 | when: 'mouseover', // Don't specify a show event |
---|
| 189 | ready: false // Show the tooltip when ready |
---|
| 190 | }, |
---|
| 191 | hide: 'mouseout', // Don't specify a hide event |
---|
| 192 | style: { |
---|
| 193 | border: { |
---|
| 194 | width: 1, |
---|
| 195 | radius: 5 |
---|
| 196 | }, |
---|
| 197 | width: { |
---|
| 198 | min: 75, |
---|
| 199 | max : 1000 |
---|
| 200 | }, |
---|
| 201 | padding: 3, |
---|
| 202 | textAlign: 'left', |
---|
| 203 | tip: true, // Give it a speech bubble tip with automatic corner detection |
---|
| 204 | name: (typeof(attach.error) == 'boolean' ? 'light' : 'red') // Style it according to the preset 'cream' style |
---|
| 205 | } |
---|
| 206 | }); |
---|
| 207 | if(!maxAttachmentSize || file.size < maxAttachmentSize){ |
---|
| 208 | if(data.fileInput){ |
---|
| 209 | fileUploadMSG.find('.fileinput-button.new').append(data.fileInput[0]).removeClass('new'); |
---|
| 210 | fileUploadMSG.find('.attachments-list').find('[type=file]').addClass('hidden'); |
---|
| 211 | } |
---|
| 212 | }else{ |
---|
| 213 | fileUploadMSG.find(' .fileinput-button.new').removeClass('new'); |
---|
| 214 | } |
---|
[6410] | 215 | CKEDITOR.instances['body_'+ID].insertHtml('<img src=""/>'); |
---|
[6930] | 216 | idattachbycontent++; |
---|
[6410] | 217 | }); |
---|
[5604] | 218 | |
---|
[6410] | 219 | CKEDITOR.dialog.getCurrent().hide(); |
---|
[6930] | 220 | |
---|
[6410] | 221 | }, |
---|
[5604] | 222 | done: function(e, data){ |
---|
[6930] | 223 | var attach_box = fileUploadMSG.find('.att-box-loading:first').parents('.att-box'); |
---|
| 224 | var attach = { |
---|
| 225 | fullFileName : attach_box.find(".att-box-fullfilename").text(), |
---|
| 226 | fileSize : attach_box.find(".att-box-filesize").text(), |
---|
| 227 | OK : true, |
---|
| 228 | error : false |
---|
| 229 | }; |
---|
| 230 | if(!!data.result && data.result != "[]" ){ |
---|
| 231 | var newAttach = data.result; |
---|
| 232 | if(!newAttach.mailAttachment.error || newAttach.rollback !== false){ |
---|
| 233 | attach_box.append('<input type="hidden" name="fileId[]" value="'+newAttach['mailAttachment'][0][0].id+'"/>'); |
---|
| 234 | addAttachment(ID,newAttach['mailAttachment'][0][0].id); |
---|
| 235 | var content_body = RichTextEditor.getData('body_'+ID); |
---|
| 236 | var rex = new RegExp('<img src="" [^\/>]*\/>', 'i'); |
---|
| 237 | var newImg = '<img src="../prototype/getArchive.php?mailAttachment='+newAttach['mailAttachment'][0][0].id+'" />'; |
---|
| 238 | content_body = content_body.replace(rex,newImg); |
---|
| 239 | RichTextEditor.setData('body_'+ID,content_body); |
---|
[6073] | 240 | }else{ |
---|
[6930] | 241 | attach_box.addClass('invalid-email-box'); |
---|
| 242 | attach.error = newAttach.mailAttachment.error ? newAttach.mailAttachment.error : 'Erro ao anexar...'; |
---|
| 243 | } |
---|
| 244 | }else { |
---|
| 245 | attach_box.addClass('invalid-email-box'); |
---|
| 246 | attach.error = 'Erro ao anexar...'; |
---|
| 247 | } |
---|
| 248 | attach_box.qtip("destroy").qtip({ |
---|
| 249 | content: DataLayer.render("../prototype/modules/mail/templates/attachment_add_itemlist_tooltip.ejs", {attach : attach}), |
---|
| 250 | position: { |
---|
| 251 | corner: { |
---|
| 252 | tooltip: 'bottomMiddle', |
---|
| 253 | target: 'topMiddle' |
---|
| 254 | }, |
---|
| 255 | adjust: { |
---|
| 256 | resize: true, |
---|
| 257 | scroll: true, |
---|
[7001] | 258 | screen: true |
---|
[6930] | 259 | } |
---|
| 260 | }, |
---|
| 261 | show: { |
---|
| 262 | when: 'mouseover', // Don't specify a show event |
---|
| 263 | ready: false // Show the tooltip when ready |
---|
| 264 | }, |
---|
| 265 | hide: 'mouseout', // Don't specify a hide event |
---|
| 266 | style: { |
---|
| 267 | border: { |
---|
| 268 | width: 1, |
---|
| 269 | radius: 5 |
---|
| 270 | }, |
---|
| 271 | width: { |
---|
| 272 | min: 75, |
---|
| 273 | max : 1000 |
---|
| 274 | }, |
---|
| 275 | padding: 3, |
---|
| 276 | textAlign: 'left', |
---|
| 277 | tip: true, // Give it a speech bubble tip with automatic corner detection |
---|
| 278 | name: (attach.error == false ? 'blue' : 'red')// Style it according to the preset 'cream' style |
---|
| 279 | } |
---|
| 280 | }); |
---|
| 281 | fileUploadMSG.find(' .att-box-loading:first').remove(); |
---|
[5604] | 282 | } |
---|
| 283 | }); |
---|
[5706] | 284 | } |
---|