| [ 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_Edit_Js("Accounts_Edit_Js",{ 11 12 },{ 13 14 //Stored history of account name and duplicate check result 15 duplicateCheckCache : {}, 16 17 //This will store the editview form 18 editViewForm : false, 19 20 //Address field mapping within module 21 addressFieldsMappingInModule : { 22 'bill_street':'ship_street', 23 'bill_pobox':'ship_pobox', 24 'bill_city' :'ship_city', 25 'bill_state':'ship_state', 26 'bill_code' :'ship_code', 27 'bill_country':'ship_country' 28 }, 29 30 // mapping address fields of MemberOf field in the module 31 memberOfAddressFieldsMapping : { 32 'bill_street':'bill_street', 33 'bill_pobox':'bill_pobox', 34 'bill_city' :'bill_city', 35 'bill_state':'bill_state', 36 'bill_code' :'bill_code', 37 'bill_country':'bill_country', 38 'ship_street' : 'ship_street', 39 'ship_pobox' : 'ship_pobox', 40 'ship_city':'ship_city', 41 'ship_state':'ship_state', 42 'ship_code':'ship_code', 43 'ship_country':'ship_country' 44 }, 45 46 /** 47 * This function will return the current form 48 */ 49 getForm : function(){ 50 if(this.editViewForm == false) { 51 this.editViewForm = jQuery('#EditView'); 52 } 53 return this.editViewForm; 54 }, 55 56 /** 57 * This function will return the account name 58 */ 59 getAccountName : function(container){ 60 return jQuery('input[name="accountname"]',container).val(); 61 }, 62 63 /** 64 * This function will return the current RecordId 65 */ 66 getRecordId : function(container){ 67 return jQuery('input[name="record"]',container).val(); 68 }, 69 70 /** 71 * This function will register before saving any record 72 */ 73 registerRecordPreSaveEvent : function(form) { 74 var thisInstance = this; 75 if(typeof form == 'undefined') { 76 form = this.getForm(); 77 } 78 79 form.on(Vtiger_Edit_Js.recordPreSave, function(e, data) { 80 var accountName = thisInstance.getAccountName(form); 81 var recordId = thisInstance.getRecordId(form); 82 var params = {}; 83 if(!(accountName in thisInstance.duplicateCheckCache)) { 84 Vtiger_Helper_Js.checkDuplicateName({ 85 'accountName' : accountName, 86 'recordId' : recordId, 87 'moduleName' : 'Accounts' 88 }).then( 89 function(data){ 90 thisInstance.duplicateCheckCache[accountName] = data['success']; 91 form.submit(); 92 }, 93 function(data, err){ 94 thisInstance.duplicateCheckCache[accountName] = data['success']; 95 thisInstance.duplicateCheckCache['message'] = data['message']; 96 var message = app.vtranslate('JS_DUPLICTAE_CREATION_CONFIRMATION'); 97 Vtiger_Helper_Js.showConfirmationBox({'message' : message}).then( 98 function(e) { 99 thisInstance.duplicateCheckCache[accountName] = false; 100 form.submit(); 101 }, 102 function(error, err) { 103 104 } 105 ); 106 } 107 ); 108 } 109 110 else { 111 if(thisInstance.duplicateCheckCache[accountName] == true){ 112 var message = app.vtranslate('JS_DUPLICTAE_CREATION_CONFIRMATION'); 113 Vtiger_Helper_Js.showConfirmationBox({'message' : message}).then( 114 function(e) { 115 thisInstance.duplicateCheckCache[accountName] = false; 116 form.submit(); 117 }, 118 function(error, err) { 119 120 } 121 ); 122 } else { 123 delete thisInstance.duplicateCheckCache[accountName]; 124 return true; 125 } 126 } 127 e.preventDefault(); 128 }) 129 }, 130 131 /** 132 * Function to swap array 133 * @param Array that need to be swapped 134 */ 135 swapObject : function(objectToSwap){ 136 var swappedArray = {}; 137 var newKey,newValue; 138 for(var key in objectToSwap){ 139 newKey = objectToSwap[key]; 140 newValue = key; 141 swappedArray[newKey] = newValue; 142 } 143 return swappedArray; 144 }, 145 146 /** 147 * Function to copy address between fields 148 * @param strings which accepts value as either odd or even 149 */ 150 copyAddress : function(swapMode, container){ 151 var thisInstance = this; 152 var addressMapping = this.addressFieldsMappingInModule; 153 if(swapMode == "false"){ 154 for(var key in addressMapping) { 155 var fromElement = container.find('[name="'+key+'"]'); 156 var toElement = container.find('[name="'+addressMapping[key]+'"]'); 157 toElement.val(fromElement.val()); 158 } 159 } else if(swapMode){ 160 var swappedArray = thisInstance.swapObject(addressMapping); 161 for(var key in swappedArray) { 162 var fromElement = container.find('[name="'+key+'"]'); 163 var toElement = container.find('[name="'+swappedArray[key]+'"]'); 164 toElement.val(fromElement.val()); 165 } 166 } 167 }, 168 169 /** 170 * Function to register event for copying address between two fileds 171 */ 172 registerEventForCopyingAddress : function(container){ 173 var thisInstance = this; 174 var swapMode; 175 jQuery('[name="copyAddress"]').on('click',function(e){ 176 var element = jQuery(e.currentTarget); 177 var target = element.data('target'); 178 if(target == "billing"){ 179 swapMode = "false"; 180 }else if(target == "shipping"){ 181 swapMode = "true"; 182 } 183 thisInstance.copyAddress(swapMode, container); 184 }) 185 }, 186 187 /** 188 * Function which will register event for Reference Fields Selection 189 */ 190 registerReferenceSelectionEvent : function(container) { 191 var thisInstance = this; 192 193 jQuery('input[name="account_id"]', container).on(Vtiger_Edit_Js.referenceSelectionEvent, function(e, data){ 194 thisInstance.referenceSelectionEventHandler(data, container); 195 }); 196 }, 197 198 /** 199 * Reference Fields Selection Event Handler 200 * On Confirmation It will copy the address details 201 */ 202 referenceSelectionEventHandler : function(data, container) { 203 var thisInstance = this; 204 var message = app.vtranslate('OVERWRITE_EXISTING_MSG1')+app.vtranslate('SINGLE_'+data['source_module'])+' ('+data['selectedName']+') '+app.vtranslate('OVERWRITE_EXISTING_MSG2'); 205 Vtiger_Helper_Js.showConfirmationBox({'message' : message}).then( 206 function(e) { 207 thisInstance.copyAddressDetails(data, container); 208 }, 209 function(error, err){ 210 }); 211 }, 212 213 /** 214 * Function which will copy the address details - without Confirmation 215 */ 216 copyAddressDetails : function(data, container) { 217 var thisInstance = this; 218 thisInstance.getRecordDetails(data).then( 219 function(data){ 220 var response = data['result']; 221 thisInstance.mapAddressDetails(thisInstance.memberOfAddressFieldsMapping, response['data'], container); 222 }, 223 function(error, err){ 224 225 }); 226 }, 227 228 /** 229 * Function which will map the address details of the selected record 230 */ 231 mapAddressDetails : function(addressDetails, result, container) { 232 for(var key in addressDetails) { 233 // While Quick Creat we don't have address fields, we should add 234 if(container.find('[name="'+key+'"]').length == 0) { 235 container.append("<input type='hidden' name='"+key+"'>"); 236 } 237 container.find('[name="'+key+'"]').val(result[addressDetails[key]]); 238 container.find('[name="'+key+'"]').trigger('change'); 239 container.find('[name="'+addressDetails[key]+'"]').val(result[addressDetails[key]]); 240 container.find('[name="'+addressDetails[key]+'"]').trigger('change'); 241 } 242 }, 243 244 /** 245 * Function which will register basic events which will be used in quick create as well 246 * 247 */ 248 registerBasicEvents : function(container) { 249 this._super(container); 250 this.registerRecordPreSaveEvent(container); 251 this.registerEventForCopyingAddress(container); 252 this.registerReferenceSelectionEvent(container); 253 //container.trigger(Vtiger_Edit_Js.recordPreSave, {'value': 'edit'}); 254 } 255 });
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 |