[ 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 Vtiger_Edit_Js("Contacts_Edit_Js",{},{ 10 11 //Will have the mapping of address fields based on the modules 12 addressFieldsMapping : {'Accounts' : 13 {'mailingstreet' : 'bill_street', 14 'otherstreet' : 'ship_street', 15 'mailingpobox' : 'bill_pobox', 16 'otherpobox' : 'ship_pobox', 17 'mailingcity' : 'bill_city', 18 'othercity' : 'ship_city', 19 'mailingstate' : 'bill_state', 20 'otherstate' : 'ship_state', 21 'mailingzip' : 'bill_code', 22 'otherzip' : 'ship_code', 23 'mailingcountry' : 'bill_country', 24 'othercountry' : 'ship_country' 25 } 26 }, 27 28 //Address field mapping within module 29 addressFieldsMappingInModule : { 30 'otherstreet' : 'mailingstreet', 31 'otherpobox' : 'mailingpobox', 32 'othercity' : 'mailingcity', 33 'otherstate' : 'mailingstate', 34 'otherzip' : 'mailingzip', 35 'othercountry' : 'mailingcountry' 36 }, 37 38 39 /** 40 * Function which will register event for Reference Fields Selection 41 */ 42 registerReferenceSelectionEvent : function(container) { 43 var thisInstance = this; 44 45 jQuery('input[name="account_id"]', container).on(Vtiger_Edit_Js.referenceSelectionEvent, function(e, data){ 46 thisInstance.referenceSelectionEventHandler(data, container); 47 }); 48 }, 49 50 /** 51 * Reference Fields Selection Event Handler 52 * On Confirmation It will copy the address details 53 */ 54 referenceSelectionEventHandler : function(data, container) { 55 var thisInstance = this; 56 var message = app.vtranslate('OVERWRITE_EXISTING_MSG1')+app.vtranslate('SINGLE_'+data['source_module'])+' ('+data['selectedName']+') '+app.vtranslate('OVERWRITE_EXISTING_MSG2'); 57 Vtiger_Helper_Js.showConfirmationBox({'message' : message}).then( 58 function(e) { 59 thisInstance.copyAddressDetails(data, container); 60 }, 61 function(error, err){ 62 }); 63 }, 64 65 /** 66 * Function which will copy the address details - without Confirmation 67 */ 68 copyAddressDetails : function(data, container) { 69 var thisInstance = this; 70 var sourceModule = data['source_module']; 71 thisInstance.getRecordDetails(data).then( 72 function(data){ 73 var response = data['result']; 74 thisInstance.mapAddressDetails(thisInstance.addressFieldsMapping[sourceModule], response['data'], container); 75 }, 76 function(error, err){ 77 78 }); 79 }, 80 81 /** 82 * Function which will map the address details of the selected record 83 */ 84 mapAddressDetails : function(addressDetails, result, container) { 85 for(var key in addressDetails) { 86 if(container.find('[name="'+key+'"]').length == 0) { 87 var create = container.append("<input type='hidden' name='"+key+"'>"); 88 } 89 container.find('[name="'+key+'"]').val(result[addressDetails[key]]); 90 container.find('[name="'+key+'"]').trigger('change'); 91 } 92 }, 93 94 /** 95 * Function to swap array 96 * @param Array that need to be swapped 97 */ 98 swapObject : function(objectToSwap){ 99 var swappedArray = {}; 100 var newKey,newValue; 101 for(var key in objectToSwap){ 102 newKey = objectToSwap[key]; 103 newValue = key; 104 swappedArray[newKey] = newValue; 105 } 106 return swappedArray; 107 }, 108 109 /** 110 * Function to copy address between fields 111 * @param strings which accepts value as either odd or even 112 */ 113 copyAddress : function(swapMode, container){ 114 var thisInstance = this; 115 var addressMapping = this.addressFieldsMappingInModule; 116 if(swapMode == "false"){ 117 for(var key in addressMapping) { 118 var fromElement = container.find('[name="'+key+'"]'); 119 var toElement = container.find('[name="'+addressMapping[key]+'"]'); 120 toElement.val(fromElement.val()); 121 } 122 } else if(swapMode){ 123 var swappedArray = thisInstance.swapObject(addressMapping); 124 for(var key in swappedArray) { 125 var fromElement = container.find('[name="'+key+'"]'); 126 var toElement = container.find('[name="'+swappedArray[key]+'"]'); 127 toElement.val(fromElement.val()); 128 } 129 } 130 }, 131 132 133 /** 134 * Function to register event for copying address between two fileds 135 */ 136 registerEventForCopyingAddress : function(container){ 137 var thisInstance = this; 138 var swapMode; 139 jQuery('[name="copyAddress"]').on('click',function(e){ 140 var element = jQuery(e.currentTarget); 141 var target = element.data('target'); 142 if(target == "other"){ 143 swapMode = "false"; 144 } else if(target == "mailing"){ 145 swapMode = "true"; 146 } 147 thisInstance.copyAddress(swapMode, container); 148 }) 149 }, 150 151 /** 152 * Function to check for Portal User 153 */ 154 checkForPortalUser : function(form){ 155 var element = jQuery('[name="portal"]',form); 156 var response = element.is(':checked'); 157 var primaryEmailField = jQuery('[name="email"]'); 158 var primaryEmailValue = primaryEmailField.val(); 159 if(response){ 160 if(primaryEmailField.length == 0){ 161 Vtiger_Helper_Js.showPnotify(app.vtranslate('JS_PRIMARY_EMAIL_FIELD_DOES_NOT_EXISTS')); 162 return false; 163 } 164 if(primaryEmailValue == ""){ 165 Vtiger_Helper_Js.showPnotify(app.vtranslate('JS_PLEASE_ENTER_PRIMARY_EMAIL_VALUE_TO_ENABLE_PORTAL_USER')); 166 return false; 167 } 168 } 169 return true; 170 }, 171 172 /** 173 * Function to register recordpresave event 174 */ 175 registerRecordPreSaveEvent : function(form){ 176 var thisInstance = this; 177 if(typeof form == 'undefined') { 178 form = this.getForm(); 179 } 180 181 form.on(Vtiger_Edit_Js.recordPreSave, function(e, data) { 182 var result = thisInstance.checkForPortalUser(form); 183 if(!result){ 184 e.preventDefault(); 185 } 186 }) 187 }, 188 189 registerBasicEvents : function(container){ 190 this._super(container); 191 this.registerReferenceSelectionEvent(container); 192 this.registerEventForCopyingAddress(container); 193 this.registerRecordPreSaveEvent(container); 194 } 195 })
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 |