[ Index ] |
PHP Cross Reference of vtigercrm-6.1.0 |
[Summary view] [Print] [Text view]
1 /*+*********************************************************************************** 2 * The contents of this file are subject to the vtiger CRM Public License Version 1.0 3 * ("License"); You may not use this file except in compliance with the License 4 * The Original Code is: vtiger CRM Open Source 5 * The Initial Developer of the Original Code is vtiger. 6 * Portions created by vtiger are Copyright (C) vtiger. 7 * All Rights Reserved. 8 *************************************************************************************/ 9 10 Vtiger_Email_Validator_Js("Vtiger_To_Email_Validator_Js", { 11 12 /** 13 *Function which invokes field validation 14 *@param accepts field element as parameter 15 * @return error if validation fails true on success 16 */ 17 invokeValidation: function(field, rules, i, options){ 18 var toEmailInstance = new Vtiger_To_Email_Validator_Js(); 19 toEmailInstance.setElement(field); 20 return toEmailInstance.validate(); 21 } 22 },{ 23 24 /** 25 * Function to validate the email field data 26 */ 27 validate: function() { 28 var fieldValue = this.getFieldValue(); 29 var fieldValuesList = fieldValue.split(','); 30 for (var i in fieldValuesList) { 31 var splittedFieldValue = fieldValuesList[i]; 32 var emailInstance = new Vtiger_Email_Validator_Js(); 33 var response = emailInstance.validateValue(splittedFieldValue); 34 if(response != true) { 35 return emailInstance.getError(); 36 } 37 } 38 } 39 40 }); 41 42 jQuery.Class("Emails_MassEdit_Js",{},{ 43 44 ckEditorInstance : false, 45 massEmailForm : false, 46 saved : "SAVED", 47 sent : "SENT", 48 attachmentsFileSize : 0, 49 documentsFileSize : 0, 50 51 /** 52 * Function to get ckEditorInstance 53 */ 54 getckEditorInstance : function(){ 55 if(this.ckEditorInstance == false){ 56 this.ckEditorInstance = new Vtiger_CkEditor_Js(); 57 } 58 return this.ckEditorInstance; 59 }, 60 61 /** 62 * function to display the email form 63 * return UI 64 */ 65 showComposeEmailForm : function(params,cb,windowName){ 66 app.hideModalWindow(); 67 var popupInstance = Vtiger_Popup_Js.getInstance(); 68 return popupInstance.show(params,cb,windowName); 69 70 }, 71 72 /* 73 * Function to get the Mass Email Form 74 */ 75 getMassEmailForm : function(){ 76 if(this.massEmailForm == false){ 77 this.massEmailForm = jQuery("#massEmailForm"); 78 } 79 return this.massEmailForm; 80 }, 81 82 /** 83 * function to call the registerevents of send Email step1 84 */ 85 registerEmailFieldSelectionEvent : function(){ 86 var thisInstance = this; 87 var selectEmailForm = jQuery("#SendEmailFormStep1"); 88 selectEmailForm.on('submit',function(e){ 89 var form = jQuery(e.currentTarget); 90 var params = form.serializeFormData(); 91 thisInstance.showComposeEmailForm(params,"","composeEmail"); 92 e.preventDefault(); 93 }); 94 }, 95 96 /* 97 * Function to register the event of send email 98 */ 99 registerSendEmailEvent : function(){ 100 this.getMassEmailForm().on('submit',function(e){ 101 //TODO close the window once the mail has sent 102 var formElement = jQuery(e.currentTarget); 103 var invalidFields = formElement.data('jqv').InvalidFields; 104 var progressElement = formElement.find('[name="progressIndicator"]'); 105 if(invalidFields.length == 0){ 106 jQuery('#sendEmail').attr('disabled',"disabled"); 107 jQuery('#saveDraft').attr('disabled',"disabled"); 108 progressElement.progressIndicator(); 109 return true; 110 } 111 return false; 112 }).on('keypress',function(e){ 113 if(e.which == 13){ 114 e.preventDefault(); 115 } 116 }); 117 }, 118 setAttachmentsFileSizeByElement : function(element){ 119 if(jQuery.browser.msie) 120 { 121 var filesize = element.fileSize; 122 if(typeof fileSize != 'undefined'){ 123 this.attachmentsFileSize += filesize; 124 } 125 } else { 126 this.attachmentsFileSize += element.get(0).files[0].size; 127 } 128 }, 129 130 setAttachmentsFileSizeBySize : function(fileSize){ 131 this.attachmentsFileSize += parseFloat(fileSize); 132 }, 133 134 removeAttachmentFileSizeByElement : function(element) { 135 if(jQuery.browser.msie) 136 { 137 var filesize = element.fileSize; 138 if(typeof fileSize != 'undefined'){ 139 this.attachmentsFileSize -= filesize; 140 } 141 } else { 142 this.attachmentsFileSize -= element.get(0).files[0].size; 143 } 144 }, 145 146 removeAttachmentFileSizeBySize : function(fileSize){ 147 this.attachmentsFileSize -= parseFloat(fileSize); 148 }, 149 150 getAttachmentsFileSize : function(){ 151 return this.attachmentsFileSize; 152 }, 153 setDocumentsFileSize : function(documentSize){ 154 this.documentsFileSize += parseFloat(documentSize); 155 }, 156 getDocumentsFileSize : function(){ 157 return this.documentsFileSize; 158 }, 159 160 getTotalAttachmentsSize : function(){ 161 return parseFloat(this.getAttachmentsFileSize())+parseFloat(this.getDocumentsFileSize()); 162 }, 163 164 getMaxUploadSize : function(){ 165 return jQuery('#maxUploadSize').val(); 166 }, 167 168 removeDocumentsFileSize : function(documentSize){ 169 this.documentsFileSize -= parseFloat(documentSize); 170 }, 171 172 removeAttachmentsFileSize : function(){ 173 //TODO update the attachment file size when you delete any attachment from the list 174 }, 175 176 fileAfterSelectHandler : function(element, value, master_element){ 177 var thisInstance = this; 178 var mode = jQuery('[name="emailMode"]').val(); 179 var existingAttachment = JSON.parse(jQuery('[name="attachments"]').val()); 180 element = jQuery(element); 181 thisInstance.setAttachmentsFileSizeByElement(element); 182 var totalAttachmentsSize = thisInstance.getTotalAttachmentsSize(); 183 var maxUploadSize = thisInstance.getMaxUploadSize(); 184 if(totalAttachmentsSize > maxUploadSize){ 185 Vtiger_Helper_Js.showPnotify(app.vtranslate('JS_MAX_FILE_UPLOAD_EXCEEDS')); 186 this.removeAttachmentFileSizeByElement(jQuery(element)); 187 master_element.list.find('.MultiFile-label:last').find('.MultiFile-remove').trigger('click'); 188 }else if((mode != "") && (existingAttachment != "")){ 189 var pattern = /\\/; 190 var val = value.split(pattern); 191 if(jQuery.browser.mozilla){ 192 fileuploaded = value; 193 } else if(jQuery.browser.webkit || jQuery.browser.msie) { 194 var fileuploaded = val[2]; 195 fileuploaded=fileuploaded.replace(" ","_"); 196 } 197 jQuery.each(existingAttachment,function(key,value){ 198 if((value['attachment'] == fileuploaded) && !(value.hasOwnProperty( "docid"))){ 199 var errorMsg = app.vtranslate("JS_THIS_FILE_HAS_ALREADY_BEEN_SELECTED")+fileuploaded; 200 Vtiger_Helper_Js.showPnotify(app.vtranslate(errorMsg)); 201 thisInstance.removeAttachmentFileSizeByElement(jQuery(element),value); 202 master_element.list.find('.MultiFile-label:last').find('.MultiFile-remove').trigger('click'); 203 return false; 204 } 205 }) 206 } 207 return true; 208 }, 209 /* 210 * Function to register the events for getting the values 211 */ 212 registerEventsToGetFlagValue : function(){ 213 var thisInstance = this; 214 jQuery('#saveDraft').on('click',function(e){ 215 jQuery('#flag').val(thisInstance.saved); 216 }); 217 jQuery('#sendEmail').on('click',function(e){ 218 jQuery('#flag').val(thisInstance.sent); 219 }); 220 }, 221 222 checkHiddenStatusofCcandBcc : function(){ 223 var ccLink = jQuery('#ccLink'); 224 var bccLink = jQuery('#bccLink'); 225 if(ccLink.is(':hidden') && bccLink.is(':hidden')){ 226 ccLink.closest('div.row-fluid').addClass('hide'); 227 } 228 }, 229 230 /* 231 * Function to register the events for bcc and cc links 232 */ 233 registerCcAndBccEvents : function(){ 234 var thisInstance = this; 235 jQuery('#ccLink').on('click',function(e){ 236 jQuery('#ccContainer').show(); 237 jQuery(e.currentTarget).hide(); 238 thisInstance.checkHiddenStatusofCcandBcc(); 239 }); 240 jQuery('#bccLink').on('click',function(e){ 241 jQuery('#bccContainer').show(); 242 jQuery(e.currentTarget).hide(); 243 thisInstance.checkHiddenStatusofCcandBcc(); 244 }); 245 }, 246 247 /* 248 * Function to register the send email template event 249 */ 250 registerSendEmailTemplateEvent : function(){ 251 252 var thisInstance = this; 253 jQuery('#selectEmailTemplate').on('click',function(e){ 254 var url = jQuery(e.currentTarget).data('url'); 255 var popupInstance = Vtiger_Popup_Js.getInstance(); 256 popupInstance.show(url,function(data){ 257 var responseData = JSON.parse(data); 258 for(var id in responseData){ 259 var selectedName = responseData[id].name; 260 var selectedTemplateBody = responseData[id].info; 261 } 262 var ckEditorInstance = thisInstance.getckEditorInstance(); 263 ckEditorInstance.loadContentsInCkeditor(selectedTemplateBody); 264 jQuery('#subject').val(selectedName); 265 },'tempalteWindow'); 266 }); 267 }, 268 getDocumentAttachmentElement : function(selectedFileName,id,selectedFileSize){ 269 return '<div class="MultiFile-label"><a class="removeAttachment cursorPointer" data-id='+id+' data-file-size='+selectedFileSize+'>x </a><span>'+selectedFileName+'</span></div>'; 270 }, 271 registerBrowseCrmEvent : function(){ 272 var thisInstance = this; 273 jQuery('#browseCrm').on('click',function(e){ 274 var selectedDocumentId; 275 var url = jQuery(e.currentTarget).data('url'); 276 var popupInstance = Vtiger_Popup_Js.getInstance(); 277 popupInstance.show(url,function(data){ 278 var responseData = JSON.parse(data); 279 for(var id in responseData){ 280 selectedDocumentId = id; 281 var selectedFileName = responseData[id].info['filename']; 282 var selectedFileSize = responseData[id].info['filesize']; 283 var response = thisInstance.writeDocumentIds(selectedDocumentId) 284 if(response){ 285 var attachmentElement = thisInstance.getDocumentAttachmentElement(selectedFileName,id,selectedFileSize); 286 //TODO handle the validation if the size exceeds 5mb before appending. 287 jQuery(attachmentElement).appendTo(jQuery('#attachments')); 288 jQuery('.MultiFile-applied,.MultiFile').addClass('removeNoFileChosen'); 289 thisInstance.setDocumentsFileSize(selectedFileSize); 290 } 291 } 292 293 },'browseCrmWindow'); 294 }); 295 }, 296 /** 297 * Function to check whether selected document 298 * is already an existing attachment 299 * @param expects document id to check 300 * @return true if present false if not present 301 */ 302 checkIfExisitingAttachment : function(selectedDocumentId){ 303 var documentExist; 304 var documentPresent; 305 var mode = jQuery('[name="emailMode"]').val(); 306 var selectedDocumentIds = jQuery('#documentIds').val(); 307 var existingAttachment = JSON.parse(jQuery('[name="attachments"]').val()); 308 if((mode != "") && (existingAttachment != "")){ 309 jQuery.each(existingAttachment,function(key,value){ 310 if(value.hasOwnProperty( "docid")){ 311 if(value['docid'] == selectedDocumentId){ 312 documentExist = 1; 313 return false; 314 } 315 } 316 }) 317 if(selectedDocumentIds != ""){ 318 selectedDocumentIds = JSON.parse(selectedDocumentIds); 319 } 320 if((documentExist == 1) || (jQuery.inArray(selectedDocumentId,selectedDocumentIds) != '-1')){ 321 documentPresent = 1; 322 } else { 323 documentPresent = 0; 324 } 325 } else if(selectedDocumentIds != ""){ 326 selectedDocumentIds = JSON.parse(selectedDocumentIds); 327 if((jQuery.inArray(selectedDocumentId,selectedDocumentIds) != '-1')){ 328 documentPresent = 1; 329 } else { 330 documentPresent = 0; 331 } 332 } 333 if(documentPresent == 1){ 334 var errorMsg = app.vtranslate("JS_THIS_DOCUMENT_HAS_ALREADY_BEEN_SELECTED"); 335 Vtiger_Helper_Js.showPnotify(app.vtranslate(errorMsg)); 336 return true; 337 } else { 338 return false; 339 } 340 }, 341 342 writeDocumentIds :function(selectedDocumentId){ 343 var thisInstance = this; 344 var newAttachment; 345 var selectedDocumentIds = jQuery('#documentIds').val(); 346 if(selectedDocumentIds != ""){ 347 selectedDocumentIds = JSON.parse(selectedDocumentIds); 348 var existingAttachment = thisInstance.checkIfExisitingAttachment(selectedDocumentId); 349 if(!existingAttachment){ 350 newAttachment = 1; 351 } else { 352 newAttachment = 0; 353 } 354 } else { 355 var existingAttachment = thisInstance.checkIfExisitingAttachment(selectedDocumentId); 356 if(!existingAttachment){ 357 newAttachment = 1; 358 var selectedDocumentIds = new Array(); 359 } 360 } 361 if(newAttachment == 1){ 362 selectedDocumentIds.push(selectedDocumentId); 363 jQuery('#documentIds').val(JSON.stringify(selectedDocumentIds)); 364 return true; 365 } else { 366 return false; 367 } 368 }, 369 370 removeDocumentIds : function(removedDocumentId){ 371 var documentIdsContainer = jQuery('#documentIds'); 372 var documentIdsArray = JSON.parse(documentIdsContainer.val()); 373 documentIdsArray.splice( jQuery.inArray('"'+removedDocumentId+'"', documentIdsArray), 1 ); 374 documentIdsContainer.val(JSON.stringify(documentIdsArray)); 375 }, 376 377 registerRemoveAttachmentEvent : function(){ 378 var thisInstance = this; 379 this.getMassEmailForm().on('click','.removeAttachment',function(e){ 380 var currentTarget = jQuery(e.currentTarget); 381 var id = currentTarget.data('id'); 382 var fileSize = currentTarget.data('fileSize'); 383 currentTarget.closest('.MultiFile-label').remove(); 384 thisInstance.removeDocumentsFileSize(fileSize); 385 thisInstance.removeDocumentIds(id); 386 if (jQuery('#attachments').is(':empty')){ 387 jQuery('.MultiFile,.MultiFile-applied').removeClass('removeNoFileChosen'); 388 } 389 }); 390 }, 391 392 /** 393 * Function to register event for to field in compose email popup 394 */ 395 registerEventsForToField : function(){ 396 var thisInstance = this; 397 this.getMassEmailForm().on('click','.selectEmail',function(e){ 398 var moduleSelected = jQuery('.emailModulesList').val(); 399 var parentElem = jQuery(e.target).closest('.toEmailField'); 400 var sourceModule = jQuery('[name=module]').val(); 401 var params = { 402 'module' : moduleSelected, 403 'src_module' : sourceModule, 404 'view': 'EmailsRelatedModulePopup' 405 } 406 var popupInstance =Vtiger_Popup_Js.getInstance(); 407 popupInstance.show(params, function(data){ 408 var responseData = JSON.parse(data); 409 for(var id in responseData){ 410 var data = { 411 'name' : responseData[id].name, 412 'id' : id, 413 'emailid' : responseData[id].email 414 } 415 thisInstance.setReferenceFieldValue(parentElem, data); 416 thisInstance.addToEmailAddressData(data); 417 thisInstance.appendToSelectedIds(id); 418 thisInstance.addToEmails(data); 419 } 420 },'relatedEmailModules'); 421 }); 422 423 this.getMassEmailForm().on('click','[name="clearToEmailField"]',function(e){ 424 var element = jQuery(e.currentTarget); 425 element.closest('div.toEmailField').find('.sourceField').val(''); 426 thisInstance.getMassEmailForm().find('[name="toemailinfo"]').val(JSON.stringify(new Array())); 427 thisInstance.getMassEmailForm().find('[name="selected_ids"]').val(JSON.stringify(new Array())); 428 thisInstance.getMassEmailForm().find('[name="to"]').val(JSON.stringify(new Array())); 429 430 var preloadData = []; 431 thisInstance.setPreloadData(preloadData); 432 thisInstance.getMassEmailForm().find('#emailField').select2('data', preloadData); 433 }); 434 435 436 }, 437 438 setReferenceFieldValue : function(container,object){ 439 var thisInstance = this; 440 var preloadData = thisInstance.getPreloadData(); 441 442 var emailInfo = { 443 'recordId' : object.id, 444 'id' : object.emailid, 445 'text' : object.name+' <b>('+object.emailid+')</b>' 446 } 447 preloadData.push(emailInfo); 448 thisInstance.setPreloadData(preloadData); 449 container.find('#emailField').select2('data', preloadData); 450 451 var toEmailField = container.find('.sourceField'); 452 var toEmailFieldExistingValue = toEmailField.val(); 453 var toEmailFieldNewValue; 454 if(toEmailFieldExistingValue != ""){ 455 toEmailFieldNewValue = toEmailFieldExistingValue+","+object.emailid; 456 } else { 457 toEmailFieldNewValue = object.emailid; 458 } 459 toEmailField.val(toEmailFieldNewValue); 460 }, 461 462 addToEmailAddressData : function(mailInfo) { 463 var mailInfoElement = this.getMassEmailForm().find('[name="toemailinfo"]'); 464 var existingToMailInfo = JSON.parse(mailInfoElement.val()); 465 //If it is an array then there are no previous records so make as map 466 if(typeof existingToMailInfo.length != 'undefined') { 467 existingToMailInfo = {}; 468 } 469 existingToMailInfo[mailInfo.id] = new Array(mailInfo.emailid); 470 mailInfoElement.val(JSON.stringify(existingToMailInfo)); 471 }, 472 473 appendToSelectedIds : function(selectedId) { 474 var selectedIdElement = this.getMassEmailForm().find('[name="selected_ids"]'); 475 var previousValue = ''; 476 if(JSON.parse(selectedIdElement.val()) != '') { 477 previousValue = JSON.parse(selectedIdElement.val()); 478 previousValue.push(selectedId); 479 } else { 480 previousValue = new Array(selectedId); 481 } 482 selectedIdElement.val(JSON.stringify(previousValue)); 483 484 }, 485 486 addToEmails : function(mailInfo){ 487 var toEmails = this.getMassEmailForm().find('[name="to"]'); 488 var value = JSON.parse(toEmails.val()); 489 if(value == ""){ 490 value = new Array(); 491 } 492 value.push(mailInfo.emailid); 493 toEmails.val(JSON.stringify(value)); 494 }, 495 496 /** 497 * Function to remove attachments that are added in 498 * edit view of email in compose email form 499 */ 500 registerEventForRemoveCustomAttachments : function(){ 501 var thisInstance = this; 502 var composeEmailForm = this.getMassEmailForm(); 503 jQuery('[name="removeAttachment"]').on('click',function(e){ 504 var attachmentsContainer = composeEmailForm.find('[ name="attachments"]'); 505 var attachmentsInfo = JSON.parse(attachmentsContainer.val()); 506 var element = jQuery(e.currentTarget); 507 var imageContainer = element.closest('div.MultiFile-label'); 508 var imageContainerData = imageContainer.data(); 509 var fileType = imageContainerData['fileType']; 510 var fileSize = imageContainerData['fileSize']; 511 var fileId = imageContainerData['fileId']; 512 if(fileType == "document"){ 513 thisInstance.removeDocumentsFileSize(fileSize); 514 } else if(fileType == "file"){ 515 thisInstance.removeAttachmentFileSizeBySize(fileSize); 516 } 517 jQuery.each(attachmentsInfo,function(index,attachmentObject){ 518 if((typeof attachmentObject != "undefined") && (attachmentObject.fileid == fileId)){ 519 attachmentsInfo.splice(index,1); 520 } 521 }) 522 attachmentsContainer.val(JSON.stringify(attachmentsInfo)); 523 imageContainer.remove(); 524 }) 525 }, 526 527 /** 528 * Function to calculate upload file size 529 */ 530 calculateUploadFileSize : function(){ 531 var thisInstance = this; 532 var composeEmailForm = this.getMassEmailForm(); 533 var attachmentsList = composeEmailForm.find('#attachments'); 534 var attachments = attachmentsList.find('.customAttachment'); 535 jQuery.each(attachments,function(){ 536 var element = jQuery(this); 537 var fileSize = element.data('fileSize'); 538 var fileType = element.data('fileType'); 539 if(fileType == "file"){ 540 thisInstance.setAttachmentsFileSizeBySize(fileSize); 541 } else if(fileType == "document"){ 542 fileSize = fileSize.replace('KB',''); 543 thisInstance.setDocumentsFileSize(fileSize); 544 } 545 }) 546 }, 547 548 /** 549 * Function to register event for saved or sent mail 550 * getting back to preview 551 */ 552 registerEventForGoToPreview : function(){ 553 jQuery('#gotoPreview').on('click',function(e){ 554 var recordId = jQuery('[name="parent_id"]').val(); 555 var parentRecordId = jQuery('[name="parent_record_id"]').val(); 556 var params = {}; 557 params['module'] = "Emails"; 558 params['view'] = "ComposeEmail"; 559 params['mode'] = "emailPreview"; 560 params['record'] = recordId; 561 params['parentId'] = parentRecordId; 562 var urlString = (typeof params == 'string')? params : jQuery.param(params); 563 var url = 'index.php?'+urlString; 564 self.location.href = url; 565 }) 566 }, 567 568 preloadData : new Array(), 569 570 getPreloadData : function() { 571 return this.preloadData; 572 }, 573 574 setPreloadData : function(dataInfo){ 575 this.preloadData = dataInfo; 576 return this; 577 }, 578 579 searchEmails : function(params) { 580 var aDeferred = jQuery.Deferred(); 581 582 if(typeof params.module == 'undefined') { 583 params.module = app.getModuleName(); 584 } 585 586 if(typeof params.action == 'undefined') { 587 params.action = 'BasicAjax'; 588 } 589 AppConnector.request(params).then( 590 function(data){ 591 aDeferred.resolve(data); 592 }, 593 function(error){ 594 aDeferred.reject(); 595 } 596 ) 597 return aDeferred.promise(); 598 }, 599 600 /** 601 * Function which will handle the reference auto complete event registrations 602 * @params - container <jQuery> - element in which auto complete fields needs to be searched 603 */ 604 registerAutoCompleteFields : function(container) { 605 var thisInstance = this; 606 607 container.find('#emailField').select2({ 608 minimumInputLength: 3, 609 closeOnSelect : false, 610 611 tags : [], 612 tokenSeparators: [","], 613 614 createSearchChoice : function(term) { 615 return {id: term, text: term}; 616 }, 617 618 ajax : { 619 'url' : 'index.php?module=Emails&action=BasicAjax', 620 'dataType' : 'json', 621 'data' : function(term,page){ 622 var data = {}; 623 data['searchValue'] = term; 624 return data; 625 }, 626 'results' : function(data){ 627 var finalResult = []; 628 var results = data.result; 629 var resultData = new Array(); 630 for(var moduleName in results) { 631 var moduleResult = []; 632 moduleResult.text = moduleName; 633 634 var children = new Array(); 635 for(var recordId in data.result[moduleName]) { 636 var emailInfo = data.result[moduleName][recordId]; 637 for (var i in emailInfo) { 638 var childrenInfo = []; 639 childrenInfo.recordId = recordId; 640 childrenInfo.id = emailInfo[i].value; 641 childrenInfo.text = emailInfo[i].label; 642 children.push(childrenInfo); 643 } 644 } 645 moduleResult.children = children; 646 resultData.push(moduleResult); 647 } 648 finalResult.results = resultData; 649 return finalResult; 650 }, 651 transport : function(params) { 652 return jQuery.ajax(params); 653 } 654 } 655 656 }).on("change", function (selectedData) { 657 var addedElement = selectedData.added; 658 if (typeof addedElement != 'undefined') { 659 var data = { 660 'id' : addedElement.recordId, 661 'name' : addedElement.text, 662 'emailid' : addedElement.id 663 } 664 thisInstance.addToEmails(data); 665 if (typeof addedElement.recordId != 'undefined') { 666 thisInstance.addToEmailAddressData(data); 667 thisInstance.appendToSelectedIds(addedElement.recordId); 668 } 669 670 var preloadData = thisInstance.getPreloadData(); 671 var emailInfo = { 672 'id' : addedElement.id 673 } 674 if (typeof addedElement.recordId != 'undefined') { 675 emailInfo['text'] = addedElement.text; 676 emailInfo['recordId'] = addedElement.recordId; 677 } else { 678 emailInfo['text'] = addedElement.id; 679 } 680 preloadData.push(emailInfo); 681 thisInstance.setPreloadData(preloadData); 682 } 683 684 var removedElement = selectedData.removed; 685 if (typeof removedElement != 'undefined') { 686 var data = { 687 'id' : removedElement.recordId, 688 'name' : removedElement.text, 689 'emailid' : removedElement.id 690 } 691 thisInstance.removeFromEmails(data); 692 if (typeof removedElement.recordId != 'undefined') { 693 thisInstance.removeFromEmailAddressData(data); 694 thisInstance.removeFromSelectedIds(removedElement.recordId); 695 } 696 697 var preloadData = thisInstance.getPreloadData(); 698 var updatedPreloadData = []; 699 for(var i in preloadData) { 700 var preloadDataInfo = preloadData[i]; 701 var skip = false; 702 if (removedElement.id == preloadDataInfo.id) { 703 skip = true; 704 } 705 if (skip == false) { 706 updatedPreloadData.push(preloadDataInfo); 707 } 708 } 709 thisInstance.setPreloadData(updatedPreloadData); 710 } 711 }); 712 713 container.find('#emailField').select2("container").find("ul.select2-choices").sortable({ 714 containment: 'parent', 715 start: function(){ 716 container.find('#emailField').select2("onSortStart"); 717 }, 718 update: function(){ 719 container.find('#emailField').select2("onSortEnd"); 720 } 721 }); 722 723 var toEmailNamesList = JSON.parse(container.find('[name="toMailNamesList"]').val()); 724 var toEmailInfo = JSON.parse(container.find('[name="toemailinfo"]').val()); 725 var toEmails = container.find('[name="toEmail"]').val(); 726 var toFieldValues = Array(); 727 if (toEmails.length > 0) { 728 toFieldValues = toEmails.split(','); 729 } 730 731 var preloadData = thisInstance.getPreloadData(); 732 if (typeof toEmailInfo != 'undefined') { 733 for(var key in toEmailInfo) { 734 if (toEmailNamesList.hasOwnProperty(key)) { 735 for (var i in toEmailNamesList[key]) { 736 var emailInfo = []; 737 var emailId = toEmailNamesList[key][i].value; 738 var emailInfo = { 739 'recordId' : key, 740 'id' : emailId, 741 'text' : toEmailNamesList[key][i].label+' <b>('+emailId+')</b>' 742 } 743 preloadData.push(emailInfo); 744 if (jQuery.inArray(emailId, toFieldValues) != -1) { 745 var index = toFieldValues.indexOf(emailId); 746 if (index !== -1) { 747 toFieldValues.splice(index, 1); 748 } 749 } 750 } 751 } 752 } 753 } 754 if (typeof toFieldValues != 'undefined') { 755 for(var i in toFieldValues) { 756 var emailId = toFieldValues[i]; 757 var emailInfo = { 758 'id' : emailId, 759 'text' : emailId 760 } 761 preloadData.push(emailInfo); 762 } 763 } 764 if (typeof preloadData != 'undefined') { 765 thisInstance.setPreloadData(preloadData); 766 container.find('#emailField').select2('data', preloadData); 767 } 768 769 }, 770 771 removeFromEmailAddressData : function(mailInfo) { 772 var mailInfoElement = this.getMassEmailForm().find('[name="toemailinfo"]'); 773 var previousValue = JSON.parse(mailInfoElement.val()); 774 775 delete previousValue[mailInfo.id]; 776 mailInfoElement.val(JSON.stringify(previousValue)); 777 }, 778 779 removeFromSelectedIds : function(selectedId) { 780 var selectedIdElement = this.getMassEmailForm().find('[name="selected_ids"]'); 781 var previousValue = JSON.parse(selectedIdElement.val()); 782 783 var updatedValue = []; 784 for (var i in previousValue) { 785 var id = previousValue[i]; 786 var skip = false; 787 if (id == selectedId) { 788 skip = true; 789 } 790 if (skip == false) { 791 updatedValue.push(id); 792 } 793 } 794 selectedIdElement.val(JSON.stringify(updatedValue)); 795 }, 796 797 removeFromEmails : function(mailInfo){ 798 var toEmails = this.getMassEmailForm().find('[name="to"]'); 799 var previousValue = JSON.parse(toEmails.val()); 800 801 var updatedValue = []; 802 for (var i in previousValue) { 803 var email = previousValue[i]; 804 var skip = false; 805 if (email == mailInfo.emailid) { 806 skip = true; 807 } 808 if (skip == false) { 809 updatedValue.push(email); 810 } 811 } 812 toEmails.val(JSON.stringify(updatedValue)); 813 }, 814 815 registerEvents : function(){ 816 var thisInstance = this; 817 var composeEmailForm = this.getMassEmailForm(); 818 if(composeEmailForm.length > 0){ 819 jQuery("#multiFile").MultiFile({ 820 list: '#attachments', 821 'afterFileSelect' : function(element, value, master_element){ 822 var masterElement = master_element; 823 var newElement = jQuery(masterElement.current); 824 newElement.addClass('removeNoFileChosen'); 825 thisInstance.fileAfterSelectHandler(element, value, master_element); 826 }, 827 'afterFileRemove' : function(element, value, master_element){ 828 if (jQuery('#attachments').is(':empty')){ 829 jQuery('.MultiFile,.MultiFile-applied').removeClass('removeNoFileChosen'); 830 } 831 thisInstance.removeAttachmentFileSizeByElement(jQuery(element)); 832 } 833 }); 834 this.getMassEmailForm().validationEngine(app.validationEngineOptions); 835 this.registerSendEmailEvent(); 836 var textAreaElement = jQuery('#description'); 837 var ckEditorInstance = this.getckEditorInstance(textAreaElement); 838 ckEditorInstance.loadCkEditor(textAreaElement); 839 this.registerAutoCompleteFields(this.getMassEmailForm()); 840 this.registerRemoveAttachmentEvent(); 841 this.registerEventsToGetFlagValue(); 842 this.registerCcAndBccEvents(); 843 this.registerSendEmailTemplateEvent(); 844 this.registerBrowseCrmEvent(); 845 this.registerEventsForToField(); 846 this.registerEventForRemoveCustomAttachments(); 847 this.calculateUploadFileSize(); 848 this.registerEventForGoToPreview(); 849 } 850 } 851 }); 852 //On Page Load 853 jQuery(document).ready(function() { 854 var emailMassEditInstance = new Emails_MassEdit_Js(); 855 emailMassEditInstance.registerEvents(); 856 }); 857
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri Nov 28 20:08:37 2014 | Cross-referenced by PHPXref 0.7.1 |